annotate dec_audio.c @ 672:c716b964679e

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