diff options
Diffstat (limited to 'apps/codecs/libatrac/atrac3.c')
-rw-r--r-- | apps/codecs/libatrac/atrac3.c | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/apps/codecs/libatrac/atrac3.c b/apps/codecs/libatrac/atrac3.c index dd00224e48..cd49aec348 100644 --- a/apps/codecs/libatrac/atrac3.c +++ b/apps/codecs/libatrac/atrac3.c | |||
@@ -55,18 +55,9 @@ | |||
55 | #define FFMIN(a,b) ((a) > (b) ? (b) : (a)) | 55 | #define FFMIN(a,b) ((a) > (b) ? (b) : (a)) |
56 | #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) | 56 | #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) |
57 | 57 | ||
58 | /** | ||
59 | * Clips a signed integer value into the -32768,32767 range. | ||
60 | */ | ||
61 | static inline int16_t av_clip_int16(int a) | ||
62 | { | ||
63 | if ((a+32768) & ~65535) return (a>>31) ^ 32767; | ||
64 | else return a; | ||
65 | } | ||
66 | |||
67 | static int32_t qmf_window[48] IBSS_ATTR; | 58 | static int32_t qmf_window[48] IBSS_ATTR; |
68 | static VLC spectral_coeff_tab[7]; | 59 | static VLC spectral_coeff_tab[7]; |
69 | static channel_unit channel_units[2]; | 60 | static channel_unit channel_units[2] IBSS_ATTR_LARGE_IRAM; |
70 | 61 | ||
71 | /** | 62 | /** |
72 | * Matrixing within quadrature mirror synthesis filter. | 63 | * Matrixing within quadrature mirror synthesis filter. |
@@ -516,7 +507,6 @@ static void gainCompensateAndOverlap (int32_t *pIn, int32_t *pPrev, int32_t *pOu | |||
516 | int32_t gain1, gain2, gain_inc; | 507 | int32_t gain1, gain2, gain_inc; |
517 | int cnt, numdata, nsample, startLoc, endLoc; | 508 | int cnt, numdata, nsample, startLoc, endLoc; |
518 | 509 | ||
519 | |||
520 | if (pGain2->num_gain_data == 0) | 510 | if (pGain2->num_gain_data == 0) |
521 | gain1 = ONE_16; | 511 | gain1 = ONE_16; |
522 | else | 512 | else |
@@ -735,7 +725,16 @@ static int decodeChannelSoundUnit (GetBitContext *gb, channel_unit *pSnd, int32_ | |||
735 | numBands = (subbandTab[numSubbands] - 1) >> 8; | 725 | numBands = (subbandTab[numSubbands] - 1) >> 8; |
736 | if (lastTonal >= 0) | 726 | if (lastTonal >= 0) |
737 | numBands = FFMAX((lastTonal + 256) >> 8, numBands); | 727 | numBands = FFMAX((lastTonal + 256) >> 8, numBands); |
738 | 728 | ||
729 | /* Remark: Hardcoded hack to add 2 bits (empty) fract part to internal sample | ||
730 | * representation. Needed for higher accuracy in internal calculations as | ||
731 | * well as for DSP configuration. See also: ../atrac3_rm.c, DSP_SET_SAMPLE_DEPTH | ||
732 | * Todo: Check spectral requantisation for using and outputting samples with | ||
733 | * fract part. */ | ||
734 | int32_t i; | ||
735 | for (i=0; i<1024; ++i) { | ||
736 | pSnd->spectrum[i] <<= 2; | ||
737 | } | ||
739 | 738 | ||
740 | /* Reconstruct time domain samples. */ | 739 | /* Reconstruct time domain samples. */ |
741 | for (band=0; band<4; band++) { | 740 | for (band=0; band<4; band++) { |
@@ -863,11 +862,9 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf, int off) | |||
863 | */ | 862 | */ |
864 | 863 | ||
865 | int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q, | 864 | int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q, |
866 | void *data, int *data_size, | 865 | int *data_size, const uint8_t *buf, int buf_size) { |
867 | const uint8_t *buf, int buf_size) { | 866 | int result = 0, off = 0; |
868 | int result = 0, off = 0, i; | ||
869 | const uint8_t* databuf; | 867 | const uint8_t* databuf; |
870 | int16_t* samples = data; | ||
871 | 868 | ||
872 | if (buf_size < rmctx->block_align) | 869 | if (buf_size < rmctx->block_align) |
873 | return buf_size; | 870 | return buf_size; |
@@ -887,19 +884,10 @@ int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q, | |||
887 | return -1; | 884 | return -1; |
888 | } | 885 | } |
889 | 886 | ||
890 | if (q->channels == 1) { | 887 | if (q->channels == 1) |
891 | /* mono */ | 888 | *data_size = 1024 * sizeof(int32_t); |
892 | for (i = 0; i<1024; i++) | 889 | else |
893 | samples[i] = av_clip_int16(q->outSamples[i]); | 890 | *data_size = 2048 * sizeof(int32_t); |
894 | *data_size = 1024 * sizeof(int16_t); | ||
895 | } else { | ||
896 | /* stereo */ | ||
897 | for (i = 0; i < 1024; i++) { | ||
898 | samples[i*2] = av_clip_int16(q->outSamples[i]); | ||
899 | samples[i*2+1] = av_clip_int16(q->outSamples[1024+i]); | ||
900 | } | ||
901 | *data_size = 2048 * sizeof(int16_t); | ||
902 | } | ||
903 | 891 | ||
904 | return rmctx->block_align; | 892 | return rmctx->block_align; |
905 | } | 893 | } |