mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
audio/mp3: Move t_mpeg1_side_info to Go
This commit is contained in:
parent
d30f025d85
commit
a0af1595de
@ -18,7 +18,6 @@ package mp3
|
|||||||
|
|
||||||
// #include "pdmp3.h"
|
// #include "pdmp3.h"
|
||||||
//
|
//
|
||||||
// extern t_mpeg1_side_info g_side_info;
|
|
||||||
// extern t_mpeg1_header g_frame_header;
|
// extern t_mpeg1_header g_frame_header;
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
@ -39,16 +38,16 @@ func init() {
|
|||||||
|
|
||||||
func requantizeProcessLong(gr, ch, is_pos, sfb int) {
|
func requantizeProcessLong(gr, ch, is_pos, sfb int) {
|
||||||
sf_mult := 0.5
|
sf_mult := 0.5
|
||||||
if C.g_side_info.scalefac_scale[gr][ch] != 0 {
|
if theMPEG1SideInfo.scalefac_scale[gr][ch] != 0 {
|
||||||
sf_mult = 1.0
|
sf_mult = 1.0
|
||||||
}
|
}
|
||||||
tmp1 := 1.0
|
tmp1 := 1.0
|
||||||
// https://github.com/technosaurus/PDMP3/issues/4
|
// https://github.com/technosaurus/PDMP3/issues/4
|
||||||
if sfb < 21 {
|
if sfb < 21 {
|
||||||
pf_x_pt := float64(C.g_side_info.preflag[gr][ch]) * pretab[sfb]
|
pf_x_pt := float64(theMPEG1SideInfo.preflag[gr][ch]) * pretab[sfb]
|
||||||
tmp1 = math.Pow(2.0, -(sf_mult * (float64(theMPEG1MainData.scalefac_l[gr][ch][sfb]) + pf_x_pt)))
|
tmp1 = math.Pow(2.0, -(sf_mult * (float64(theMPEG1MainData.scalefac_l[gr][ch][sfb]) + pf_x_pt)))
|
||||||
}
|
}
|
||||||
tmp2 := math.Pow(2.0, 0.25*(float64(C.g_side_info.global_gain[gr][ch])-210))
|
tmp2 := math.Pow(2.0, 0.25*(float64(theMPEG1SideInfo.global_gain[gr][ch])-210))
|
||||||
tmp3 := 0.0
|
tmp3 := 0.0
|
||||||
if theMPEG1MainData.is[gr][ch][is_pos] < 0.0 {
|
if theMPEG1MainData.is[gr][ch][is_pos] < 0.0 {
|
||||||
tmp3 = -powtab34[int(-theMPEG1MainData.is[gr][ch][is_pos])]
|
tmp3 = -powtab34[int(-theMPEG1MainData.is[gr][ch][is_pos])]
|
||||||
@ -60,7 +59,7 @@ func requantizeProcessLong(gr, ch, is_pos, sfb int) {
|
|||||||
|
|
||||||
func requantizeProcessShort(gr, ch, is_pos, sfb, win int) {
|
func requantizeProcessShort(gr, ch, is_pos, sfb, win int) {
|
||||||
sf_mult := 0.5
|
sf_mult := 0.5
|
||||||
if C.g_side_info.scalefac_scale[gr][ch] != 0 {
|
if theMPEG1SideInfo.scalefac_scale[gr][ch] != 0 {
|
||||||
sf_mult = 1.0
|
sf_mult = 1.0
|
||||||
}
|
}
|
||||||
tmp1 := 1.0
|
tmp1 := 1.0
|
||||||
@ -68,8 +67,8 @@ func requantizeProcessShort(gr, ch, is_pos, sfb, win int) {
|
|||||||
if sfb < 12 {
|
if sfb < 12 {
|
||||||
tmp1 = math.Pow(2.0, -(sf_mult * float64(theMPEG1MainData.scalefac_s[gr][ch][sfb][win])))
|
tmp1 = math.Pow(2.0, -(sf_mult * float64(theMPEG1MainData.scalefac_s[gr][ch][sfb][win])))
|
||||||
}
|
}
|
||||||
tmp2 := math.Pow(2.0, 0.25*(float64(C.g_side_info.global_gain[gr][ch])-210.0-
|
tmp2 := math.Pow(2.0, 0.25*(float64(theMPEG1SideInfo.global_gain[gr][ch])-210.0-
|
||||||
8.0*float64(C.g_side_info.subblock_gain[gr][ch][win])))
|
8.0*float64(theMPEG1SideInfo.subblock_gain[gr][ch][win])))
|
||||||
tmp3 := 0.0
|
tmp3 := 0.0
|
||||||
if theMPEG1MainData.is[gr][ch][is_pos] < 0 {
|
if theMPEG1MainData.is[gr][ch][is_pos] < 0 {
|
||||||
tmp3 = -powtab34[int(-theMPEG1MainData.is[gr][ch][is_pos])]
|
tmp3 = -powtab34[int(-theMPEG1MainData.is[gr][ch][is_pos])]
|
||||||
@ -105,10 +104,10 @@ func l3Requantize(gr int, ch int) {
|
|||||||
/* Setup sampling frequency index */
|
/* Setup sampling frequency index */
|
||||||
sfreq := C.g_frame_header.sampling_frequency
|
sfreq := C.g_frame_header.sampling_frequency
|
||||||
/* Determine type of block to process */
|
/* Determine type of block to process */
|
||||||
if (C.g_side_info.win_switch_flag[gr][ch] == 1) && (C.g_side_info.block_type[gr][ch] == 2) { /* Short blocks */
|
if (theMPEG1SideInfo.win_switch_flag[gr][ch] == 1) && (theMPEG1SideInfo.block_type[gr][ch] == 2) { /* Short blocks */
|
||||||
/* Check if the first two subbands
|
/* Check if the first two subbands
|
||||||
*(=2*18 samples = 8 long or 3 short sfb's) uses long blocks */
|
*(=2*18 samples = 8 long or 3 short sfb's) uses long blocks */
|
||||||
if C.g_side_info.mixed_block_flag[gr][ch] != 0 { /* 2 longbl. sb first */
|
if theMPEG1SideInfo.mixed_block_flag[gr][ch] != 0 { /* 2 longbl. sb first */
|
||||||
/* First process the 2 long block subbands at the start */
|
/* First process the 2 long block subbands at the start */
|
||||||
sfb := 0
|
sfb := 0
|
||||||
next_sfb := sfBandIndicesSet[sfreq].l[sfb+1]
|
next_sfb := sfBandIndicesSet[sfreq].l[sfb+1]
|
||||||
@ -125,7 +124,7 @@ func l3Requantize(gr int, ch int) {
|
|||||||
win_len := sfBandIndicesSet[sfreq].s[sfb+1] -
|
win_len := sfBandIndicesSet[sfreq].s[sfb+1] -
|
||||||
sfBandIndicesSet[sfreq].s[sfb]
|
sfBandIndicesSet[sfreq].s[sfb]
|
||||||
|
|
||||||
for i := 36; i < int(C.g_side_info.count1[gr][ch]); /* i++ done below! */ {
|
for i := 36; i < int(theMPEG1SideInfo.count1[gr][ch]); /* i++ done below! */ {
|
||||||
/* Check if we're into the next scalefac band */
|
/* Check if we're into the next scalefac band */
|
||||||
if i == next_sfb { /* Yes */
|
if i == next_sfb { /* Yes */
|
||||||
sfb++
|
sfb++
|
||||||
@ -146,7 +145,7 @@ func l3Requantize(gr int, ch int) {
|
|||||||
next_sfb := sfBandIndicesSet[sfreq].s[sfb+1] * 3
|
next_sfb := sfBandIndicesSet[sfreq].s[sfb+1] * 3
|
||||||
win_len := sfBandIndicesSet[sfreq].s[sfb+1] -
|
win_len := sfBandIndicesSet[sfreq].s[sfb+1] -
|
||||||
sfBandIndicesSet[sfreq].s[sfb]
|
sfBandIndicesSet[sfreq].s[sfb]
|
||||||
for i := 0; i < int(C.g_side_info.count1[gr][ch]); /* i++ done below! */ {
|
for i := 0; i < int(theMPEG1SideInfo.count1[gr][ch]); /* i++ done below! */ {
|
||||||
/* Check if we're into the next scalefac band */
|
/* Check if we're into the next scalefac band */
|
||||||
if i == next_sfb {
|
if i == next_sfb {
|
||||||
sfb++
|
sfb++
|
||||||
@ -165,7 +164,7 @@ func l3Requantize(gr int, ch int) {
|
|||||||
} else { /* Only long blocks */
|
} else { /* Only long blocks */
|
||||||
sfb := 0
|
sfb := 0
|
||||||
next_sfb := sfBandIndicesSet[sfreq].l[sfb+1]
|
next_sfb := sfBandIndicesSet[sfreq].l[sfb+1]
|
||||||
for i := 0; i < int(C.g_side_info.count1[gr][ch]); i++ {
|
for i := 0; i < int(theMPEG1SideInfo.count1[gr][ch]); i++ {
|
||||||
if i == next_sfb {
|
if i == next_sfb {
|
||||||
sfb++
|
sfb++
|
||||||
next_sfb = sfBandIndicesSet[sfreq].l[sfb+1]
|
next_sfb = sfBandIndicesSet[sfreq].l[sfb+1]
|
||||||
@ -180,12 +179,12 @@ func l3Reorder(gr int, ch int) {
|
|||||||
|
|
||||||
sfreq := C.g_frame_header.sampling_frequency /* Setup sampling freq index */
|
sfreq := C.g_frame_header.sampling_frequency /* Setup sampling freq index */
|
||||||
/* Only reorder short blocks */
|
/* Only reorder short blocks */
|
||||||
if (C.g_side_info.win_switch_flag[gr][ch] == 1) && (C.g_side_info.block_type[gr][ch] == 2) { /* Short blocks */
|
if (theMPEG1SideInfo.win_switch_flag[gr][ch] == 1) && (theMPEG1SideInfo.block_type[gr][ch] == 2) { /* Short blocks */
|
||||||
/* Check if the first two subbands
|
/* Check if the first two subbands
|
||||||
*(=2*18 samples = 8 long or 3 short sfb's) uses long blocks */
|
*(=2*18 samples = 8 long or 3 short sfb's) uses long blocks */
|
||||||
sfb := 0
|
sfb := 0
|
||||||
/* 2 longbl. sb first */
|
/* 2 longbl. sb first */
|
||||||
if C.g_side_info.mixed_block_flag[gr][ch] != 0 {
|
if theMPEG1SideInfo.mixed_block_flag[gr][ch] != 0 {
|
||||||
sfb = 3
|
sfb = 3
|
||||||
}
|
}
|
||||||
next_sfb := sfBandIndicesSet[sfreq].s[sfb+1] * 3
|
next_sfb := sfBandIndicesSet[sfreq].s[sfb+1] * 3
|
||||||
@ -202,7 +201,7 @@ func l3Reorder(gr int, ch int) {
|
|||||||
theMPEG1MainData.is[gr][ch][3*sfBandIndicesSet[sfreq].s[sfb]+j] = re[j]
|
theMPEG1MainData.is[gr][ch][3*sfBandIndicesSet[sfreq].s[sfb]+j] = re[j]
|
||||||
}
|
}
|
||||||
/* Check if this band is above the rzero region,if so we're done */
|
/* Check if this band is above the rzero region,if so we're done */
|
||||||
if C.uint(i) >= C.g_side_info.count1[gr][ch] {
|
if i >= theMPEG1SideInfo.count1[gr][ch] {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sfb++
|
sfb++
|
||||||
@ -290,10 +289,10 @@ func l3Stereo(gr int) {
|
|||||||
if (C.g_frame_header.mode_extension & 0x2) != 0 {
|
if (C.g_frame_header.mode_extension & 0x2) != 0 {
|
||||||
/* Determine how many frequency lines to transform */
|
/* Determine how many frequency lines to transform */
|
||||||
i := 0
|
i := 0
|
||||||
if C.g_side_info.count1[gr][0] > C.g_side_info.count1[gr][1] {
|
if theMPEG1SideInfo.count1[gr][0] > theMPEG1SideInfo.count1[gr][1] {
|
||||||
i = 1
|
i = 1
|
||||||
}
|
}
|
||||||
max_pos := int(C.g_side_info.count1[gr][i])
|
max_pos := int(theMPEG1SideInfo.count1[gr][i])
|
||||||
/* Do the actual processing */
|
/* Do the actual processing */
|
||||||
const invSqrt2 = math.Sqrt2 / 2
|
const invSqrt2 = math.Sqrt2 / 2
|
||||||
for i := 0; i < max_pos; i++ {
|
for i := 0; i < max_pos; i++ {
|
||||||
@ -311,28 +310,28 @@ func l3Stereo(gr int) {
|
|||||||
* band on or above count1 frequency line. N.B.: Intensity stereo coding is
|
* band on or above count1 frequency line. N.B.: Intensity stereo coding is
|
||||||
* only done for higher subbands, but logic is here for lower subbands. */
|
* only done for higher subbands, but logic is here for lower subbands. */
|
||||||
/* Determine type of block to process */
|
/* Determine type of block to process */
|
||||||
if (C.g_side_info.win_switch_flag[gr][0] == 1) &&
|
if (theMPEG1SideInfo.win_switch_flag[gr][0] == 1) &&
|
||||||
(C.g_side_info.block_type[gr][0] == 2) { /* Short blocks */
|
(theMPEG1SideInfo.block_type[gr][0] == 2) { /* Short blocks */
|
||||||
/* Check if the first two subbands
|
/* Check if the first two subbands
|
||||||
*(=2*18 samples = 8 long or 3 short sfb's) uses long blocks */
|
*(=2*18 samples = 8 long or 3 short sfb's) uses long blocks */
|
||||||
if C.g_side_info.mixed_block_flag[gr][0] != 0 { /* 2 longbl. sb first */
|
if theMPEG1SideInfo.mixed_block_flag[gr][0] != 0 { /* 2 longbl. sb first */
|
||||||
for sfb := 0; sfb < 8; sfb++ { /* First process 8 sfb's at start */
|
for sfb := 0; sfb < 8; sfb++ { /* First process 8 sfb's at start */
|
||||||
/* Is this scale factor band above count1 for the right channel? */
|
/* Is this scale factor band above count1 for the right channel? */
|
||||||
if C.unsigned(sfBandIndicesSet[sfreq].l[sfb]) >= C.g_side_info.count1[gr][1] {
|
if sfBandIndicesSet[sfreq].l[sfb] >= theMPEG1SideInfo.count1[gr][1] {
|
||||||
stereoProcessIntensityLong(int(gr), int(sfb))
|
stereoProcessIntensityLong(int(gr), int(sfb))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* And next the remaining bands which uses short blocks */
|
/* And next the remaining bands which uses short blocks */
|
||||||
for sfb := 3; sfb < 12; sfb++ {
|
for sfb := 3; sfb < 12; sfb++ {
|
||||||
/* Is this scale factor band above count1 for the right channel? */
|
/* Is this scale factor band above count1 for the right channel? */
|
||||||
if C.unsigned(sfBandIndicesSet[sfreq].s[sfb])*3 >= C.g_side_info.count1[gr][1] {
|
if sfBandIndicesSet[sfreq].s[sfb]*3 >= theMPEG1SideInfo.count1[gr][1] {
|
||||||
stereoProcessIntensityShort(int(gr), int(sfb)) /* intensity stereo processing */
|
stereoProcessIntensityShort(int(gr), int(sfb)) /* intensity stereo processing */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { /* Only short blocks */
|
} else { /* Only short blocks */
|
||||||
for sfb := 0; sfb < 12; sfb++ {
|
for sfb := 0; sfb < 12; sfb++ {
|
||||||
/* Is this scale factor band above count1 for the right channel? */
|
/* Is this scale factor band above count1 for the right channel? */
|
||||||
if C.unsigned(sfBandIndicesSet[sfreq].s[sfb])*3 >= C.g_side_info.count1[gr][1] {
|
if sfBandIndicesSet[sfreq].s[sfb]*3 >= theMPEG1SideInfo.count1[gr][1] {
|
||||||
stereoProcessIntensityShort(int(gr), int(sfb)) /* intensity stereo processing */
|
stereoProcessIntensityShort(int(gr), int(sfb)) /* intensity stereo processing */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -340,7 +339,7 @@ func l3Stereo(gr int) {
|
|||||||
} else { /* Only long blocks */
|
} else { /* Only long blocks */
|
||||||
for sfb := 0; sfb < 21; sfb++ {
|
for sfb := 0; sfb < 21; sfb++ {
|
||||||
/* Is this scale factor band above count1 for the right channel? */
|
/* Is this scale factor band above count1 for the right channel? */
|
||||||
if C.unsigned(sfBandIndicesSet[sfreq].l[sfb]) >= C.g_side_info.count1[gr][1] {
|
if sfBandIndicesSet[sfreq].l[sfb] >= theMPEG1SideInfo.count1[gr][1] {
|
||||||
/* Perform the intensity stereo processing */
|
/* Perform the intensity stereo processing */
|
||||||
stereoProcessIntensityLong(int(gr), int(sfb))
|
stereoProcessIntensityLong(int(gr), int(sfb))
|
||||||
}
|
}
|
||||||
@ -356,16 +355,16 @@ var (
|
|||||||
|
|
||||||
func l3Antialias(gr int, ch int) {
|
func l3Antialias(gr int, ch int) {
|
||||||
/* No antialiasing is done for short blocks */
|
/* No antialiasing is done for short blocks */
|
||||||
if (C.g_side_info.win_switch_flag[gr][ch] == 1) &&
|
if (theMPEG1SideInfo.win_switch_flag[gr][ch] == 1) &&
|
||||||
(C.g_side_info.block_type[gr][ch] == 2) &&
|
(theMPEG1SideInfo.block_type[gr][ch] == 2) &&
|
||||||
(C.g_side_info.mixed_block_flag[gr][ch]) == 0 {
|
(theMPEG1SideInfo.mixed_block_flag[gr][ch]) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
/* Setup the limit for how many subbands to transform */
|
/* Setup the limit for how many subbands to transform */
|
||||||
sblim := 32
|
sblim := 32
|
||||||
if (C.g_side_info.win_switch_flag[gr][ch] == 1) &&
|
if (theMPEG1SideInfo.win_switch_flag[gr][ch] == 1) &&
|
||||||
(C.g_side_info.block_type[gr][ch] == 2) &&
|
(theMPEG1SideInfo.block_type[gr][ch] == 2) &&
|
||||||
(C.g_side_info.mixed_block_flag[gr][ch] == 1) {
|
(theMPEG1SideInfo.mixed_block_flag[gr][ch] == 1) {
|
||||||
sblim = 2
|
sblim = 2
|
||||||
}
|
}
|
||||||
/* Do the actual antialiasing */
|
/* Do the actual antialiasing */
|
||||||
@ -386,9 +385,9 @@ var store = [2][32][18]float32{}
|
|||||||
func l3HybridSynthesis(gr int, ch int) {
|
func l3HybridSynthesis(gr int, ch int) {
|
||||||
for sb := 0; sb < 32; sb++ { /* Loop through all 32 subbands */
|
for sb := 0; sb < 32; sb++ { /* Loop through all 32 subbands */
|
||||||
/* Determine blocktype for this subband */
|
/* Determine blocktype for this subband */
|
||||||
bt := int(C.g_side_info.block_type[gr][ch])
|
bt := int(theMPEG1SideInfo.block_type[gr][ch])
|
||||||
if (C.g_side_info.win_switch_flag[gr][ch] == 1) &&
|
if (theMPEG1SideInfo.win_switch_flag[gr][ch] == 1) &&
|
||||||
(C.g_side_info.mixed_block_flag[gr][ch] == 1) && (sb < 2) {
|
(theMPEG1SideInfo.mixed_block_flag[gr][ch] == 1) && (sb < 2) {
|
||||||
bt = 0
|
bt = 0
|
||||||
}
|
}
|
||||||
/* Do the inverse modified DCT and windowing */
|
/* Do the inverse modified DCT and windowing */
|
||||||
|
@ -19,7 +19,6 @@ package mp3
|
|||||||
// #include "pdmp3.h"
|
// #include "pdmp3.h"
|
||||||
//
|
//
|
||||||
// extern t_mpeg1_header g_frame_header;
|
// extern t_mpeg1_header g_frame_header;
|
||||||
// extern t_mpeg1_side_info g_side_info;
|
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -64,7 +63,7 @@ func readMainL3() error {
|
|||||||
* frames that should be used. This buffer is later accessed by the
|
* frames that should be used. This buffer is later accessed by the
|
||||||
* getMainBits function in the same way as the side info is.
|
* getMainBits function in the same way as the side info is.
|
||||||
*/
|
*/
|
||||||
if err := getMainData(main_data_size, int(C.g_side_info.main_data_begin)); err != nil {
|
if err := getMainData(main_data_size, int(theMPEG1SideInfo.main_data_begin)); err != nil {
|
||||||
/* This could be due to not enough data in reservoir */
|
/* This could be due to not enough data in reservoir */
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -72,10 +71,10 @@ func readMainL3() error {
|
|||||||
for ch := 0; ch < nch; ch++ {
|
for ch := 0; ch < nch; ch++ {
|
||||||
part_2_start := getMainPos()
|
part_2_start := getMainPos()
|
||||||
/* Number of bits in the bitstream for the bands */
|
/* Number of bits in the bitstream for the bands */
|
||||||
slen1 := mpeg1_scalefac_sizes[C.g_side_info.scalefac_compress[gr][ch]][0]
|
slen1 := mpeg1_scalefac_sizes[theMPEG1SideInfo.scalefac_compress[gr][ch]][0]
|
||||||
slen2 := mpeg1_scalefac_sizes[C.g_side_info.scalefac_compress[gr][ch]][1]
|
slen2 := mpeg1_scalefac_sizes[theMPEG1SideInfo.scalefac_compress[gr][ch]][1]
|
||||||
if (C.g_side_info.win_switch_flag[gr][ch] != 0) && (C.g_side_info.block_type[gr][ch] == 2) {
|
if (theMPEG1SideInfo.win_switch_flag[gr][ch] != 0) && (theMPEG1SideInfo.block_type[gr][ch] == 2) {
|
||||||
if C.g_side_info.mixed_block_flag[gr][ch] != 0 {
|
if theMPEG1SideInfo.mixed_block_flag[gr][ch] != 0 {
|
||||||
for sfb := 0; sfb < 8; sfb++ {
|
for sfb := 0; sfb < 8; sfb++ {
|
||||||
theMPEG1MainData.scalefac_l[gr][ch][sfb] = getMainBits(slen1)
|
theMPEG1MainData.scalefac_l[gr][ch][sfb] = getMainBits(slen1)
|
||||||
}
|
}
|
||||||
@ -103,44 +102,44 @@ func readMainL3() error {
|
|||||||
}
|
}
|
||||||
} else { /* block_type == 0 if winswitch == 0 */
|
} else { /* block_type == 0 if winswitch == 0 */
|
||||||
/* Scale factor bands 0-5 */
|
/* Scale factor bands 0-5 */
|
||||||
if (C.g_side_info.scfsi[ch][0] == 0) || (gr == 0) {
|
if (theMPEG1SideInfo.scfsi[ch][0] == 0) || (gr == 0) {
|
||||||
for sfb := 0; sfb < 6; sfb++ {
|
for sfb := 0; sfb < 6; sfb++ {
|
||||||
theMPEG1MainData.scalefac_l[gr][ch][sfb] = getMainBits(slen1)
|
theMPEG1MainData.scalefac_l[gr][ch][sfb] = getMainBits(slen1)
|
||||||
}
|
}
|
||||||
} else if (C.g_side_info.scfsi[ch][0] == 1) && (gr == 1) {
|
} else if (theMPEG1SideInfo.scfsi[ch][0] == 1) && (gr == 1) {
|
||||||
/* Copy scalefactors from granule 0 to granule 1 */
|
/* Copy scalefactors from granule 0 to granule 1 */
|
||||||
for sfb := 0; sfb < 6; sfb++ {
|
for sfb := 0; sfb < 6; sfb++ {
|
||||||
theMPEG1MainData.scalefac_l[1][ch][sfb] = theMPEG1MainData.scalefac_l[0][ch][sfb]
|
theMPEG1MainData.scalefac_l[1][ch][sfb] = theMPEG1MainData.scalefac_l[0][ch][sfb]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Scale factor bands 6-10 */
|
/* Scale factor bands 6-10 */
|
||||||
if (C.g_side_info.scfsi[ch][1] == 0) || (gr == 0) {
|
if (theMPEG1SideInfo.scfsi[ch][1] == 0) || (gr == 0) {
|
||||||
for sfb := 6; sfb < 11; sfb++ {
|
for sfb := 6; sfb < 11; sfb++ {
|
||||||
theMPEG1MainData.scalefac_l[gr][ch][sfb] = getMainBits(slen1)
|
theMPEG1MainData.scalefac_l[gr][ch][sfb] = getMainBits(slen1)
|
||||||
}
|
}
|
||||||
} else if (C.g_side_info.scfsi[ch][1] == 1) && (gr == 1) {
|
} else if (theMPEG1SideInfo.scfsi[ch][1] == 1) && (gr == 1) {
|
||||||
/* Copy scalefactors from granule 0 to granule 1 */
|
/* Copy scalefactors from granule 0 to granule 1 */
|
||||||
for sfb := 6; sfb < 11; sfb++ {
|
for sfb := 6; sfb < 11; sfb++ {
|
||||||
theMPEG1MainData.scalefac_l[1][ch][sfb] = theMPEG1MainData.scalefac_l[0][ch][sfb]
|
theMPEG1MainData.scalefac_l[1][ch][sfb] = theMPEG1MainData.scalefac_l[0][ch][sfb]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Scale factor bands 11-15 */
|
/* Scale factor bands 11-15 */
|
||||||
if (C.g_side_info.scfsi[ch][2] == 0) || (gr == 0) {
|
if (theMPEG1SideInfo.scfsi[ch][2] == 0) || (gr == 0) {
|
||||||
for sfb := 11; sfb < 16; sfb++ {
|
for sfb := 11; sfb < 16; sfb++ {
|
||||||
theMPEG1MainData.scalefac_l[gr][ch][sfb] = getMainBits(slen2)
|
theMPEG1MainData.scalefac_l[gr][ch][sfb] = getMainBits(slen2)
|
||||||
}
|
}
|
||||||
} else if (C.g_side_info.scfsi[ch][2] == 1) && (gr == 1) {
|
} else if (theMPEG1SideInfo.scfsi[ch][2] == 1) && (gr == 1) {
|
||||||
/* Copy scalefactors from granule 0 to granule 1 */
|
/* Copy scalefactors from granule 0 to granule 1 */
|
||||||
for sfb := 11; sfb < 16; sfb++ {
|
for sfb := 11; sfb < 16; sfb++ {
|
||||||
theMPEG1MainData.scalefac_l[1][ch][sfb] = theMPEG1MainData.scalefac_l[0][ch][sfb]
|
theMPEG1MainData.scalefac_l[1][ch][sfb] = theMPEG1MainData.scalefac_l[0][ch][sfb]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Scale factor bands 16-20 */
|
/* Scale factor bands 16-20 */
|
||||||
if (C.g_side_info.scfsi[ch][3] == 0) || (gr == 0) {
|
if (theMPEG1SideInfo.scfsi[ch][3] == 0) || (gr == 0) {
|
||||||
for sfb := 16; sfb < 21; sfb++ {
|
for sfb := 16; sfb < 21; sfb++ {
|
||||||
theMPEG1MainData.scalefac_l[gr][ch][sfb] = getMainBits(slen2)
|
theMPEG1MainData.scalefac_l[gr][ch][sfb] = getMainBits(slen2)
|
||||||
}
|
}
|
||||||
} else if (C.g_side_info.scfsi[ch][3] == 1) && (gr == 1) {
|
} else if (theMPEG1SideInfo.scfsi[ch][3] == 1) && (gr == 1) {
|
||||||
/* Copy scalefactors from granule 0 to granule 1 */
|
/* Copy scalefactors from granule 0 to granule 1 */
|
||||||
for sfb := 16; sfb < 21; sfb++ {
|
for sfb := 16; sfb < 21; sfb++ {
|
||||||
theMPEG1MainData.scalefac_l[1][ch][sfb] = theMPEG1MainData.scalefac_l[0][ch][sfb]
|
theMPEG1MainData.scalefac_l[1][ch][sfb] = theMPEG1MainData.scalefac_l[0][ch][sfb]
|
||||||
|
@ -60,7 +60,6 @@ g_sampling_frequency[3] = { 44100 * Hz,48000 * Hz,32000 * Hz };
|
|||||||
unsigned synth_init = 1;
|
unsigned synth_init = 1;
|
||||||
|
|
||||||
t_mpeg1_header g_frame_header;
|
t_mpeg1_header g_frame_header;
|
||||||
t_mpeg1_side_info g_side_info; /* < 100 words */
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
static void dmp_fr(t_mpeg1_header *hdr){
|
static void dmp_fr(t_mpeg1_header *hdr){
|
||||||
|
@ -47,30 +47,5 @@ typedef struct { /* MPEG1 Layer 1-3 frame header */
|
|||||||
unsigned emphasis; /* 2 bits */
|
unsigned emphasis; /* 2 bits */
|
||||||
}
|
}
|
||||||
t_mpeg1_header;
|
t_mpeg1_header;
|
||||||
typedef struct { /* MPEG1 Layer 3 Side Information : [2][2] means [gr][ch] */
|
|
||||||
unsigned main_data_begin; /* 9 bits */
|
|
||||||
unsigned private_bits; /* 3 bits in mono,5 in stereo */
|
|
||||||
unsigned scfsi[2][4]; /* 1 bit */
|
|
||||||
unsigned part2_3_length[2][2]; /* 12 bits */
|
|
||||||
unsigned big_values[2][2]; /* 9 bits */
|
|
||||||
unsigned global_gain[2][2]; /* 8 bits */
|
|
||||||
unsigned scalefac_compress[2][2]; /* 4 bits */
|
|
||||||
unsigned win_switch_flag[2][2]; /* 1 bit */
|
|
||||||
/* if(win_switch_flag[][]) */ //use a union dammit
|
|
||||||
unsigned block_type[2][2]; /* 2 bits */
|
|
||||||
unsigned mixed_block_flag[2][2]; /* 1 bit */
|
|
||||||
unsigned table_select[2][2][3]; /* 5 bits */
|
|
||||||
unsigned subblock_gain[2][2][3]; /* 3 bits */
|
|
||||||
/* else */
|
|
||||||
/* table_select[][][] */
|
|
||||||
unsigned region0_count[2][2]; /* 4 bits */
|
|
||||||
unsigned region1_count[2][2]; /* 3 bits */
|
|
||||||
/* end */
|
|
||||||
unsigned preflag[2][2]; /* 1 bit */
|
|
||||||
unsigned scalefac_scale[2][2]; /* 1 bit */
|
|
||||||
unsigned count1table_select[2][2];/* 1 bit */
|
|
||||||
unsigned count1[2][2]; /* Not in file,calc. by huff.dec.! */
|
|
||||||
}
|
|
||||||
t_mpeg1_side_info;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,7 +18,6 @@ package mp3
|
|||||||
|
|
||||||
// #include "pdmp3.h"
|
// #include "pdmp3.h"
|
||||||
//
|
//
|
||||||
// extern t_mpeg1_side_info g_side_info;
|
|
||||||
// extern t_mpeg1_header g_frame_header;
|
// extern t_mpeg1_header g_frame_header;
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
@ -171,37 +170,37 @@ func readHeader() error {
|
|||||||
|
|
||||||
func readHuffman(part_2_start, gr, ch int) error {
|
func readHuffman(part_2_start, gr, ch int) error {
|
||||||
/* Check that there is any data to decode. If not,zero the array. */
|
/* Check that there is any data to decode. If not,zero the array. */
|
||||||
if C.g_side_info.part2_3_length[gr][ch] == 0 {
|
if theMPEG1SideInfo.part2_3_length[gr][ch] == 0 {
|
||||||
for is_pos := 0; is_pos < 576; is_pos++ {
|
for is_pos := 0; is_pos < 576; is_pos++ {
|
||||||
theMPEG1MainData.is[gr][ch][is_pos] = 0.0
|
theMPEG1MainData.is[gr][ch][is_pos] = 0.0
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
/* Calculate bit_pos_end which is the index of the last bit for this part. */
|
/* Calculate bit_pos_end which is the index of the last bit for this part. */
|
||||||
bit_pos_end := part_2_start + int(C.g_side_info.part2_3_length[gr][ch]) - 1
|
bit_pos_end := part_2_start + int(theMPEG1SideInfo.part2_3_length[gr][ch]) - 1
|
||||||
/* Determine region boundaries */
|
/* Determine region boundaries */
|
||||||
region_1_start := 0
|
region_1_start := 0
|
||||||
region_2_start := 0
|
region_2_start := 0
|
||||||
if (C.g_side_info.win_switch_flag[gr][ch] == 1) && (C.g_side_info.block_type[gr][ch] == 2) {
|
if (theMPEG1SideInfo.win_switch_flag[gr][ch] == 1) && (theMPEG1SideInfo.block_type[gr][ch] == 2) {
|
||||||
region_1_start = 36 /* sfb[9/3]*3=36 */
|
region_1_start = 36 /* sfb[9/3]*3=36 */
|
||||||
region_2_start = 576 /* No Region2 for short block case. */
|
region_2_start = 576 /* No Region2 for short block case. */
|
||||||
} else {
|
} else {
|
||||||
sfreq := C.g_frame_header.sampling_frequency
|
sfreq := C.g_frame_header.sampling_frequency
|
||||||
region_1_start =
|
region_1_start =
|
||||||
sfBandIndicesSet[sfreq].l[C.g_side_info.region0_count[gr][ch]+1]
|
sfBandIndicesSet[sfreq].l[theMPEG1SideInfo.region0_count[gr][ch]+1]
|
||||||
region_2_start =
|
region_2_start =
|
||||||
sfBandIndicesSet[sfreq].l[C.g_side_info.region0_count[gr][ch]+
|
sfBandIndicesSet[sfreq].l[theMPEG1SideInfo.region0_count[gr][ch]+
|
||||||
C.g_side_info.region1_count[gr][ch]+2]
|
theMPEG1SideInfo.region1_count[gr][ch]+2]
|
||||||
}
|
}
|
||||||
/* Read big_values using tables according to region_x_start */
|
/* Read big_values using tables according to region_x_start */
|
||||||
for is_pos := 0; is_pos < int(C.g_side_info.big_values[gr][ch])*2; is_pos++ {
|
for is_pos := 0; is_pos < int(theMPEG1SideInfo.big_values[gr][ch])*2; is_pos++ {
|
||||||
table_num := 0
|
table_num := 0
|
||||||
if is_pos < region_1_start {
|
if is_pos < region_1_start {
|
||||||
table_num = int(C.g_side_info.table_select[gr][ch][0])
|
table_num = int(theMPEG1SideInfo.table_select[gr][ch][0])
|
||||||
} else if is_pos < region_2_start {
|
} else if is_pos < region_2_start {
|
||||||
table_num = int(C.g_side_info.table_select[gr][ch][1])
|
table_num = int(theMPEG1SideInfo.table_select[gr][ch][1])
|
||||||
} else {
|
} else {
|
||||||
table_num = int(C.g_side_info.table_select[gr][ch][2])
|
table_num = int(theMPEG1SideInfo.table_select[gr][ch][2])
|
||||||
}
|
}
|
||||||
/* Get next Huffman coded words */
|
/* Get next Huffman coded words */
|
||||||
x, y, _, _, err := huffmanDecode(table_num)
|
x, y, _, _, err := huffmanDecode(table_num)
|
||||||
@ -214,8 +213,8 @@ func readHuffman(part_2_start, gr, ch int) error {
|
|||||||
theMPEG1MainData.is[gr][ch][is_pos] = float32(y)
|
theMPEG1MainData.is[gr][ch][is_pos] = float32(y)
|
||||||
}
|
}
|
||||||
/* Read small values until is_pos = 576 or we run out of huffman data */
|
/* Read small values until is_pos = 576 or we run out of huffman data */
|
||||||
table_num := int(C.g_side_info.count1table_select[gr][ch]) + 32
|
table_num := int(theMPEG1SideInfo.count1table_select[gr][ch]) + 32
|
||||||
is_pos := int(C.g_side_info.big_values[gr][ch]) * 2
|
is_pos := int(theMPEG1SideInfo.big_values[gr][ch]) * 2
|
||||||
for ; (is_pos <= 572) && (getMainPos() <= bit_pos_end); is_pos++ {
|
for ; (is_pos <= 572) && (getMainPos() <= bit_pos_end); is_pos++ {
|
||||||
/* Get next Huffman coded words */
|
/* Get next Huffman coded words */
|
||||||
x, y, v, w, err := huffmanDecode(table_num)
|
x, y, v, w, err := huffmanDecode(table_num)
|
||||||
@ -245,7 +244,7 @@ func readHuffman(part_2_start, gr, ch int) error {
|
|||||||
is_pos -= 4
|
is_pos -= 4
|
||||||
}
|
}
|
||||||
/* Setup count1 which is the index of the first sample in the rzero reg. */
|
/* Setup count1 which is the index of the first sample in the rzero reg. */
|
||||||
C.g_side_info.count1[gr][ch] = C.unsigned(is_pos)
|
theMPEG1SideInfo.count1[gr][ch] = is_pos
|
||||||
/* Zero out the last part if necessary */
|
/* Zero out the last part if necessary */
|
||||||
for ; /* is_pos comes from last for-loop */ is_pos < 576; is_pos++ {
|
for ; /* is_pos comes from last for-loop */ is_pos < 576; is_pos++ {
|
||||||
theMPEG1MainData.is[gr][ch][is_pos] = 0.0
|
theMPEG1MainData.is[gr][ch][is_pos] = 0.0
|
||||||
|
@ -19,7 +19,6 @@ package mp3
|
|||||||
// #include "pdmp3.h"
|
// #include "pdmp3.h"
|
||||||
//
|
//
|
||||||
// extern t_mpeg1_header g_frame_header;
|
// extern t_mpeg1_header g_frame_header;
|
||||||
// extern t_mpeg1_side_info g_side_info;
|
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -74,54 +73,54 @@ func readAudioL3() error {
|
|||||||
}
|
}
|
||||||
/* Parse audio data */
|
/* Parse audio data */
|
||||||
/* Pointer to where we should start reading main data */
|
/* Pointer to where we should start reading main data */
|
||||||
C.g_side_info.main_data_begin = C.uint(getSideBits(9))
|
theMPEG1SideInfo.main_data_begin = getSideBits(9)
|
||||||
/* Get private bits. Not used for anything. */
|
/* Get private bits. Not used for anything. */
|
||||||
if C.g_frame_header.mode == C.mpeg1_mode_single_channel {
|
if C.g_frame_header.mode == C.mpeg1_mode_single_channel {
|
||||||
C.g_side_info.private_bits = C.uint(getSideBits(5))
|
theMPEG1SideInfo.private_bits = getSideBits(5)
|
||||||
} else {
|
} else {
|
||||||
C.g_side_info.private_bits = C.uint(getSideBits(3))
|
theMPEG1SideInfo.private_bits = getSideBits(3)
|
||||||
}
|
}
|
||||||
/* Get scale factor selection information */
|
/* Get scale factor selection information */
|
||||||
for ch := 0; ch < nch; ch++ {
|
for ch := 0; ch < nch; ch++ {
|
||||||
for scfsi_band := 0; scfsi_band < 4; scfsi_band++ {
|
for scfsi_band := 0; scfsi_band < 4; scfsi_band++ {
|
||||||
C.g_side_info.scfsi[ch][scfsi_band] = C.uint(getSideBits(1))
|
theMPEG1SideInfo.scfsi[ch][scfsi_band] = getSideBits(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Get the rest of the side information */
|
/* Get the rest of the side information */
|
||||||
for gr := 0; gr < 2; gr++ {
|
for gr := 0; gr < 2; gr++ {
|
||||||
for ch := 0; ch < nch; ch++ {
|
for ch := 0; ch < nch; ch++ {
|
||||||
C.g_side_info.part2_3_length[gr][ch] = C.uint(getSideBits(12))
|
theMPEG1SideInfo.part2_3_length[gr][ch] = getSideBits(12)
|
||||||
C.g_side_info.big_values[gr][ch] = C.uint(getSideBits(9))
|
theMPEG1SideInfo.big_values[gr][ch] = getSideBits(9)
|
||||||
C.g_side_info.global_gain[gr][ch] = C.uint(getSideBits(8))
|
theMPEG1SideInfo.global_gain[gr][ch] = getSideBits(8)
|
||||||
C.g_side_info.scalefac_compress[gr][ch] = C.uint(getSideBits(4))
|
theMPEG1SideInfo.scalefac_compress[gr][ch] = getSideBits(4)
|
||||||
C.g_side_info.win_switch_flag[gr][ch] = C.uint(getSideBits(1))
|
theMPEG1SideInfo.win_switch_flag[gr][ch] = getSideBits(1)
|
||||||
if C.g_side_info.win_switch_flag[gr][ch] == 1 {
|
if theMPEG1SideInfo.win_switch_flag[gr][ch] == 1 {
|
||||||
C.g_side_info.block_type[gr][ch] = C.uint(getSideBits(2))
|
theMPEG1SideInfo.block_type[gr][ch] = getSideBits(2)
|
||||||
C.g_side_info.mixed_block_flag[gr][ch] = C.uint(getSideBits(1))
|
theMPEG1SideInfo.mixed_block_flag[gr][ch] = getSideBits(1)
|
||||||
for region := 0; region < 2; region++ {
|
for region := 0; region < 2; region++ {
|
||||||
C.g_side_info.table_select[gr][ch][region] = C.uint(getSideBits(5))
|
theMPEG1SideInfo.table_select[gr][ch][region] = getSideBits(5)
|
||||||
}
|
}
|
||||||
for window := 0; window < 3; window++ {
|
for window := 0; window < 3; window++ {
|
||||||
C.g_side_info.subblock_gain[gr][ch][window] = C.uint(getSideBits(3))
|
theMPEG1SideInfo.subblock_gain[gr][ch][window] = getSideBits(3)
|
||||||
}
|
}
|
||||||
if (C.g_side_info.block_type[gr][ch] == 2) && (C.g_side_info.mixed_block_flag[gr][ch] == 0) {
|
if (theMPEG1SideInfo.block_type[gr][ch] == 2) && (theMPEG1SideInfo.mixed_block_flag[gr][ch] == 0) {
|
||||||
C.g_side_info.region0_count[gr][ch] = 8 /* Implicit */
|
theMPEG1SideInfo.region0_count[gr][ch] = 8 /* Implicit */
|
||||||
} else {
|
} else {
|
||||||
C.g_side_info.region0_count[gr][ch] = 7 /* Implicit */
|
theMPEG1SideInfo.region0_count[gr][ch] = 7 /* Implicit */
|
||||||
}
|
}
|
||||||
/* The standard is wrong on this!!! */ /* Implicit */
|
/* The standard is wrong on this!!! */ /* Implicit */
|
||||||
C.g_side_info.region1_count[gr][ch] = 20 - C.g_side_info.region0_count[gr][ch]
|
theMPEG1SideInfo.region1_count[gr][ch] = 20 - theMPEG1SideInfo.region0_count[gr][ch]
|
||||||
} else {
|
} else {
|
||||||
for region := 0; region < 3; region++ {
|
for region := 0; region < 3; region++ {
|
||||||
C.g_side_info.table_select[gr][ch][region] = C.uint(getSideBits(5))
|
theMPEG1SideInfo.table_select[gr][ch][region] = getSideBits(5)
|
||||||
}
|
}
|
||||||
C.g_side_info.region0_count[gr][ch] = C.uint(getSideBits(4))
|
theMPEG1SideInfo.region0_count[gr][ch] = getSideBits(4)
|
||||||
C.g_side_info.region1_count[gr][ch] = C.uint(getSideBits(3))
|
theMPEG1SideInfo.region1_count[gr][ch] = getSideBits(3)
|
||||||
C.g_side_info.block_type[gr][ch] = 0 /* Implicit */
|
theMPEG1SideInfo.block_type[gr][ch] = 0 /* Implicit */
|
||||||
}
|
}
|
||||||
C.g_side_info.preflag[gr][ch] = C.uint(getSideBits(1))
|
theMPEG1SideInfo.preflag[gr][ch] = getSideBits(1)
|
||||||
C.g_side_info.scalefac_scale[gr][ch] = C.uint(getSideBits(1))
|
theMPEG1SideInfo.scalefac_scale[gr][ch] = getSideBits(1)
|
||||||
C.g_side_info.count1table_select[gr][ch] = C.uint(getSideBits(1))
|
theMPEG1SideInfo.count1table_select[gr][ch] = getSideBits(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user