mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
253 lines
10 KiB
Go
253 lines
10 KiB
Go
// 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
|
|
|
|
var imdctWinData = [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,
|
|
},
|
|
}
|
|
|
|
func imdctWin(in []float32, blockType int) []float32 {
|
|
out := make([]float32, 36)
|
|
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 += in[i+3*m] * cos_N12[m][p]
|
|
}
|
|
out[6*i+p+6] += sum * imdctWinData[blockType][p]
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
N := 36
|
|
for p := 0; p < N; p++ {
|
|
sum := float32(0.0)
|
|
for m := 0; m < N/2; m++ {
|
|
sum += in[m] * cos_N36[m][p]
|
|
}
|
|
out[p] = sum * imdctWinData[blockType][p]
|
|
}
|
|
return out
|
|
}
|