Mercurial > mplayer.hg
annotate libao2/ao_pcm.c @ 13488:1efd9eb7da2f
synced with 1.749 + random fixes
author | paszczi |
---|---|
date | Mon, 27 Sep 2004 10:07:49 +0000 |
parents | c1955840883d |
children | a92101a7eb49 |
rev | line source |
---|---|
6237 | 1 #include "config.h" |
2 | |
1107 | 3 #include <stdio.h> |
4 #include <stdlib.h> | |
6237 | 5 #include <string.h> |
1107 | 6 |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
7 #include "bswap.h" |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
8 #include "afmt.h" |
1107 | 9 #include "audio_out.h" |
10 #include "audio_out_internal.h" | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
11 #include "../mp_msg.h" |
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
12 #include "../help_mp.h" |
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
13 |
1107 | 14 |
15 static ao_info_t info = | |
16 { | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
17 "RAW PCM/WAVE file writer audio output", |
1107 | 18 "pcm", |
19 "Atmosfear", | |
20 "" | |
21 }; | |
22 | |
23 LIBAO_EXTERN(pcm) | |
24 | |
4914
de4074ab4e5f
good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
25 extern int vo_pts; |
de4074ab4e5f
good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
26 |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
27 char *ao_outputfilename = NULL; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
28 int ao_pcm_waveheader = 1; |
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 #define WAV_ID_RIFF 0x46464952 /* "RIFF" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
31 #define WAV_ID_WAVE 0x45564157 /* "WAVE" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
32 #define WAV_ID_FMT 0x20746d66 /* "fmt " */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
33 #define WAV_ID_DATA 0x61746164 /* "data" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
34 #define WAV_ID_PCM 0x0001 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
35 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
36 struct WaveHeader |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
37 { |
11270 | 38 uint32_t riff; |
39 uint32_t file_length; | |
40 uint32_t wave; | |
41 uint32_t fmt; | |
42 uint32_t fmt_length; | |
43 uint16_t fmt_tag; | |
44 uint16_t channels; | |
45 uint32_t sample_rate; | |
46 uint32_t bytes_per_second; | |
47 uint16_t block_align; | |
48 uint16_t bits; | |
49 uint32_t data; | |
50 uint32_t data_length; | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
51 }; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
52 |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
53 /* init with default values */ |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
54 static struct WaveHeader wavhdr = { |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
55 le2me_32(WAV_ID_RIFF), |
9026 | 56 /* same conventions than in sox/wav.c/wavwritehdr() */ |
9223
b639f4560740
temporary 'inifinte' length disabled (commit r1.13 reversed) due to user
arpi
parents:
9156
diff
changeset
|
57 0, //le2me_32(0x7ffff024), |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
58 le2me_32(WAV_ID_WAVE), |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
59 le2me_32(WAV_ID_FMT), |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
60 le2me_32(16), |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
61 le2me_16(WAV_ID_PCM), |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
62 le2me_16(2), |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
63 le2me_32(44100), |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
64 le2me_32(192000), |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
65 le2me_16(4), |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
66 le2me_16(16), |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
67 le2me_32(WAV_ID_DATA), |
9223
b639f4560740
temporary 'inifinte' length disabled (commit r1.13 reversed) due to user
arpi
parents:
9156
diff
changeset
|
68 0, //le2me_32(0x7ffff000) |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
69 }; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
70 |
1107 | 71 static FILE *fp = NULL; |
72 | |
73 // to set/get/query special features/parameters | |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
9277
diff
changeset
|
74 static int control(int cmd,void *arg){ |
1107 | 75 return -1; |
76 } | |
77 | |
78 // open & setup audio device | |
79 // return: 1=success 0=fail | |
80 static int init(int rate,int channels,int format,int flags){ | |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
81 int bits; |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
82 if(!ao_outputfilename) { |
9156
a75cab40c985
double free(), found by Olivier Galibert <galibert@pobox.com>
arpi
parents:
9026
diff
changeset
|
83 ao_outputfilename = strdup(ao_pcm_waveheader ? "audiodump.wav" : "audiodump.pcm"); |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
84 } |
7658 | 85 |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
86 /* bits is only equal to format if (format == 8) or (format == 16); |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
87 this means that the following "if" is a kludge and should |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
88 really be a switch to be correct in all cases */ |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
89 |
7658 | 90 bits=8; |
91 switch(format){ | |
92 case AFMT_S8: | |
93 format=AFMT_U8; | |
94 case AFMT_U8: | |
95 break; | |
96 default: | |
97 format=AFMT_S16_LE; | |
98 bits=16; | |
99 break; | |
100 } | |
101 | |
102 ao_data.outburst = 65536; | |
103 ao_data.buffersize= 2*65536; | |
104 ao_data.channels=channels; | |
105 ao_data.samplerate=rate; | |
106 ao_data.format=format; | |
107 ao_data.bps=channels*rate*(bits/8); | |
108 | |
109 wavhdr.channels = le2me_16(ao_data.channels); | |
110 wavhdr.sample_rate = le2me_32(ao_data.samplerate); | |
111 wavhdr.bytes_per_second = le2me_32(ao_data.bps); | |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
112 wavhdr.bits = le2me_16(bits); |
9277
d824f1a3c341
The "initialize wav header with infinite lenght" broke the
arpi
parents:
9223
diff
changeset
|
113 |
d824f1a3c341
The "initialize wav header with infinite lenght" broke the
arpi
parents:
9223
diff
changeset
|
114 wavhdr.data_length=le2me_32(0x7ffff000); |
d824f1a3c341
The "initialize wav header with infinite lenght" broke the
arpi
parents:
9223
diff
changeset
|
115 wavhdr.file_length = wavhdr.data_length + sizeof(wavhdr) - 8; |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
116 |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
117 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_PCM_FileInfo, ao_outputfilename, |
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
118 (ao_pcm_waveheader?"WAVE":"RAW PCM"), rate, |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
119 (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format)); |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
120 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_PCM_HintInfo); |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
121 |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
122 fp = fopen(ao_outputfilename, "wb"); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
123 if(fp) { |
9277
d824f1a3c341
The "initialize wav header with infinite lenght" broke the
arpi
parents:
9223
diff
changeset
|
124 if(ao_pcm_waveheader){ /* Reserve space for wave header */ |
6501 | 125 fwrite(&wavhdr,sizeof(wavhdr),1,fp); |
9277
d824f1a3c341
The "initialize wav header with infinite lenght" broke the
arpi
parents:
9223
diff
changeset
|
126 wavhdr.file_length=wavhdr.data_length=0; |
d824f1a3c341
The "initialize wav header with infinite lenght" broke the
arpi
parents:
9223
diff
changeset
|
127 } |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
128 return 1; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
129 } |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
130 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_PCM_CantOpenOutputFile, |
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
131 ao_outputfilename); |
1107 | 132 return 0; |
133 } | |
134 | |
135 // close audio device | |
12145 | 136 static void uninit(int immed){ |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
137 |
6501 | 138 if(ao_pcm_waveheader && fseek(fp, 0, SEEK_SET) == 0){ /* Write wave header */ |
4914
de4074ab4e5f
good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
139 wavhdr.file_length = wavhdr.data_length + sizeof(wavhdr) - 8; |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
140 wavhdr.file_length = le2me_32(wavhdr.file_length); |
6762 | 141 wavhdr.data_length = le2me_32(wavhdr.data_length); |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
142 fwrite(&wavhdr,sizeof(wavhdr),1,fp); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
143 } |
1107 | 144 fclose(fp); |
145 } | |
146 | |
147 // stop playing and empty buffers (for seeking/pause) | |
148 static void reset(){ | |
149 | |
150 } | |
151 | |
152 // stop playing, keep buffers (for pause) | |
153 static void audio_pause() | |
154 { | |
155 // for now, just call reset(); | |
156 reset(); | |
157 } | |
158 | |
159 // resume playing, after audio_pause() | |
160 static void audio_resume() | |
161 { | |
162 } | |
163 | |
164 // return: how many bytes can be played without blocking | |
165 static int get_space(){ | |
166 | |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
167 if(vo_pts) |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
168 return ao_data.pts < vo_pts ? ao_data.outburst : 0; |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
169 return ao_data.outburst; |
1107 | 170 } |
171 | |
172 // plays 'len' bytes of 'data' | |
173 // it should round it down to outburst*n | |
174 // return: number of bytes played | |
175 static int play(void* data,int len,int flags){ | |
176 | |
7658 | 177 // let libaf to do the conversion... |
178 #if 0 | |
179 //#ifdef WORDS_BIGENDIAN | |
180 if (ao_data.format == AFMT_S16_LE) { | |
181 unsigned short *buffer = (unsigned short *) data; | |
182 register int i; | |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
183 for(i = 0; i < len/2; ++i) { |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
184 buffer[i] = le2me_16(buffer[i]); |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
185 } |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
186 } |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
187 #endif |
7658 | 188 |
1107 | 189 //printf("PCM: Writing chunk!\n"); |
190 fwrite(data,len,1,fp); | |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
191 |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
192 if(ao_pcm_waveheader) |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
193 wavhdr.data_length += len; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
194 |
1107 | 195 return len; |
196 } | |
197 | |
3095 | 198 // return: delay in seconds between first and last sample in buffer |
199 static float get_delay(){ | |
1107 | 200 |
3095 | 201 return 0.0; |
1107 | 202 } |
203 | |
204 | |
205 | |
206 | |
207 | |
208 |