comparison libmpcodecs/ad_liba52.c @ 18720:4bad7f00556e

sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com< part 1: functional changes
author rathann
date Thu, 15 Jun 2006 22:58:06 +0000
parents befc16265bb1
children a1807995e2ab
comparison
equal deleted inserted replaced
18719:5d01eb066fa3 18720:4bad7f00556e
17 #include "libaf/af_format.h" 17 #include "libaf/af_format.h"
18 18
19 #include "liba52/a52.h" 19 #include "liba52/a52.h"
20 #include "liba52/mm_accel.h" 20 #include "liba52/mm_accel.h"
21 21
22 static sample_t * a52_samples; 22 static a52_state_t *a52_state;
23 static a52_state_t a52_state;
24 static uint32_t a52_flags=0; 23 static uint32_t a52_flags=0;
25 /** Used by a52_resample_float, it defines the mapping between liba52 24 /** Used by a52_resample_float, it defines the mapping between liba52
26 * channels and output channels. The ith nibble from the right in the 25 * channels and output channels. The ith nibble from the right in the
27 * hex representation of channel_map is the index of the source 26 * hex representation of channel_map is the index of the source
28 * channel corresponding to the ith output channel. Source channels are 27 * channel corresponding to the ith output channel. Source channels are
167 if(gCpuCaps.hasMMX) a52_accel|=MM_ACCEL_X86_MMX; 166 if(gCpuCaps.hasMMX) a52_accel|=MM_ACCEL_X86_MMX;
168 if(gCpuCaps.hasMMX2) a52_accel|=MM_ACCEL_X86_MMXEXT; 167 if(gCpuCaps.hasMMX2) a52_accel|=MM_ACCEL_X86_MMXEXT;
169 if(gCpuCaps.has3DNow) a52_accel|=MM_ACCEL_X86_3DNOW; 168 if(gCpuCaps.has3DNow) a52_accel|=MM_ACCEL_X86_3DNOW;
170 if(gCpuCaps.has3DNowExt) a52_accel|=MM_ACCEL_X86_3DNOWEXT; 169 if(gCpuCaps.has3DNowExt) a52_accel|=MM_ACCEL_X86_3DNOWEXT;
171 if(gCpuCaps.hasAltiVec) a52_accel|=MM_ACCEL_PPC_ALTIVEC; 170 if(gCpuCaps.hasAltiVec) a52_accel|=MM_ACCEL_PPC_ALTIVEC;
172 a52_samples=a52_init (a52_accel); 171 a52_state=a52_init (a52_accel);
173 if (a52_samples == NULL) { 172 if (a52_state == NULL) {
174 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 init failed\n"); 173 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 init failed\n");
175 return 0; 174 return 0;
176 } 175 }
177 if(a52_fillbuff(sh_audio)<0){ 176 if(a52_fillbuff(sh_audio)<0){
178 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n"); 177 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n");
208 case 6: a52_flags=A52_3F2R|A52_LFE; break; /* 5.1*/ 207 case 6: a52_flags=A52_3F2R|A52_LFE; break; /* 5.1*/
209 } 208 }
210 /* test:*/ 209 /* test:*/
211 flags=a52_flags|A52_ADJUST_LEVEL; 210 flags=a52_flags|A52_ADJUST_LEVEL;
212 mp_msg(MSGT_DECAUDIO,MSGL_V,"A52 flags before a52_frame: 0x%X\n",flags); 211 mp_msg(MSGT_DECAUDIO,MSGL_V,"A52 flags before a52_frame: 0x%X\n",flags);
213 if (a52_frame (&a52_state, sh_audio->a_in_buffer, &flags, &level, bias)){ 212 if (a52_frame (a52_state, sh_audio->a_in_buffer, &flags, &level, bias)){
214 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"a52: error decoding frame -> nosound\n"); 213 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"a52: error decoding frame -> nosound\n");
215 return 0; 214 return 0;
216 } 215 }
217 mp_msg(MSGT_DECAUDIO,MSGL_V,"A52 flags after a52_frame: 0x%X\n",flags); 216 mp_msg(MSGT_DECAUDIO,MSGL_V,"A52 flags after a52_frame: 0x%X\n",flags);
218 /* frame decoded, let's init resampler:*/ 217 /* frame decoded, let's init resampler:*/
286 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen) 285 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
287 { 286 {
288 sample_t level=a52_level, bias=384; 287 sample_t level=a52_level, bias=384;
289 int flags=a52_flags|A52_ADJUST_LEVEL; 288 int flags=a52_flags|A52_ADJUST_LEVEL;
290 int i,len=-1; 289 int i,len=-1;
291 if (maxlen / sh_audio->samplesize / 256 / sh_audio->channels < 6) {
292 mp_msg(MSGT_DECAUDIO, MSGL_V, "maxlen too small in decode_audio\n");
293 return len;
294 }
295 if (sh_audio->sample_format == AF_FORMAT_FLOAT_NE) 290 if (sh_audio->sample_format == AF_FORMAT_FLOAT_NE)
296 bias = 0; 291 bias = 0;
297 if(!sh_audio->a_in_buffer_len) 292 if(!sh_audio->a_in_buffer_len)
298 if(a52_fillbuff(sh_audio)<0) return len; /* EOF */ 293 if(a52_fillbuff(sh_audio)<0) return len; /* EOF */
299 sh_audio->a_in_buffer_len=0; 294 sh_audio->a_in_buffer_len=0;
300 if (a52_frame (&a52_state, sh_audio->a_in_buffer, &flags, &level, bias)){ 295 if (a52_frame (a52_state, sh_audio->a_in_buffer, &flags, &level, bias)){
301 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error decoding frame\n"); 296 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error decoding frame\n");
302 return len; 297 return len;
303 } 298 }
304 299
305 /* handle dynrng */ 300 /* handle dynrng */
306 if (a52_drc_action != DRC_NO_ACTION) { 301 if (a52_drc_action != DRC_NO_ACTION) {
307 if (a52_drc_action == DRC_NO_COMPRESSION) 302 if (a52_drc_action == DRC_NO_COMPRESSION)
308 a52_dynrng(&a52_state, NULL, NULL); 303 a52_dynrng(a52_state, NULL, NULL);
309 else 304 else
310 a52_dynrng(&a52_state, dynrng_call, NULL); 305 a52_dynrng(a52_state, dynrng_call, NULL);
311 } 306 }
312 307
313 len=0; 308 len=0;
314 for (i = 0; i < 6; i++) { 309 for (i = 0; i < 6; i++) {
315 if (a52_block (&a52_state, a52_samples)){ 310 if (a52_block (a52_state)){
316 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error at resampling\n"); 311 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error at resampling\n");
317 break; 312 break;
318 } 313 }
319 len+=2*a52_resample(a52_samples,(int16_t *)&buf[len]); 314 len+=2*a52_resample(a52_samples(a52_state),(int16_t *)&buf[len]);
320 } 315 }
321 assert(len <= maxlen); 316 assert(len <= maxlen);
322 return len; 317 return len;
323 } 318 }
324 #endif 319 #endif