hide more
This commit is contained in:
parent
96c279820d
commit
193b38ec0e
8
const.go
8
const.go
|
@ -10,6 +10,7 @@ const (
|
|||
MIN_BPS = 16
|
||||
MAX_NCH = 6
|
||||
TTA_FIFO_BUFFER_SIZE = 5120
|
||||
PCM_BUFFER_LENGTH = 5120
|
||||
|
||||
// TTA audio format
|
||||
TTA_FORMAT_SIMPLE = 1
|
||||
|
@ -17,7 +18,8 @@ const (
|
|||
TTA_VERSION = "2.3-go"
|
||||
)
|
||||
|
||||
var ( // TTA_CODEC_STATUS
|
||||
var (
|
||||
// TTA_CODEC_STATUS
|
||||
TTA_NO_ERROR error = nil // no known errors found
|
||||
TTA_OPEN_ERROR = errors.New("can't open file")
|
||||
TTA_FORMAT_ERROR = errors.New("not compatible file format")
|
||||
|
@ -25,9 +27,11 @@ var ( // TTA_CODEC_STATUS
|
|||
TTA_READ_ERROR = errors.New("can't read from input file")
|
||||
TTA_WRITE_ERROR = errors.New("can't write to output file")
|
||||
TTA_SEEK_ERROR = errors.New("file seek error")
|
||||
TTA_MEMORY_ERROR = errors.New("insufficient memory available")
|
||||
TTA_PASSWORD_ERROR = errors.New("password protected file")
|
||||
TTA_NOT_SUPPORTED = errors.New("unsupported architecture")
|
||||
|
||||
PARTIAL_WRITTEN_ERROR = errors.New("partial written")
|
||||
PARTIAL_READ_ERROR = errors.New("partial read")
|
||||
)
|
||||
|
||||
const ( // CPU_ARCH_TYPE
|
||||
|
|
|
@ -37,10 +37,10 @@ func Decompress(infile, outfile *os.File, passwd string, cb Callback) (err error
|
|||
smp_size := info.nch * ((info.bps + 7) / 8)
|
||||
data_size := info.samples * smp_size
|
||||
wave_hdr := WaveHeader{
|
||||
chunk_id: RIFF_SIGN,
|
||||
chunk_id: _RIFF_SIGN,
|
||||
chunk_size: data_size + 36,
|
||||
format: WAVE_SIGN,
|
||||
subchunk_id: fmt_SIGN,
|
||||
format: _WAVE_SIGN,
|
||||
subchunk_id: _FMT_SIGN,
|
||||
subchunk_size: 16,
|
||||
audio_format: 1,
|
||||
num_channels: uint16(info.nch),
|
||||
|
|
|
@ -35,8 +35,8 @@ func Compress(infile, outfile *os.File, passwd string, cb Callback) (err error)
|
|||
err = fmt.Errorf("incorrect data size info in wav file: %x", data_size)
|
||||
return
|
||||
}
|
||||
if (wave_hdr.chunk_id != RIFF_SIGN) ||
|
||||
(wave_hdr.format != WAVE_SIGN) ||
|
||||
if (wave_hdr.chunk_id != _RIFF_SIGN) ||
|
||||
(wave_hdr.format != _WAVE_SIGN) ||
|
||||
(wave_hdr.num_channels == 0) ||
|
||||
(wave_hdr.num_channels > MAX_NCH) ||
|
||||
(wave_hdr.bits_per_sample == 0) ||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// TODO: SSE4 optimization
|
||||
package tta
|
||||
|
||||
func NewCompatibleFilter(data [8]byte, shift int32) *tta_filter_compat {
|
||||
func NewCompatibleFilter(data [8]byte, shift int32) tta_filter {
|
||||
this := tta_filter_compat{}
|
||||
this.shift = shift
|
||||
this.round = 1 << uint32(shift-1)
|
||||
|
@ -119,7 +119,7 @@ func (this *tta_filter_compat) Encode(in *int32) {
|
|||
this.error = *in
|
||||
}
|
||||
|
||||
func NewSSEFilter(data [8]byte, shift int32) *tta_filter_sse {
|
||||
func NewSSEFilter(data [8]byte, shift int32) tta_filter {
|
||||
this := tta_filter_sse{}
|
||||
this.shift = shift
|
||||
this.round = 1 << uint32(shift-1)
|
||||
|
|
23
wav.go
23
wav.go
|
@ -1,26 +1,21 @@
|
|||
package tta
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
RIFF_SIGN = 0x46464952
|
||||
WAVE_SIGN = 0x45564157
|
||||
fmt_SIGN = 0x20746D66
|
||||
data_SIGN = 0x61746164
|
||||
_RIFF_SIGN = 0x46464952
|
||||
_WAVE_SIGN = 0x45564157
|
||||
_FMT_SIGN = 0x20746D66
|
||||
_DATA_SIGN = 0x61746164
|
||||
|
||||
WAVE_FORMAT_PCM = 1
|
||||
WAVE_FORMAT_EXTENSIBLE = 0xFFFE
|
||||
PCM_BUFFER_LENGTH = 5120
|
||||
_WAVE_FORMAT_PCM = 1
|
||||
_WAVE_FORMAT_EXTENSIBLE = 0xFFFE
|
||||
)
|
||||
|
||||
var PARTIAL_WRITTEN_ERROR = errors.New("partial written")
|
||||
var PARTIAL_READ_ERROR = errors.New("partial read")
|
||||
|
||||
type WaveHeader struct {
|
||||
chunk_id uint32
|
||||
chunk_size uint32
|
||||
|
@ -90,7 +85,7 @@ func (this *WaveHeader) Read(fd *os.File) (subchunk_size uint32, err error) {
|
|||
err = PARTIAL_READ_ERROR
|
||||
return
|
||||
}
|
||||
if this.audio_format == WAVE_FORMAT_EXTENSIBLE {
|
||||
if this.audio_format == _WAVE_FORMAT_EXTENSIBLE {
|
||||
wave_hdr_ex := WaveExtHeader{}
|
||||
if read_len, err = fd.Read(wave_hdr_ex.Bytes()); err != nil {
|
||||
return
|
||||
|
@ -119,7 +114,7 @@ func (this *WaveHeader) Read(fd *os.File) (subchunk_size uint32, err error) {
|
|||
err = PARTIAL_READ_ERROR
|
||||
return
|
||||
}
|
||||
if subchunk_hdr.subchunk_id == data_SIGN {
|
||||
if subchunk_hdr.subchunk_id == _DATA_SIGN {
|
||||
break
|
||||
}
|
||||
if _, err = fd.Seek(int64(subchunk_hdr.subchunk_size), os.SEEK_SET); err != nil {
|
||||
|
@ -140,7 +135,7 @@ func (this *WaveHeader) Write(fd *os.File, size uint32) (err error) {
|
|||
return
|
||||
}
|
||||
// Write Subchunk header
|
||||
subchunk_hdr := WaveSubchunkHeader{data_SIGN, size}
|
||||
subchunk_hdr := WaveSubchunkHeader{_DATA_SIGN, size}
|
||||
if write_len, err = fd.Write(subchunk_hdr.Bytes()); err != nil {
|
||||
return
|
||||
} else if write_len != int(unsafe.Sizeof(subchunk_hdr)) {
|
||||
|
|
Loading…
Reference in a new issue