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