summaryrefslogtreecommitdiffstats
path: root/libao2
diff options
context:
space:
mode:
authoratmosfear <atmosfear@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-06-12 14:24:26 +0000
committeratmosfear <atmosfear@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-06-12 14:24:26 +0000
commitb9e199808dbb4875ab8095952eeeaadaf7860849 (patch)
tree0954fb04004672f0918bccd97604095f4112da4c /libao2
parent2fe79a9b759e01ca79b5ef2f95559e358bf2494d (diff)
downloadmpv-b9e199808dbb4875ab8095952eeeaadaf7860849.tar.bz2
mpv-b9e199808dbb4875ab8095952eeeaadaf7860849.tar.xz
Added support for writing wave files and specifying filename to write to.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@1113 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libao2')
-rw-r--r--libao2/ao_pcm.c78
1 files changed, 73 insertions, 5 deletions
diff --git a/libao2/ao_pcm.c b/libao2/ao_pcm.c
index 165b2acba4..51ab5bace2 100644
--- a/libao2/ao_pcm.c
+++ b/libao2/ao_pcm.c
@@ -6,7 +6,7 @@
static ao_info_t info =
{
- "PCM writer audio output",
+ "RAW PCM/WAVE file writer audio output",
"pcm",
"Atmosfear",
""
@@ -22,6 +22,49 @@ LIBAO_EXTERN(pcm)
// ao_outburst
// 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;
// to set/get/query special features/parameters
@@ -32,22 +75,44 @@ static int control(int cmd,int arg){
// open & setup audio device
// 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"));
+ }
- printf("PCM: File: audiodump.pcm Samplerate: %iHz Channels: %s Format %s\n", rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format));
+ 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");
- fp = fopen("audiodump.pcm", "wb");
+ 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) return 1;
- printf("PCM: Failed to open audiodump.pcm for writing!\n");
+ 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;
}
// 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);
}
// stop playing and empty buffers (for seeking/pause)
@@ -81,6 +146,9 @@ static int play(void* data,int len,int flags){
//printf("PCM: Writing chunk!\n");
fwrite(data,len,1,fp);
+ if(ao_pcm_waveheader)
+ wavhdr.data_length += len;
+
return len;
}