[prev in list] [next in list] [prev in thread] [next in thread] 

List:       alsaplayer-devel
Subject:    Re: [Alsaplayer-devel] want to write raw output to a file
From:       Frank Baumgart <godot () uni-paderborn ! de>
Date:       2004-11-24 23:27:42
Message-ID: 41A518EE.206 () uni-paderborn ! de
[Download RAW message or body]

Kevin Seghetti wrote:
> I am using alsaplayer-0.99.76, and I want to output raw samples to a
> file (so that I can later do amplitude analysis on it). I didn't see an
> output plugin that could do that, so I wrote one (just copied the oss
> output plugin and modified it). When I use it I get files which are much
> larger than they should be, which contains the music I am trying to
> output, with large chunks of zeros between them. (Playing a 54MB wave
> file results in a 1.1GB output file).

Is there a constant factor between expected and obtained result?

> I am sure I just missed something, but looking at the other output
> plugins mine isn't much different.
> Anyone have any idea what I am doing wrong? (I have enclosed my plugin
> source). 

just some review comments, no testing etc.

...
> #include "alsaplayer_error.h"
> 
> static int file_fd;
> 
> static int file_init(void)
> {
> 	// Always return ok for now
> 	file_fd = -1;
> fprintf(stderr, "file_init:\n");
> 	return 1;
> }
> 
> static int file_open(const char *name)
> {
> fprintf(stderr, "file_open:%s\n",name);
> 	if (name[0] == '-') 
> {
> file_fd = STDOUT_FILENO;
> 	}
> else
> {
> if ((file_fd = open(name,  O_WRONLY|O_CREAT, 0)) == -1) 
> {
> alsaplayer_error("error opening %s", name);
> return 0;
> }
> 	}
> 	return 1;
> }
> 
> 
> static int writeCount=0;
> 
> static void file_close(void)
> {
> if(file_fd != STDOUT_FILENO)
> close(file_fd);

file_fd must be > 0, not just unequal to STDOUT_FILENO

> 
> fprintf(stderr, "write count = %d\n",writeCount);
> 	return;
> }
> 
> static int file_write(void *data, int count)
> {
> static int writeSize=0;
> writeCount++;
> if(writeSize != count)
> {
> fprintf(stderr, "file_write: new write size: %d\n",count);
> writeSize = count;
> }

what do you want to accomplish here?

> 	write(file_fd, data, count);

check file_fd for validity
check the return value
does "count" represent the number of bytes, the number of samples or 
sth. else?

> 	return 1;
> }
> 
> 
> static int file_set_buffer(int *fragment_size, int *fragment_count, int *channels)
> {
> fprintf(stderr, "file_set_buffer: fragment_size = %d,fragment_count = %d, channels \
> = %d\n",*fragment_size,*fragment_count,*channels);  return 1;
> }
> 
> 
> static unsigned int file_set_sample_rate(unsigned int rate)
> {
> 	return rate;
> }
> 
> output_plugin file_output;
> 
> #ifdef __cplusplus
> extern "C" {
> #endif
> 
> output_plugin *output_plugin_info(void)
> {
> 	memset(&file_output, 0, sizeof(output_plugin));
> 	file_output.version = OUTPUT_PLUGIN_VERSION;
> 	file_output.name = "FILE output v1.1";
> 	file_output.author = "Kevin Seghetti";
> 	file_output.init = file_init;
> 	file_output.open = file_open;
> 	file_output.close = file_close;
> 	file_output.write = file_write;
> 	file_output.set_buffer = file_set_buffer;
> 	file_output.set_sample_rate = file_set_sample_rate;
> 	return &file_output;
> }
> 
> #ifdef __cplusplus
> }
> #endif

_______________________________________________
alsaplayer-devel mailing list
alsaplayer-devel@lists.tartarus.org
http://lists.tartarus.org/mailman/listinfo/alsaplayer-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic