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