diff options
Diffstat (limited to 'apps/codecs/libfaad/decoder.c')
-rw-r--r-- | apps/codecs/libfaad/decoder.c | 218 |
1 files changed, 93 insertions, 125 deletions
diff --git a/apps/codecs/libfaad/decoder.c b/apps/codecs/libfaad/decoder.c index eb810de59e..c374ad3284 100644 --- a/apps/codecs/libfaad/decoder.c +++ b/apps/codecs/libfaad/decoder.c | |||
@@ -48,14 +48,35 @@ | |||
48 | #include "ssr.h" | 48 | #include "ssr.h" |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | /* Globals */ | ||
51 | #ifdef ANALYSIS | 52 | #ifdef ANALYSIS |
52 | uint16_t dbg_count; | 53 | uint16_t dbg_count; |
53 | #endif | 54 | #endif |
54 | 55 | ||
56 | /* static variables */ | ||
57 | static NeAACDecStruct s_AACDec; | ||
58 | static real_t s_fb_intermed [MAX_CHANNELS][1*FRAME_LEN] IBSS_ATTR_FAAD_LARGE_IRAM MEM_ALIGN_ATTR; | ||
59 | static real_t s_time_buf_1024[MAX_CHANNELS][1*FRAME_LEN] IBSS_ATTR_FAAD_LARGE_IRAM MEM_ALIGN_ATTR; | ||
60 | #ifdef SBR_DEC | ||
61 | #ifdef FAAD_STATIC_ALLOC | ||
62 | static real_t s_time_buf_2048[MAX_CHANNELS][2*FRAME_LEN] MEM_ALIGN_ATTR; | ||
63 | #endif | ||
64 | #endif | ||
65 | #ifdef SSR_DEC | ||
66 | static real_t s_ssr_overlap [MAX_CHANNELS][2*FRAME_LEN] MEM_ALIGN_ATTR; | ||
67 | static real_t s_prev_fmd [MAX_CHANNELS][2*FRAME_LEN] MEM_ALIGN_ATTR; | ||
68 | #endif | ||
69 | #ifdef MAIN_DEC | ||
70 | static pred_state s_pred_stat[MAX_CHANNELS][1*FRAME_LEN] MEM_ALIGN_ATTR; | ||
71 | #endif | ||
72 | #ifdef LTP_DEC | ||
73 | static int16_t s_lt_pred_stat[MAX_CHANNELS][4*FRAME_LEN] MEM_ALIGN_ATTR; | ||
74 | #endif | ||
75 | |||
76 | |||
55 | /* static function declarations */ | 77 | /* static function declarations */ |
56 | static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, | 78 | static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, |
57 | uint8_t *buffer, uint32_t buffer_size, | 79 | uint8_t *buffer, uint32_t buffer_size); |
58 | void **sample_buffer, int32_t sample_buffer_size); | ||
59 | static void create_channel_config(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo); | 80 | static void create_channel_config(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo); |
60 | 81 | ||
61 | 82 | ||
@@ -101,14 +122,21 @@ NeAACDecHandle NEAACDECAPI NeAACDecOpen(void) | |||
101 | coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE); | 122 | coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE); |
102 | #endif | 123 | #endif |
103 | 124 | ||
104 | if ((hDecoder = (NeAACDecHandle)faad_malloc(sizeof(NeAACDecStruct))) == NULL) | 125 | hDecoder = &s_AACDec; |
105 | return NULL; | ||
106 | 126 | ||
107 | memset(hDecoder, 0, sizeof(NeAACDecStruct)); | 127 | memset(hDecoder , 0, sizeof(NeAACDecStruct)); |
128 | memset(s_fb_intermed, 0, sizeof(s_fb_intermed)); | ||
129 | #ifdef SSR_DEC | ||
130 | memset(s_ssr_overlap, 0, sizeof(s_ssr_overlap)); | ||
131 | memset(s_prev_fmd , 0, sizeof(s_prev_fmd)); | ||
132 | #endif | ||
133 | #ifdef LTP_DEC | ||
134 | memset(s_lt_pred_stat, 0, sizeof(s_s_lt_pred_statpred_stat)); | ||
135 | #endif | ||
108 | 136 | ||
109 | hDecoder->config.outputFormat = FAAD_FMT_16BIT; | 137 | hDecoder->config.outputFormat = FAAD_FMT_16BIT; |
110 | hDecoder->config.defObjectType = MAIN; | 138 | hDecoder->config.defObjectType = MAIN; |
111 | hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */ | 139 | hDecoder->config.defSampleRate = 44100; |
112 | hDecoder->config.downMatrix = 0; | 140 | hDecoder->config.downMatrix = 0; |
113 | hDecoder->adts_header_present = 0; | 141 | hDecoder->adts_header_present = 0; |
114 | hDecoder->adif_header_present = 0; | 142 | hDecoder->adif_header_present = 0; |
@@ -117,26 +145,28 @@ NeAACDecHandle NEAACDECAPI NeAACDecOpen(void) | |||
117 | hDecoder->aacScalefactorDataResilienceFlag = 0; | 145 | hDecoder->aacScalefactorDataResilienceFlag = 0; |
118 | hDecoder->aacSpectralDataResilienceFlag = 0; | 146 | hDecoder->aacSpectralDataResilienceFlag = 0; |
119 | #endif | 147 | #endif |
120 | hDecoder->frameLength = 1024; | 148 | hDecoder->frameLength = FRAME_LEN; |
121 | 149 | ||
122 | hDecoder->frame = 0; | 150 | hDecoder->frame = 0; |
123 | hDecoder->sample_buffer = NULL; | ||
124 | 151 | ||
125 | for (i = 0; i < MAX_CHANNELS; i++) | 152 | for (i = 0; i < MAX_CHANNELS; i++) |
126 | { | 153 | { |
127 | hDecoder->window_shape_prev[i] = 0; | 154 | hDecoder->window_shape_prev[i] = 0; |
128 | hDecoder->time_out[i] = NULL; | 155 | hDecoder->time_out[i] = NULL; |
129 | hDecoder->fb_intermed[i] = NULL; | 156 | hDecoder->fb_intermed[i] = s_fb_intermed[i]; |
130 | #ifdef SSR_DEC | 157 | #ifdef SSR_DEC |
131 | hDecoder->ssr_overlap[i] = NULL; | 158 | hDecoder->ssr_overlap[i] = s_ssr_overlap[i]; |
132 | hDecoder->prev_fmd[i] = NULL; | 159 | hDecoder->prev_fmd[i] = s_prev_fmd[i]; |
160 | for (int k = 0; k < 2048; k++) | ||
161 | hDecoder->prev_fmd[i][k] = REAL_CONST(-1); | ||
133 | #endif | 162 | #endif |
134 | #ifdef MAIN_DEC | 163 | #ifdef MAIN_DEC |
135 | hDecoder->pred_stat[i] = NULL; | 164 | hDecoder->pred_stat[i] = s_pred_stat[i]; |
165 | reset_all_predictors(hDecoder->pred_stat[channel], FRAME_LEN); | ||
136 | #endif | 166 | #endif |
137 | #ifdef LTP_DEC | 167 | #ifdef LTP_DEC |
138 | hDecoder->ltp_lag[i] = 0; | 168 | hDecoder->ltp_lag[i] = 0; |
139 | hDecoder->lt_pred_stat[i] = NULL; | 169 | hDecoder->lt_pred_stat[i] = s_lt_pred_stat[i]; |
140 | #endif | 170 | #endif |
141 | } | 171 | } |
142 | 172 | ||
@@ -204,6 +234,7 @@ int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer, | |||
204 | uint32_t buffer_size, | 234 | uint32_t buffer_size, |
205 | uint32_t *samplerate, uint8_t *channels) | 235 | uint32_t *samplerate, uint8_t *channels) |
206 | { | 236 | { |
237 | uint32_t i; | ||
207 | uint32_t bits = 0; | 238 | uint32_t bits = 0; |
208 | bitfile ld; | 239 | bitfile ld; |
209 | adif_header adif; | 240 | adif_header adif; |
@@ -298,6 +329,28 @@ int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer, | |||
298 | hDecoder->frameLength >>= 1; | 329 | hDecoder->frameLength >>= 1; |
299 | #endif | 330 | #endif |
300 | 331 | ||
332 | for (i=0; i<MAX_CHANNELS; ++i) | ||
333 | { | ||
334 | #ifdef SBR_DEC | ||
335 | hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0; | ||
336 | if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | ||
337 | { | ||
338 | #ifdef FAAD_STATIC_ALLOC | ||
339 | hDecoder->time_out[i] = s_time_buf_2048[i]; | ||
340 | #else | ||
341 | hDecoder->time_out[i] = (real_t*)faad_malloc(2*FRAME_LEN*sizeof(real_t)); | ||
342 | #endif | ||
343 | memset(hDecoder->time_out[i], 0, 2*FRAME_LEN); | ||
344 | hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; | ||
345 | } | ||
346 | else | ||
347 | #endif | ||
348 | { | ||
349 | hDecoder->time_out[i] = s_time_buf_1024[i]; | ||
350 | memset(hDecoder->time_out[i], 0, 1*FRAME_LEN); | ||
351 | } | ||
352 | } | ||
353 | |||
301 | if (can_decode_ot(hDecoder->object_type) < 0) | 354 | if (can_decode_ot(hDecoder->object_type) < 0) |
302 | return -1; | 355 | return -1; |
303 | 356 | ||
@@ -310,6 +363,7 @@ int8_t NEAACDECAPI NeAACDecInit2(NeAACDecHandle hDecoder, uint8_t *pBuffer, | |||
310 | uint32_t *samplerate, uint8_t *channels) | 363 | uint32_t *samplerate, uint8_t *channels) |
311 | { | 364 | { |
312 | int8_t rc; | 365 | int8_t rc; |
366 | uint32_t i; | ||
313 | mp4AudioSpecificConfig mp4ASC; | 367 | mp4AudioSpecificConfig mp4ASC; |
314 | 368 | ||
315 | if((hDecoder == NULL) | 369 | if((hDecoder == NULL) |
@@ -391,6 +445,28 @@ int8_t NEAACDECAPI NeAACDecInit2(NeAACDecHandle hDecoder, uint8_t *pBuffer, | |||
391 | hDecoder->frameLength >>= 1; | 445 | hDecoder->frameLength >>= 1; |
392 | #endif | 446 | #endif |
393 | 447 | ||
448 | for (i=0; i<MAX_CHANNELS; ++i) | ||
449 | { | ||
450 | #ifdef SBR_DEC | ||
451 | hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0; | ||
452 | if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | ||
453 | { | ||
454 | #ifdef FAAD_STATIC_ALLOC | ||
455 | hDecoder->time_out[i] = s_time_buf_2048[i]; | ||
456 | #else | ||
457 | hDecoder->time_out[i] = (real_t*)faad_malloc(2*FRAME_LEN*sizeof(real_t)); | ||
458 | #endif | ||
459 | memset(hDecoder->time_out[i], 0, 2*FRAME_LEN); | ||
460 | hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; | ||
461 | } | ||
462 | else | ||
463 | #endif | ||
464 | { | ||
465 | hDecoder->time_out[i] = s_time_buf_1024[i]; | ||
466 | memset(hDecoder->time_out[i], 0, 1*FRAME_LEN); | ||
467 | } | ||
468 | } | ||
469 | |||
394 | return 0; | 470 | return 0; |
395 | } | 471 | } |
396 | 472 | ||
@@ -401,8 +477,6 @@ int8_t NEAACDECAPI NeAACDecInitDRM(NeAACDecHandle *hDecoder, uint32_t samplerate | |||
401 | if (hDecoder == NULL) | 477 | if (hDecoder == NULL) |
402 | return 1; /* error */ | 478 | return 1; /* error */ |
403 | 479 | ||
404 | NeAACDecClose(*hDecoder); | ||
405 | |||
406 | *hDecoder = NeAACDecOpen(); | 480 | *hDecoder = NeAACDecOpen(); |
407 | 481 | ||
408 | /* Special object type defined for DRM */ | 482 | /* Special object type defined for DRM */ |
@@ -435,59 +509,6 @@ int8_t NEAACDECAPI NeAACDecInitDRM(NeAACDecHandle *hDecoder, uint32_t samplerate | |||
435 | } | 509 | } |
436 | #endif | 510 | #endif |
437 | 511 | ||
438 | void NEAACDECAPI NeAACDecClose(NeAACDecHandle hDecoder) | ||
439 | { | ||
440 | uint8_t i; | ||
441 | |||
442 | if (hDecoder == NULL) | ||
443 | return; | ||
444 | |||
445 | #ifdef PROFILE | ||
446 | printf("AAC decoder total: %I64d cycles\n", hDecoder->cycles); | ||
447 | printf("requant: %I64d cycles\n", hDecoder->requant_cycles); | ||
448 | printf("spectral_data: %I64d cycles\n", hDecoder->spectral_cycles); | ||
449 | printf("scalefactors: %I64d cycles\n", hDecoder->scalefac_cycles); | ||
450 | printf("output: %I64d cycles\n", hDecoder->output_cycles); | ||
451 | #endif | ||
452 | |||
453 | for (i = 0; i < MAX_CHANNELS; i++) | ||
454 | { | ||
455 | if (hDecoder->time_out[i]) faad_free(hDecoder->time_out[i]); | ||
456 | if (hDecoder->fb_intermed[i]) faad_free(hDecoder->fb_intermed[i]); | ||
457 | #ifdef SSR_DEC | ||
458 | if (hDecoder->ssr_overlap[i]) faad_free(hDecoder->ssr_overlap[i]); | ||
459 | if (hDecoder->prev_fmd[i]) faad_free(hDecoder->prev_fmd[i]); | ||
460 | #endif | ||
461 | #ifdef MAIN_DEC | ||
462 | if (hDecoder->pred_stat[i]) faad_free(hDecoder->pred_stat[i]); | ||
463 | #endif | ||
464 | #ifdef LTP_DEC | ||
465 | if (hDecoder->lt_pred_stat[i]) faad_free(hDecoder->lt_pred_stat[i]); | ||
466 | #endif | ||
467 | } | ||
468 | |||
469 | #ifdef SSR_DEC | ||
470 | if (hDecoder->object_type == SSR) | ||
471 | ssr_filter_bank_end(hDecoder->fb); | ||
472 | else | ||
473 | #endif | ||
474 | |||
475 | |||
476 | drc_end(hDecoder->drc); | ||
477 | |||
478 | if (hDecoder->sample_buffer) faad_free(hDecoder->sample_buffer); | ||
479 | |||
480 | #ifdef SBR_DEC | ||
481 | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | ||
482 | { | ||
483 | if (hDecoder->sbr[i]) | ||
484 | sbrDecodeEnd(hDecoder->sbr[i]); | ||
485 | } | ||
486 | #endif | ||
487 | |||
488 | if (hDecoder) faad_free(hDecoder); | ||
489 | } | ||
490 | |||
491 | void NEAACDECAPI NeAACDecPostSeekReset(NeAACDecHandle hDecoder, int32_t frame) | 512 | void NEAACDECAPI NeAACDecPostSeekReset(NeAACDecHandle hDecoder, int32_t frame) |
492 | { | 513 | { |
493 | if (hDecoder) | 514 | if (hDecoder) |
@@ -708,34 +729,17 @@ void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder, | |||
708 | NeAACDecFrameInfo *hInfo, | 729 | NeAACDecFrameInfo *hInfo, |
709 | uint8_t *buffer, uint32_t buffer_size) | 730 | uint8_t *buffer, uint32_t buffer_size) |
710 | { | 731 | { |
711 | return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, NULL, 0); | 732 | return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size); |
712 | } | ||
713 | |||
714 | void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hDecoder, | ||
715 | NeAACDecFrameInfo *hInfo, | ||
716 | uint8_t *buffer, uint32_t buffer_size, | ||
717 | void **sample_buffer, uint32_t sample_buffer_size) | ||
718 | { | ||
719 | if ((sample_buffer == NULL) || (sample_buffer_size == 0)) | ||
720 | { | ||
721 | hInfo->error = 27; | ||
722 | return NULL; | ||
723 | } | ||
724 | |||
725 | return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, | ||
726 | sample_buffer, sample_buffer_size); | ||
727 | } | 733 | } |
728 | 734 | ||
729 | static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, | 735 | static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, |
730 | uint8_t *buffer, uint32_t buffer_size, | 736 | uint8_t *buffer, uint32_t buffer_size) |
731 | void **sample_buffer2, int32_t sample_buffer_size) | ||
732 | { | 737 | { |
733 | uint8_t channels = 0; | 738 | uint8_t channels = 0; |
734 | uint8_t output_channels = 0; | 739 | uint8_t output_channels = 0; |
735 | bitfile ld; | 740 | bitfile ld; |
736 | uint32_t bitsconsumed; | 741 | uint32_t bitsconsumed; |
737 | uint16_t frame_len; | 742 | uint16_t frame_len; |
738 | void *sample_buffer; | ||
739 | 743 | ||
740 | #ifdef PROFILE | 744 | #ifdef PROFILE |
741 | int64_t count = faad_get_ts(); | 745 | int64_t count = faad_get_ts(); |
@@ -908,42 +912,11 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, | |||
908 | } | 912 | } |
909 | 913 | ||
910 | /* allocate the buffer for the final samples */ | 914 | /* allocate the buffer for the final samples */ |
911 | if ((hDecoder->sample_buffer == NULL) || | 915 | if (hDecoder->alloced_channels != output_channels) |
912 | (hDecoder->alloced_channels != output_channels)) | ||
913 | { | 916 | { |
914 | static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t), | ||
915 | sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t), | ||
916 | sizeof(int16_t), sizeof(int16_t), 0, 0, 0 | ||
917 | }; | ||
918 | uint8_t stride = str[hDecoder->config.outputFormat-1]; | ||
919 | #ifdef SBR_DEC | ||
920 | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1)) | ||
921 | { | ||
922 | stride = 2 * stride; | ||
923 | } | ||
924 | #endif | ||
925 | /* check if we want to use internal sample_buffer */ | ||
926 | if (sample_buffer_size == 0) | ||
927 | { | ||
928 | if (hDecoder->sample_buffer) | ||
929 | faad_free(hDecoder->sample_buffer); | ||
930 | hDecoder->sample_buffer = NULL; | ||
931 | hDecoder->sample_buffer = faad_malloc(frame_len*output_channels*stride); | ||
932 | } else if (sample_buffer_size < frame_len*output_channels*stride) { | ||
933 | /* provided sample buffer is not big enough */ | ||
934 | hInfo->error = 27; | ||
935 | return NULL; | ||
936 | } | ||
937 | hDecoder->alloced_channels = output_channels; | 917 | hDecoder->alloced_channels = output_channels; |
938 | } | 918 | } |
939 | 919 | ||
940 | if (sample_buffer_size == 0) | ||
941 | { | ||
942 | sample_buffer = hDecoder->sample_buffer; | ||
943 | } else { | ||
944 | sample_buffer = *sample_buffer2; | ||
945 | } | ||
946 | |||
947 | #ifdef SBR_DEC | 920 | #ifdef SBR_DEC |
948 | if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | 921 | if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) |
949 | { | 922 | { |
@@ -982,11 +955,6 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, | |||
982 | } | 955 | } |
983 | #endif | 956 | #endif |
984 | 957 | ||
985 | /* we don't need sample conversion in rockbox. | ||
986 | sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer, | ||
987 | output_channels, frame_len, hDecoder->config.outputFormat); | ||
988 | */ | ||
989 | |||
990 | hDecoder->postSeekResetFlag = 0; | 958 | hDecoder->postSeekResetFlag = 0; |
991 | 959 | ||
992 | hDecoder->frame++; | 960 | hDecoder->frame++; |
@@ -1014,7 +982,7 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, | |||
1014 | hDecoder->cycles += count; | 982 | hDecoder->cycles += count; |
1015 | #endif | 983 | #endif |
1016 | 984 | ||
1017 | return sample_buffer; | 985 | return hDecoder; /* return void* != NULL */ |
1018 | 986 | ||
1019 | error: | 987 | error: |
1020 | 988 | ||