[Mplayer-cvslog] CVS: main/libao2 ao_pcm.c,1.1,1.2

Felix Buenemann atmosfear at users.sourceforge.net
Tue Jun 12 16:24:29 CEST 2001


Update of /cvsroot/mplayer/main/libao2
In directory usw-pr-cvs1:/tmp/cvs-serv8585/libao2

Modified Files:
	ao_pcm.c 
Log Message:
Added support for writing wave files and specifying filename to write to.


Index: ao_pcm.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/ao_pcm.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ao_pcm.c	2001/06/12 11:00:15	1.1
--- ao_pcm.c	2001/06/12 14:24:26	1.2
***************
*** 7,11 ****
  static ao_info_t info = 
  {
! 	"PCM writer audio output",
  	"pcm",
  	"Atmosfear",
--- 7,11 ----
  static ao_info_t info = 
  {
! 	"RAW PCM/WAVE file writer audio output",
  	"pcm",
  	"Atmosfear",
***************
*** 23,26 ****
--- 23,69 ----
  // ao_buffersize
  
+ char *ao_outputfilename = NULL;
+ int ao_pcm_waveheader = 1;
+ 
+ #define WAV_ID_RIFF 0x46464952 /* "RIFF" */
+ #define WAV_ID_WAVE 0x45564157 /* "WAVE" */
+ #define WAV_ID_FMT  0x20746d66 /* "fmt " */
+ #define WAV_ID_DATA 0x61746164 /* "data" */
+ #define WAV_ID_PCM  0x0001
+ 
+ struct WaveHeader
+ {
+ 	unsigned long riff;
+ 	unsigned long file_length;
+ 	unsigned long wave;
+ 	unsigned long fmt;
+ 	unsigned long fmt_length;
+ 	short fmt_tag;
+ 	short channels;
+ 	unsigned long sample_rate;
+ 	unsigned long bytes_per_second;
+ 	short block_align;
+ 	short bits;
+ 	unsigned long data;
+ 	unsigned long data_length;
+ };
+ 
+ 
+ static struct WaveHeader wavhdr = {
+ 	WAV_ID_RIFF,
+ 	0x00000000,
+ 	WAV_ID_WAVE,
+ 	WAV_ID_FMT,
+ 	16,
+ 	WAV_ID_PCM,
+ 	2,
+ 	44100,
+ 	192000,
+ 	4,
+ 	16,
+ 	WAV_ID_DATA,
+ 	0x00000000
+ };
+ 
  static FILE *fp = NULL;
  
***************
*** 33,46 ****
  // return: 1=success 0=fail
  static int init(int rate,int channels,int format,int flags){
  	
! 	printf("PCM: File: audiodump.pcm Samplerate: %iHz Channels: %s Format %s\n", rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format));
  	printf("PCM: Info - fastest dumping is achieved with -vo null -hardframedrop.\n");
! 	fp = fopen("audiodump.pcm", "wb");
  
  	ao_outburst = 4096;
  
  
! 	if(fp) return 1;
! 	printf("PCM: Failed to open audiodump.pcm for writing!\n");
  	return 0;
  }
--- 76,104 ----
  // return: 1=success 0=fail
  static int init(int rate,int channels,int format,int flags){
+ 	if(!ao_outputfilename) {
+ 		ao_outputfilename = (char *) malloc(sizeof(char) * 14);
+ 		strcpy(ao_outputfilename,(ao_pcm_waveheader ? "audiodump.wav" : "audiodump.pcm"));
+ 	}
  	
! 	wavhdr.fmt_length = 16; /* = format? */
! 	wavhdr.channels = channels;
! 	wavhdr.sample_rate = rate;
! 	wavhdr.bytes_per_second = rate * (format / 8) * channels;
! 	wavhdr.bits = format,
! 
! 	printf("PCM: File: %s (%s) Samplerate: %iHz Channels: %s Format %s\n", ao_outputfilename, (ao_pcm_waveheader?"WAVE":"RAW PCM"), rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format));
  	printf("PCM: Info - fastest dumping is achieved with -vo null -hardframedrop.\n");
! 	printf("PCM: Info - to write WAVE files use -waveheader (default), for RAW PCM -nowaveheader.\n");
! 	fp = fopen(ao_outputfilename, "wb");
  
  	ao_outburst = 4096;
  
  
! 	if(fp) {
! 		if(ao_pcm_waveheader) /* Reserve space for wave header */
! 			fseek(fp, sizeof(wavhdr), SEEK_SET);
! 		return 1;
! 	}
! 	printf("PCM: Failed to open %s for writing!\n", ao_outputfilename);
  	return 0;
  }
***************
*** 48,52 ****
--- 106,117 ----
  // close audio device
  static void uninit(){
+ 	
+ 	if(ao_pcm_waveheader){ /* Write wave header */
+ 		wavhdr.file_length = wavhdr.data_length + sizeof(wavhdr);
+ 		fseek(fp, 0, SEEK_SET);
+ 		fwrite(&wavhdr,sizeof(wavhdr),1,fp);
+ 	}
  	fclose(fp);
+ 	free(ao_outputfilename);
  }
  
***************
*** 81,84 ****
--- 146,152 ----
  	//printf("PCM: Writing chunk!\n");
  	fwrite(data,len,1,fp);
+ 	
+ 	if(ao_pcm_waveheader)
+ 		wavhdr.data_length += len;
  	
  	return len;


_______________________________________________
Mplayer-cvslog mailing list
Mplayer-cvslog at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/mplayer-cvslog



More information about the MPlayer-cvslog mailing list