Mercurial > mplayer.hg
annotate dec_audio.c @ 732:e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
author | arpi_esp |
---|---|
date | Tue, 08 May 2001 21:49:00 +0000 |
parents | ef7249823af2 |
children | cd1f0d4de0b8 |
rev | line source |
---|---|
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
1 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
2 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
3 #include <stdlib.h> |
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 "config.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
6 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
7 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
|
8 |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
9 #ifdef USE_FAKE_MONO |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
10 int fakemono=0; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
11 #endif |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
12 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
13 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
14 #include "demuxer.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
15 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
16 #include "wine/mmreg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
17 #include "wine/avifmt.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
18 #include "wine/vfw.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
19 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
20 #include "codec-cfg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
21 #include "stheader.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
22 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
23 #include "mp3lib/mp3.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
24 #include "libac3/ac3.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
25 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
26 #include "alaw.c" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
27 #include "xa/xa_gsm.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
28 |
604 | 29 #include "loader/DirectShow/DS_AudioDec.h" |
30 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
31 static sh_audio_t* ac3_audio_sh=NULL; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
32 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
33 // AC3 decoder buffer callback: |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
34 static void ac3_fill_buffer(uint8_t **start,uint8_t **end){ |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
35 int len=ds_get_packet(ac3_audio_sh->ds,start); |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
36 //printf("<ac3:%d>\n",len); |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
37 if(len<0) |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
38 *start = *end = NULL; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
39 else |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
40 *end = *start + len; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
41 } |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
42 |
296 | 43 |
44 int init_audio(sh_audio_t *sh_audio){ | |
303 | 45 |
46 int driver=sh_audio->codec->driver; | |
296 | 47 |
604 | 48 extern int init_acm_audio_codec(sh_audio_t *sh_audio); |
49 extern int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int len); | |
50 | |
296 | 51 sh_audio->samplesize=2; |
303 | 52 sh_audio->samplerate=0; |
401 | 53 //sh_audio->pcm_bswap=0; |
303 | 54 |
296 | 55 sh_audio->a_buffer_size=16384; // default size, maybe not enough for Win32/ACM |
303 | 56 sh_audio->a_buffer=NULL; |
296 | 57 |
303 | 58 if(driver==4){ |
296 | 59 // Win32 ACM audio codec: |
60 if(init_acm_audio_codec(sh_audio)){ | |
61 sh_audio->channels=sh_audio->o_wf.nChannels; | |
62 sh_audio->samplerate=sh_audio->o_wf.nSamplesPerSec; | |
63 if(sh_audio->a_buffer_size<sh_audio->audio_out_minsize+OUTBURST) | |
64 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+OUTBURST; | |
65 } else { | |
66 printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n"); | |
303 | 67 driver=0; |
296 | 68 } |
69 } | |
70 | |
303 | 71 if(driver==7){ |
296 | 72 #ifndef USE_DIRECTSHOW |
73 printf("Compiled without DirectShow support -> force nosound :(\n"); | |
303 | 74 driver=0; |
296 | 75 #else |
76 // Win32 DShow audio codec: | |
340 | 77 // printf("DShow_audio: channs=%d rate=%d\n",sh_audio->channels,sh_audio->samplerate); |
296 | 78 |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
79 if(DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf)){ |
303 | 80 printf("ERROR: Could not load/initialize Win32/DirctShow AUDIO codec: %s\n",sh_audio->codec->dll); |
81 driver=0; | |
82 } else { | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
83 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
|
84 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
|
85 sh_audio->audio_in_minsize=2*sh_audio->wf->nBlockAlign; |
296 | 86 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192; |
87 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
88 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
89 sh_audio->a_in_buffer_len=0; | |
90 } | |
91 #endif | |
92 } | |
93 | |
303 | 94 if(!driver) return 0; |
296 | 95 |
96 // allocate audio out buffer: | |
97 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); | |
98 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); | |
99 sh_audio->a_buffer_len=0; | |
100 | |
303 | 101 switch(driver){ |
102 case 4: { | |
296 | 103 int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,sh_audio->a_buffer_size); |
104 if(ret<0){ | |
303 | 105 printf("ACM decoding error: %d\n",ret); |
106 driver=0; | |
296 | 107 } |
640 | 108 sh_audio->a_buffer_len=ret; |
303 | 109 break; |
296 | 110 } |
303 | 111 case 2: { |
296 | 112 // 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
|
113 WAVEFORMATEX *h=sh_audio->wf; |
296 | 114 sh_audio->channels=h->nChannels; |
115 sh_audio->samplerate=h->nSamplesPerSec; | |
116 sh_audio->samplesize=(h->wBitsPerSample+7)/8; | |
401 | 117 break; |
118 } | |
119 case 8: { | |
120 // DVD PCM Audio: | |
121 sh_audio->channels=2; | |
122 sh_audio->samplerate=48000; | |
296 | 123 // sh_audio->pcm_bswap=1; |
303 | 124 break; |
125 } | |
126 case 3: { | |
296 | 127 // Dolby AC3 audio: |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
128 ac3_audio_sh=sh_audio; // save sh_audio for the callback: |
296 | 129 ac3_config.fill_buffer_callback = ac3_fill_buffer; |
130 ac3_config.num_output_ch = 2; | |
131 ac3_config.flags = 0; | |
132 #ifdef HAVE_MMX | |
133 ac3_config.flags |= AC3_MMX_ENABLE; | |
134 #endif | |
135 #ifdef HAVE_3DNOW | |
136 ac3_config.flags |= AC3_3DNOW_ENABLE; | |
137 #endif | |
138 ac3_init(); | |
139 sh_audio->ac3_frame = ac3_decode_frame(); | |
140 if(sh_audio->ac3_frame){ | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
141 sh_audio->samplerate=((ac3_frame_t*)sh_audio->ac3_frame)->sampling_rate; |
296 | 142 sh_audio->channels=2; |
303 | 143 } else { |
144 driver=0; // bad frame -> disable audio | |
145 } | |
146 break; | |
147 } | |
148 case 5: { | |
296 | 149 // aLaw audio codec: |
150 Gen_aLaw_2_Signed(); // init table | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
151 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
|
152 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
303 | 153 break; |
154 } | |
155 case 6: { | |
296 | 156 // MS-GSM audio codec: |
157 GSM_Init(); | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
158 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
|
159 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
303 | 160 break; |
296 | 161 } |
303 | 162 case 1: { |
296 | 163 // MPEG Audio: |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
164 #ifdef USE_FAKE_MONO |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
165 MP3_Init(fakemono); |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
166 #else |
296 | 167 MP3_Init(); |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
168 #endif |
296 | 169 MP3_samplerate=MP3_channels=0; |
170 // printf("[\n"); | |
171 sh_audio->a_buffer_len=MP3_DecodeFrame(sh_audio->a_buffer,-1); | |
172 // printf("]\n"); | |
173 sh_audio->channels=2; // hack | |
174 sh_audio->samplerate=MP3_samplerate; | |
303 | 175 break; |
176 } | |
296 | 177 } |
178 | |
179 if(!sh_audio->channels || !sh_audio->samplerate){ | |
180 printf("Unknown/missing audio format, using nosound\n"); | |
303 | 181 driver=0; |
296 | 182 } |
183 | |
303 | 184 if(!driver){ |
185 if(sh_audio->a_buffer) free(sh_audio->a_buffer); | |
186 sh_audio->o_bps=0; | |
187 return 0; | |
188 } | |
296 | 189 |
303 | 190 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; |
191 return driver; | |
296 | 192 } |
291 | 193 |
194 // Audio decoding | |
195 | |
196 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int maxlen){ | |
197 int len=-1; | |
303 | 198 switch(sh_audio->codec->driver){ |
291 | 199 case 1: // MPEG layer 2 or 3 |
200 len=MP3_DecodeFrame(buf,-1); | |
296 | 201 sh_audio->channels=2; // hack |
291 | 202 break; |
401 | 203 case 2: // AVI PCM |
291 | 204 { len=demux_read_data(sh_audio->ds,buf,OUTBURST); |
401 | 205 break; |
206 } | |
207 case 8: // DVD PCM | |
208 { int j; | |
209 len=demux_read_data(sh_audio->ds,buf,OUTBURST); | |
291 | 210 //if(i&1){ printf("Warning! pcm_audio_size&1 !=0 (%d)\n",i);i&=~1; } |
211 for(j=0;j<len;j+=2){ | |
212 char x=buf[j]; | |
213 buf[j]=buf[j+1]; | |
214 buf[j+1]=x; | |
215 } | |
216 break; | |
217 } | |
218 case 5: // aLaw decoder | |
219 { int l=demux_read_data(sh_audio->ds,buf,OUTBURST/2); | |
220 unsigned short *d=(unsigned short *) buf; | |
221 unsigned char *s=buf; | |
222 len=2*l; | |
223 while(l>0){ | |
224 --l; | |
225 d[l]=xa_alaw_2_sign[s[l]]; | |
226 } | |
227 break; | |
228 } | |
229 case 6: // MS-GSM decoder | |
230 { unsigned char buf[65]; // 65 bytes / frame | |
231 len=0; | |
232 while(len<OUTBURST){ | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
233 if(demux_read_data(sh_audio->ds,buf,65)!=65) break; // EOF |
291 | 234 XA_MSGSM_Decoder(buf,(unsigned short *) buf); // decodes 65 byte -> 320 short |
296 | 235 // XA_GSM_Decoder(buf,(unsigned short *) &sh_audio->a_buffer[sh_audio->a_buffer_len]); // decodes 33 byte -> 160 short |
291 | 236 len+=2*320; |
237 } | |
238 break; | |
239 } | |
240 case 3: // AC3 decoder | |
241 //printf("{1:%d}",avi_header.idx_pos);fflush(stdout); | |
242 if(!sh_audio->ac3_frame) sh_audio->ac3_frame=ac3_decode_frame(); | |
243 //printf("{2:%d}",avi_header.idx_pos);fflush(stdout); | |
244 if(sh_audio->ac3_frame){ | |
296 | 245 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
|
246 memcpy(buf,((ac3_frame_t*)sh_audio->ac3_frame)->audio_data,len); |
291 | 247 sh_audio->ac3_frame=NULL; |
248 } | |
249 //printf("{3:%d}",avi_header.idx_pos);fflush(stdout); | |
250 break; | |
251 case 4: | |
252 { len=acm_decode_audio(sh_audio,buf,maxlen); | |
253 break; | |
254 } | |
255 #ifdef USE_DIRECTSHOW | |
256 case 7: // DirectShow | |
257 { int ret; | |
258 int size_in=0; | |
259 int size_out=0; | |
260 int srcsize=DS_AudioDecoder_GetSrcSize(maxlen); | |
261 if(verbose>2)printf("DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen); | |
262 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! | |
263 if(sh_audio->a_in_buffer_len<srcsize){ | |
264 sh_audio->a_in_buffer_len+= | |
265 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], | |
266 srcsize-sh_audio->a_in_buffer_len); | |
267 } | |
268 DS_AudioDecoder_Convert(sh_audio->a_in_buffer,sh_audio->a_in_buffer_len, | |
269 buf,maxlen, &size_in,&size_out); | |
270 if(verbose>2)printf("DShow: audio %d -> %d converted (in_buf_len=%d of %d)\n",size_in,size_out,sh_audio->a_in_buffer_len,sh_audio->a_in_buffer_size); | |
271 if(size_in>=sh_audio->a_in_buffer_len){ | |
272 sh_audio->a_in_buffer_len=0; | |
273 } else { | |
274 sh_audio->a_in_buffer_len-=size_in; | |
275 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len); | |
276 } | |
277 len=size_out; | |
278 break; | |
279 } | |
280 #endif | |
281 } | |
282 return len; | |
283 } | |
284 | |
285 |