Mercurial > mplayer.hg
annotate libao2/ao_pcm.c @ 5039:da65bafd5e99
very obsoleted...
author | arpi |
---|---|
date | Mon, 11 Mar 2002 00:58:32 +0000 |
parents | de4074ab4e5f |
children | 7e082f42497a |
rev | line source |
---|---|
1107 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
4 #include "audio_out.h" | |
5 #include "audio_out_internal.h" | |
6 | |
7 static ao_info_t info = | |
8 { | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
9 "RAW PCM/WAVE file writer audio output", |
1107 | 10 "pcm", |
11 "Atmosfear", | |
12 "" | |
13 }; | |
14 | |
15 LIBAO_EXTERN(pcm) | |
16 | |
4914
de4074ab4e5f
good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
17 extern int vo_pts; |
de4074ab4e5f
good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
18 |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
19 char *ao_outputfilename = NULL; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
20 int ao_pcm_waveheader = 1; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
21 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
22 #define WAV_ID_RIFF 0x46464952 /* "RIFF" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
23 #define WAV_ID_WAVE 0x45564157 /* "WAVE" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
24 #define WAV_ID_FMT 0x20746d66 /* "fmt " */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
25 #define WAV_ID_DATA 0x61746164 /* "data" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
26 #define WAV_ID_PCM 0x0001 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
27 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
28 struct WaveHeader |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
29 { |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
30 unsigned long riff; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
31 unsigned long file_length; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
32 unsigned long wave; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
33 unsigned long fmt; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
34 unsigned long fmt_length; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
35 short fmt_tag; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
36 short channels; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
37 unsigned long sample_rate; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
38 unsigned long bytes_per_second; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
39 short block_align; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
40 short bits; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
41 unsigned long data; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
42 unsigned long data_length; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
43 }; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
44 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
45 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
46 static struct WaveHeader wavhdr = { |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
47 WAV_ID_RIFF, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
48 0x00000000, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
49 WAV_ID_WAVE, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
50 WAV_ID_FMT, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
51 16, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
52 WAV_ID_PCM, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
53 2, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
54 44100, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
55 192000, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
56 4, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
57 16, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
58 WAV_ID_DATA, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
59 0x00000000 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
60 }; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
61 |
1107 | 62 static FILE *fp = NULL; |
63 | |
64 // to set/get/query special features/parameters | |
65 static int control(int cmd,int arg){ | |
66 return -1; | |
67 } | |
68 | |
69 // open & setup audio device | |
70 // return: 1=success 0=fail | |
71 static int init(int rate,int channels,int format,int flags){ | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
72 if(!ao_outputfilename) { |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
73 ao_outputfilename = (char *) malloc(sizeof(char) * 14); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
74 strcpy(ao_outputfilename,(ao_pcm_waveheader ? "audiodump.wav" : "audiodump.pcm")); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
75 } |
1107 | 76 |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
77 wavhdr.channels = channels; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
78 wavhdr.sample_rate = rate; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
79 wavhdr.bytes_per_second = rate * (format / 8) * channels; |
1113 | 80 wavhdr.bits = format; |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
81 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
82 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)); |
1107 | 83 printf("PCM: Info - fastest dumping is achieved with -vo null -hardframedrop.\n"); |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
84 printf("PCM: Info - to write WAVE files use -waveheader (default), for RAW PCM -nowaveheader.\n"); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
85 fp = fopen(ao_outputfilename, "wb"); |
1107 | 86 |
4914
de4074ab4e5f
good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
87 ao_data.outburst = 65536; |
1107 | 88 |
89 | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
90 if(fp) { |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
91 if(ao_pcm_waveheader) /* Reserve space for wave header */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
92 fseek(fp, sizeof(wavhdr), SEEK_SET); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
93 return 1; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
94 } |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
95 printf("PCM: Failed to open %s for writing!\n", ao_outputfilename); |
1107 | 96 return 0; |
97 } | |
98 | |
99 // close audio device | |
100 static void uninit(){ | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
101 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
102 if(ao_pcm_waveheader){ /* Write wave header */ |
4914
de4074ab4e5f
good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
103 wavhdr.file_length = wavhdr.data_length + sizeof(wavhdr) - 8; |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
104 fseek(fp, 0, SEEK_SET); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
105 fwrite(&wavhdr,sizeof(wavhdr),1,fp); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
106 } |
1107 | 107 fclose(fp); |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
108 free(ao_outputfilename); |
1107 | 109 } |
110 | |
111 // stop playing and empty buffers (for seeking/pause) | |
112 static void reset(){ | |
113 | |
114 } | |
115 | |
116 // stop playing, keep buffers (for pause) | |
117 static void audio_pause() | |
118 { | |
119 // for now, just call reset(); | |
120 reset(); | |
121 } | |
122 | |
123 // resume playing, after audio_pause() | |
124 static void audio_resume() | |
125 { | |
126 } | |
127 | |
128 // return: how many bytes can be played without blocking | |
129 static int get_space(){ | |
130 | |
4914
de4074ab4e5f
good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
131 return ao_data.pts < vo_pts ? ao_data.outburst : 0; |
1107 | 132 } |
133 | |
134 // plays 'len' bytes of 'data' | |
135 // it should round it down to outburst*n | |
136 // return: number of bytes played | |
137 static int play(void* data,int len,int flags){ | |
138 | |
139 //printf("PCM: Writing chunk!\n"); | |
140 fwrite(data,len,1,fp); | |
141 | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
142 if(ao_pcm_waveheader) |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
143 wavhdr.data_length += len; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
144 |
1107 | 145 return len; |
146 } | |
147 | |
3095 | 148 // return: delay in seconds between first and last sample in buffer |
149 static float get_delay(){ | |
1107 | 150 |
3095 | 151 return 0.0; |
1107 | 152 } |
153 | |
154 | |
155 | |
156 | |
157 | |
158 |