Mercurial > mplayer.hg
annotate dec_audio.c @ 4037:2ec3b5e24955
portable problem solution. Should be generated in the future from pci.ids
author | nick |
---|---|
date | Mon, 07 Jan 2002 17:38:40 +0000 |
parents | ae6f97724b84 |
children | 6ad5da34c463 |
rev | line source |
---|---|
3866 | 1 |
2 #define USE_G72X | |
3886 | 3 //#define USE_LIBAC3 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
4 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
5 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
6 #include <stdlib.h> |
1430 | 7 #include <unistd.h> |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
8 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
9 #include "config.h" |
1567 | 10 #include "mp_msg.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
11 #include "help_mp.h" |
1567 | 12 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
13 extern int verbose; // defined in mplayer.c |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
14 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
15 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
16 #include "demuxer.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
17 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
18 #include "codec-cfg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
19 #include "stheader.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
20 |
2563 | 21 #include "dec_audio.h" |
22 | |
23 //========================================================================== | |
24 | |
25 #include "libao2/afmt.h" | |
26 | |
2049
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
27 #include "dll_init.h" |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
28 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
29 #include "mp3lib/mp3.h" |
3886 | 30 |
31 #ifdef USE_LIBAC3 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
32 #include "libac3/ac3.h" |
3886 | 33 #endif |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
34 |
3413 | 35 #include "liba52/a52.h" |
3907 | 36 #include "liba52/mm_accel.h" |
3413 | 37 static sample_t * a52_samples; |
38 static a52_state_t a52_state; | |
3907 | 39 static uint32_t a52_accel=0; |
3911 | 40 static uint32_t a52_flags=0; |
3413 | 41 |
3866 | 42 #ifdef USE_G72X |
3426 | 43 #include "g72x/g72x.h" |
44 static G72x_DATA g72x_data; | |
3866 | 45 #endif |
3413 | 46 |
883 | 47 #include "alaw.h" |
48 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
49 #include "xa/xa_gsm.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
50 |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
51 #include "ac3-iec958.h" |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
52 |
3756 | 53 #include "adpcm.h" |
2420 | 54 |
3145 | 55 #include "cpudetect.h" |
56 | |
3182
95bbd21e8e1f
moved num_audio_channels out of LIBMAD ifdef, where it didn't belong!
steve
parents:
3181
diff
changeset
|
57 /* used for ac3surround decoder - set using -channels option */ |
95bbd21e8e1f
moved num_audio_channels out of LIBMAD ifdef, where it didn't belong!
steve
parents:
3181
diff
changeset
|
58 int audio_output_channels = 2; |
95bbd21e8e1f
moved num_audio_channels out of LIBMAD ifdef, where it didn't belong!
steve
parents:
3181
diff
changeset
|
59 |
2563 | 60 #ifdef USE_FAKE_MONO |
61 int fakemono=0; | |
62 #endif | |
63 | |
1291 | 64 #ifdef USE_DIRECTSHOW |
3947
2eb8c8aacca7
using dshow headers from dshow/ instead of c++ version
arpi
parents:
3933
diff
changeset
|
65 #include "loader/dshow/DS_AudioDecoder.h" |
2eb8c8aacca7
using dshow headers from dshow/ instead of c++ version
arpi
parents:
3933
diff
changeset
|
66 static DS_AudioDecoder* ds_adec=NULL; |
1291 | 67 #endif |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
68 |
1828 | 69 #ifdef HAVE_OGGVORBIS |
70 /* XXX is math.h really needed? - atmos */ | |
71 #include <math.h> | |
72 #include <vorbis/codec.h> | |
2341 | 73 |
74 typedef struct ov_struct_st { | |
75 ogg_sync_state oy; /* sync and verify incoming physical bitstream */ | |
76 ogg_stream_state os; /* take physical pages, weld into a logical | |
77 stream of packets */ | |
78 ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */ | |
79 ogg_packet op; /* one raw packet of data for decode */ | |
3145 | 80 |
2341 | 81 vorbis_info vi; /* struct that stores all the static vorbis bitstream |
82 settings */ | |
83 vorbis_comment vc; /* struct that stores all the bitstream user comments */ | |
84 vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */ | |
85 vorbis_block vb; /* local working space for packet->PCM decode */ | |
86 } ov_struct_t; | |
1828 | 87 #endif |
88 | |
1927 | 89 #ifdef USE_LIBAVCODEC |
2496 | 90 #ifdef USE_LIBAVCODEC_SO |
91 #include <libffmpeg/avcodec.h> | |
92 #else | |
1927 | 93 #include "libavcodec/avcodec.h" |
2496 | 94 #endif |
1927 | 95 static AVCodec *lavc_codec=NULL; |
96 static AVCodecContext lavc_context; | |
97 extern int avcodec_inited; | |
98 #endif | |
99 | |
2415 | 100 |
101 | |
102 #ifdef USE_LIBMAD | |
103 #include <mad.h> | |
104 static struct mad_stream mad_stream; | |
105 static struct mad_frame mad_frame; | |
106 static struct mad_synth mad_synth; | |
107 | |
108 // ensure buffer is filled with some data | |
109 static void mad_prepare_buffer(sh_audio_t* sh_audio, struct mad_stream* ms, int length) | |
110 { | |
111 if(sh_audio->a_in_buffer_len < length) { | |
112 int len = demux_read_data(sh_audio->ds, sh_audio->a_in_buffer+sh_audio->a_in_buffer_len, length-sh_audio->a_in_buffer_len); | |
113 sh_audio->a_in_buffer_len += len; | |
3874 | 114 // printf("mad_prepare_buffer: read %d bytes\n", len); |
2415 | 115 } |
116 } | |
117 | |
118 static void mad_postprocess_buffer(sh_audio_t* sh_audio, struct mad_stream* ms) | |
119 { | |
120 int delta = (unsigned char*)ms->next_frame - (unsigned char *)sh_audio->a_in_buffer; | |
121 if(delta != 0) { | |
122 sh_audio->a_in_buffer_len -= delta; | |
123 memcpy(sh_audio->a_in_buffer, ms->next_frame, sh_audio->a_in_buffer_len); | |
124 } | |
125 } | |
126 | |
127 | |
128 static inline | |
129 signed short mad_scale(mad_fixed_t sample) | |
130 { | |
131 /* round */ | |
132 sample += (1L << (MAD_F_FRACBITS - 16)); | |
133 | |
134 /* clip */ | |
135 if (sample >= MAD_F_ONE) | |
136 sample = MAD_F_ONE - 1; | |
137 else if (sample < -MAD_F_ONE) | |
138 sample = -MAD_F_ONE; | |
139 | |
140 /* quantize */ | |
141 return sample >> (MAD_F_FRACBITS + 1 - 16); | |
3871 | 142 |
143 } | |
144 | |
145 static void mad_sync(sh_audio_t* sh_audio, struct mad_stream* ms) | |
146 { | |
147 int len; | |
3874 | 148 #if 1 |
3871 | 149 int skipped = 0; |
150 | |
151 // printf("buffer len: %d\n", sh_audio->a_in_buffer_len); | |
152 while(sh_audio->a_in_buffer_len - skipped) | |
153 { | |
154 len = mp_decode_mp3_header(sh_audio->a_in_buffer+skipped); | |
155 if (len != -1) | |
156 { | |
157 // printf("Frame len=%d\n", len); | |
158 break; | |
159 } | |
160 else | |
161 skipped++; | |
162 } | |
163 if (skipped) | |
164 { | |
165 printf("Audio synced, skipped bytes: %d\n", skipped); | |
3874 | 166 // ms->skiplen += skipped; |
167 // printf("skiplen: %d (skipped: %d)\n", ms->skiplen, skipped); | |
168 | |
169 // if (sh_audio->a_in_buffer_len - skipped < MAD_BUFFER_GUARD) | |
170 // printf("Mad reports: too small buffer\n"); | |
171 | |
172 // mad_stream_buffer(ms, sh_audio->a_in_buffer+skipped, sh_audio->a_in_buffer_len-skipped); | |
173 // mad_prepare_buffer(sh_audio, ms, sh_audio->a_in_buffer_len-skipped); | |
174 | |
175 /* move frame to the beginning of the buffer and fill up to a_in_buffer_size */ | |
176 sh_audio->a_in_buffer_len -= skipped; | |
177 memcpy(sh_audio->a_in_buffer, sh_audio->a_in_buffer+skipped, sh_audio->a_in_buffer_len); | |
178 mad_prepare_buffer(sh_audio, ms, sh_audio->a_in_buffer_size); | |
179 mad_stream_buffer(ms, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len); | |
180 // printf("bufflen: %d\n", sh_audio->a_in_buffer_len); | |
181 | |
182 // len = mp_decode_mp3_header(sh_audio->a_in_buffer); | |
183 // printf("len: %d\n", len); | |
184 ms->md_len = len; | |
3871 | 185 } |
3874 | 186 #else |
3871 | 187 len = mad_stream_sync(&ms); |
188 if (len == -1) | |
189 { | |
190 printf("Mad sync failed\n"); | |
191 } | |
192 #endif | |
2415 | 193 } |
3874 | 194 |
195 static void mad_print_error(struct mad_stream *mad_stream) | |
196 { | |
197 printf("error (0x%x): ", mad_stream->error); | |
198 switch(mad_stream->error) | |
199 { | |
200 case MAD_ERROR_BUFLEN: printf("buffer too small"); break; | |
201 case MAD_ERROR_BUFPTR: printf("invalid buffer pointer"); break; | |
202 case MAD_ERROR_NOMEM: printf("not enought memory"); break; | |
203 case MAD_ERROR_LOSTSYNC: printf("lost sync"); break; | |
204 case MAD_ERROR_BADLAYER: printf("bad layer"); break; | |
205 case MAD_ERROR_BADBITRATE: printf("bad bitrate"); break; | |
206 case MAD_ERROR_BADSAMPLERATE: printf("bad samplerate"); break; | |
207 case MAD_ERROR_BADEMPHASIS: printf("bad emphasis"); break; | |
208 case MAD_ERROR_BADCRC: printf("bad crc"); break; | |
209 case MAD_ERROR_BADBITALLOC: printf("forbidden bit alloc val"); break; | |
210 case MAD_ERROR_BADSCALEFACTOR: printf("bad scalefactor index"); break; | |
211 case MAD_ERROR_BADFRAMELEN: printf("bad frame length"); break; | |
212 case MAD_ERROR_BADBIGVALUES: printf("bad bigvalues count"); break; | |
213 case MAD_ERROR_BADBLOCKTYPE: printf("reserved blocktype"); break; | |
214 case MAD_ERROR_BADSCFSI: printf("bad scalefactor selinfo"); break; | |
215 case MAD_ERROR_BADDATAPTR: printf("bad maindatabegin ptr"); break; | |
216 case MAD_ERROR_BADPART3LEN: printf("bad audio data len"); break; | |
217 case MAD_ERROR_BADHUFFTABLE: printf("bad huffman table sel"); break; | |
218 case MAD_ERROR_BADHUFFDATA: printf("huffman data overrun"); break; | |
219 case MAD_ERROR_BADSTEREO: printf("incomp. blocktype for JS"); break; | |
220 default: | |
221 printf("unknown error"); | |
222 } | |
223 printf("\n"); | |
224 } | |
2415 | 225 #endif |
226 | |
227 | |
3413 | 228 static int a52_fillbuff(sh_audio_t *sh_audio){ |
229 int length=0; | |
230 int flags=0; | |
231 int sample_rate=0; | |
232 int bit_rate=0; | |
3834 | 233 |
234 sh_audio->a_in_buffer_len=0; | |
235 // sync frame: | |
3413 | 236 while(1){ |
237 while(sh_audio->a_in_buffer_len<7){ | |
238 int c=demux_getc(sh_audio->ds); | |
239 if(c<0) return -1; // EOF | |
240 sh_audio->a_in_buffer[sh_audio->a_in_buffer_len++]=c; | |
241 } | |
242 length = a52_syncinfo (sh_audio->a_in_buffer, &flags, &sample_rate, &bit_rate); | |
3834 | 243 if(length>=7 && length<=3840) break; // we're done. |
244 // bad file => resync | |
245 memcpy(sh_audio->a_in_buffer,sh_audio->a_in_buffer+1,6); | |
246 --sh_audio->a_in_buffer_len; | |
247 } | |
3413 | 248 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"a52: len=%d flags=0x%X %d Hz %d bit/s\n",length,flags,sample_rate,bit_rate); |
249 sh_audio->samplerate=sample_rate; | |
250 sh_audio->i_bps=bit_rate/8; | |
251 demux_read_data(sh_audio->ds,sh_audio->a_in_buffer+7,length-7); | |
3891 | 252 |
253 if(crc16_block(sh_audio->a_in_buffer+2,length-2)!=0) | |
254 mp_msg(MSGT_DECAUDIO,MSGL_STATUS,"a52: CRC check failed! \n"); | |
255 | |
3413 | 256 return length; |
257 } | |
2415 | 258 |
3887 | 259 // returns: number of available channels |
260 static int a52_printinfo(sh_audio_t *sh_audio){ | |
261 int flags, sample_rate, bit_rate; | |
262 char* mode="unknown"; | |
263 int channels=0; | |
264 a52_syncinfo (sh_audio->a_in_buffer, &flags, &sample_rate, &bit_rate); | |
265 switch(flags&A52_CHANNEL_MASK){ | |
266 case A52_CHANNEL: mode="channel"; channels=2; break; | |
267 case A52_MONO: mode="mono"; channels=1; break; | |
268 case A52_STEREO: mode="stereo"; channels=2; break; | |
269 case A52_3F: mode="3f";channels=3;break; | |
270 case A52_2F1R: mode="2f+1r";channels=3;break; | |
271 case A52_3F1R: mode="3f+1r";channels=4;break; | |
272 case A52_2F2R: mode="2f+2r";channels=4;break; | |
273 case A52_3F2R: mode="3f+2r";channels=5;break; | |
274 case A52_CHANNEL1: mode="channel1"; channels=2; break; | |
275 case A52_CHANNEL2: mode="channel2"; channels=2; break; | |
276 case A52_DOLBY: mode="dolby"; channels=2; break; | |
277 } | |
278 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"AC3: %d.%d (%s%s) %d Hz %3.1f kbit/s\n", | |
279 channels, (flags&A52_LFE)?1:0, | |
280 mode, (flags&A52_LFE)?"+lfe":"", | |
281 sample_rate, bit_rate*0.001f); | |
282 return (flags&A52_LFE) ? (channels+1) : channels; | |
283 } | |
284 | |
1927 | 285 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen); |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
286 |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
287 |
1289 | 288 static sh_audio_t* dec_audio_sh=NULL; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
289 |
3886 | 290 #ifdef USE_LIBAC3 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
291 // AC3 decoder buffer callback: |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
292 static void ac3_fill_buffer(uint8_t **start,uint8_t **end){ |
1289 | 293 int len=ds_get_packet(dec_audio_sh->ds,start); |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
294 //printf("<ac3:%d>\n",len); |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
295 if(len<0) |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
296 *start = *end = NULL; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
297 else |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
298 *end = *start + len; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
299 } |
3886 | 300 #endif |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
301 |
1289 | 302 // MP3 decoder buffer callback: |
303 int mplayer_audio_read(char *buf,int size){ | |
304 int len; | |
305 len=demux_read_data(dec_audio_sh->ds,buf,size); | |
306 return len; | |
307 } | |
308 | |
296 | 309 int init_audio(sh_audio_t *sh_audio){ |
303 | 310 int driver=sh_audio->codec->driver; |
296 | 311 |
312 sh_audio->samplesize=2; | |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
313 #if WORDS_BIGENDIAN |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
314 sh_audio->sample_format=AFMT_S16_BE; |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
315 #else |
758 | 316 sh_audio->sample_format=AFMT_S16_LE; |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
317 #endif |
303 | 318 sh_audio->samplerate=0; |
401 | 319 //sh_audio->pcm_bswap=0; |
1529 | 320 sh_audio->o_bps=0; |
303 | 321 |
758 | 322 sh_audio->a_buffer_size=0; |
303 | 323 sh_audio->a_buffer=NULL; |
296 | 324 |
746 | 325 sh_audio->a_in_buffer_len=0; |
326 | |
758 | 327 // setup required min. in/out buffer size: |
328 sh_audio->audio_out_minsize=8192;// default size, maybe not enough for Win32/ACM | |
329 | |
330 switch(driver){ | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
331 case AFM_ACM: |
1517
0e9c29538a86
Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents:
1485
diff
changeset
|
332 #ifndef USE_WIN32DLL |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
333 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoACMSupport); |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
334 driver=0; |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
335 #else |
296 | 336 // Win32 ACM audio codec: |
337 if(init_acm_audio_codec(sh_audio)){ | |
746 | 338 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; |
296 | 339 sh_audio->channels=sh_audio->o_wf.nChannels; |
340 sh_audio->samplerate=sh_audio->o_wf.nSamplesPerSec; | |
758 | 341 // if(sh_audio->audio_out_minsize>16384) sh_audio->audio_out_minsize=16384; |
342 // sh_audio->a_buffer_size=sh_audio->audio_out_minsize; | |
343 // if(sh_audio->a_buffer_size<sh_audio->audio_out_minsize+MAX_OUTBURST) | |
344 // sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; | |
296 | 345 } else { |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
346 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ACMiniterror); |
303 | 347 driver=0; |
296 | 348 } |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
349 #endif |
758 | 350 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
351 case AFM_DSHOW: |
296 | 352 #ifndef USE_DIRECTSHOW |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
353 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoDShowAudio); |
303 | 354 driver=0; |
296 | 355 #else |
356 // Win32 DShow audio codec: | |
340 | 357 // printf("DShow_audio: channs=%d rate=%d\n",sh_audio->channels,sh_audio->samplerate); |
3442 | 358 if(!(ds_adec=DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf))){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
359 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_audio->codec->dll); |
303 | 360 driver=0; |
361 } else { | |
746 | 362 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
363 sh_audio->channels=sh_audio->wf->nChannels; |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
364 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
365 sh_audio->audio_in_minsize=2*sh_audio->wf->nBlockAlign; |
296 | 366 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192; |
367 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
368 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
369 sh_audio->a_in_buffer_len=0; | |
758 | 370 sh_audio->audio_out_minsize=16384; |
296 | 371 } |
372 #endif | |
758 | 373 break; |
1828 | 374 case AFM_VORBIS: |
375 #ifndef HAVE_OGGVORBIS | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
376 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoOggVorbis); |
1828 | 377 driver=0; |
378 #else | |
379 /* OggVorbis audio via libvorbis, compatible with files created by nandub and zorannt codec */ | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
380 sh_audio->audio_out_minsize=1024*4; // 1024 samples/frame |
1828 | 381 #endif |
382 break; | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
383 case AFM_PCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
384 case AFM_DVDPCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
385 case AFM_ALAW: |
758 | 386 // PCM, aLaw |
387 sh_audio->audio_out_minsize=2048; | |
388 break; | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
389 case AFM_AC3: |
3413 | 390 case AFM_A52: |
758 | 391 // Dolby AC3 audio: |
3181
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3145
diff
changeset
|
392 // however many channels, 2 bytes in a word, 256 samples in a block, 6 blocks in a frame |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3145
diff
changeset
|
393 sh_audio->audio_out_minsize=audio_output_channels*2*256*6; |
758 | 394 break; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
395 case AFM_HWAC3: |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
396 // Dolby AC3 audio: |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
397 sh_audio->audio_out_minsize=4*256*6; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
398 sh_audio->sample_format = AFMT_AC3; |
3829 | 399 sh_audio->channels=1; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
400 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
401 case AFM_GSM: |
758 | 402 // MS-GSM audio codec: |
403 sh_audio->audio_out_minsize=4*320; | |
404 break; | |
3787 | 405 case AFM_IMAADPCM: |
3756 | 406 sh_audio->audio_out_minsize=4096; |
407 sh_audio->ds->ss_div=IMA_ADPCM_SAMPLES_PER_BLOCK; | |
408 sh_audio->ds->ss_mul=IMA_ADPCM_BLOCK_SIZE; | |
2420 | 409 break; |
3787 | 410 case AFM_MSADPCM: |
3875
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
411 sh_audio->audio_out_minsize=sh_audio->wf->nBlockAlign * 8; |
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
412 sh_audio->ds->ss_div = MS_ADPCM_SAMPLES_PER_BLOCK; |
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
413 sh_audio->ds->ss_mul = sh_audio->wf->nBlockAlign; |
3787 | 414 break; |
3933
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
415 case AFM_FOX61ADPCM: |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
416 sh_audio->audio_out_minsize=FOX61_ADPCM_SAMPLES_PER_BLOCK * 4; |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
417 sh_audio->ds->ss_div=FOX61_ADPCM_SAMPLES_PER_BLOCK; |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
418 sh_audio->ds->ss_mul=FOX61_ADPCM_BLOCK_SIZE; |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
419 break; |
3826
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
420 case AFM_FOX62ADPCM: |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
421 sh_audio->audio_out_minsize=FOX62_ADPCM_SAMPLES_PER_BLOCK * 4; |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
422 sh_audio->ds->ss_div=FOX62_ADPCM_SAMPLES_PER_BLOCK; |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
423 sh_audio->ds->ss_mul=FOX62_ADPCM_BLOCK_SIZE; |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
424 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
425 case AFM_MPEG: |
758 | 426 // MPEG Audio: |
427 sh_audio->audio_out_minsize=4608; | |
428 break; | |
3866 | 429 #ifdef USE_G72X |
3426 | 430 case AFM_G72X: |
431 // g72x_reader_init(&g72x_data,G723_16_BITS_PER_SAMPLE); | |
432 g72x_reader_init(&g72x_data,G723_24_BITS_PER_SAMPLE); | |
433 // g72x_reader_init(&g72x_data,G721_32_BITS_PER_SAMPLE); | |
434 // g72x_reader_init(&g72x_data,G721_40_BITS_PER_SAMPLE); | |
435 sh_audio->audio_out_minsize=g72x_data.samplesperblock*4; | |
436 break; | |
3866 | 437 #endif |
1927 | 438 case AFM_FFMPEG: |
439 #ifndef USE_LIBAVCODEC | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
440 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoLAVCsupport); |
1927 | 441 return 0; |
442 #else | |
443 // FFmpeg Audio: | |
444 sh_audio->audio_out_minsize=AVCODEC_MAX_AUDIO_FRAME_SIZE; | |
445 break; | |
446 #endif | |
2415 | 447 |
448 #ifdef USE_LIBMAD | |
449 case AFM_MAD: | |
450 printf(__FILE__ ":%d:mad: setting minimum outputsize\n", __LINE__); | |
451 sh_audio->audio_out_minsize=4608; | |
452 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192; | |
453 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
454 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
455 sh_audio->a_in_buffer_len=0; | |
456 break; | |
457 #endif | |
296 | 458 } |
459 | |
303 | 460 if(!driver) return 0; |
296 | 461 |
462 // allocate audio out buffer: | |
758 | 463 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; // worst case calc. |
464 | |
1567 | 465 mp_msg(MSGT_DECAUDIO,MSGL_V,"dec_audio: Allocating %d + %d = %d bytes for output buffer\n", |
758 | 466 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size); |
467 | |
296 | 468 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); |
758 | 469 if(!sh_audio->a_buffer){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
470 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf); |
758 | 471 return 0; |
472 } | |
296 | 473 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); |
474 sh_audio->a_buffer_len=0; | |
475 | |
303 | 476 switch(driver){ |
1517
0e9c29538a86
Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents:
1485
diff
changeset
|
477 #ifdef USE_WIN32DLL |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
478 case AFM_ACM: { |
758 | 479 int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,4096,sh_audio->a_buffer_size); |
296 | 480 if(ret<0){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
481 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"ACM decoding error: %d\n",ret); |
303 | 482 driver=0; |
296 | 483 } |
640 | 484 sh_audio->a_buffer_len=ret; |
303 | 485 break; |
296 | 486 } |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
487 #endif |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
488 case AFM_PCM: { |
296 | 489 // AVI PCM Audio: |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
490 WAVEFORMATEX *h=sh_audio->wf; |
746 | 491 sh_audio->i_bps=h->nAvgBytesPerSec; |
296 | 492 sh_audio->channels=h->nChannels; |
493 sh_audio->samplerate=h->nSamplesPerSec; | |
494 sh_audio->samplesize=(h->wBitsPerSample+7)/8; | |
758 | 495 switch(sh_audio->format){ // hardware formats: |
496 case 0x6: sh_audio->sample_format=AFMT_A_LAW;break; | |
497 case 0x7: sh_audio->sample_format=AFMT_MU_LAW;break; | |
498 case 0x11: sh_audio->sample_format=AFMT_IMA_ADPCM;break; | |
499 case 0x50: sh_audio->sample_format=AFMT_MPEG;break; | |
2547 | 500 case 0x736F7774: sh_audio->sample_format=AFMT_S16_LE;sh_audio->codec->driver=AFM_DVDPCM;break; |
758 | 501 // case 0x2000: sh_audio->sample_format=AFMT_AC3; |
502 default: sh_audio->sample_format=(sh_audio->samplesize==2)?AFMT_S16_LE:AFMT_U8; | |
503 } | |
401 | 504 break; |
505 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
506 case AFM_DVDPCM: { |
401 | 507 // DVD PCM Audio: |
508 sh_audio->channels=2; | |
509 sh_audio->samplerate=48000; | |
746 | 510 sh_audio->i_bps=2*2*48000; |
296 | 511 // sh_audio->pcm_bswap=1; |
303 | 512 break; |
513 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
514 case AFM_AC3: { |
3886 | 515 #ifndef USE_LIBAC3 |
516 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"WARNING: libac3 support is disabled. (hint: upgrade codecs.conf)\n"); | |
517 driver=0; | |
518 #else | |
296 | 519 // Dolby AC3 audio: |
1289 | 520 dec_audio_sh=sh_audio; // save sh_audio for the callback: |
296 | 521 ac3_config.fill_buffer_callback = ac3_fill_buffer; |
3181
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3145
diff
changeset
|
522 ac3_config.num_output_ch = audio_output_channels; |
296 | 523 ac3_config.flags = 0; |
3145 | 524 if(gCpuCaps.hasMMX){ |
296 | 525 ac3_config.flags |= AC3_MMX_ENABLE; |
3145 | 526 } |
527 if(gCpuCaps.has3DNow){ | |
296 | 528 ac3_config.flags |= AC3_3DNOW_ENABLE; |
3145 | 529 } |
296 | 530 ac3_init(); |
531 sh_audio->ac3_frame = ac3_decode_frame(); | |
532 if(sh_audio->ac3_frame){ | |
746 | 533 ac3_frame_t* fr=(ac3_frame_t*)sh_audio->ac3_frame; |
534 sh_audio->samplerate=fr->sampling_rate; | |
3181
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3145
diff
changeset
|
535 sh_audio->channels=ac3_config.num_output_ch; |
746 | 536 // 1 frame: 6*256 samples 1 sec: sh_audio->samplerate samples |
537 //sh_audio->i_bps=fr->frame_size*fr->sampling_rate/(6*256); | |
538 sh_audio->i_bps=fr->bit_rate*(1000/8); | |
303 | 539 } else { |
540 driver=0; // bad frame -> disable audio | |
541 } | |
3886 | 542 #endif |
303 | 543 break; |
544 } | |
3413 | 545 case AFM_A52: { |
3911 | 546 sample_t level=1, bias=384; |
547 int flags=0; | |
3413 | 548 // Dolby AC3 audio: |
3907 | 549 if(gCpuCaps.hasSSE) a52_accel|=MM_ACCEL_X86_SSE; |
550 if(gCpuCaps.hasMMX) a52_accel|=MM_ACCEL_X86_MMX; | |
551 if(gCpuCaps.hasMMX2) a52_accel|=MM_ACCEL_X86_MMXEXT; | |
552 if(gCpuCaps.has3DNow) a52_accel|=MM_ACCEL_X86_3DNOW; | |
553 a52_samples=a52_init (a52_accel); | |
3413 | 554 if (a52_samples == NULL) { |
555 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 init failed\n"); | |
556 driver=0;break; | |
557 } | |
558 sh_audio->a_in_buffer_size=3840; | |
559 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
560 sh_audio->a_in_buffer_len=0; | |
561 if(a52_fillbuff(sh_audio)<0){ | |
562 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n"); | |
563 driver=0;break; | |
564 } | |
3887 | 565 // 'a52 cannot upmix' hotfix: |
3968 | 566 a52_printinfo(sh_audio); |
567 // if(audio_output_channels<sh_audio->channels) | |
568 // sh_audio->channels=audio_output_channels; | |
3911 | 569 // channels setup: |
3968 | 570 sh_audio->channels=audio_output_channels; |
571 while(sh_audio->channels>0){ | |
3911 | 572 switch(sh_audio->channels){ |
573 case 1: a52_flags=A52_MONO; break; | |
574 // case 2: a52_flags=A52_STEREO; break; | |
575 case 2: a52_flags=A52_DOLBY; break; | |
576 // case 3: a52_flags=A52_3F; break; | |
577 case 3: a52_flags=A52_2F1R; break; | |
578 case 4: a52_flags=A52_2F2R; break; // 2+2 | |
579 case 5: a52_flags=A52_3F2R; break; | |
580 case 6: a52_flags=A52_3F2R|A52_LFE; break; // 5.1 | |
581 } | |
582 // test: | |
583 flags=a52_flags|A52_ADJUST_LEVEL; | |
584 mp_msg(MSGT_DECAUDIO,MSGL_V,"A52 flags before a52_frame: 0x%X\n",flags); | |
585 if (a52_frame (&a52_state, sh_audio->a_in_buffer, &flags, &level, bias)){ | |
586 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"a52: error decoding frame -> nosound\n"); | |
587 driver=0;break; | |
588 } | |
589 mp_msg(MSGT_DECAUDIO,MSGL_V,"A52 flags after a52_frame: 0x%X\n",flags); | |
590 // frame decoded, let's init resampler: | |
3968 | 591 if(a52_resample_init(a52_accel,flags,sh_audio->channels)) break; |
592 --sh_audio->channels; // try to decrease no. of channels | |
593 } | |
594 if(sh_audio->channels<=0){ | |
3911 | 595 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"a52: no resampler. try different channel setup!\n"); |
596 driver=0;break; | |
597 } | |
3413 | 598 break; |
599 } | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
600 case AFM_HWAC3: { |
3829 | 601 // Dolby AC3 passthrough: |
3907 | 602 a52_samples=a52_init (a52_accel); |
3829 | 603 if (a52_samples == NULL) { |
604 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 init failed\n"); | |
605 driver=0;break; | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
606 } |
3829 | 607 sh_audio->a_in_buffer_size=3840; |
608 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
609 sh_audio->a_in_buffer_len=0; | |
610 if(a52_fillbuff(sh_audio)<0) { | |
611 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n"); | |
612 driver=0;break; | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
613 } |
3829 | 614 |
615 //sh_audio->samplerate=ai.samplerate; // SET by a52_fillbuff() | |
616 //sh_audio->samplesize=ai.framesize; | |
617 //sh_audio->i_bps=ai.bitrate*(1000/8); // SET by a52_fillbuff() | |
618 //sh_audio->ac3_frame=malloc(6144); | |
619 //sh_audio->o_bps=sh_audio->i_bps; // XXX FIXME!!! XXX | |
620 | |
621 // o_bps is calculated from samplesize*channels*samplerate | |
622 // a single ac3 frame is always translated to 6144 byte packet. (zero padding) | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
623 sh_audio->channels=1; |
3829 | 624 sh_audio->samplesize=4; // 1*4*(6*256) = 6144 (very TRICKY!) |
625 | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
626 break; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
627 } |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
628 case AFM_ALAW: { |
296 | 629 // aLaw audio codec: |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
630 sh_audio->channels=sh_audio->wf->nChannels; |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
631 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
746 | 632 sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate; |
303 | 633 break; |
634 } | |
3866 | 635 #ifdef USE_G72X |
3426 | 636 case AFM_G72X: { |
637 // GSM 723 audio codec: | |
638 sh_audio->channels=sh_audio->wf->nChannels; | |
639 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; | |
640 sh_audio->i_bps=(sh_audio->samplerate/g72x_data.samplesperblock)*g72x_data.blocksize; | |
641 break; | |
642 } | |
3866 | 643 #endif |
1927 | 644 #ifdef USE_LIBAVCODEC |
645 case AFM_FFMPEG: { | |
646 int x; | |
647 mp_msg(MSGT_DECAUDIO,MSGL_V,"FFmpeg's libavcodec audio codec\n"); | |
648 if(!avcodec_inited){ | |
649 avcodec_init(); | |
650 avcodec_register_all(); | |
651 avcodec_inited=1; | |
652 } | |
653 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_audio->codec->dll); | |
654 if(!lavc_codec){ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
655 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh_audio->codec->dll); |
1927 | 656 return 0; |
657 } | |
658 memset(&lavc_context, 0, sizeof(lavc_context)); | |
659 /* open it */ | |
660 if (avcodec_open(&lavc_context, lavc_codec) < 0) { | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
661 mp_msg(MSGT_DECAUDIO,MSGL_ERR, MSGTR_CantOpenCodec); |
1927 | 662 return 0; |
663 } | |
664 mp_msg(MSGT_DECAUDIO,MSGL_V,"INFO: libavcodec init OK!\n"); | |
665 | |
666 // Decode at least 1 byte: (to get header filled) | |
667 x=decode_audio(sh_audio,sh_audio->a_buffer,1,sh_audio->a_buffer_size); | |
668 if(x>0) sh_audio->a_buffer_len=x; | |
669 | |
670 #if 1 | |
671 sh_audio->channels=lavc_context.channels; | |
672 sh_audio->samplerate=lavc_context.sample_rate; | |
673 sh_audio->i_bps=lavc_context.bit_rate/8; | |
674 #else | |
675 sh_audio->channels=sh_audio->wf->nChannels; | |
676 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; | |
677 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; | |
678 #endif | |
679 break; | |
680 } | |
681 #endif | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
682 case AFM_GSM: { |
296 | 683 // MS-GSM audio codec: |
684 GSM_Init(); | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
685 sh_audio->channels=sh_audio->wf->nChannels; |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
686 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
746 | 687 // decodes 65 byte -> 320 short |
688 // 1 sec: sh_audio->channels*sh_audio->samplerate samples | |
689 // 1 frame: 320 samples | |
690 sh_audio->i_bps=65*(sh_audio->channels*sh_audio->samplerate)/320; // 1:10 | |
303 | 691 break; |
296 | 692 } |
3787 | 693 case AFM_IMAADPCM: |
2420 | 694 // IMA-ADPCM 4:1 audio codec: |
695 sh_audio->channels=sh_audio->wf->nChannels; | |
696 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; | |
697 // decodes 34 byte -> 64 short | |
3756 | 698 sh_audio->i_bps=IMA_ADPCM_BLOCK_SIZE*(sh_audio->channels*sh_audio->samplerate)/IMA_ADPCM_SAMPLES_PER_BLOCK; // 1:4 |
2420 | 699 break; |
3787 | 700 case AFM_MSADPCM: |
701 sh_audio->channels=sh_audio->wf->nChannels; | |
702 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; | |
3875
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
703 sh_audio->i_bps = sh_audio->wf->nBlockAlign * |
3826
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
704 (sh_audio->channels*sh_audio->samplerate) / MS_ADPCM_SAMPLES_PER_BLOCK; |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
705 break; |
3933
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
706 case AFM_FOX61ADPCM: |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
707 sh_audio->channels=sh_audio->wf->nChannels; |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
708 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
709 sh_audio->i_bps=FOX61_ADPCM_BLOCK_SIZE* |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
710 (sh_audio->channels*sh_audio->samplerate) / FOX61_ADPCM_SAMPLES_PER_BLOCK; |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
711 break; |
3826
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
712 case AFM_FOX62ADPCM: |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
713 sh_audio->channels=sh_audio->wf->nChannels; |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
714 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
715 sh_audio->i_bps=FOX62_ADPCM_BLOCK_SIZE* |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
716 (sh_audio->channels*sh_audio->samplerate) / FOX62_ADPCM_SAMPLES_PER_BLOCK; |
3787 | 717 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
718 case AFM_MPEG: { |
296 | 719 // MPEG Audio: |
1289 | 720 dec_audio_sh=sh_audio; // save sh_audio for the callback: |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
721 #ifdef USE_FAKE_MONO |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
722 MP3_Init(fakemono); |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
723 #else |
296 | 724 MP3_Init(); |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
725 #endif |
296 | 726 MP3_samplerate=MP3_channels=0; |
727 // printf("[\n"); | |
728 sh_audio->a_buffer_len=MP3_DecodeFrame(sh_audio->a_buffer,-1); | |
729 // printf("]\n"); | |
730 sh_audio->channels=2; // hack | |
731 sh_audio->samplerate=MP3_samplerate; | |
746 | 732 sh_audio->i_bps=MP3_bitrate*(1000/8); |
303 | 733 break; |
734 } | |
1828 | 735 #ifdef HAVE_OGGVORBIS |
736 case AFM_VORBIS: { | |
737 // OggVorbis Audio: | |
738 #if 0 /* just here for reference - atmos */ | |
739 ogg_sync_state oy; /* sync and verify incoming physical bitstream */ | |
740 ogg_stream_state os; /* take physical pages, weld into a logical | |
741 stream of packets */ | |
742 ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */ | |
743 ogg_packet op; /* one raw packet of data for decode */ | |
744 | |
745 vorbis_info vi; /* struct that stores all the static vorbis bitstream | |
746 settings */ | |
747 vorbis_comment vc; /* struct that stores all the bitstream user comments */ | |
748 vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */ | |
749 vorbis_block vb; /* local working space for packet->PCM decode */ | |
750 #else | |
751 /* nix, nada, rien, nothing, nem, nüx */ | |
752 #endif | |
753 | |
754 uint32_t hdrsizes[3];/* stores vorbis header sizes from AVI audio header, | |
755 maybe use ogg_uint32_t */ | |
756 //int i; | |
757 int ret; | |
758 char *buffer; | |
759 ogg_packet hdr; | |
760 //ov_struct_t *s=&sh_audio->ov; | |
761 sh_audio->ov=malloc(sizeof(ov_struct_t)); | |
762 //s=&sh_audio->ov; | |
763 | |
764 vorbis_info_init(&sh_audio->ov->vi); | |
765 vorbis_comment_init(&sh_audio->ov->vc); | |
766 | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
767 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"OggVorbis: cbsize: %i\n", sh_audio->wf->cbSize); |
1828 | 768 memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX), 3*sizeof(uint32_t)); |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
769 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"OggVorbis: Read header sizes: initial: %i comment: %i codebook: %i\n", hdrsizes[0], hdrsizes[1], hdrsizes[2]); |
1828 | 770 /*for(i=12; i <= 40; i+=2) { // header bruteforce :) |
771 memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+i, 3*sizeof(uint32_t)); | |
772 printf("OggVorbis: Read header sizes (%i): %ld %ld %ld\n", i, hdrsizes[0], hdrsizes[1], hdrsizes[2]); | |
773 }*/ | |
774 | |
775 /* read headers */ // FIXME disable sound on errors here, we absolutely need this headers! - atmos | |
776 hdr.packet=NULL; | |
777 hdr.b_o_s = 1; /* beginning of stream for first packet */ | |
778 hdr.bytes = hdrsizes[0]; | |
779 hdr.packet = realloc(hdr.packet,hdr.bytes); | |
780 memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t),hdr.bytes); | |
781 if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0) | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
782 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: initial (identification) header broken!\n"); |
1828 | 783 hdr.b_o_s = 0; |
784 hdr.bytes = hdrsizes[1]; | |
785 hdr.packet = realloc(hdr.packet,hdr.bytes); | |
786 memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0],hdr.bytes); | |
787 if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0) | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
788 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: comment header broken!\n"); |
1828 | 789 hdr.bytes = hdrsizes[2]; |
790 hdr.packet = realloc(hdr.packet,hdr.bytes); | |
791 memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0]+hdrsizes[1],hdr.bytes); | |
792 if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0) | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
793 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: codebook header broken!\n"); |
1828 | 794 hdr.bytes=0; |
795 hdr.packet = realloc(hdr.packet,hdr.bytes); /* free */ | |
796 /* done with the headers */ | |
797 | |
798 | |
799 /* Throw the comments plus a few lines about the bitstream we're | |
800 decoding */ | |
801 { | |
802 char **ptr=sh_audio->ov->vc.user_comments; | |
803 while(*ptr){ | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
804 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbisComment: %s\n",*ptr); |
1828 | 805 ++ptr; |
806 } | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
807 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Bitstream is %d channel, %ldHz, %ldkbit/s %cBR\n",sh_audio->ov->vi.channels,sh_audio->ov->vi.rate,sh_audio->ov->vi.bitrate_nominal/1000, (sh_audio->ov->vi.bitrate_lower!=sh_audio->ov->vi.bitrate_nominal)||(sh_audio->ov->vi.bitrate_upper!=sh_audio->ov->vi.bitrate_nominal)?'V':'C'); |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
808 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Encoded by: %s\n",sh_audio->ov->vc.vendor); |
1828 | 809 } |
810 sh_audio->channels=sh_audio->ov->vi.channels; | |
811 sh_audio->samplerate=sh_audio->ov->vi.rate; | |
812 sh_audio->i_bps=sh_audio->ov->vi.bitrate_nominal/8; | |
813 | |
814 // printf("[\n"); | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
815 // sh_audio->a_buffer_len=sh_audio->audio_out_minsize;///ov->vi.channels; |
1828 | 816 // printf("]\n"); |
817 | |
818 /* OK, got and parsed all three headers. Initialize the Vorbis | |
819 packet->PCM decoder. */ | |
820 vorbis_synthesis_init(&sh_audio->ov->vd,&sh_audio->ov->vi); /* central decode state */ | |
821 vorbis_block_init(&sh_audio->ov->vd,&sh_audio->ov->vb); /* local state for most of the decode | |
822 so multiple block decodes can | |
823 proceed in parallel. We could init | |
824 multiple vorbis_block structures | |
825 for vd here */ | |
826 //printf("OggVorbis: synthesis and block init done.\n"); | |
827 ogg_sync_init(&sh_audio->ov->oy); /* Now we can read pages */ | |
828 | |
829 while((ret = ogg_sync_pageout(&sh_audio->ov->oy,&sh_audio->ov->og))!=1) { | |
830 if(ret == -1) | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
831 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: Pageout: not properly synced, had to skip some bytes.\n"); |
1828 | 832 else |
833 if(ret == 0) { | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
834 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: need more data to verify page, reading more data.\n"); |
1828 | 835 /* submit a a_buffer_len block to libvorbis' Ogg layer */ |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
836 buffer=ogg_sync_buffer(&sh_audio->ov->oy,256); |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
837 ogg_sync_wrote(&sh_audio->ov->oy,demux_read_data(sh_audio->ds,buffer,256)); |
1828 | 838 } |
839 } | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
840 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: successfull.\n"); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
841 ogg_stream_pagein(&sh_audio->ov->os,&sh_audio->ov->og); /* we can ignore any errors here |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
842 as they'll also become apparent |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
843 at packetout */ |
1828 | 844 |
845 /* Get the serial number and set up the rest of decode. */ | |
846 /* serialno first; use it to set up a logical stream */ | |
847 ogg_stream_init(&sh_audio->ov->os,ogg_page_serialno(&sh_audio->ov->og)); | |
848 | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
849 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Init OK!\n"); |
1828 | 850 |
851 break; | |
852 } | |
853 #endif | |
2415 | 854 |
855 #ifdef USE_LIBMAD | |
856 case AFM_MAD: | |
857 { | |
3871 | 858 printf("%s %s %s (%s)\n", mad_version, mad_copyright, mad_author, mad_build); |
859 | |
2415 | 860 printf(__FILE__ ":%d:mad: initialising\n", __LINE__); |
861 mad_frame_init(&mad_frame); | |
862 mad_stream_init(&mad_stream); | |
863 | |
864 printf(__FILE__ ":%d:mad: preparing buffer\n", __LINE__); | |
865 mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size); | |
866 mad_stream_buffer(&mad_stream, (unsigned char*)(sh_audio->a_in_buffer), sh_audio->a_in_buffer_len); | |
3871 | 867 // mad_stream_sync(&mad_stream); |
868 mad_sync(sh_audio, &mad_stream); | |
2415 | 869 mad_synth_init(&mad_synth); |
870 | |
871 if(mad_frame_decode(&mad_frame, &mad_stream) == 0) | |
872 { | |
873 printf(__FILE__ ":%d:mad: post processing buffer\n", __LINE__); | |
874 mad_postprocess_buffer(sh_audio, &mad_stream); | |
875 } | |
876 else | |
877 { | |
878 printf(__FILE__ ":%d:mad: frame decoding failed\n", __LINE__); | |
3874 | 879 mad_print_error(&mad_stream); |
2415 | 880 } |
881 | |
2434
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
882 switch (mad_frame.header.mode) |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
883 { |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
884 case MAD_MODE_SINGLE_CHANNEL: |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
885 sh_audio->channels=1; |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
886 break; |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
887 case MAD_MODE_DUAL_CHANNEL: |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
888 case MAD_MODE_JOINT_STEREO: |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
889 case MAD_MODE_STEREO: |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
890 sh_audio->channels=2; |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
891 break; |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
892 default: |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
893 mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "mad: unknown number of channels\n"); |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
894 } |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
895 mp_msg(MSGT_DECAUDIO, MSGL_HINT, "mad: channels: %d (mad channel mode: %d)\n", |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
896 sh_audio->channels, mad_frame.header.mode); |
2432 | 897 /* var. name changed in 0.13.0 (beta) (libmad/CHANGES) -- alex */ |
898 #if (MAD_VERSION_MAJOR >= 0) && (MAD_VERSION_MINOR >= 13) | |
899 sh_audio->samplerate=mad_frame.header.samplerate; | |
900 #else | |
2415 | 901 sh_audio->samplerate=mad_frame.header.sfreq; |
2432 | 902 #endif |
2415 | 903 sh_audio->i_bps=mad_frame.header.bitrate; |
904 printf(__FILE__ ":%d:mad: continuing\n", __LINE__); | |
905 break; | |
906 } | |
907 #endif | |
296 | 908 } |
909 | |
910 if(!sh_audio->channels || !sh_audio->samplerate){ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
911 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio); |
303 | 912 driver=0; |
296 | 913 } |
914 | |
303 | 915 if(!driver){ |
916 if(sh_audio->a_buffer) free(sh_audio->a_buffer); | |
1313
d797ecb9778f
sh_audio->a_buffer is freed twice (here and in mplayer.c), can result to
jkeil
parents:
1309
diff
changeset
|
917 sh_audio->a_buffer=NULL; |
303 | 918 return 0; |
919 } | |
296 | 920 |
1529 | 921 if(!sh_audio->o_bps) |
303 | 922 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; |
923 return driver; | |
296 | 924 } |
291 | 925 |
746 | 926 // Audio decoding: |
291 | 927 |
746 | 928 // Decode a single frame (mp3,acm etc) or 'minlen' bytes (pcm/alaw etc) |
929 // buffer length is 'maxlen' bytes, it shouldn't be exceeded... | |
930 | |
931 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){ | |
291 | 932 int len=-1; |
303 | 933 switch(sh_audio->codec->driver){ |
1927 | 934 #ifdef USE_LIBAVCODEC |
935 case AFM_FFMPEG: { | |
936 unsigned char *start=NULL; | |
937 int y; | |
938 while(len<minlen){ | |
939 int len2=0; | |
940 int x=ds_get_packet(sh_audio->ds,&start); | |
941 if(x<=0) break; // error | |
2049
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
942 y=avcodec_decode_audio(&lavc_context,(INT16*)buf,&len2,start,x); |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
943 if(y<0){ mp_msg(MSGT_DECAUDIO,MSGL_V,"lavc_audio: error\n");break; } |
1927 | 944 if(y<x) sh_audio->ds->buffer_pos+=y-x; // put back data (HACK!) |
945 if(len2>0){ | |
946 //len=len2;break; | |
947 if(len<0) len=len2; else len+=len2; | |
948 buf+=len2; | |
949 } | |
950 mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"Decoded %d -> %d \n",y,len2); | |
951 } | |
952 } | |
953 break; | |
954 #endif | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
955 case AFM_MPEG: // MPEG layer 2 or 3 |
291 | 956 len=MP3_DecodeFrame(buf,-1); |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1456
diff
changeset
|
957 // len=MP3_DecodeFrame(buf,3); |
291 | 958 break; |
1830 | 959 #ifdef HAVE_OGGVORBIS |
1828 | 960 case AFM_VORBIS: { // OggVorbis |
961 /* note: good minlen would be 4k or 8k IMHO - atmos */ | |
962 int ret; | |
963 char *buffer; | |
964 int bytes; | |
965 int samples; | |
966 float **pcm; | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
967 //ogg_int16_t convbuffer[4096]; |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
968 // int convsize; |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
969 int readlen=1024; |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
970 len=0; |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
971 // convsize=minlen/sh_audio->ov->vi.channels; |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
972 |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
973 while(len < minlen) { /* double loop allows for break in inner loop */ |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
974 while(len < minlen) { /* without aborting the outer loop - atmos */ |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
975 ret=ogg_stream_packetout(&sh_audio->ov->os,&sh_audio->ov->op); |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
976 if(ret==0) { |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
977 int xxx=0; |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
978 //printf("OggVorbis: Packetout: need more data, paging!\n"); |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
979 while((ret = ogg_sync_pageout(&sh_audio->ov->oy,&sh_audio->ov->og))!=1) { |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
980 if(ret == -1) |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
981 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: not properly synced, had to skip some bytes.\n"); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
982 else |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
983 if(ret == 0) { |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
984 //printf("OggVorbis: Pageout: need more data to verify page, reading more data.\n"); |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
985 /* submit a readlen k block to libvorbis' Ogg layer */ |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
986 buffer=ogg_sync_buffer(&sh_audio->ov->oy,readlen); |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
987 bytes=demux_read_data(sh_audio->ds,buffer,readlen); |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
988 xxx+=bytes; |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
989 ogg_sync_wrote(&sh_audio->ov->oy,bytes); |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
990 if(bytes==0) |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
991 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: 0Bytes written, possible End of Stream\n"); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
992 } |
1828 | 993 } |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
994 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[sync: %d ]\n",xxx); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
995 //printf("OggVorbis: Pageout: successfull, pagin in.\n"); |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
996 if(ogg_stream_pagein(&sh_audio->ov->os,&sh_audio->ov->og)<0) |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
997 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pagein failed!\n"); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
998 break; |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
999 } else if(ret<0) { |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1000 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Packetout: missing or corrupt data, skipping packet!\n"); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
1001 break; |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
1002 } else { |
1828 | 1003 |
1004 /* we have a packet. Decode it */ | |
1005 | |
1006 if(vorbis_synthesis(&sh_audio->ov->vb,&sh_audio->ov->op)==0) /* test for success! */ | |
1007 vorbis_synthesis_blockin(&sh_audio->ov->vd,&sh_audio->ov->vb); | |
1008 | |
1009 /* **pcm is a multichannel float vector. In stereo, for | |
1010 example, pcm[0] is left, and pcm[1] is right. samples is | |
1011 the size of each channel. Convert the float values | |
1012 (-1.<=range<=1.) to whatever PCM format and write it out */ | |
1013 | |
1014 while((samples=vorbis_synthesis_pcmout(&sh_audio->ov->vd,&pcm))>0){ | |
1015 int i,j; | |
1016 int clipflag=0; | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1017 int convsize=(maxlen-len)/(2*sh_audio->ov->vi.channels); // max size! |
1828 | 1018 int bout=(samples<convsize?samples:convsize); |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1019 |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1020 if(bout<=0) break; |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1021 |
1828 | 1022 /* convert floats to 16 bit signed ints (host order) and |
1023 interleave */ | |
1024 for(i=0;i<sh_audio->ov->vi.channels;i++){ | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1025 ogg_int16_t *convbuffer=(ogg_int16_t *)(&buf[len]); |
1828 | 1026 ogg_int16_t *ptr=convbuffer+i; |
1027 float *mono=pcm[i]; | |
1028 for(j=0;j<bout;j++){ | |
1029 #if 1 | |
1030 int val=mono[j]*32767.f; | |
1031 #else /* optional dither */ | |
1032 int val=mono[j]*32767.f+drand48()-0.5f; | |
1033 #endif | |
1034 /* might as well guard against clipping */ | |
1035 if(val>32767){ | |
1036 val=32767; | |
1037 clipflag=1; | |
1038 } | |
1039 if(val<-32768){ | |
1040 val=-32768; | |
1041 clipflag=1; | |
1042 } | |
1043 *ptr=val; | |
1044 ptr+=sh_audio->ov->vi.channels; | |
1045 } | |
1046 } | |
1047 | |
1048 if(clipflag) | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1049 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"Clipping in frame %ld\n",(long)(sh_audio->ov->vd.sequence)); |
1828 | 1050 |
1051 //fwrite(convbuffer,2*sh_audio->ov->vi.channels,bout,stderr); //dump pcm to file for debugging | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1052 //memcpy(buf+len,convbuffer,2*sh_audio->ov->vi.channels*bout); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
1053 len+=2*sh_audio->ov->vi.channels*bout; |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1054 |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1055 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[decoded: %d / %d ]\n",bout,samples); |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1056 |
1828 | 1057 vorbis_synthesis_read(&sh_audio->ov->vd,bout); /* tell libvorbis how |
1058 many samples we | |
1059 actually consumed */ | |
1060 } | |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
1061 } // from else, packetout ok |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
1062 } // while len |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
1063 } // outer while len |
1828 | 1064 if(ogg_page_eos(&sh_audio->ov->og)) |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1065 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: End of Stream reached!\n"); // FIXME clearup decoder, notify mplayer - atmos |
1828 | 1066 |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
1067 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[len: %d ]\n",len); |
1828 | 1068 |
1069 break; | |
1831 | 1070 } |
1830 | 1071 #endif |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1072 case AFM_PCM: // AVI PCM |
1058 | 1073 len=demux_read_data(sh_audio->ds,buf,minlen); |
401 | 1074 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1075 case AFM_DVDPCM: // DVD PCM |
401 | 1076 { int j; |
746 | 1077 len=demux_read_data(sh_audio->ds,buf,minlen); |
291 | 1078 //if(i&1){ printf("Warning! pcm_audio_size&1 !=0 (%d)\n",i);i&=~1; } |
746 | 1079 // swap endian: |
291 | 1080 for(j=0;j<len;j+=2){ |
1081 char x=buf[j]; | |
1082 buf[j]=buf[j+1]; | |
1083 buf[j+1]=x; | |
1084 } | |
1085 break; | |
1086 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1087 case AFM_ALAW: // aLaw decoder |
746 | 1088 { int l=demux_read_data(sh_audio->ds,buf,minlen/2); |
291 | 1089 unsigned short *d=(unsigned short *) buf; |
1090 unsigned char *s=buf; | |
1091 len=2*l; | |
758 | 1092 if(sh_audio->format==6){ |
1093 // aLaw | |
883 | 1094 while(l>0){ --l; d[l]=alaw2short[s[l]]; } |
758 | 1095 } else { |
1096 // uLaw | |
883 | 1097 while(l>0){ --l; d[l]=ulaw2short[s[l]]; } |
291 | 1098 } |
1099 break; | |
1100 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1101 case AFM_GSM: // MS-GSM decoder |
2420 | 1102 { unsigned char ibuf[65]; // 65 bytes / frame |
1103 if(demux_read_data(sh_audio->ds,ibuf,65)!=65) break; // EOF | |
1104 XA_MSGSM_Decoder(ibuf,(unsigned short *) buf); // decodes 65 byte -> 320 short | |
746 | 1105 // XA_GSM_Decoder(buf,(unsigned short *) &sh_audio->a_buffer[sh_audio->a_buffer_len]); // decodes 33 byte -> 160 short |
1106 len=2*320; | |
291 | 1107 break; |
1108 } | |
3866 | 1109 #ifdef USE_G72X |
3426 | 1110 case AFM_G72X: // GSM 723 decoder |
1111 { if(demux_read_data(sh_audio->ds,g72x_data.block, g72x_data.blocksize)!=g72x_data.blocksize) break; // EOF | |
1112 g72x_decode_block(&g72x_data); | |
1113 len=2*g72x_data.samplesperblock; | |
1114 memcpy(buf,g72x_data.samples,len); | |
1115 break; | |
1116 } | |
3866 | 1117 #endif |
3787 | 1118 case AFM_IMAADPCM: |
3756 | 1119 { unsigned char ibuf[IMA_ADPCM_BLOCK_SIZE * 2]; // bytes / stereo frame |
1120 if (demux_read_data(sh_audio->ds, ibuf, | |
3787 | 1121 IMA_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) != |
3756 | 1122 IMA_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) |
1123 break; // EOF | |
1124 len=2*ima_adpcm_decode_block((unsigned short*)buf,ibuf, sh_audio->wf->nChannels); | |
3787 | 1125 break; |
1126 } | |
1127 case AFM_MSADPCM: | |
3875
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
1128 { static unsigned char *ibuf = NULL; |
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
1129 if (!ibuf) |
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
1130 ibuf = (unsigned char *)malloc |
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
1131 (sh_audio->wf->nBlockAlign * sh_audio->wf->nChannels); |
3787 | 1132 if (demux_read_data(sh_audio->ds, ibuf, |
3875
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
1133 sh_audio->wf->nBlockAlign) != |
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
1134 sh_audio->wf->nBlockAlign) |
3787 | 1135 break; // EOF |
3875
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
1136 len= 2 * ms_adpcm_decode_block( |
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
1137 (unsigned short*)buf,ibuf, sh_audio->wf->nChannels, |
e3caff2daa98
fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents:
3874
diff
changeset
|
1138 sh_audio->wf->nBlockAlign); |
2420 | 1139 break; |
1140 } | |
3933
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
1141 case AFM_FOX61ADPCM: |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
1142 { unsigned char ibuf[FOX61_ADPCM_BLOCK_SIZE]; // bytes / stereo frame |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
1143 if (demux_read_data(sh_audio->ds, ibuf, FOX61_ADPCM_BLOCK_SIZE) != |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
1144 FOX61_ADPCM_BLOCK_SIZE) |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
1145 break; // EOF |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
1146 len=2*fox61_adpcm_decode_block((unsigned short*)buf,ibuf); |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
1147 break; |
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
1148 } |
3826
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
1149 case AFM_FOX62ADPCM: |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
1150 { unsigned char ibuf[FOX62_ADPCM_BLOCK_SIZE * 2]; // bytes / stereo frame |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
1151 if (demux_read_data(sh_audio->ds, ibuf, |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
1152 FOX62_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) != |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
1153 FOX62_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
1154 break; // EOF |
3933
60db4273246d
added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents:
3911
diff
changeset
|
1155 len = 2 * fox62_adpcm_decode_block( |
4001 | 1156 (unsigned short*)buf,ibuf); |
3826
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
1157 break; |
8a88ed2473aa
added initial, not-yet-functional, support for fox62 audio
melanson
parents:
3787
diff
changeset
|
1158 } |
3886 | 1159 #ifdef USE_LIBAC3 |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1160 case AFM_AC3: // AC3 decoder |
291 | 1161 //printf("{1:%d}",avi_header.idx_pos);fflush(stdout); |
1162 if(!sh_audio->ac3_frame) sh_audio->ac3_frame=ac3_decode_frame(); | |
1163 //printf("{2:%d}",avi_header.idx_pos);fflush(stdout); | |
1164 if(sh_audio->ac3_frame){ | |
296 | 1165 len = 256 * 6 *sh_audio->channels*sh_audio->samplesize; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
1166 memcpy(buf,((ac3_frame_t*)sh_audio->ac3_frame)->audio_data,len); |
291 | 1167 sh_audio->ac3_frame=NULL; |
1168 } | |
1169 //printf("{3:%d}",avi_header.idx_pos);fflush(stdout); | |
1170 break; | |
3886 | 1171 #endif |
3413 | 1172 case AFM_A52: { // AC3 decoder |
3911 | 1173 sample_t level=1, bias=384; |
1174 int flags=a52_flags|A52_ADJUST_LEVEL; | |
3413 | 1175 int i; |
1176 if(!sh_audio->a_in_buffer_len) | |
1177 if(a52_fillbuff(sh_audio)<0) break; // EOF | |
1178 sh_audio->a_in_buffer_len=0; | |
1179 if (a52_frame (&a52_state, sh_audio->a_in_buffer, &flags, &level, bias)){ | |
1180 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error decoding frame\n"); | |
1181 break; | |
1182 } | |
1183 // a52_dynrng (&state, NULL, NULL); // disable dynamic range compensation | |
1184 | |
1185 // frame decoded, let's resample: | |
3911 | 1186 //a52_resample_init(a52_accel,flags,sh_audio->channels); |
3413 | 1187 len=0; |
1188 for (i = 0; i < 6; i++) { | |
1189 if (a52_block (&a52_state, a52_samples)){ | |
1190 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error at resampling\n"); | |
1191 break; | |
1192 } | |
1193 len+=2*a52_resample(a52_samples,&buf[len]); | |
1194 } | |
3417 | 1195 // printf("len = %d \n",len); // 6144 on all vobs I tried so far... (5.1 and 2.0) ::atmos |
3413 | 1196 break; |
1197 } | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
1198 case AFM_HWAC3: // AC3 through SPDIF |
3829 | 1199 if(!sh_audio->a_in_buffer_len) |
1200 if((len=a52_fillbuff(sh_audio))<0) break; //EOF | |
1201 sh_audio->a_in_buffer_len=0; | |
1202 len = ac3_iec958_build_burst(len, 0x01, 1, sh_audio->a_in_buffer, buf); | |
1203 // len = 6144 = 4*(6*256) | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
1204 break; |
1517
0e9c29538a86
Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents:
1485
diff
changeset
|
1205 #ifdef USE_WIN32DLL |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1206 case AFM_ACM: |
758 | 1207 // len=sh_audio->audio_out_minsize; // optimal decoded fragment size |
1208 // if(len<minlen) len=minlen; else | |
1209 // if(len>maxlen) len=maxlen; | |
1210 // len=acm_decode_audio(sh_audio,buf,len); | |
1211 len=acm_decode_audio(sh_audio,buf,minlen,maxlen); | |
291 | 1212 break; |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
1213 #endif |
746 | 1214 |
291 | 1215 #ifdef USE_DIRECTSHOW |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1216 case AFM_DSHOW: // DirectShow |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1217 { int size_in=0; |
291 | 1218 int size_out=0; |
3442 | 1219 int srcsize=DS_AudioDecoder_GetSrcSize(ds_adec, maxlen); |
1567 | 1220 mp_msg(MSGT_DECAUDIO,MSGL_DBG3,"DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen); |
291 | 1221 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! |
1222 if(sh_audio->a_in_buffer_len<srcsize){ | |
1223 sh_audio->a_in_buffer_len+= | |
1224 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], | |
1225 srcsize-sh_audio->a_in_buffer_len); | |
1226 } | |
3442 | 1227 DS_AudioDecoder_Convert(ds_adec, sh_audio->a_in_buffer,sh_audio->a_in_buffer_len, |
291 | 1228 buf,maxlen, &size_in,&size_out); |
1567 | 1229 mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"DShow: audio %d -> %d converted (in_buf_len=%d of %d) %d\n",size_in,size_out,sh_audio->a_in_buffer_len,sh_audio->a_in_buffer_size,ds_tell_pts(sh_audio->ds)); |
291 | 1230 if(size_in>=sh_audio->a_in_buffer_len){ |
1231 sh_audio->a_in_buffer_len=0; | |
1232 } else { | |
1233 sh_audio->a_in_buffer_len-=size_in; | |
1234 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len); | |
1235 } | |
1236 len=size_out; | |
1237 break; | |
1238 } | |
1239 #endif | |
2415 | 1240 |
1241 #ifdef USE_LIBMAD | |
1242 case AFM_MAD: | |
1243 { | |
1244 mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size); | |
1245 mad_stream_buffer(&mad_stream, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len); | |
3871 | 1246 // mad_stream_sync(&mad_stream); |
1247 mad_sync(sh_audio, &mad_stream); | |
2415 | 1248 if(mad_frame_decode(&mad_frame, &mad_stream) == 0) |
1249 { | |
1250 mad_synth_frame(&mad_synth, &mad_frame); | |
1251 mad_postprocess_buffer(sh_audio, &mad_stream); | |
1252 | |
1253 /* and fill buffer */ | |
1254 | |
1255 { | |
1256 int i; | |
1257 int end_size = mad_synth.pcm.length; | |
1258 signed short* samples = (signed short*)buf; | |
1259 if(end_size > maxlen/4) | |
1260 end_size=maxlen/4; | |
1261 | |
1262 for(i=0; i<mad_synth.pcm.length; ++i) { | |
1263 *samples++ = mad_scale(mad_synth.pcm.samples[0][i]); | |
1264 *samples++ = mad_scale(mad_synth.pcm.samples[0][i]); | |
1265 // *buf++ = mad_scale(mad_synth.pcm.sampAles[1][i]); | |
1266 } | |
1267 len = end_size*4; | |
1268 } | |
1269 } | |
1270 else | |
1271 { | |
3871 | 1272 printf(__FILE__ ":%d:mad: frame decoding failed (error: %d)\n", __LINE__, |
1273 mad_stream.error); | |
3874 | 1274 mad_print_error(&mad_stream); |
2415 | 1275 } |
1276 | |
1277 break; | |
1278 } | |
1279 #endif | |
291 | 1280 } |
1281 return len; | |
1282 } | |
1283 | |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1284 void resync_audio_stream(sh_audio_t *sh_audio){ |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1285 switch(sh_audio->codec->driver){ |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1286 case AFM_MPEG: |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1287 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1288 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1289 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1290 break; |
1849
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1291 #ifdef HAVE_OGGVORBIS |
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1292 case AFM_VORBIS: |
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1293 //printf("OggVorbis: resetting stream.\n"); |
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1294 ogg_sync_reset(&sh_audio->ov->oy); |
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1295 ogg_stream_reset(&sh_audio->ov->os); |
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1296 break; |
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1297 #endif |
3886 | 1298 #ifdef USE_LIBAC3 |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1299 case AFM_AC3: |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1300 ac3_bitstream_reset(); // reset AC3 bitstream buffer |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1301 // if(verbose){ printf("Resyncing AC3 audio...");fflush(stdout);} |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1302 sh_audio->ac3_frame=ac3_decode_frame(); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1303 // if(verbose) printf(" OK!\n"); |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1304 break; |
3886 | 1305 #endif |
3413 | 1306 case AFM_A52: |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1307 case AFM_ACM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1308 case AFM_DSHOW: |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
1309 case AFM_HWAC3: |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1310 sh_audio->a_in_buffer_len=0; // reset ACM/DShow audio buffer |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1311 break; |
2415 | 1312 |
1313 #ifdef USE_LIBMAD | |
1314 case AFM_MAD: | |
1315 mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size); | |
1316 mad_stream_buffer(&mad_stream, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len); | |
3871 | 1317 // mad_stream_sync(&mad_stream); |
1318 mad_sync(sh_audio, &mad_stream); | |
2415 | 1319 mad_postprocess_buffer(sh_audio, &mad_stream); |
1320 break; | |
2418 | 1321 #endif |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1322 } |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1323 } |
291 | 1324 |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1325 void skip_audio_frame(sh_audio_t *sh_audio){ |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1326 switch(sh_audio->codec->driver){ |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1327 case AFM_MPEG: MP3_DecodeFrame(NULL,-2);break; // skip MPEG frame |
3886 | 1328 #ifdef USE_LIBAC3 |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1329 case AFM_AC3: sh_audio->ac3_frame=ac3_decode_frame();break; // skip AC3 frame |
3886 | 1330 #endif |
3829 | 1331 case AFM_HWAC3: |
3413 | 1332 case AFM_A52: a52_fillbuff(sh_audio);break; // skip AC3 frame |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1333 case AFM_ACM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1334 case AFM_DSHOW: { |
1408 | 1335 int skip=sh_audio->wf->nBlockAlign; |
1336 if(skip<16){ | |
1337 skip=(sh_audio->wf->nAvgBytesPerSec/16)&(~7); | |
1338 if(skip<16) skip=16; | |
1339 } | |
1340 demux_read_data(sh_audio->ds,NULL,skip); | |
1341 break; | |
1342 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1343 case AFM_PCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1344 case AFM_DVDPCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1345 case AFM_ALAW: { |
1408 | 1346 int skip=sh_audio->i_bps/16; |
1347 skip=skip&(~3); | |
1348 demux_read_data(sh_audio->ds,NULL,skip); | |
1349 break; | |
1350 } | |
2415 | 1351 #ifdef USE_LIBMAD |
1352 case AFM_MAD: | |
1353 { | |
1354 mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size); | |
1355 mad_stream_buffer(&mad_stream, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len); | |
1356 mad_stream_skip(&mad_stream, 2); | |
3871 | 1357 // mad_stream_sync(&mad_stream); |
1358 mad_sync(sh_audio, &mad_stream); | |
2415 | 1359 mad_postprocess_buffer(sh_audio, &mad_stream); |
1360 break; | |
1361 } | |
1362 #endif | |
1363 | |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1364 default: ds_fill_buffer(sh_audio->ds); // skip PCM frame |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1365 } |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1366 } |