diff --git a/audio/mp3/decode_notjs.go b/audio/mp3/decode_notjs.go index 6d806eec7..8b4dea14e 100644 --- a/audio/mp3/decode_notjs.go +++ b/audio/mp3/decode_notjs.go @@ -124,19 +124,18 @@ func getBytes(buf []int) (int, error) { return len(buf), nil } -//export Get_Filepos -func Get_Filepos() C.unsigned { +func getFilepos() int { if len(readerCache) == 0 && readerEOF { return eof } - return C.unsigned(readerPos) + return readerPos } func decode(r io.Reader, w io.Writer) error { // TODO: Decoder should know number of channels reader = r writer = w - for Get_Filepos() != eof { + for getFilepos() != eof { err := readFrame() if err == nil { if err := decodeL3(); err != nil { @@ -144,7 +143,7 @@ func decode(r io.Reader, w io.Writer) error { } continue } - if Get_Filepos() == eof { + if getFilepos() == eof { break } return err diff --git a/audio/mp3/maindata.go b/audio/mp3/maindata.go index 04f804c92..fe3474add 100644 --- a/audio/mp3/maindata.go +++ b/audio/mp3/maindata.go @@ -71,7 +71,7 @@ func readMainL3() error { } for gr := 0; gr < 2; gr++ { for ch := 0; ch < nch; ch++ { - part_2_start := int(Get_Main_Pos()) + part_2_start := getMainPos() /* Number of bits in the bitstream for the bands */ slen1 := mpeg1_scalefac_sizes[C.g_side_info.scalefac_compress[gr][ch]][0] slen2 := mpeg1_scalefac_sizes[C.g_side_info.scalefac_compress[gr][ch]][1] @@ -270,18 +270,15 @@ func getMainBits(num int) int { return int(tmp) } -//export Get_Main_Pos -func Get_Main_Pos() C.unsigned { +func getMainPos() int { pos := theMainDataBytes.pos pos *= 8 /* Multiply by 8 to get number of bits */ pos += theMainDataBytes.idx /* Add current bit index */ - return C.unsigned(pos) + return pos } -//export Set_Main_Pos -func Set_Main_Pos(bit_pos C.unsigned) C.int { +func setMainPos(bit_pos int) { theMainDataBytes.ptr = theMainDataBytes.vec[bit_pos>>3:] theMainDataBytes.pos = int(bit_pos) >> 3 theMainDataBytes.idx = int(bit_pos) & 0x7 - return C.OK } diff --git a/audio/mp3/pdmp3.h b/audio/mp3/pdmp3.h index 4c74b0740..48165b3c7 100644 --- a/audio/mp3/pdmp3.h +++ b/audio/mp3/pdmp3.h @@ -84,9 +84,4 @@ typedef struct { /* Scale factor band indices,for long and short windows */ } t_sf_band_indices; -unsigned Get_Filepos(void); - -unsigned Get_Main_Pos(void); -int Set_Main_Pos(unsigned bit_pos); - #endif diff --git a/audio/mp3/read.go b/audio/mp3/read.go index 56ea27268..ff254dab6 100644 --- a/audio/mp3/read.go +++ b/audio/mp3/read.go @@ -148,23 +148,23 @@ func readHeader() error { /* Check for invalid values and impossible combinations */ if C.g_frame_header.id != 3 { return fmt.Errorf("mp3: ID must be 3\nHeader word is 0x%08x at file pos %d", - header, C.Get_Filepos()) + header, getFilepos()) } if C.g_frame_header.bitrate_index == 0 { return fmt.Errorf("mp3: Free bitrate format NIY!\nHeader word is 0x%08x at file pos %d", - header, Get_Filepos()) + header, getFilepos()) } if C.g_frame_header.bitrate_index == 15 { return fmt.Errorf("mp3: bitrate_index = 15 is invalid!\nHeader word is 0x%08x at file pos %d", - header, Get_Filepos()) + header, getFilepos()) } if C.g_frame_header.sampling_frequency == 3 { return fmt.Errorf("mp3: sampling_frequency = 3 is invalid! Header word is 0x%08x at file pos %d", - header, Get_Filepos()) + header, getFilepos()) } if C.g_frame_header.layer == 0 { return fmt.Errorf("mp3: layer = 0 is invalid! Header word is 0x%08x at file pos %d", - header, Get_Filepos()) + header, getFilepos()) } C.g_frame_header.layer = 4 - C.g_frame_header.layer return nil @@ -217,7 +217,7 @@ func readHuffman(part_2_start, gr, ch int) error { /* 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 is_pos := int(C.g_side_info.big_values[gr][ch]) * 2 - for ; (is_pos <= 572) && (int(Get_Main_Pos()) <= bit_pos_end); is_pos++ { + for ; (is_pos <= 572) && (getMainPos() <= bit_pos_end); is_pos++ { /* Get next Huffman coded words */ x, y, v, w, err := huffmanDecode(table_num) if err != nil { @@ -241,7 +241,7 @@ func readHuffman(part_2_start, gr, ch int) error { C.g_main_data.is[gr][ch][is_pos] = C.float(y) } /* Check that we didn't read past the end of this section */ - if int(C.Get_Main_Pos()) > (bit_pos_end + 1) { + if getMainPos() > (bit_pos_end + 1) { /* Remove last words read */ is_pos -= 4 } @@ -252,6 +252,6 @@ func readHuffman(part_2_start, gr, ch int) error { C.g_main_data.is[gr][ch][is_pos] = 0.0 } /* Set the bitpos to point to the next part to read */ - C.Set_Main_Pos(C.unsigned(bit_pos_end) + 1) + setMainPos(bit_pos_end + 1) return nil } diff --git a/audio/mp3/sideinfo.go b/audio/mp3/sideinfo.go index 03ce9fcaa..db5cff9c4 100644 --- a/audio/mp3/sideinfo.go +++ b/audio/mp3/sideinfo.go @@ -149,7 +149,7 @@ func getSideinfo(size int) error { return fmt.Errorf("mp3: unexpected EOF at getSideinfo") } return fmt.Errorf("mp3: couldn't read sideinfo %d bytes at pos %d: %v", - size, Get_Filepos(), err) + size, getFilepos(), err) } theSideInfo.vec = buf[:n] theSideInfo.idx = 0