From f40bfc9267b13b54e6379dfe7539447662879d24 Mon Sep 17 00:00:00 2001 From: Sean Bartell Date: Sat, 25 Jun 2011 21:32:25 -0400 Subject: Add codecs to librbcodec. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97 Reviewed-on: http://gerrit.rockbox.org/137 Reviewed-by: Nils Wallménius Tested-by: Nils Wallménius --- lib/rbcodec/codecs/libatrac/README.rockbox | 30 + lib/rbcodec/codecs/libatrac/SOURCES | 8 + lib/rbcodec/codecs/libatrac/atrac3.c | 1293 ++++++++++++++++++++++++ lib/rbcodec/codecs/libatrac/atrac3.h | 114 +++ lib/rbcodec/codecs/libatrac/atrac3_arm.S | 172 ++++ lib/rbcodec/codecs/libatrac/atrac3_armv5e.S | 163 +++ lib/rbcodec/codecs/libatrac/atrac3data.h | 148 +++ lib/rbcodec/codecs/libatrac/atrac3data_fixed.h | 108 ++ lib/rbcodec/codecs/libatrac/fixp_math.h | 111 ++ lib/rbcodec/codecs/libatrac/libatrac.make | 18 + 10 files changed, 2165 insertions(+) create mode 100644 lib/rbcodec/codecs/libatrac/README.rockbox create mode 100644 lib/rbcodec/codecs/libatrac/SOURCES create mode 100644 lib/rbcodec/codecs/libatrac/atrac3.c create mode 100644 lib/rbcodec/codecs/libatrac/atrac3.h create mode 100644 lib/rbcodec/codecs/libatrac/atrac3_arm.S create mode 100644 lib/rbcodec/codecs/libatrac/atrac3_armv5e.S create mode 100644 lib/rbcodec/codecs/libatrac/atrac3data.h create mode 100644 lib/rbcodec/codecs/libatrac/atrac3data_fixed.h create mode 100644 lib/rbcodec/codecs/libatrac/fixp_math.h create mode 100644 lib/rbcodec/codecs/libatrac/libatrac.make (limited to 'lib/rbcodec/codecs/libatrac') diff --git a/lib/rbcodec/codecs/libatrac/README.rockbox b/lib/rbcodec/codecs/libatrac/README.rockbox new file mode 100644 index 0000000000..30703a3e49 --- /dev/null +++ b/lib/rbcodec/codecs/libatrac/README.rockbox @@ -0,0 +1,30 @@ +Library: libatrac +Imported by : Mohamed Tarek +Import date : 10-August-2009 + +LICENSING INFORMATION + +ffmpeg is licensed under the Lesser GNU General Public License. + +IMPORT DETAILS + +The decoder is based on ffmpeg-svn r18110 : Mar 21 2009. +Some changes were done on in order to use static VLC tables +according to this commit : +http://git.ffmpeg.org/?p=ffmpeg;a=commit;h=4c20cf13a166577d93f5b2b0abb4609c60104d33 + +The decoder had been modified to use fixed-point arithmetic. + +TESTING + +The test program should compile in any Unix-like environment using the +command "make -f Makefile.test". + +For ARM targets add -DCPU_ARM to CFLAGS in Makefile.test to make use of +the asm ARM optimisations in rockbox's mdct library. + +For Big-endian targets, change -D"ROCKBOX_LITTLE_ENDIAN=1" +to -D"ROCKBOX_BIG_ENDIAN=1" in Makefile.test. + +Running "./atractest file.rm" will decode the audio data to a WAV file +called "output.wav" in the current directory. diff --git a/lib/rbcodec/codecs/libatrac/SOURCES b/lib/rbcodec/codecs/libatrac/SOURCES new file mode 100644 index 0000000000..85f011cb87 --- /dev/null +++ b/lib/rbcodec/codecs/libatrac/SOURCES @@ -0,0 +1,8 @@ +atrac3.c +#if defined(CPU_ARM) +atrac3_arm.S +#if (ARM_ARCH >= 5) +atrac3_armv5e.S +#endif +#endif + diff --git a/lib/rbcodec/codecs/libatrac/atrac3.c b/lib/rbcodec/codecs/libatrac/atrac3.c new file mode 100644 index 0000000000..bb52dd4cf0 --- /dev/null +++ b/lib/rbcodec/codecs/libatrac/atrac3.c @@ -0,0 +1,1293 @@ +/* + * Atrac 3 compatible decoder + * Copyright (c) 2006-2008 Maxim Poliakovski + * Copyright (c) 2006-2008 Benjamin Larsson + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file libavcodec/atrac3.c + * Atrac 3 compatible decoder. + * This decoder handles Sony's ATRAC3 data. + * + * Container formats used to store atrac 3 data: + * RealMedia (.rm), RIFF WAV (.wav, .at3), Sony OpenMG (.oma, .aa3). + * + * To use this decoder, a calling application must supply the extradata + * bytes provided in the containers above. + */ + +#include +#include +#include + +#include "atrac3.h" +#include "atrac3data.h" +#include "atrac3data_fixed.h" +#include "fixp_math.h" + +#define JOINT_STEREO 0x12 +#define STEREO 0x2 + +#ifdef ROCKBOX +#undef DEBUGF +#define DEBUGF(...) +#endif /* ROCKBOX */ + +/* FFMAX/MIN/SWAP and av_clip were taken from libavutil/common.h */ +#define FFMAX(a,b) ((a) > (b) ? (a) : (b)) +#define FFMIN(a,b) ((a) > (b) ? (b) : (a)) +#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) + +#if defined(CPU_ARM) && (ARM_ARCH >= 5) + #define QMFWIN_TYPE int16_t /* ARMv5e+ uses 32x16 multiplication */ +#else + #define QMFWIN_TYPE int32_t +#endif + +static VLC spectral_coeff_tab[7] IBSS_ATTR_LARGE_IRAM; +static QMFWIN_TYPE qmf_window[48] IBSS_ATTR MEM_ALIGN_ATTR; +static int32_t atrac3_spectrum [2][1024] IBSS_ATTR MEM_ALIGN_ATTR; +static int32_t atrac3_IMDCT_buf[2][ 512] IBSS_ATTR MEM_ALIGN_ATTR; +static int32_t atrac3_prevFrame[2][1024] IBSS_ATTR MEM_ALIGN_ATTR; +static channel_unit channel_units[2] IBSS_ATTR_LARGE_IRAM; +static VLC_TYPE atrac3_vlc_table[4096][2] IBSS_ATTR_LARGE_IRAM; +static int vlcs_initialized = 0; + + + +/** + * Matrixing within quadrature mirror synthesis filter. + * + * @param p3 output buffer + * @param inlo lower part of spectrum + * @param inhi higher part of spectrum + * @param nIn size of spectrum buffer + */ + +#if defined(CPU_ARM) + extern void + atrac3_iqmf_matrixing(int32_t *p3, + int32_t *inlo, + int32_t *inhi, + unsigned int nIn); +#else + static inline void + atrac3_iqmf_matrixing(int32_t *p3, + int32_t *inlo, + int32_t *inhi, + unsigned int nIn) + { + uint32_t i; + for(i=0; i= 5) + extern void + atrac3_iqmf_dewindowing_armv5e(int32_t *out, + int32_t *in, + int16_t *win, + unsigned int nIn); + static inline void + atrac3_iqmf_dewindowing(int32_t *out, + int32_t *in, + int16_t *win, + unsigned int nIn) + { + atrac3_iqmf_dewindowing_armv5e(out, in, win, nIn); + + } + + +#elif defined(CPU_ARM) + extern void + atrac3_iqmf_dewindowing(int32_t *out, + int32_t *in, + int32_t *win, + unsigned int nIn); + +#elif defined (CPU_COLDFIRE) + #define MULTIPLY_ADD_BLOCK \ + "movem.l (%[win]), %%d0-%%d7 \n\t" \ + "lea.l (8*4, %[win]), %[win] \n\t" \ + "mac.l %%d0, %%a5, (%[in])+, %%a5, %%acc0\n\t" \ + "mac.l %%d1, %%a5, (%[in])+, %%a5, %%acc1\n\t" \ + "mac.l %%d2, %%a5, (%[in])+, %%a5, %%acc0\n\t" \ + "mac.l %%d3, %%a5, (%[in])+, %%a5, %%acc1\n\t" \ + "mac.l %%d4, %%a5, (%[in])+, %%a5, %%acc0\n\t" \ + "mac.l %%d5, %%a5, (%[in])+, %%a5, %%acc1\n\t" \ + "mac.l %%d6, %%a5, (%[in])+, %%a5, %%acc0\n\t" \ + "mac.l %%d7, %%a5, (%[in])+, %%a5, %%acc1\n\t" \ + + + static inline void + atrac3_iqmf_dewindowing(int32_t *out, + int32_t *in, + int32_t *win, + unsigned int nIn) + { + int32_t j; + int32_t *_in, *_win; + for (j = nIn; j != 0; j--, in+=2, out+=2) { + _in = in; + _win = win; + + asm volatile ( + "move.l (%[in])+, %%a5 \n\t" /* preload frist in value */ + MULTIPLY_ADD_BLOCK /* 0.. 7 */ + MULTIPLY_ADD_BLOCK /* 8..15 */ + MULTIPLY_ADD_BLOCK /* 16..23 */ + MULTIPLY_ADD_BLOCK /* 24..31 */ + MULTIPLY_ADD_BLOCK /* 32..39 */ + /* 40..47 */ + "movem.l (%[win]), %%d0-%%d7 \n\t" + "mac.l %%d0, %%a5, (%[in])+, %%a5, %%acc0 \n\t" + "mac.l %%d1, %%a5, (%[in])+, %%a5, %%acc1 \n\t" + "mac.l %%d2, %%a5, (%[in])+, %%a5, %%acc0 \n\t" + "mac.l %%d3, %%a5, (%[in])+, %%a5, %%acc1 \n\t" + "mac.l %%d4, %%a5, (%[in])+, %%a5, %%acc0 \n\t" + "mac.l %%d5, %%a5, (%[in])+, %%a5, %%acc1 \n\t" + "mac.l %%d6, %%a5, (%[in])+, %%a5, %%acc0 \n\t" + "mac.l %%d7, %%a5, %%acc1 \n\t" + "movclr.l %%acc0, %%d1 \n\t" /* s1 */ + "movclr.l %%acc1, %%d0 \n\t" /* s2 */ + "movem.l %%d0-%%d1, (%[out]) \n\t" + : [in] "+a" (_in), [win] "+a" (_win) + : [out] "a" (out) + : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5", "memory"); + } + } +#else + #define MULTIPLY_ADD_BLOCK(y1, y2, x, c, k) \ + y1 += fixmul31(c[k], x[k]); k++; \ + y2 += fixmul31(c[k], x[k]); k++; \ + y1 += fixmul31(c[k], x[k]); k++; \ + y2 += fixmul31(c[k], x[k]); k++; \ + y1 += fixmul31(c[k], x[k]); k++; \ + y2 += fixmul31(c[k], x[k]); k++; \ + y1 += fixmul31(c[k], x[k]); k++; \ + y2 += fixmul31(c[k], x[k]); k++; + + static inline void + atrac3_iqmf_dewindowing(int32_t *out, + int32_t *in, + int32_t *win, + unsigned int nIn) + { + int32_t i, j, s1, s2; + + for (j = nIn; j != 0; j--, in+=2, out+=2) { + s1 = s2 = i = 0; + + MULTIPLY_ADD_BLOCK(s1, s2, in, win, i); /* 0.. 7 */ + MULTIPLY_ADD_BLOCK(s1, s2, in, win, i); /* 8..15 */ + MULTIPLY_ADD_BLOCK(s1, s2, in, win, i); /* 16..23 */ + MULTIPLY_ADD_BLOCK(s1, s2, in, win, i); /* 24..31 */ + MULTIPLY_ADD_BLOCK(s1, s2, in, win, i); /* 32..39 */ + MULTIPLY_ADD_BLOCK(s1, s2, in, win, i); /* 40..47 */ + + out[0] = s2; + out[1] = s1; + + } + + } +#endif + + +/** + * IMDCT windowing. + * + * @param buffer sample buffer + * @param win window coefficients + */ + +static inline void +atrac3_imdct_windowing(int32_t *buffer, + const int32_t *win) +{ + int32_t i; + /* win[0..127] = win[511..384], win[128..383] = 1 */ + for(i = 0; i<128; i++) { + buffer[ i] = fixmul31(win[i], buffer[ i]); + buffer[511-i] = fixmul31(win[i], buffer[511-i]); + } +} + + +/** + * Quadrature mirror synthesis filter. + * + * @param inlo lower part of spectrum + * @param inhi higher part of spectrum + * @param nIn size of spectrum buffer + * @param pOut out buffer + * @param delayBuf delayBuf buffer + * @param temp temp buffer + */ + +static void iqmf (int32_t *inlo, int32_t *inhi, unsigned int nIn, int32_t *pOut, int32_t *delayBuf, int32_t *temp) +{ + + /* Restore the delay buffer */ + memcpy(temp, delayBuf, 46*sizeof(int32_t)); + + /* loop1: matrixing */ + atrac3_iqmf_matrixing(temp + 46, inlo, inhi, nIn); + + /* loop2: dewindowing */ + atrac3_iqmf_dewindowing(pOut, temp, qmf_window, nIn); + + /* Save the delay buffer */ + memcpy(delayBuf, temp + (nIn << 1), 46*sizeof(int32_t)); +} + + +/** + * Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands + * caused by the reverse spectra of the QMF. + * + * @param pInput input + * @param pOutput output + * @param odd_band 1 if the band is an odd band + */ + +static void IMLT(int32_t *pInput, int32_t *pOutput) +{ + /* Apply the imdct. */ + ff_imdct_calc(9, pOutput, pInput); + + /* Windowing. */ + atrac3_imdct_windowing(pOutput, window_lookup); + +} + + +/** + * Atrac 3 indata descrambling, only used for data coming from the rm container + * + * @param in pointer to 8 bit array of indata + * @param bits amount of bits + * @param out pointer to 8 bit array of outdata + */ + +static int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){ + int i, off; + uint32_t c; + const uint32_t* buf; + uint32_t* obuf = (uint32_t*) out; + +#if ((defined(TEST) || defined(SIMULATOR)) && !defined(CPU_ARM)) + off = 0; /* no check for memory alignment of inbuffer */ +#else + off = (intptr_t)inbuffer & 3; +#endif /* TEST */ + buf = (const uint32_t*) (inbuffer - off); + + c = be2me_32((0x537F6103 >> (off*8)) | (0x537F6103 << (32-(off*8)))); + bytes += 3 + off; + for (i = 0; i < bytes/4; i++) + obuf[i] = c ^ buf[i]; + + return off; +} + + +static void init_atrac3_transforms(void) +{ + int32_t s; + int i; + + /* Generate the mdct window, for details see + * http://wiki.multimedia.cx/index.php?title=RealAudio_atrc#Windows */ + + /* mdct window had been generated and saved as a lookup table in atrac3data_fixed.h */ + + /* Generate the QMF window. */ + for (i=0 ; i<24; i++) { + s = qmf_48tap_half_fix[i] << 1; + #if defined(CPU_ARM) && (ARM_ARCH >= 5) + qmf_window[i] = qmf_window[47-i] = (int16_t)((s+(1<<15))>>16); + #else + qmf_window[i] = qmf_window[47-i] = s; + #endif + } + +} + + +/** + * Mantissa decoding + * + * @param gb the GetBit context + * @param selector what table is the output values coded with + * @param codingFlag constant length coding or variable length coding + * @param mantissas mantissa output table + * @param numCodes amount of values to get + */ + +static void readQuantSpectralCoeffs (GetBitContext *gb, int selector, int codingFlag, int* mantissas, int numCodes) +{ + int numBits, cnt, code, huffSymb; + + if (selector == 1) + numCodes /= 2; + + if (codingFlag != 0) { + /* constant length coding (CLC) */ + numBits = CLCLengthTab[selector]; + + if (selector > 1) { + for (cnt = 0; cnt < numCodes; cnt++) { + if (numBits) + code = get_sbits(gb, numBits); + else + code = 0; + mantissas[cnt] = code; + } + } else { + for (cnt = 0; cnt < numCodes; cnt++) { + if (numBits) + code = get_bits(gb, numBits); /* numBits is always 4 in this case */ + else + code = 0; + mantissas[cnt*2] = seTab_0[code >> 2]; + mantissas[cnt*2+1] = seTab_0[code & 3]; + } + } + } else { + /* variable length coding (VLC) */ + if (selector != 1) { + for (cnt = 0; cnt < numCodes; cnt++) { + huffSymb = get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].bits, 3); + huffSymb += 1; + code = huffSymb >> 1; + if (huffSymb & 1) + code = -code; + mantissas[cnt] = code; + } + } else { + for (cnt = 0; cnt < numCodes; cnt++) { + huffSymb = get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].bits, 3); + mantissas[cnt*2] = decTable1[huffSymb*2]; + mantissas[cnt*2+1] = decTable1[huffSymb*2+1]; + } + } + } +} + + +/** + * Requantize the spectrum. + * + * @param *mantissas pointer to mantissas for each spectral line + * @param pOut requantized band spectrum + * @param first first spectral line in subband + * @param last last spectral line in subband + * @param SF scalefactor for all spectral lines of this band + */ + +static void inverseQuantizeSpectrum(int *mantissas, int32_t *pOut, + int32_t first, int32_t last, int32_t SF) +{ + int *pIn = mantissas; + + /* Inverse quantize the coefficients. */ + if((first/256) &1) { + /* Odd band - Reverse coefficients */ + do { + pOut[last--] = fixmul16(*pIn++, SF); + pOut[last--] = fixmul16(*pIn++, SF); + pOut[last--] = fixmul16(*pIn++, SF); + pOut[last--] = fixmul16(*pIn++, SF); + pOut[last--] = fixmul16(*pIn++, SF); + pOut[last--] = fixmul16(*pIn++, SF); + pOut[last--] = fixmul16(*pIn++, SF); + pOut[last--] = fixmul16(*pIn++, SF); + } while (last>first); + } else { + /* Even band - Do not reverse coefficients */ + do { + pOut[first++] = fixmul16(*pIn++, SF); + pOut[first++] = fixmul16(*pIn++, SF); + pOut[first++] = fixmul16(*pIn++, SF); + pOut[first++] = fixmul16(*pIn++, SF); + pOut[first++] = fixmul16(*pIn++, SF); + pOut[first++] = fixmul16(*pIn++, SF); + pOut[first++] = fixmul16(*pIn++, SF); + pOut[first++] = fixmul16(*pIn++, SF); + } while (first> 2] == 0) + continue; + + coded_components = get_bits(gb,3); + + for (k=0; kgBlock; + + for (i=0 ; i<=numBands; i++) + { + numData = get_bits(gb,3); + pGain[i].num_gain_data = numData; + pLevel = pGain[i].levcode; + pLoc = pGain[i].loccode; + + for (cf = 0; cf < numData; cf++){ + pLevel[cf]= get_bits(gb,4); + pLoc [cf]= get_bits(gb,5); + if(cf && pLoc[cf] <= pLoc[cf-1]) + return -1; + } + } + + /* Clear the unused blocks. */ + for (; i<4 ; i++) + pGain[i].num_gain_data = 0; + + return 0; +} + + +/** + * Apply fix (constant) gain and overlap for sample[start...255]. + * + * @param pIn input buffer + * @param pPrev previous buffer to perform overlap against + * @param pOut output buffer + * @param start index to start with (always a multiple of 8) + * @param gain gain to apply + */ + +static void applyFixGain (int32_t *pIn, int32_t *pPrev, int32_t *pOut, + int32_t start, int32_t gain) +{ + int32_t i = start; + + /* start is always a multiple of 8 and therefore allows us to unroll the + * loop to 8 calculation per loop + */ + if (ONE_16 == gain) { + /* gain1 = 1.0 -> no multiplication needed, just adding */ + /* Remark: This path is called >90%. */ + while (i<256) { + pOut[i] = pIn[i] + pPrev[i]; i++; + pOut[i] = pIn[i] + pPrev[i]; i++; + pOut[i] = pIn[i] + pPrev[i]; i++; + pOut[i] = pIn[i] + pPrev[i]; i++; + pOut[i] = pIn[i] + pPrev[i]; i++; + pOut[i] = pIn[i] + pPrev[i]; i++; + pOut[i] = pIn[i] + pPrev[i]; i++; + pOut[i] = pIn[i] + pPrev[i]; i++; + }; + } else { + /* gain1 != 1.0 -> we need to do a multiplication */ + /* Remark: This path is called seldom. */ + while (i<256) { + pOut[i] = fixmul16(pIn[i], gain) + pPrev[i]; i++; + pOut[i] = fixmul16(pIn[i], gain) + pPrev[i]; i++; + pOut[i] = fixmul16(pIn[i], gain) + pPrev[i]; i++; + pOut[i] = fixmul16(pIn[i], gain) + pPrev[i]; i++; + pOut[i] = fixmul16(pIn[i], gain) + pPrev[i]; i++; + pOut[i] = fixmul16(pIn[i], gain) + pPrev[i]; i++; + pOut[i] = fixmul16(pIn[i], gain) + pPrev[i]; i++; + pOut[i] = fixmul16(pIn[i], gain) + pPrev[i]; i++; + }; + } +} + + +/** + * Apply variable gain and overlap. Returns sample index after applying gain, + * resulting sample index is always a multiple of 8. + * + * @param pIn input buffer + * @param pPrev previous buffer to perform overlap against + * @param pOut output buffer + * @param start index to start with (always a multiple of 8) + * @param end end index for first loop (always a multiple of 8) + * @param gain1 current bands gain to apply + * @param gain2 next bands gain to apply + * @param gain_inc stepwise adaption from gain1 to gain2 + */ + +static int applyVariableGain (int32_t *pIn, int32_t *pPrev, int32_t *pOut, + int32_t start, int32_t end, + int32_t gain1, int32_t gain2, int32_t gain_inc) +{ + int32_t i = start; + + /* Apply fix gains until end index is reached */ + do { + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + } while (i < end); + + /* Interpolation is done over next eight samples */ + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + gain2 = fixmul16(gain2, gain_inc); + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + gain2 = fixmul16(gain2, gain_inc); + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + gain2 = fixmul16(gain2, gain_inc); + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + gain2 = fixmul16(gain2, gain_inc); + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + gain2 = fixmul16(gain2, gain_inc); + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + gain2 = fixmul16(gain2, gain_inc); + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + gain2 = fixmul16(gain2, gain_inc); + pOut[i] = fixmul16((fixmul16(pIn[i], gain1) + pPrev[i]), gain2); i++; + gain2 = fixmul16(gain2, gain_inc); + + return i; +} + + +/** + * Apply gain parameters and perform the MDCT overlapping part + * + * @param pIn input buffer + * @param pPrev previous buffer to perform overlap against + * @param pOut output buffer + * @param pGain1 current band gain info + * @param pGain2 next band gain info + */ + +static void gainCompensateAndOverlap (int32_t *pIn, int32_t *pPrev, int32_t *pOut, + gain_info *pGain1, gain_info *pGain2) +{ + /* gain compensation function */ + int32_t gain1, gain2, gain_inc; + int cnt, numdata, nsample, startLoc; + + if (pGain2->num_gain_data == 0) + gain1 = ONE_16; + else + gain1 = (ONE_16<<4)>>(pGain2->levcode[0]); + + if (pGain1->num_gain_data == 0) { + /* Remark: This path is called >90%. */ + /* Apply gain for all samples from 0...255 */ + applyFixGain(pIn, pPrev, pOut, 0, gain1); + } else { + /* Remark: This path is called seldom. */ + numdata = pGain1->num_gain_data; + pGain1->loccode[numdata] = 32; + pGain1->levcode[numdata] = 4; + + nsample = 0; /* starting loop with =0 */ + + for (cnt = 0; cnt < numdata; cnt++) { + startLoc = pGain1->loccode[cnt] * 8; + + gain2 = (ONE_16<<4)>>(pGain1->levcode[cnt]); + gain_inc = gain_tab2[(pGain1->levcode[cnt+1] - pGain1->levcode[cnt])+15]; + + /* Apply variable gain (gain1 -> gain2) to samples */ + nsample = applyVariableGain(pIn, pPrev, pOut, nsample, startLoc, gain1, gain2, gain_inc); + } + /* Apply gain for the residual samples from nsample...255 */ + applyFixGain(pIn, pPrev, pOut, nsample, gain1); + } + + /* Delay for the overlapping part. */ + memcpy(pPrev, &pIn[256], 256*sizeof(int32_t)); +} + + +/** + * Combine the tonal band spectrum and regular band spectrum + * Return position of the last tonal coefficient + + * + * @param pSpectrum output spectrum buffer + * @param numComponents amount of tonal components + * @param pComponent tonal components for this band + */ + +static int addTonalComponents (int32_t *pSpectrum, int numComponents, tonal_component *pComponent) +{ + int cnt, i, lastPos = -1; + int32_t *pOut; + int32_t *pIn; + + for (cnt = 0; cnt < numComponents; cnt++){ + lastPos = FFMAX(pComponent[cnt].pos + pComponent[cnt].numCoefs, lastPos); + pIn = pComponent[cnt].coef; + pOut = &(pSpectrum[pComponent[cnt].pos]); + + for (i=0 ; i>3), (((y) - (x))))) +*/ +#define INTERPOLATE_FP16(x, y, s) ((x) + ((s*((y)-(x)))>>3)) + +static void reverseMatrixing(int32_t *su1, int32_t *su2, int *pPrevCode, int *pCurrCode) +{ + int i, band, nsample, s1, s2; + int32_t c1, c2; + int32_t mc1_l, mc1_r, mc2_l, mc2_r; + + for (i=0,band = 0; band < 4*256; band+=256,i++) { + s1 = pPrevCode[i]; + s2 = pCurrCode[i]; + nsample = 0; + + if (s1 != s2) { + /* Selector value changed, interpolation needed. */ + mc1_l = matrixCoeffs_fix[s1<<1]; + mc1_r = matrixCoeffs_fix[(s1<<1)+1]; + mc2_l = matrixCoeffs_fix[s2<<1]; + mc2_r = matrixCoeffs_fix[(s2<<1)+1]; + + /* Interpolation is done over the first eight samples. */ + for(; nsample < 8; nsample++) { + c1 = su1[band+nsample]; + c2 = su2[band+nsample]; + c2 = fixmul16(c1, INTERPOLATE_FP16(mc1_l, mc2_l, nsample)) + fixmul16(c2, INTERPOLATE_FP16(mc1_r, mc2_r, nsample)); + su1[band+nsample] = c2; + su2[band+nsample] = (c1 << 1) - c2; + } + } + + /* Apply the matrix without interpolation. */ + switch (s2) { + case 0: /* M/S decoding */ + for (; nsample < 256; nsample++) { + c1 = su1[band+nsample]; + c2 = su2[band+nsample]; + su1[band+nsample] = c2 << 1; + su2[band+nsample] = (c1 - c2) << 1; + } + break; + + case 1: + for (; nsample < 256; nsample++) { + c1 = su1[band+nsample]; + c2 = su2[band+nsample]; + su1[band+nsample] = (c1 + c2) << 1; + su2[band+nsample] = -1*(c2 << 1); + } + break; + case 2: + case 3: + for (; nsample < 256; nsample++) { + c1 = su1[band+nsample]; + c2 = su2[band+nsample]; + su1[band+nsample] = c1 + c2; + su2[band+nsample] = c1 - c2; + } + break; + default: + /* assert(0) */; + break; + } + } +} + +static void getChannelWeights (int indx, int flag, int32_t ch[2]){ + /* Read channel weights from table */ + if (flag) { + /* Swap channel weights */ + ch[1] = channelWeights0[indx&7]; + ch[0] = channelWeights1[indx&7]; + } else { + ch[0] = channelWeights0[indx&7]; + ch[1] = channelWeights1[indx&7]; + } +} + +static void channelWeighting (int32_t *su1, int32_t *su2, int *p3) +{ + int band, nsample; + /* w[x][y] y=0 is left y=1 is right */ + int32_t w[2][2]; + + if (p3[1] != 7 || p3[3] != 7){ + getChannelWeights(p3[1], p3[0], w[0]); + getChannelWeights(p3[3], p3[2], w[1]); + + for(band = 1; band < 4; band++) { + /* scale the channels by the weights */ + for(nsample = 0; nsample < 8; nsample++) { + su1[band*256+nsample] = fixmul16(su1[band*256+nsample], INTERPOLATE_FP16(w[0][0], w[0][1], nsample)); + su2[band*256+nsample] = fixmul16(su2[band*256+nsample], INTERPOLATE_FP16(w[1][0], w[1][1], nsample)); + } + + for(; nsample < 256; nsample++) { + su1[band*256+nsample] = fixmul16(su1[band*256+nsample], w[1][0]); + su2[band*256+nsample] = fixmul16(su2[band*256+nsample], w[1][1]); + } + } + } +} + +/** + * Decode a Sound Unit + * + * @param gb the GetBit context + * @param pSnd the channel unit to be used + * @param pOut the decoded samples before IQMF + * @param channelNum channel number + * @param codingMode the coding mode (JOINT_STEREO or regular stereo/mono) + */ + +static int decodeChannelSoundUnit (GetBitContext *gb, channel_unit *pSnd, int32_t *pOut, int channelNum, int codingMode) +{ + int band, result=0, numSubbands, lastTonal, numBands; + if (codingMode == JOINT_STEREO && channelNum == 1) { + if (get_bits(gb,2) != 3) { + DEBUGF("JS mono Sound Unit id != 3.\n"); + return -1; + } + } else { + if (get_bits(gb,6) != 0x28) { + DEBUGF("Sound Unit id != 0x28.\n"); + return -1; + } + } + + /* number of coded QMF bands */ + pSnd->bandsCoded = get_bits(gb,2); + + result = decodeGainControl (gb, &(pSnd->gainBlock[pSnd->gcBlkSwitch]), pSnd->bandsCoded); + if (result) return result; + + pSnd->numComponents = decodeTonalComponents (gb, pSnd->components, pSnd->bandsCoded); + if (pSnd->numComponents == -1) return -1; + + numSubbands = decodeSpectrum (gb, pSnd->spectrum); + + /* Merge the decoded spectrum and tonal components. */ + lastTonal = addTonalComponents (pSnd->spectrum, pSnd->numComponents, pSnd->components); + + + /* calculate number of used MLT/QMF bands according to the amount of coded spectral lines */ + numBands = (subbandTab[numSubbands] - 1) >> 8; + if (lastTonal >= 0) + numBands = FFMAX((lastTonal + 256) >> 8, numBands); + + /* Reconstruct time domain samples. */ + for (band=0; band<4; band++) { + /* Perform the IMDCT step without overlapping. */ + if (band <= numBands) { + IMLT(&(pSnd->spectrum[band*256]), pSnd->IMDCT_buf); + } else { + memset(pSnd->IMDCT_buf, 0, 512 * sizeof(int32_t)); + } + + /* gain compensation and overlapping */ + gainCompensateAndOverlap (pSnd->IMDCT_buf, &(pSnd->prevFrame[band*256]), &(pOut[band*256]), + &((pSnd->gainBlock[1 - (pSnd->gcBlkSwitch)]).gBlock[band]), + &((pSnd->gainBlock[pSnd->gcBlkSwitch]).gBlock[band])); + } + + /* Swap the gain control buffers for the next frame. */ + pSnd->gcBlkSwitch ^= 1; + + return 0; +} + +/** + * Frame handling + * + * @param q Atrac3 private context + * @param databuf the input data + */ + +static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf, int off) +{ + int result, i; + int32_t *p1, *p2, *p3, *p4; + uint8_t *ptr1; + + if (q->codingMode == JOINT_STEREO) { + + /* channel coupling mode */ + /* decode Sound Unit 1 */ + init_get_bits(&q->gb,databuf,q->bits_per_frame); + + result = decodeChannelSoundUnit(&q->gb, q->pUnits, q->outSamples, 0, JOINT_STEREO); + if (result != 0) + return (result); + + /* Framedata of the su2 in the joint-stereo mode is encoded in + * reverse byte order so we need to swap it first. */ + if (databuf == q->decoded_bytes_buffer) { + uint8_t *ptr2 = q->decoded_bytes_buffer+q->bytes_per_frame-1; + ptr1 = q->decoded_bytes_buffer; + for (i = 0; i < (q->bytes_per_frame/2); i++, ptr1++, ptr2--) { + FFSWAP(uint8_t,*ptr1,*ptr2); + } + } else { + const uint8_t *ptr2 = databuf+q->bytes_per_frame-1; + for (i = 0; i < q->bytes_per_frame; i++) + q->decoded_bytes_buffer[i] = *ptr2--; + } + + /* Skip the sync codes (0xF8). */ + ptr1 = q->decoded_bytes_buffer; + for (i = 4; *ptr1 == 0xF8; i++, ptr1++) { + if (i >= q->bytes_per_frame) + return -1; + } + + + /* set the bitstream reader at the start of the second Sound Unit*/ + init_get_bits(&q->gb,ptr1,q->bits_per_frame); + + /* Fill the Weighting coeffs delay buffer */ + memmove(q->weighting_delay,&(q->weighting_delay[2]),4*sizeof(int)); + q->weighting_delay[4] = get_bits1(&q->gb); + q->weighting_delay[5] = get_bits(&q->gb,3); + + for (i = 0; i < 4; i++) { + q->matrix_coeff_index_prev[i] = q->matrix_coeff_index_now[i]; + q->matrix_coeff_index_now[i] = q->matrix_coeff_index_next[i]; + q->matrix_coeff_index_next[i] = get_bits(&q->gb,2); + } + + /* Decode Sound Unit 2. */ + result = decodeChannelSoundUnit(&q->gb, &q->pUnits[1], &q->outSamples[1024], 1, JOINT_STEREO); + if (result != 0) + return (result); + + /* Reconstruct the channel coefficients. */ + reverseMatrixing(q->outSamples, &q->outSamples[1024], q->matrix_coeff_index_prev, q->matrix_coeff_index_now); + + channelWeighting(q->outSamples, &q->outSamples[1024], q->weighting_delay); + + } else { + /* normal stereo mode or mono */ + /* Decode the channel sound units. */ + for (i=0 ; ichannels ; i++) { + + /* Set the bitstream reader at the start of a channel sound unit. */ + init_get_bits(&q->gb, databuf+((i*q->bytes_per_frame)/q->channels)+off, (q->bits_per_frame)/q->channels); + + result = decodeChannelSoundUnit(&q->gb, &q->pUnits[i], &q->outSamples[i*1024], i, q->codingMode); + if (result != 0) + return (result); + } + } + + /* Apply the iQMF synthesis filter. */ + p1= q->outSamples; + for (i=0 ; ichannels ; i++) { + p2= p1+256; + p3= p2+256; + p4= p3+256; + iqmf (p1, p2, 256, p1, q->pUnits[i].delayBuf1, q->tempBuf); + iqmf (p4, p3, 256, p3, q->pUnits[i].delayBuf2, q->tempBuf); + iqmf (p1, p3, 512, p1, q->pUnits[i].delayBuf3, q->tempBuf); + p1 +=1024; + } + + return 0; +} + + +/** + * Atrac frame decoding + * + * @param rmctx pointer to the AVCodecContext + */ + +int atrac3_decode_frame(unsigned long block_align, ATRAC3Context *q, + int *data_size, const uint8_t *buf, int buf_size) { + int result = 0, off = 0; + const uint8_t* databuf; + + if ((unsigned)buf_size < block_align) + return buf_size; + + /* Check if we need to descramble and what buffer to pass on. */ + if (q->scrambled_stream) { + off = decode_bytes(buf, q->decoded_bytes_buffer, block_align); + databuf = q->decoded_bytes_buffer; + } else { + databuf = buf; + } + + result = decodeFrame(q, databuf, off); + + if (result != 0) { + DEBUGF("Frame decoding error!\n"); + return -1; + } + + if (q->channels == 1) + *data_size = 1024 * sizeof(int32_t); + else + *data_size = 2048 * sizeof(int32_t); + + return block_align; +} + + +/** + * Atrac3 initialization + * + * @param rmctx pointer to the RMContext + */ +int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3) +{ + int i; + uint8_t *edata_ptr = (uint8_t*)&id3->id3v2buf; + +#if defined(CPU_COLDFIRE) + coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE); +#endif + + /* Take data from the RM container. */ + q->sample_rate = id3->frequency; + q->channels = id3->channels; + q->bit_rate = id3->bitrate * 1000; + q->bits_per_frame = id3->bytesperframe * 8; + q->bytes_per_frame = id3->bytesperframe; + + /* Take care of the codec-specific extradata. */ + + if (id3->extradata_size == 14) { + /* Parse the extradata, WAV format */ + DEBUGF("[0-1] %d\n",rm_get_uint16le(&edata_ptr[0])); /* Unknown value always 1 */ + q->samples_per_channel = rm_get_uint32le(&edata_ptr[2]); + q->codingMode = rm_get_uint16le(&edata_ptr[6]); + DEBUGF("[8-9] %d\n",rm_get_uint16le(&edata_ptr[8])); /* Dupe of coding mode */ + q->frame_factor = rm_get_uint16le(&edata_ptr[10]); /* Unknown always 1 */ + DEBUGF("[12-13] %d\n",rm_get_uint16le(&edata_ptr[12])); /* Unknown always 0 */ + + /* setup */ + q->samples_per_frame = 1024 * q->channels; + q->atrac3version = 4; + q->delay = 0x88E; + if (q->codingMode) + q->codingMode = JOINT_STEREO; + else + q->codingMode = STEREO; + q->scrambled_stream = 0; + + if ((q->bytes_per_frame == 96*q->channels*q->frame_factor) || (q->bytes_per_frame == 152*q->channels*q->frame_factor) || (q->bytes_per_frame == 192*q->channels*q->frame_factor)) { + } else { + DEBUGF("Unknown frame/channel/frame_factor configuration %d/%d/%d\n", q->bytes_per_frame, q->channels, q->frame_factor); + return -1; + } + + } else if (id3->extradata_size == 10) { + /* Parse the extradata, RM format. */ + q->atrac3version = rm_get_uint32be(&edata_ptr[0]); + q->samples_per_frame = rm_get_uint16be(&edata_ptr[4]); + q->delay = rm_get_uint16be(&edata_ptr[6]); + q->codingMode = rm_get_uint16be(&edata_ptr[8]); + + q->samples_per_channel = q->samples_per_frame / q->channels; + q->scrambled_stream = 1; + + } else { + DEBUGF("Unknown extradata size %d.\n",id3->extradata_size); + } + /* Check the extradata. */ + + if (q->atrac3version != 4) { + DEBUGF("Version %d != 4.\n",q->atrac3version); + return -1; + } + + if (q->samples_per_frame != 1024 && q->samples_per_frame != 2048) { + DEBUGF("Unknown amount of samples per frame %d.\n",q->samples_per_frame); + return -1; + } + + if (q->delay != 0x88E) { + DEBUGF("Unknown amount of delay %x != 0x88E.\n",q->delay); + return -1; + } + + if (q->codingMode == STEREO) { + DEBUGF("Normal stereo detected.\n"); + } else if (q->codingMode == JOINT_STEREO) { + DEBUGF("Joint stereo detected.\n"); + } else { + DEBUGF("Unknown channel coding mode %x!\n",q->codingMode); + return -1; + } + + if (id3->channels <= 0 || id3->channels > 2 ) { + DEBUGF("Channel configuration error!\n"); + return -1; + } + + + if(id3->bytesperframe >= UINT16_MAX/2) + return -1; + + + /* Initialize the VLC tables. */ + if (!vlcs_initialized) { + for (i=0 ; i<7 ; i++) { + spectral_coeff_tab[i].table = &atrac3_vlc_table[atrac3_vlc_offs[i]]; + spectral_coeff_tab[i].table_allocated = atrac3_vlc_offs[i + 1] - atrac3_vlc_offs[i]; + init_vlc (&spectral_coeff_tab[i], 9, huff_tab_sizes[i], + huff_bits[i], 1, 1, + huff_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + } + + vlcs_initialized = 1; + + } + + init_atrac3_transforms(); + + /* init the joint-stereo decoding data */ + q->weighting_delay[0] = 0; + q->weighting_delay[1] = 7; + q->weighting_delay[2] = 0; + q->weighting_delay[3] = 7; + q->weighting_delay[4] = 0; + q->weighting_delay[5] = 7; + + for (i=0; i<4; i++) { + q->matrix_coeff_index_prev[i] = 3; + q->matrix_coeff_index_now[i] = 3; + q->matrix_coeff_index_next[i] = 3; + } + + /* Link the iram'ed arrays to the decoder's data structure */ + q->pUnits = channel_units; + q->pUnits[0].spectrum = &atrac3_spectrum [0][0]; + q->pUnits[1].spectrum = &atrac3_spectrum [1][0]; + q->pUnits[0].IMDCT_buf = &atrac3_IMDCT_buf[0][0]; + q->pUnits[1].IMDCT_buf = &atrac3_IMDCT_buf[1][0]; + q->pUnits[0].prevFrame = &atrac3_prevFrame[0][0]; + q->pUnits[1].prevFrame = &atrac3_prevFrame[1][0]; + + return 0; +} + diff --git a/lib/rbcodec/codecs/libatrac/atrac3.h b/lib/rbcodec/codecs/libatrac/atrac3.h new file mode 100644 index 0000000000..64086b6411 --- /dev/null +++ b/lib/rbcodec/codecs/libatrac/atrac3.h @@ -0,0 +1,114 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 Mohamed Tarek + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "ffmpeg_get_bits.h" +#include "../librm/rm.h" +#include "codeclib.h" + +#if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || \ + (CONFIG_CPU == MCF5250) || defined(CPU_S5L870X) +/* PP5022/24, MCF5250 and S5L870x have larger IRAM */ +#define IBSS_ATTR_LARGE_IRAM IBSS_ATTR +#define ICODE_ATTR_LARGE_IRAM ICODE_ATTR +#define ICONST_ATTR_LARGE_IRAM ICONST_ATTR +#else +/* other CPUs IRAM is not large enough */ +#define IBSS_ATTR_LARGE_IRAM +#define ICODE_ATTR_LARGE_IRAM +#define ICONST_ATTR_LARGE_IRAM +#endif + +/* These structures are needed to store the parsed gain control data. */ +typedef struct { + int num_gain_data; + int levcode[8]; + int loccode[8]; +} gain_info; + +typedef struct { + gain_info gBlock[4]; +} gain_block; + +typedef struct { + int pos; + int numCoefs; + int32_t coef[8]; +} tonal_component; + +typedef struct { + int bandsCoded; + int numComponents; + tonal_component components[64]; + int32_t *prevFrame; + int gcBlkSwitch; + gain_block gainBlock[2]; + + int32_t *spectrum; + int32_t *IMDCT_buf; + + int32_t delayBuf1[46] MEM_ALIGN_ATTR; /// ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: + * + * Copyright (C) 2009 by Andree Buschmann + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" + + .section .text, "ax", %progbits + +/**************************************************************************** + * void atrac3_iqmf_matrixing(int32_t *dest, + * int32_t *inlo, + * int32_t *inhi, + * unsigned int count); + * + * Matrixing step within iqmf of atrac3 synthesis. Reference implementation: + * + * for(i=0; i>31 || hi<<1 */ + mov r12, r12, lsr #31 + orr r8, r12, r8, lsl #1 /* s2 = low>>31 || hi<<1 */ + + stmia r0!, {r8, r9} /* store result out[0]=s2, out[1]=s1 */ + sub r1, r1, #184 /* roll back 64 entries = 184 bytes */ + sub r2, r2, #192 /* roll back 48 entries = 192 bytes = win[0] */ + + subs r3, r3, #1 /* outer loop -= 1 */ + bgt .iqmf_dewindow_outer_loop + + ldmpc regs=r4-r9 /* restore registers */ + +.atrac3_iqmf_dewindowing_end: + .size atrac3_iqmf_dewindowing,.atrac3_iqmf_dewindowing_end-atrac3_iqmf_dewindowing diff --git a/lib/rbcodec/codecs/libatrac/atrac3_armv5e.S b/lib/rbcodec/codecs/libatrac/atrac3_armv5e.S new file mode 100644 index 0000000000..1d9d35a5da --- /dev/null +++ b/lib/rbcodec/codecs/libatrac/atrac3_armv5e.S @@ -0,0 +1,163 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: + * + * Copyright (C) 2010 by Michael Giacomelli + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" + + .section .text, "ax", %progbits + + +/**************************************************************************** + * atrac3_iqmf_dewindowing_armv5e(int32_t *out, + * int32_t *in, + * int32_t *win, + * unsigned int nIn); + * + * Dewindowing step within iqmf of atrac3 synthesis using 16 bit filter + * coefficients and armv5e packed multiply instructions. Uses 2.5 cycles + * per filter coefficient (ideal). Benchmarked 3.54 per coefficient (Clip+). + * + * Reference implementation: + * + * for (j = nIn; j != 0; j--) { + * s1 = fixmul32(in[0], win[0]); + * s2 = fixmul32(in[1], win[1]); + * for (i = 2; i < 48; i += 2) { + * s1 += fixmul32(in[i ], win[i ]); + * s2 += fixmul32(in[i+1], win[i+1]); + * } + * out[0] = s2 << 1; + * out[1] = s1 << 1; + * in += 2; + * out += 2; + * } + * Note: r12 is a scratch register and can be used without restorage. + ****************************************************************************/ + .align 2 + .global atrac3_iqmf_dewindowing_armv5e + .type atrac3_iqmf_dewindowing_armv5e, %function + +atrac3_iqmf_dewindowing_armv5e: + /* r0 = dest */ + /* r1 = input samples */ + /* r2 = window coefficients */ + /* r3 = counter */ + stmfd sp!, {r4-r11, lr} /* save non-scratch registers */ + +.iqmf_dewindow_outer_loop: /* outer loop 0...counter-1 */ + /* 0.. 7 */ + ldmia r2!, {r4, r5, r8, r9} /* load win[0..7] */ + ldmia r1!, {r6, r7, r10, r11} /* load in[0..3] to avoid stall on arm11 */ + smulwb lr, r6, r4 /* s1 = in[0] * win[0] */ + smulwt r12, r7, r4 /* s2 = in[1] * win[1] */ + smlawb lr, r10, r5, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r11,r5, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + + ldmia r1!, {r6, r7, r10, r11} /* load in[i...i+3] */ + smlawb lr, r6, r8, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r7, r8, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + smlawb lr, r10, r9, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r11, r9, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + + /* 8..15 */ + ldmia r2!, {r4, r5, r8, r9} /* load win[8..15] */ + ldmia r1!, {r6, r7, r10, r11} /* load in[i...i+3] */ + smlawb lr, r6, r4, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r7, r4, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + smlawb lr, r10, r5, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r11,r5, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + + ldmia r1!, {r6, r7, r10, r11} /* load in[i...i+3] */ + smlawb lr, r6, r8, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r7, r8, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + smlawb lr, r10, r9, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r11,r9, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + + /* 16..23 */ + ldmia r2!, {r4, r5, r8, r9} /* load win[16..23] */ + ldmia r1!, {r6, r7, r10, r11} /* load in[i...i+3] */ + smlawb lr, r6, r4, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r7, r4, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + smlawb lr, r10, r5, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r11,r5, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + + ldmia r1!, {r6, r7, r10, r11} /* load in[i...i+3] */ + smlawb lr, r6, r8, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r7, r8, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + smlawb lr, r10, r9, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r11,r9, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + + /* 24..31 */ + ldmia r2!, {r4, r5, r8, r9} /* load win[24..31] */ + ldmia r1!, {r6, r7, r10, r11} /* load in[i...i+3] */ + smlawb lr, r6, r4, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r7, r4, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + smlawb lr, r10, r5, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r11,r5, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + + ldmia r1!, {r6, r7, r10, r11} /* load in[i...i+3] */ + smlawb lr, r6, r8, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r7, r8, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + smlawb lr, r10, r9, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r11,r9, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + + /* 32..39 */ + ldmia r2!, {r4, r5, r8, r9} /* load win[32..39] */ + ldmia r1!, {r6, r7, r10, r11} /* load in[i...i+3] */ + smlawb lr, r6, r4, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r7, r4, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + smlawb lr, r10, r5, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r11,r5, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + + ldmia r1!, {r6, r7, r10, r11} /* load in[i...i+3] */ + smlawb lr, r6, r8, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r7, r8, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + smlawb lr, r10, r9, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r11,r9, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + + /* 40..47 */ + ldmia r2!, {r4, r5, r8, r9} /* load win[40..47] */ + ldmia r1!, {r6, r7, r10, r11} /* load in[i...i+3] */ + smlawb lr, r6, r4, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r7, r4, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + smlawb lr, r10, r5, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r11,r5, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + + ldmia r1!, {r6, r7, r10, r11} /* load in[i...i+3] */ + smlawb lr, r6, r8, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r7, r8, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + smlawb lr, r10, r9, lr /* s1 += in[i ] * win[i ] >> 16 */ + smlawt r12, r11,r9, r12 /* s2 += in[i+1] * win[i+1] >> 16 */ + + + mov lr , lr , lsl #1 + mov r12, r12, lsl #1 + + stmia r0!, {r12, lr} /* store result out[0]=s2, out[1]=s1 */ + sub r1, r1, #184 /* roll back 64 entries = 184 bytes */ + sub r2, r2, #96 /* roll back 48 entries * 2 bytes = 96 bytes = win[0] */ + + subs r3, r3, #1 /* outer loop -= 1 */ + bgt .iqmf_dewindow_outer_loop + + ldmpc regs=r4-r11 /* restore registers */ + +.atrac3_iqmf_dewindowing_armv5e_end: + .size atrac3_iqmf_dewindowing_armv5e,.atrac3_iqmf_dewindowing_armv5e_end-atrac3_iqmf_dewindowing_armv5e diff --git a/lib/rbcodec/codecs/libatrac/atrac3data.h b/lib/rbcodec/codecs/libatrac/atrac3data.h new file mode 100644 index 0000000000..30abb37572 --- /dev/null +++ b/lib/rbcodec/codecs/libatrac/atrac3data.h @@ -0,0 +1,148 @@ +/* + * Atrac 3 compatible decoder data + * Copyright (c) 2006-2007 Maxim Poliakovski + * Copyright (c) 2006-2007 Benjamin Larsson + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file libavcodec/atrac3data.h + * Atrac 3 AKA RealAudio 8 compatible decoder data + */ + +#ifndef AVCODEC_ATRAC3DATA_H +#define AVCODEC_ATRAC3DATA_H + +#include + +/* VLC tables */ + +static const uint8_t huffcode1[9] ICONST_ATTR_LARGE_IRAM = { + 0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F, +}; + +static const uint8_t huffbits1[9] ICONST_ATTR_LARGE_IRAM = { + 1,3,3,4,4,5,5,5,5, +}; + +static const uint8_t huffcode2[5] ICONST_ATTR_LARGE_IRAM = { + 0x0,0x4,0x5,0x6,0x7, +}; + +static const uint8_t huffbits2[5] ICONST_ATTR_LARGE_IRAM = { + 1,3,3,3,3, +}; + +static const uint8_t huffcode3[7] ICONST_ATTR_LARGE_IRAM = { +0x0,0x4,0x5,0xC,0xD,0xE,0xF, +}; + +static const uint8_t huffbits3[7] ICONST_ATTR_LARGE_IRAM = { + 1,3,3,4,4,4,4, +}; + +static const uint8_t huffcode4[9] ICONST_ATTR_LARGE_IRAM = { + 0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F, +}; + +static const uint8_t huffbits4[9] ICONST_ATTR_LARGE_IRAM = { + 1,3,3,4,4,5,5,5,5, +}; + +static const uint8_t huffcode5[15] ICONST_ATTR_LARGE_IRAM = { + 0x0,0x2,0x3,0x8,0x9,0xA,0xB,0x1C,0x1D,0x3C,0x3D,0x3E,0x3F,0xC,0xD, +}; + +static const uint8_t huffbits5[15] ICONST_ATTR_LARGE_IRAM = { + 2,3,3,4,4,4,4,5,5,6,6,6,6,4,4 +}; + +static const uint8_t huffcode6[31] ICONST_ATTR_LARGE_IRAM = { + 0x0,0x2,0x3,0x4,0x5,0x6,0x7,0x14,0x15,0x16,0x17,0x18,0x19,0x34,0x35, + 0x36,0x37,0x38,0x39,0x3A,0x3B,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,0x8,0x9, +}; + +static const uint8_t huffbits6[31] ICONST_ATTR_LARGE_IRAM = { + 3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,4,4 +}; + +static const uint8_t huffcode7[63] ICONST_ATTR_LARGE_IRAM = { + 0x0,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x24,0x25,0x26,0x27,0x28, + 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x68,0x69,0x6A,0x6B,0x6C, + 0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2, + 0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x2,0x3, +}; + +static const uint8_t huffbits7[63] ICONST_ATTR_LARGE_IRAM = { + 3,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,4,4 +}; + +static const uint8_t huff_tab_sizes[7] ICONST_ATTR_LARGE_IRAM = { + 9, 5, 7, 9, 15, 31, 63, +}; + +static const uint8_t* const huff_codes[7] ICONST_ATTR_LARGE_IRAM = { + huffcode1,huffcode2,huffcode3,huffcode4,huffcode5,huffcode6,huffcode7, +}; + +static const uint8_t* const huff_bits[7] ICONST_ATTR_LARGE_IRAM = { + huffbits1,huffbits2,huffbits3,huffbits4,huffbits5,huffbits6,huffbits7, +}; + +static const uint16_t atrac3_vlc_offs[] ICONST_ATTR_LARGE_IRAM = { + 0,512,1024,1536,2048,2560,3072,3584,4096 +}; + +/* selector tables */ + +static const uint8_t CLCLengthTab[8] ICONST_ATTR_LARGE_IRAM = { + 0, 4, 3, 3, 4, 4, 5, 6}; +static const int8_t seTab_0[4] ICONST_ATTR_LARGE_IRAM = { + 0, 1, -2, -1}; +static const int8_t decTable1[18] ICONST_ATTR_LARGE_IRAM = { + 0,0, 0,1, 0,-1, 1,0, -1,0, 1,1, 1,-1, -1,1, -1,-1}; + + +/* tables for the scalefactor decoding */ +/* not needed anymore +static const float iMaxQuant[8] = { + 0.0, 1.0/1.5, 1.0/2.5, 1.0/3.5, 1.0/4.5, 1.0/7.5, 1.0/15.5, 1.0/31.5 +}; +*/ +static const uint16_t subbandTab[33] ICONST_ATTR_LARGE_IRAM = { + 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, + 256, 288, 320, 352, 384, 416, 448, 480, 512, 576, 640, 704, 768, 896, 1024 +}; + +/* transform data */ +/* not needed anymore +static const float qmf_48tap_half[24] = { + -0.00001461907, -0.00009205479, -0.000056157569, 0.00030117269, + 0.0002422519,-0.00085293897, -0.0005205574, 0.0020340169, + 0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944, + -0.000061169922, -0.01344162, 0.0024626821, 0.021736089, + -0.007801671, -0.034090221, 0.01880949, 0.054326009, + -0.043596379, -0.099384367, 0.13207909, 0.46424159 +}; +*/ +/* joint stereo related tables */ +/* not needed anymore +static const float matrixCoeffs[8] = {0.0, 2.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0}; +*/ +#endif /* AVCODEC_ATRAC3DATA_H */ diff --git a/lib/rbcodec/codecs/libatrac/atrac3data_fixed.h b/lib/rbcodec/codecs/libatrac/atrac3data_fixed.h new file mode 100644 index 0000000000..9eb79731ce --- /dev/null +++ b/lib/rbcodec/codecs/libatrac/atrac3data_fixed.h @@ -0,0 +1,108 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 Michael Giacomelli + * Copyright (C) 2009 Mohamed Tarek + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +/* tables for the scalefactor decoding */ +/* scaled by 2^31*/ +static const int32_t iMaxQuant_fix[8] ICONST_ATTR = { + 0x0, 0x55555580, 0x33333340, 0x24924940, 0x1c71c720, 0x11111120, 0x8421080, + 0x4104108 +}; + +/* scaled by 2^16 */ +static const int32_t SFTable_fixed[64] ICONST_ATTR = { + 0x00000800, 0x00000a14, 0x00000cb3, 0x00001000, 0x00001429, 0x00001966, + 0x00002000, 0x00002851, 0x000032cc, 0x00004000, 0x000050a3, 0x00006598, + 0x00008000, 0x0000a145, 0x0000cb30, 0x00010000, 0x0001428a, 0x00019660, + 0x00020000, 0x00028514, 0x00032cc0, 0x00040000, 0x00050a29, 0x00065980, + 0x00080000, 0x000a1452, 0x000cb2ff, 0x00100000, 0x001428a3, 0x001965ff, + 0x00200000, 0x00285146, 0x0032cbfd, 0x00400000, 0x0050a28c, 0x006597fb, + 0x00800000, 0x00a14518, 0x00cb2ff5, 0x01000000, 0x01428a30, 0x01965fea, + 0x02000000, 0x02851460, 0x032cbfd4, 0x04000000, 0x050a28c0, 0x06597fa8, + 0x08000000, 0x0a145180, 0x0cb2ff50, 0x10000000, 0x1428a300, 0x1965fea0, + 0x20000000, 0x28514600, 0x32cbfd40, 0x40000000, 0x50a28c00, 0x6597fa80, + 0x80000000, 0x80000000, 0x80000000, 0x80000000, +}; + +/* transform data */ +/* floating point values scaled by 2^31 */ +static const int32_t qmf_48tap_half_fix[24] = { + 0xffff855e, 0xfffcfbca, 0xfffe28eb, 0x0009de6b, 0x0007f028, 0xffe40d08, + 0xffeef140, 0x0042a692, 0x0019ab1f, 0xff75dec7, 0xffe738f5, 0x0100e928, + 0xfffdfedf, 0xfe478b84, 0x0050b279, 0x02c83f88, 0xff005ad7, 0xfba2ee80, + 0x02685970, 0x06f42798, 0xfa6b6f10, 0xf3475f80, 0x10e7f7c0, 0x3b6c44c0 +}; + +/* mdct window scaled by 2^31 */ +/* Remark: The preceding sign corrects the sign of the hexadecimal values */ +static const int32_t window_lookup[128] ICONST_ATTR MEM_ALIGN_ATTR = { + -0xffffb10c, -0xfffd394b, -0xfff8494f, -0xfff0e025, -0xffe6fc5f, -0xffda9c15, + -0xffcbbce6, -0xffba5bf4, -0xffa675e8, -0xff9006f0, -0xff770aba, -0xff5b7c7e, + -0xff3d56f2, -0xff1c9452, -0xfef92e59, -0xfed31e45, -0xfeaa5cd5, -0xfe7ee247, + -0xfe50a657, -0xfe1fa041, -0xfdebc6c1, -0xfdb5100d, -0xfd7b71d5, -0xfd3ee149, + -0xfcff5311, -0xfcbcbb49, -0xfc770d99, -0xfc2e3d15, -0xfbe23c39, -0xfb92fd29, + -0xfb407141, -0xfaea8989, -0xfa913661, -0xfa3467b1, -0xf9d40cd9, -0xf9701499, + -0xf9086d41, -0xf89d04a9, -0xf82dc7f1, -0xf7baa3e1, -0xf74384b1, -0xf6c85611, + -0xf6490321, -0xf5c576b1, -0xf53d9b21, -0xf4b15a01, -0xf4209ce1, -0xf38b4c71, + -0xf2f15171, -0xf2529411, -0xf1aefbf1, -0xf10670a1, -0xf058d941, -0xefa61cc1, + -0xeeee21c1, -0xee30cec1, -0xed6e0a41, -0xeca5ba61, -0xebd7c5c1, -0xeb041241, + -0xea2a8601, -0xe94b0861, -0xe8657f61, -0xe779d241, -0xe687e861, -0xe58fa9e1, + -0xe490fec1, -0xe38bd101, -0xe28009c1, -0xe16d93e1, -0xe0545ba1, -0xdf344dc1, + -0xde0d5881, -0xdcdf6bc1, -0xdbaa7801, -0xda6e70c1, -0xd92b4ac1, -0xd7e0fc81, + -0xd68f7ec1, -0xd536cd41, -0xd3d6e5c1, -0xd26fc901, -0xd10179c1, -0xcf8bff41, + -0xce0f6301, -0xcc8bb241, -0xcb00fdc1, -0xc96f5b01, -0xc7d6e141, -0xc637af41, + -0xc491e4c1, -0xc2e5a801, -0xc1332401, -0xbf7a8701, -0xbdbc0681, -0xbbf7da01, + -0xba2e4181, -0xb85f7f81, -0xb68bde01, -0xb4b3a981, -0xb2d73781, -0xb0f6df01, + -0xaf12ff01, -0xad2bfa81, -0xab423981, -0xa9562981, -0xa7683c01, -0xa578e701, + -0xa388a681, -0xa197f801, -0x9fa75e81, -0x9db75f01, -0x9bc88201, -0x99db5301, + -0x97f06001, -0x96083601, -0x94236601, -0x92427f81, -0x90661481, -0x8e8eb481, + -0x8cbced01, -0x8af14d81, -0x892c5f81, -0x876eab01, -0x85b8b681, -0x840b0301, + -0x82660c01, -0x80ca4a01, +}; + +/* Gain tables scaled by 2^16 */ +static const int32_t gain_tab2[31] ICONST_ATTR = { + 0x0003ab03, 0x00035d14, 0x0003159d, 0x0002d414, 0x000297fb, 0x000260e0, + 0x00022e57, 0x00020000, 0x0001d582, 0x0001ae8a, 0x00018ace, 0x00016a0a, + 0x00014bfe, 0x00013070, 0x0001172c, 0x00010000, 0x0000eac1, 0x0000d745, + 0x0000c567, 0x0000b505, 0x0000a5ff, 0x00009838, 0x00008b96, 0x00008000, + 0x00007560, 0x00006ba2, 0x000062b4, 0x00005a82, 0x000052ff, 0x00004c1c, + 0x000045cb, + +}; + +/* Joint-Stereo related tables, scaled by 2^16 */ +static const int32_t matrixCoeffs_fix[8] ICONST_ATTR = { + 0x00000000, 0x00020000, 0x00020000, 0x00020000, + 0x00000000, 0x00000000, 0x00010000, 0x00010000, +}; + +/* channelWeights0[i] = ONE_16 * ((i & 7)/7) */ +static const int32_t channelWeights0[8] = { + 0x00000000, 0x00002492, 0x00004925, 0x00006DB7, + 0x00009249, 0x0000B6DB, 0x0000DB6D, 0x00010000, +}; + +/* channelWeights1[i] = ONE_16 * sqrt(2-channelWeights0^2) */ +static const int32_t channelWeights1[8] = { + 0x00016A0A, 0x00016830, 0x00016293, 0x00015904, + 0x00014B2B, 0x00013877, 0x00011FF7, 0x00010000, +}; + diff --git a/lib/rbcodec/codecs/libatrac/fixp_math.h b/lib/rbcodec/codecs/libatrac/fixp_math.h new file mode 100644 index 0000000000..014c5aa559 --- /dev/null +++ b/lib/rbcodec/codecs/libatrac/fixp_math.h @@ -0,0 +1,111 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 Mohamed Tarek + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include +#include + +/* Macros for converting between various fixed-point representations and floating point. */ +#define ONE_16 (1L << 16) +#define fixtof64(x) (float)((float)(x) / (float)(1 << 16)) //does not work on int64_t! +#define ftofix32(x) ((int32_t)((x) * (float)(1 << 16) + ((x) < 0 ? -0.5 : 0.5))) +#define ftofix31(x) ((int32_t)((x) * (float)(1 << 31) + ((x) < 0 ? -0.5 : 0.5))) +#define fix31tof64(x) (float)((float)(x) / (float)(1 << 31)) + +/* Fixed point math routines for use in atrac3.c */ + +#if defined(CPU_ARM) + /* Calculates: result = (X*Y)>>16 */ + #define fixmul16(X,Y) \ + ({ \ + int32_t lo; \ + int32_t hi; \ + asm volatile ( \ + "smull %[lo], %[hi], %[x], %[y] \n\t" /* multiply */ \ + "mov %[lo], %[lo], lsr #16 \n\t" /* lo >>= 16 */ \ + "orr %[lo], %[lo], %[hi], lsl #16" /* lo |= (hi << 16) */ \ + : [lo]"=&r"(lo), [hi]"=&r"(hi) \ + : [x]"r"(X), [y]"r"(Y)); \ + lo; \ + }) + + /* Calculates: result = (X*Y)>>31 */ + /* Use scratch register r12 */ + #define fixmul31(X,Y) \ + ({ \ + int32_t lo; \ + int32_t hi; \ + asm volatile ( \ + "smull %[lo], %[hi], %[x], %[y] \n\t" /* multiply */ \ + "mov %[lo], %[lo], lsr #31 \n\t" /* lo >>= 31 */ \ + "orr %[lo], %[lo], %[hi], lsl #1" /* lo |= (hi << 1) */ \ + : [lo]"=&r"(lo), [hi]"=&r"(hi) \ + : [x]"r"(X), [y]"r"(Y)); \ + lo; \ + }) +#elif defined(CPU_COLDFIRE) + /* Calculates: result = (X*Y)>>16 */ + #define fixmul16(X,Y) \ + ({ \ + int32_t t, x = (X); \ + asm volatile ( \ + "mac.l %[x],%[y],%%acc0\n\t" /* multiply */ \ + "mulu.l %[y],%[x] \n\t" /* get lower half, avoid emac stall */ \ + "movclr.l %%acc0,%[t] \n\t" /* get higher half */ \ + "lsr.l #1,%[t] \n\t" /* hi >>= 1 to compensate emac shift */ \ + "move.w %[t],%[x] \n\t" /* combine halfwords */\ + "swap %[x] \n\t" \ + : [t]"=&d"(t), [x] "+d" (x) \ + : [y] "d" ((Y))); \ + x; \ + }) + + #define fixmul31(X,Y) \ + ({ \ + int32_t t; \ + asm volatile ( \ + "mac.l %[x], %[y], %%acc0\n\t" /* multiply */ \ + "movclr.l %%acc0, %[t]\n\t" /* get higher half as result */ \ + : [t] "=d" (t) \ + : [x] "r" ((X)), [y] "r" ((Y))); \ + t; \ + }) +#else + static inline int32_t fixmul16(int32_t x, int32_t y) + { + int64_t temp; + temp = x; + temp *= y; + + temp >>= 16; + + return (int32_t)temp; + } + + static inline int32_t fixmul31(int32_t x, int32_t y) + { + int64_t temp; + temp = x; + temp *= y; + + temp >>= 31; //16+31-16 = 31 bits + + return (int32_t)temp; + } +#endif diff --git a/lib/rbcodec/codecs/libatrac/libatrac.make b/lib/rbcodec/codecs/libatrac/libatrac.make new file mode 100644 index 0000000000..69a66eb6f5 --- /dev/null +++ b/lib/rbcodec/codecs/libatrac/libatrac.make @@ -0,0 +1,18 @@ +# __________ __ ___. +# Open \______ \ ____ ____ | | _\_ |__ _______ ___ +# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +# \/ \/ \/ \/ \/ +# $Id: libatrac.make 20151 2009-03-01 09:04:15Z amiconn $ +# + +# libatrac +ATRACLIB := $(CODECDIR)/libatrac.a +ATRACLIB_SRC := $(call preprocess, $(RBCODECLIB_DIR)/codecs/libatrac/SOURCES) +ATRACLIB_OBJ := $(call c2obj, $(ATRACLIB_SRC)) +OTHER_SRC += $(ATRACLIB_SRC) + +$(ATRACLIB): $(ATRACLIB_OBJ) + $(SILENT)$(shell rm -f $@) + $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null -- cgit v1.2.3