audio/mp3: Move IMDCT_Win to Go

This commit is contained in:
Hajime Hoshi 2017-06-14 01:36:49 +09:00
parent b3e3adb9f0
commit 49c95eb69f
3 changed files with 272 additions and 216 deletions

267
audio/mp3/imdct.go Normal file
View File

@ -0,0 +1,267 @@
// Copyright 2017 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build !js
package mp3
// #include "pdmp3.h"
//
// static float getFloatFromArray(float* arr, int index) {
// return arr[index];
// }
//
// static void setFloatToArray(float* arr, int index, float value) {
// arr[index] = value;
// }
import "C"
var imdctWin = [4][36]float32{
{
0.043619, 0.130526, 0.216440, 0.300706, 0.382683, 0.461749,
0.537300, 0.608761, 0.675590, 0.737277, 0.793353, 0.843391,
0.887011, 0.923880, 0.953717, 0.976296, 0.991445, 0.999048,
0.999048, 0.991445, 0.976296, 0.953717, 0.923879, 0.887011,
0.843391, 0.793353, 0.737277, 0.675590, 0.608761, 0.537299,
0.461748, 0.382683, 0.300706, 0.216439, 0.130526, 0.043619,
},
{
0.043619, 0.130526, 0.216440, 0.300706, 0.382683, 0.461749,
0.537300, 0.608761, 0.675590, 0.737277, 0.793353, 0.843391,
0.887011, 0.923880, 0.953717, 0.976296, 0.991445, 0.999048,
1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
0.991445, 0.923880, 0.793353, 0.608761, 0.382683, 0.130526,
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
},
{
0.130526, 0.382683, 0.608761, 0.793353, 0.923880, 0.991445,
0.991445, 0.923880, 0.793353, 0.608761, 0.382683, 0.130526,
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
},
{
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
0.130526, 0.382683, 0.608761, 0.793353, 0.923880, 0.991445,
1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
0.999048, 0.991445, 0.976296, 0.953717, 0.923879, 0.887011,
0.843391, 0.793353, 0.737277, 0.675590, 0.608761, 0.537299,
0.461748, 0.382683, 0.300706, 0.216439, 0.130526, 0.043619,
},
}
var cos_N12 = [6][12]float32{
{
0.608761, 0.382683, 0.130526, -0.130526, -0.382683, -0.608761,
-0.793353, -0.923880, -0.991445, -0.991445, -0.923879, -0.793353,
},
{
-0.923880, -0.923879, -0.382683, 0.382684, 0.923880, 0.923879,
0.382683, -0.382684, -0.923880, -0.923879, -0.382683, 0.382684,
},
{
-0.130526, 0.923880, 0.608761, -0.608762, -0.923879, 0.130526,
0.991445, 0.382683, -0.793354, -0.793353, 0.382684, 0.991445,
},
{
0.991445, -0.382684, -0.793353, 0.793354, 0.382683, -0.991445,
0.130527, 0.923879, -0.608762, -0.608761, 0.923880, 0.130525,
},
{
-0.382684, -0.382683, 0.923879, -0.923880, 0.382684, 0.382683,
-0.923879, 0.923880, -0.382684, -0.382683, 0.923879, -0.923880,
},
{
-0.793353, 0.923879, -0.991445, 0.991445, -0.923880, 0.793354,
-0.608762, 0.382684, -0.130527, -0.130525, 0.382682, -0.608761,
},
}
var cos_N36 = [18][36]float32{
{
0.675590, 0.608761, 0.537300, 0.461749, 0.382683, 0.300706,
0.216440, 0.130526, 0.043619, -0.043619, -0.130526, -0.216440,
-0.300706, -0.382684, -0.461749, -0.537300, -0.608762, -0.675590,
-0.737277, -0.793353, -0.843392, -0.887011, -0.923880, -0.953717,
-0.976296, -0.991445, -0.999048, -0.999048, -0.991445, -0.976296,
-0.953717, -0.923879, -0.887011, -0.843391, -0.793353, -0.737277,
},
{
-0.793353, -0.923880, -0.991445, -0.991445, -0.923879, -0.793353,
-0.608761, -0.382683, -0.130526, 0.130526, 0.382684, 0.608762,
0.793354, 0.923880, 0.991445, 0.991445, 0.923879, 0.793353,
0.608761, 0.382683, 0.130526, -0.130527, -0.382684, -0.608762,
-0.793354, -0.923880, -0.991445, -0.991445, -0.923879, -0.793353,
-0.608761, -0.382683, -0.130526, 0.130527, 0.382684, 0.608762,
},
{
-0.537299, -0.130526, 0.300706, 0.675590, 0.923880, 0.999048,
0.887011, 0.608761, 0.216439, -0.216440, -0.608762, -0.887011,
-0.999048, -0.923879, -0.675590, -0.300705, 0.130527, 0.537300,
0.843392, 0.991445, 0.953717, 0.737277, 0.382683, -0.043620,
-0.461749, -0.793354, -0.976296, -0.976296, -0.793353, -0.461748,
-0.043618, 0.382684, 0.737278, 0.953717, 0.991445, 0.843391,
},
{
0.887011, 0.991445, 0.737277, 0.216439, -0.382684, -0.843392,
-0.999048, -0.793353, -0.300705, 0.300706, 0.793354, 0.999048,
0.843391, 0.382683, -0.216440, -0.737278, -0.991445, -0.887010,
-0.461748, 0.130527, 0.675591, 0.976296, 0.923879, 0.537299,
-0.043621, -0.608762, -0.953717, -0.953717, -0.608760, -0.043618,
0.537301, 0.923880, 0.976296, 0.675589, 0.130525, -0.461750,
},
{
0.382683, -0.382684, -0.923880, -0.923879, -0.382683, 0.382684,
0.923880, 0.923879, 0.382683, -0.382684, -0.923880, -0.923879,
-0.382683, 0.382684, 0.923880, 0.923879, 0.382682, -0.382685,
-0.923880, -0.923879, -0.382682, 0.382685, 0.923880, 0.923879,
0.382682, -0.382685, -0.923880, -0.923879, -0.382682, 0.382685,
0.923880, 0.923879, 0.382682, -0.382685, -0.923880, -0.923879,
},
{
0.953717, -0.793353, 0.043620, 0.843392, 0.923879, 0.216439,
-0.675591, -0.991445, -0.461748, 0.461749, 0.991445, 0.675589,
-0.216441, -0.923880, -0.843391, -0.043618, 0.793354, 0.953717,
0.300704, -0.608763, -0.999048, -0.537298, 0.382685, 0.976296,
0.737276, -0.130528, -0.887012, -0.887010, -0.130524, 0.737279,
0.976296, 0.382681, -0.537301, -0.999048, -0.608760, 0.300708,
},
{
-0.216439, 0.793354, 0.887010, -0.043620, -0.923880, -0.737277,
0.300707, 0.991445, 0.537299, -0.537301, -0.991445, -0.300705,
0.737278, 0.923879, 0.043618, -0.887012, -0.793352, 0.216441,
0.976296, 0.608760, -0.461750, -0.999048, -0.382682, 0.675592,
0.953716, 0.130524, -0.843393, -0.843390, 0.130529, 0.953718,
0.675588, -0.382686, -0.999048, -0.461746, 0.608764, 0.976295,
},
{
0.991445, 0.382683, -0.793354, -0.793353, 0.382684, 0.991445,
0.130525, -0.923880, -0.608760, 0.608763, 0.923879, -0.130528,
-0.991445, -0.382682, 0.793354, 0.793352, -0.382685, -0.991445,
-0.130524, 0.923880, 0.608760, -0.608763, -0.923879, 0.130529,
0.991445, 0.382681, -0.793355, -0.793352, 0.382686, 0.991444,
0.130523, -0.923881, -0.608759, 0.608764, 0.923878, -0.130529,
},
{
0.043619, -0.991445, -0.216439, 0.953717, 0.382682, -0.887011,
-0.537299, 0.793354, 0.675589, -0.675591, -0.793352, 0.537301,
0.887010, -0.382685, -0.953716, 0.216442, 0.991445, -0.043622,
-0.999048, -0.130524, 0.976297, 0.300703, -0.923881, -0.461746,
0.843393, 0.608759, -0.737279, -0.737275, 0.608764, 0.843390,
-0.461752, -0.923878, 0.300709, 0.976295, -0.130530, -0.999048,
},
{
-0.999048, 0.130527, 0.976296, -0.300707, -0.923879, 0.461750,
0.843391, -0.608763, -0.737276, 0.737279, 0.608760, -0.843392,
-0.461747, 0.923880, 0.300704, -0.976297, -0.130524, 0.999048,
-0.043622, -0.991445, 0.216442, 0.953716, -0.382686, -0.887009,
0.537302, 0.793351, -0.675593, -0.675588, 0.793355, 0.537297,
-0.887013, -0.382680, 0.953718, 0.216436, -0.991445, -0.043615,
},
{
0.130527, 0.923879, -0.608762, -0.608760, 0.923880, 0.130525,
-0.991445, 0.382685, 0.793352, -0.793355, -0.382682, 0.991445,
-0.130528, -0.923879, 0.608763, 0.608759, -0.923881, -0.130523,
0.991444, -0.382686, -0.793351, 0.793355, 0.382680, -0.991445,
0.130530, 0.923878, -0.608764, -0.608758, 0.923881, 0.130522,
-0.991444, 0.382687, 0.793351, -0.793356, -0.382679, 0.991445,
},
{
0.976296, -0.608762, -0.461747, 0.999048, -0.382685, -0.675589,
0.953717, -0.130528, -0.843390, 0.843393, 0.130524, -0.953716,
0.675592, 0.382681, -0.999048, 0.461751, 0.608759, -0.976297,
0.216443, 0.793351, -0.887012, -0.043616, 0.923878, -0.737280,
-0.300702, 0.991444, -0.537303, -0.537296, 0.991445, -0.300710,
-0.737274, 0.923881, -0.043624, -0.887009, 0.793356, 0.216435,
},
{
-0.300707, -0.608760, 0.999048, -0.537301, -0.382682, 0.976296,
-0.737279, -0.130524, 0.887010, -0.887012, 0.130529, 0.737276,
-0.976297, 0.382686, 0.537297, -0.999048, 0.608764, 0.300703,
-0.953716, 0.793355, 0.043616, -0.843389, 0.923881, -0.216444,
-0.675587, 0.991445, -0.461752, -0.461745, 0.991444, -0.675594,
-0.216435, 0.923878, -0.843394, 0.043625, 0.793350, -0.953719,
},
{
-0.923879, 0.923880, -0.382685, -0.382682, 0.923879, -0.923880,
0.382685, 0.382681, -0.923879, 0.923880, -0.382686, -0.382681,
0.923878, -0.923881, 0.382686, 0.382680, -0.923878, 0.923881,
-0.382687, -0.382680, 0.923878, -0.923881, 0.382687, 0.382679,
-0.923878, 0.923881, -0.382688, -0.382679, 0.923878, -0.923881,
0.382688, 0.382678, -0.923877, 0.923882, -0.382689, -0.382678,
},
{
0.461750, 0.130525, -0.675589, 0.976296, -0.923880, 0.537301,
0.043617, -0.608760, 0.953716, -0.953718, 0.608764, -0.043622,
-0.537297, 0.923878, -0.976297, 0.675593, -0.130530, -0.461745,
0.887009, -0.991445, 0.737280, -0.216444, -0.382679, 0.843389,
-0.999048, 0.793356, -0.300711, -0.300701, 0.793350, -0.999048,
0.843394, -0.382689, -0.216434, 0.737273, -0.991444, 0.887014,
},
{
0.843391, -0.991445, 0.953717, -0.737279, 0.382685, 0.043617,
-0.461747, 0.793352, -0.976295, 0.976297, -0.793355, 0.461751,
-0.043623, -0.382680, 0.737275, -0.953716, 0.991445, -0.843394,
0.537303, -0.130530, -0.300702, 0.675587, -0.923878, 0.999048,
-0.887013, 0.608766, -0.216445, -0.216434, 0.608757, -0.887008,
0.999048, -0.923882, 0.675595, -0.300712, -0.130520, 0.537294,
},
{
-0.608763, 0.382685, -0.130528, -0.130524, 0.382681, -0.608760,
0.793352, -0.923879, 0.991444, -0.991445, 0.923881, -0.793355,
0.608764, -0.382687, 0.130530, 0.130522, -0.382680, 0.608758,
-0.793351, 0.923878, -0.991444, 0.991446, -0.923881, 0.793357,
-0.608766, 0.382689, -0.130532, -0.130520, 0.382678, -0.608756,
0.793349, -0.923877, 0.991444, -0.991446, 0.923882, -0.793358,
},
{
-0.737276, 0.793352, -0.843390, 0.887010, -0.923879, 0.953716,
-0.976295, 0.991444, -0.999048, 0.999048, -0.991445, 0.976297,
-0.953718, 0.923881, -0.887013, 0.843394, -0.793356, 0.737280,
-0.675594, 0.608765, -0.537304, 0.461753, -0.382688, 0.300711,
-0.216445, 0.130532, -0.043625, -0.043613, 0.130520, -0.216433,
0.300699, -0.382677, 0.461742, -0.537293, 0.608755, -0.675585,
},
}
//export IMDCT_Win
func IMDCT_Win(in *C.float, out *C.float, blockType C.unsigned) {
for i := 0; i < 36; i++ {
C.setFloatToArray(out, C.int(i), 0)
}
if blockType == 2 {
N := 12
for i := 0; i < 3; i++ {
for p := 0; p < N; p++ {
sum := float32(0.0)
for m := 0; m < N/2; m++ {
sum += float32(C.getFloatFromArray(in, C.int(i+3*m))) * cos_N12[m][p]
}
v := float32(C.getFloatFromArray(out, C.int(6*i+p+6)))
v += sum * imdctWin[blockType][p]
C.setFloatToArray(out, C.int(6*i+p+6), C.float(v))
}
}
return
}
N := 36
for p := 0; p < N; p++ {
sum := float32(0.0)
for m := 0; m < N/2; m++ {
sum += float32(C.getFloatFromArray(in, C.int(m))) * cos_N36[m][p]
}
C.setFloatToArray(out, C.int(p), C.float(sum*imdctWin[blockType][p]))
}
}

View File

@ -115,7 +115,6 @@ static void audio_write(unsigned *samples,unsigned nsamples,int sample_rate);
static void audio_write_raw(unsigned *samples,unsigned nsamples);
static void Decode_L3_Init_Song(void);
static void Error(const char *s,int e);
static void IMDCT_Win(float in[18],float out[36],unsigned block_type);
static void L3_Antialias(unsigned gr,unsigned ch);
static void L3_Frequency_Inversion(unsigned gr,unsigned ch);
static void L3_Hybrid_Synthesis(unsigned gr,unsigned ch);
@ -148,165 +147,10 @@ mpeg1_scalefac_sizes[16][2 /* slen1,slen2 */] = {
{2,1},{2,2},{2,3},{3,1},{3,2},{3,3},{4,2},{4,3}
};
static const float ci[8]={-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037},
static const float //ci[8]={-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037},
cs[8]={0.857493,0.881742,0.949629,0.983315,0.995518,0.999161,0.999899,0.999993},
ca[8]={-0.514496,-0.471732,-0.313377,-0.181913,-0.094574,-0.040966,-0.014199,-0.003700},
is_ratios[6] = {0.000000f,0.267949f,0.577350f,1.000000f,1.732051f,3.732051f},
#ifdef IMDCT_TABLES
g_imdct_win[4][36] = {
{0.043619f,0.130526f,0.216440f,0.300706f,0.382683f,0.461749f,
0.537300f,0.608761f,0.675590f,0.737277f,0.793353f,0.843391f,
0.887011f,0.923880f,0.953717f,0.976296f,0.991445f,0.999048f,
0.999048f,0.991445f,0.976296f,0.953717f,0.923879f,0.887011f,
0.843391f,0.793353f,0.737277f,0.675590f,0.608761f,0.537299f,
0.461748f,0.382683f,0.300706f,0.216439f,0.130526f,0.043619f
},{0.043619f,0.130526f,0.216440f,0.300706f,0.382683f,0.461749f,
0.537300f,0.608761f,0.675590f,0.737277f,0.793353f,0.843391f,
0.887011f,0.923880f,0.953717f,0.976296f,0.991445f,0.999048f,
1.000000f,1.000000f,1.000000f,1.000000f,1.000000f,1.000000f,
0.991445f,0.923880f,0.793353f,0.608761f,0.382683f,0.130526f,
0.000000f,0.000000f,0.000000f,0.000000f,0.000000f,0.000000f
},{0.130526f,0.382683f,0.608761f,0.793353f,0.923880f,0.991445f,
0.991445f,0.923880f,0.793353f,0.608761f,0.382683f,0.130526f,
0.000000f,0.000000f,0.000000f,0.000000f,0.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,0.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,0.000000f,0.000000f,
0.000000f,0.000000f,0.000000f,0.000000f,0.000000f,0.000000f,
},{0.000000f,0.000000f,0.000000f,0.000000f,0.000000f,0.000000f,
0.130526f,0.382683f,0.608761f,0.793353f,0.923880f,0.991445f,
1.000000f,1.000000f,1.000000f,1.000000f,1.000000f,1.000000f,
0.999048f,0.991445f,0.976296f,0.953717f,0.923879f,0.887011f,
0.843391f,0.793353f,0.737277f,0.675590f,0.608761f,0.537299f,
0.461748f,0.382683f,0.300706f,0.216439f,0.130526f,0.043619f,
}
},
#endif
#ifdef IMDCT_NTABLES
cos_N12[6][12] = {
{ 0.608761f,0.382683f,0.130526f,-0.130526f,-0.382683f,-0.608761f,
-0.793353f,-0.923880f,-0.991445f,-0.991445f,-0.923879f,-0.793353f
},{-0.923880f,-0.923879f,-0.382683f,0.382684f,0.923880f,0.923879f,
0.382683f,-0.382684f,-0.923880f,-0.923879f,-0.382683f,0.382684f
},{-0.130526f,0.923880f,0.608761f,-0.608762f,-0.923879f,0.130526f,
0.991445f,0.382683f,-0.793354f,-0.793353f,0.382684f,0.991445f
},{ 0.991445f,-0.382684f,-0.793353f,0.793354f,0.382683f,-0.991445f,
0.130527f,0.923879f,-0.608762f,-0.608761f,0.923880f,0.130525f
},{-0.382684f,-0.382683f,0.923879f,-0.923880f,0.382684f,0.382683f,
-0.923879f,0.923880f,-0.382684f,-0.382683f,0.923879f,-0.923880f
},{-0.793353f,0.923879f,-0.991445f,0.991445f,-0.923880f,0.793354f,
-0.608762f,0.382684f,-0.130527f,-0.130525f,0.382682f,-0.608761f,},
},
cos_N36[18][36] = {
{ 0.675590f,0.608761f,0.537300f,0.461749f,0.382683f,0.300706f,
0.216440f,0.130526f,0.043619f,-0.043619f,-0.130526f,-0.216440f,
-0.300706f,-0.382684f,-0.461749f,-0.537300f,-0.608762f,-0.675590f,
-0.737277f,-0.793353f,-0.843392f,-0.887011f,-0.923880f,-0.953717f,
-0.976296f,-0.991445f,-0.999048f,-0.999048f,-0.991445f,-0.976296f,
-0.953717f,-0.923879f,-0.887011f,-0.843391f,-0.793353f,-0.737277f
},{-0.793353f,-0.923880f,-0.991445f,-0.991445f,-0.923879f,-0.793353f,
-0.608761f,-0.382683f,-0.130526f,0.130526f,0.382684f,0.608762f,
0.793354f,0.923880f,0.991445f,0.991445f,0.923879f,0.793353f,
0.608761f,0.382683f,0.130526f,-0.130527f,-0.382684f,-0.608762f,
-0.793354f,-0.923880f,-0.991445f,-0.991445f,-0.923879f,-0.793353f,
-0.608761f,-0.382683f,-0.130526f,0.130527f,0.382684f,0.608762f
},{-0.537299f,-0.130526f,0.300706f,0.675590f,0.923880f,0.999048f,
0.887011f,0.608761f,0.216439f,-0.216440f,-0.608762f,-0.887011f,
-0.999048f,-0.923879f,-0.675590f,-0.300705f,0.130527f,0.537300f,
0.843392f,0.991445f,0.953717f,0.737277f,0.382683f,-0.043620f,
-0.461749f,-0.793354f,-0.976296f,-0.976296f,-0.793353f,-0.461748f,
-0.043618f,0.382684f,0.737278f,0.953717f,0.991445f,0.843391f
},{ 0.887011f,0.991445f,0.737277f,0.216439f,-0.382684f,-0.843392f,
-0.999048f,-0.793353f,-0.300705f,0.300706f,0.793354f,0.999048f,
0.843391f,0.382683f,-0.216440f,-0.737278f,-0.991445f,-0.887010f,
-0.461748f,0.130527f,0.675591f,0.976296f,0.923879f,0.537299f,
-0.043621f,-0.608762f,-0.953717f,-0.953717f,-0.608760f,-0.043618f,
0.537301f,0.923880f,0.976296f,0.675589f,0.130525f,-0.461750f
},{ 0.382683f,-0.382684f,-0.923880f,-0.923879f,-0.382683f,0.382684f,
0.923880f,0.923879f,0.382683f,-0.382684f,-0.923880f,-0.923879f,
-0.382683f,0.382684f,0.923880f,0.923879f,0.382682f,-0.382685f,
-0.923880f,-0.923879f,-0.382682f,0.382685f,0.923880f,0.923879f,
0.382682f,-0.382685f,-0.923880f,-0.923879f,-0.382682f,0.382685f,
0.923880f,0.923879f,0.382682f,-0.382685f,-0.923880f,-0.923879f
},{-0.953717f,-0.793353f,0.043620f,0.843392f,0.923879f,0.216439f,
-0.675591f,-0.991445f,-0.461748f,0.461749f,0.991445f,0.675589f,
-0.216441f,-0.923880f,-0.843391f,-0.043618f,0.793354f,0.953717f,
0.300704f,-0.608763f,-0.999048f,-0.537298f,0.382685f,0.976296f,
0.737276f,-0.130528f,-0.887012f,-0.887010f,-0.130524f,0.737279f,
0.976296f,0.382681f,-0.537301f,-0.999048f,-0.608760f,0.300708f
},{-0.216439f,0.793354f,0.887010f,-0.043620f,-0.923880f,-0.737277f,
0.300707f,0.991445f,0.537299f,-0.537301f,-0.991445f,-0.300705f,
0.737278f,0.923879f,0.043618f,-0.887012f,-0.793352f,0.216441f,
0.976296f,0.608760f,-0.461750f,-0.999048f,-0.382682f,0.675592f,
0.953716f,0.130524f,-0.843393f,-0.843390f,0.130529f,0.953718f,
0.675588f,-0.382686f,-0.999048f,-0.461746f,0.608764f,0.976295f
},{ 0.991445f,0.382683f,-0.793354f,-0.793353f,0.382684f,0.991445f,
0.130525f,-0.923880f,-0.608760f,0.608763f,0.923879f,-0.130528f,
-0.991445f,-0.382682f,0.793354f,0.793352f,-0.382685f,-0.991445f,
-0.130524f,0.923880f,0.608760f,-0.608763f,-0.923879f,0.130529f,
0.991445f,0.382681f,-0.793355f,-0.793352f,0.382686f,0.991444f,
0.130523f,-0.923881f,-0.608759f,0.608764f,0.923878f,-0.130529f
},{ 0.043619f,-0.991445f,-0.216439f,0.953717f,0.382682f,-0.887011f,
-0.537299f,0.793354f,0.675589f,-0.675591f,-0.793352f,0.537301f,
0.887010f,-0.382685f,-0.953716f,0.216442f,0.991445f,-0.043622f,
-0.999048f,-0.130524f,0.976297f,0.300703f,-0.923881f,-0.461746f,
0.843393f,0.608759f,-0.737279f,-0.737275f,0.608764f,0.843390f,
-0.461752f,-0.923878f,0.300709f,0.976295f,-0.130530f,-0.999048f
},{-0.999048f,0.130527f,0.976296f,-0.300707f,-0.923879f,0.461750f,
0.843391f,-0.608763f,-0.737276f,0.737279f,0.608760f,-0.843392f,
-0.461747f,0.923880f,0.300704f,-0.976297f,-0.130524f,0.999048f,
-0.043622f,-0.991445f,0.216442f,0.953716f,-0.382686f,-0.887009f,
0.537302f,0.793351f,-0.675593f,-0.675588f,0.793355f,0.537297f,
-0.887013f,-0.382680f,0.953718f,0.216436f,-0.991445f,-0.043615f
},{ 0.130527f,0.923879f,-0.608762f,-0.608760f,0.923880f,0.130525f,
-0.991445f,0.382685f,0.793352f,-0.793355f,-0.382682f,0.991445f,
-0.130528f,-0.923879f,0.608763f,0.608759f,-0.923881f,-0.130523f,
0.991444f,-0.382686f,-0.793351f,0.793355f,0.382680f,-0.991445f,
0.130530f,0.923878f,-0.608764f,-0.608758f,0.923881f,0.130522f,
-0.991444f,0.382687f,0.793351f,-0.793356f,-0.382679f,0.991445f
},{ 0.976296f,-0.608762f,-0.461747f,0.999048f,-0.382685f,-0.675589f,
0.953717f,-0.130528f,-0.843390f,0.843393f,0.130524f,-0.953716f,
0.675592f,0.382681f,-0.999048f,0.461751f,0.608759f,-0.976297f,
0.216443f,0.793351f,-0.887012f,-0.043616f,0.923878f,-0.737280f,
-0.300702f,0.991444f,-0.537303f,-0.537296f,0.991445f,-0.300710f,
-0.737274f,0.923881f,-0.043624f,-0.887009f,0.793356f,0.216435f
},{-0.300707f,-0.608760f,0.999048f,-0.537301f,-0.382682f,0.976296f,
-0.737279f,-0.130524f,0.887010f,-0.887012f,0.130529f,0.737276f,
-0.976297f,0.382686f,0.537297f,-0.999048f,0.608764f,0.300703f,
-0.953716f,0.793355f,0.043616f,-0.843389f,0.923881f,-0.216444f,
-0.675587f,0.991445f,-0.461752f,-0.461745f,0.991444f,-0.675594f,
-0.216435f,0.923878f,-0.843394f,0.043625f,0.793350f,-0.953719f
},{-0.923879f,0.923880f,-0.382685f,-0.382682f,0.923879f,-0.923880f,
0.382685f,0.382681f,-0.923879f,0.923880f,-0.382686f,-0.382681f,
0.923878f,-0.923881f,0.382686f,0.382680f,-0.923878f,0.923881f,
-0.382687f,-0.382680f,0.923878f,-0.923881f,0.382687f,0.382679f,
-0.923878f,0.923881f,-0.382688f,-0.382679f,0.923878f,-0.923881f,
0.382688f,0.382678f,-0.923877f,0.923882f,-0.382689f,-0.382678f
},{ 0.461750f,0.130525f,-0.675589f,0.976296f,-0.923880f,0.537301f,
0.043617f,-0.608760f,0.953716f,-0.953718f,0.608764f,-0.043622f,
-0.537297f,0.923878f,-0.976297f,0.675593f,-0.130530f,-0.461745f,
0.887009f,-0.991445f,0.737280f,-0.216444f,-0.382679f,0.843389f,
-0.999048f,0.793356f,-0.300711f,-0.300701f,0.793350f,-0.999048f,
0.843394f,-0.382689f,-0.216434f,0.737273f,-0.991444f,0.887014f
},{ 0.843391f,-0.991445f,0.953717f,-0.737279f,0.382685f,0.043617f,
-0.461747f,0.793352f,-0.976295f,0.976297f,-0.793355f,0.461751f,
-0.043623f,-0.382680f,0.737275f,-0.953716f,0.991445f,-0.843394f,
0.537303f,-0.130530f,-0.300702f,0.675587f,-0.923878f,0.999048f,
-0.887013f,0.608766f,-0.216445f,-0.216434f,0.608757f,-0.887008f,
0.999048f,-0.923882f,0.675595f,-0.300712f,-0.130520f,0.537294f
},{-0.608763f,0.382685f,-0.130528f,-0.130524f,0.382681f,-0.608760f,
0.793352f,-0.923879f,0.991444f,-0.991445f,0.923881f,-0.793355f,
0.608764f,-0.382687f,0.130530f,0.130522f,-0.382680f,0.608758f,
-0.793351f,0.923878f,-0.991444f,0.991446f,-0.923881f,0.793357f,
-0.608766f,0.382689f,-0.130532f,-0.130520f,0.382678f,-0.608756f,
0.793349f,-0.923877f,0.991444f,-0.991446f,0.923882f,-0.793358f
},{-0.737276f,0.793352f,-0.843390f,0.887010f,-0.923879f,0.953716f,
-0.976295f,0.991444f,-0.999048f,0.999048f,-0.991445f,0.976297f,
-0.953718f,0.923881f,-0.887013f,0.843394f,-0.793356f,0.737280f,
-0.675594f,0.608765f,-0.537304f,0.461753f,-0.382688f,0.300711f,
-0.216445f,0.130532f,-0.043625f,-0.043613f,0.130520f,-0.216433f,
0.300699f,-0.382677f,0.461742f,-0.537293f,0.608755f,-0.675585f
}};
#endif
is_ratios[6] = {0.000000f,0.267949f,0.577350f,1.000000f,1.732051f,3.732051f};
#ifdef POW34_ITERATE
static const float powtab34[32] = {
0.000000f,1.000000f,2.519842f,4.326749f,6.349605f,8.549880f,10.902724f,
@ -972,63 +816,6 @@ static void Decode_L3_Init_Song(void){
//g_main_data_top = 0; /* Clear bit reservoir */
}
/**Description: Does inverse modified DCT and windowing.
* Parameters: TBD
* Return value: TBD
* Author: Krister Lagerström(krister@kmlager.com) **/
static void IMDCT_Win(float in[18],float out[36],unsigned block_type){
unsigned i,m,N,p;
float tmp[12],sum,tin[18];
#ifndef IMDCT_TABLES
static float g_imdct_win[4][36];
static unsigned init = 1;
//TODO : move to separate init function
if(init) { /* Setup the four(one for each block type) window vectors */
for(i = 0; i < 36; i++) g_imdct_win[0][i] = sin(C_PI/36 *(i + 0.5)); //0
for(i = 0; i < 18; i++) g_imdct_win[1][i] = sin(C_PI/36 *(i + 0.5)); //1
for(i = 18; i < 24; i++) g_imdct_win[1][i] = 1.0;
for(i = 24; i < 30; i++) g_imdct_win[1][i] = sin(C_PI/12 *(i + 0.5 - 18.0));
for(i = 30; i < 36; i++) g_imdct_win[1][i] = 0.0;
for(i = 0; i < 12; i++) g_imdct_win[2][i] = sin(C_PI/12 *(i + 0.5)); //2
for(i = 12; i < 36; i++) g_imdct_win[2][i] = 0.0;
for(i = 0; i < 6; i++) g_imdct_win[3][i] = 0.0; //3
for(i = 6; i < 12; i++) g_imdct_win[3][i] = sin(C_PI/12 *(i + 0.5 - 6.0));
for(i = 12; i < 18; i++) g_imdct_win[3][i] = 1.0;
for(i = 18; i < 36; i++) g_imdct_win[3][i] = sin(C_PI/36 *(i + 0.5));
init = 0;
} /* end of init */
#endif
for(i = 0; i < 36; i++) out[i] = 0.0;
for(i = 0; i < 18; i++) tin[i] = in[i];
if(block_type == 2) { /* 3 short blocks */
N = 12;
for(i = 0; i < 3; i++) {
for(p = 0; p < N; p++) {
sum = 0.0;
for(m = 0;m < N/2; m++)
#ifdef IMDCT_NTABLES
sum += tin[i+3*m] * cos_N12[m][p];
#else
sum += tin[i+3*m] * cos(C_PI/(2*N)*(2*p+1+N/2)*(2*m+1));
#endif
out[6*i+p+6] += sum * g_imdct_win[block_type][p]; //TODO FIXME +=?
}
} /* end for(i... */
}else{ /* block_type != 2 */
N = 36;
for(p = 0; p < N; p++){
sum = 0.0;
for(m = 0; m < N/2; m++)
#ifdef IMDCT_NTABLES
sum += in[m] * cos_N36[m][p];
#else
sum += in[m] * cos(C_PI/(2*N)*(2*p+1+N/2)*(2*m+1));
#endif
out[p] = sum * g_imdct_win[block_type][p];
}
}
}
/**Description: TBD
* Parameters: TBD
* Return value: TBD

View File

@ -34,6 +34,8 @@ unsigned Get_Main_Bits(unsigned number_of_bits);
void Get_Sideinfo(unsigned sideinfo_size);
unsigned Get_Side_Bits(unsigned number_of_bits);
void IMDCT_Win(float* in, float* out,unsigned block_type);
int Read_CRC(void);
int Huffman_Decode(unsigned table_num, int32_t* x, int32_t*y, int32_t* v, int32_t* w);