mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio/mp3: Move L3_Hybrid_Synthesis to Go
This commit is contained in:
parent
78626426fe
commit
b54f711243
@ -17,17 +17,9 @@
|
||||
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{
|
||||
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,
|
||||
@ -236,32 +228,28 @@ var cos_N36 = [18][36]float32{
|
||||
},
|
||||
}
|
||||
|
||||
//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)
|
||||
}
|
||||
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 += float32(C.getFloatFromArray(in, C.int(i+3*m))) * cos_N12[m][p]
|
||||
sum += in[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))
|
||||
out[6*i+p+6] += sum * imdctWinData[blockType][p]
|
||||
}
|
||||
}
|
||||
return
|
||||
return out
|
||||
}
|
||||
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]
|
||||
sum += in[m] * cos_N36[m][p]
|
||||
}
|
||||
C.setFloatToArray(out, C.int(p), C.float(sum*imdctWin[blockType][p]))
|
||||
out[p] = sum * imdctWinData[blockType][p]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
48
audio/mp3/l3.go
Normal file
48
audio/mp3/l3.go
Normal file
@ -0,0 +1,48 @@
|
||||
// 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"
|
||||
//
|
||||
// extern unsigned hsynth_init, synth_init;
|
||||
// extern t_mpeg1_main_data g_main_data;
|
||||
// extern t_mpeg1_side_info g_side_info;
|
||||
import "C"
|
||||
|
||||
var store = [2][32][18]float32{}
|
||||
|
||||
//export L3_Hybrid_Synthesis
|
||||
func L3_Hybrid_Synthesis(gr C.unsigned, ch C.unsigned) {
|
||||
for sb := 0; sb < 32; sb++ { /* Loop through all 32 subbands */
|
||||
/* Determine blocktype for this subband */
|
||||
bt := 0
|
||||
if (C.g_side_info.win_switch_flag[gr][ch] == 1) &&
|
||||
(C.g_side_info.mixed_block_flag[gr][ch] == 1) && (sb < 2) {
|
||||
bt = int(C.g_side_info.block_type[gr][ch])
|
||||
}
|
||||
/* Do the inverse modified DCT and windowing */
|
||||
in := make([]float32, 18)
|
||||
for i := range in {
|
||||
in[i] = float32(C.g_main_data.is[gr][ch][sb*18+i])
|
||||
}
|
||||
rawout := imdctWin(in, bt)
|
||||
for i := 0; i < 18; i++ { /* Overlapp add with stored vector into main_data vector */
|
||||
C.g_main_data.is[gr][ch][sb*18+i] = C.float(rawout[i] + store[ch][sb][i])
|
||||
store[ch][sb][i] = rawout[i+18]
|
||||
}
|
||||
}
|
||||
}
|
@ -46,7 +46,6 @@ static void Decode_L3_Init_Song(void);
|
||||
static void Error(const char *s,int e);
|
||||
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);
|
||||
static void L3_Requantize(unsigned gr,unsigned ch);
|
||||
static void L3_Reorder(unsigned gr,unsigned ch);
|
||||
static void L3_Stereo(unsigned gr);
|
||||
@ -216,8 +215,7 @@ static const float powtab34[32] = {
|
||||
//},g_synth_n_win[64][32]={
|
||||
};
|
||||
|
||||
|
||||
static unsigned hsynth_init = 1,synth_init = 1;
|
||||
unsigned synth_init = 1;
|
||||
|
||||
/* Scale factor band indices
|
||||
*
|
||||
@ -557,7 +555,7 @@ static void Error(const char *s,int e){
|
||||
* Return value: None
|
||||
* Author: Krister Lagerström(krister@kmlager.com) **/
|
||||
static void Decode_L3_Init_Song(void){
|
||||
hsynth_init = synth_init = 1;
|
||||
synth_init = 1;
|
||||
}
|
||||
|
||||
/**Description: TBD
|
||||
@ -606,40 +604,6 @@ static void L3_Frequency_Inversion(unsigned gr,unsigned ch){
|
||||
return; /* Done */
|
||||
}
|
||||
|
||||
/**Description: TBD
|
||||
* Parameters: TBD
|
||||
* Return value: TBD
|
||||
* Author: Krister Lagerström(krister@kmlager.com) **/
|
||||
static void L3_Hybrid_Synthesis(unsigned gr,unsigned ch){
|
||||
unsigned sb,i,j,bt;
|
||||
float rawout[36];
|
||||
static float store[2][32][18];
|
||||
|
||||
if(hsynth_init) { /* Clear stored samples vector. OPT? use memset */
|
||||
for(j = 0; j < 2; j++) {
|
||||
for(sb = 0; sb < 32; sb++) {
|
||||
for(i = 0; i < 18; i++) {
|
||||
store[j][sb][i] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
hsynth_init = 0;
|
||||
} /* end if(hsynth_init) */
|
||||
for(sb = 0; sb < 32; sb++) { /* Loop through all 32 subbands */
|
||||
/* Determine blocktype for this subband */
|
||||
bt =((g_side_info.win_switch_flag[gr][ch] == 1) &&
|
||||
(g_side_info.mixed_block_flag[gr][ch] == 1) &&(sb < 2))
|
||||
? 0 : g_side_info.block_type[gr][ch];
|
||||
/* Do the inverse modified DCT and windowing */
|
||||
IMDCT_Win(&(g_main_data.is[gr][ch][sb*18]),rawout,bt);
|
||||
for(i = 0; i < 18; i++) { /* Overlapp add with stored vector into main_data vector */
|
||||
g_main_data.is[gr][ch][sb*18 + i] = rawout[i] + store[ch][sb][i];
|
||||
store[ch][sb][i] = rawout[i + 18];
|
||||
} /* end for(i... */
|
||||
} /* end for(sb... */
|
||||
return; /* Done */
|
||||
}
|
||||
|
||||
/**Description: TBD
|
||||
* Parameters: TBD
|
||||
* Return value: TBD
|
||||
|
@ -99,7 +99,7 @@ int Read_Audio_L3(void);
|
||||
static int Read_Header(void);
|
||||
void Read_Huffman(unsigned part_2_start,unsigned gr,unsigned ch);
|
||||
|
||||
void IMDCT_Win(float* in, float* out,unsigned block_type);
|
||||
void L3_Hybrid_Synthesis(unsigned gr,unsigned ch);
|
||||
|
||||
int Read_CRC(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user