seperate fifo with tta header
This commit is contained in:
parent
56b11626fa
commit
af5022af62
23
decoder.go
23
decoder.go
|
@ -290,6 +290,27 @@ func (this *Decoder) SetInfo(info *tta_info) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (this *Decoder) ReadHeader(info *tta_info) (uint32, error) {
|
||||
size := this.fifo.skip_id3v2()
|
||||
this.fifo.reset()
|
||||
if 'T' != this.fifo.read_byte() ||
|
||||
'T' != this.fifo.read_byte() ||
|
||||
'A' != this.fifo.read_byte() ||
|
||||
'1' != this.fifo.read_byte() {
|
||||
return 0, TTA_FORMAT_ERROR
|
||||
}
|
||||
info.format = uint32(this.fifo.read_uint16())
|
||||
info.nch = uint32(this.fifo.read_uint16())
|
||||
info.bps = uint32(this.fifo.read_uint16())
|
||||
info.sps = this.fifo.read_uint32()
|
||||
info.samples = this.fifo.read_uint32()
|
||||
if !this.fifo.read_crc32() {
|
||||
return 0, TTA_FILE_ERROR
|
||||
}
|
||||
size += 22
|
||||
return size, nil
|
||||
}
|
||||
|
||||
func (this *Decoder) GetInfo(info *tta_info, pos int64) (err error) {
|
||||
if pos != 0 {
|
||||
if _, err = this.fifo.io.Seek(pos, os.SEEK_SET); err != nil {
|
||||
|
@ -299,7 +320,7 @@ func (this *Decoder) GetInfo(info *tta_info, pos int64) (err error) {
|
|||
}
|
||||
this.fifo.read_start()
|
||||
var p uint32
|
||||
if p, err = this.fifo.read_tta_header(info); err != nil {
|
||||
if p, err = this.ReadHeader(info); err != nil {
|
||||
return
|
||||
}
|
||||
if info.format > 2 ||
|
||||
|
|
40
encoder.go
40
encoder.go
|
@ -250,6 +250,44 @@ func (this *Encoder) frame_reset(frame uint32, iocb io.ReadWriteSeeker) {
|
|||
this.frame_init(frame)
|
||||
}
|
||||
|
||||
func (this *Encoder) WriteHeader(info *tta_info) (size uint32, err error) {
|
||||
this.fifo.reset()
|
||||
// write TTA1 signature
|
||||
if err = this.fifo.write_byte('T'); err != nil {
|
||||
return
|
||||
}
|
||||
if err = this.fifo.write_byte('T'); err != nil {
|
||||
return
|
||||
}
|
||||
if err = this.fifo.write_byte('A'); err != nil {
|
||||
return
|
||||
}
|
||||
if err = this.fifo.write_byte('1'); err != nil {
|
||||
return
|
||||
}
|
||||
if err = this.fifo.write_uint16(uint16(info.format)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = this.fifo.write_uint16(uint16(info.nch)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = this.fifo.write_uint16(uint16(info.bps)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = this.fifo.write_uint32(info.sps); err != nil {
|
||||
return
|
||||
}
|
||||
if err = this.fifo.write_uint32(info.samples); err != nil {
|
||||
return
|
||||
}
|
||||
if err = this.fifo.write_crc32(); err != nil {
|
||||
return
|
||||
}
|
||||
size = 22
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (this *Encoder) SetInfo(info *tta_info, pos int64) (err error) {
|
||||
if info.format > 2 ||
|
||||
info.bps < MIN_BPS ||
|
||||
|
@ -266,7 +304,7 @@ func (this *Encoder) SetInfo(info *tta_info, pos int64) (err error) {
|
|||
}
|
||||
this.fifo.write_start()
|
||||
var p uint32
|
||||
if p, err = this.fifo.write_tta_header(info); err != nil {
|
||||
if p, err = this.WriteHeader(info); err != nil {
|
||||
return
|
||||
}
|
||||
this.offset = uint64(pos) + uint64(p)
|
||||
|
|
61
fifo.go
61
fifo.go
|
@ -71,27 +71,6 @@ func (s *tta_fifo) skip_id3v2() (size uint32) {
|
|||
return
|
||||
}
|
||||
|
||||
func (s *tta_fifo) read_tta_header(info *tta_info) (uint32, error) {
|
||||
size := s.skip_id3v2()
|
||||
s.reset()
|
||||
if 'T' != s.read_byte() ||
|
||||
'T' != s.read_byte() ||
|
||||
'A' != s.read_byte() ||
|
||||
'1' != s.read_byte() {
|
||||
return 0, TTA_FORMAT_ERROR
|
||||
}
|
||||
info.format = uint32(s.read_uint16())
|
||||
info.nch = uint32(s.read_uint16())
|
||||
info.bps = uint32(s.read_uint16())
|
||||
info.sps = s.read_uint32()
|
||||
info.samples = s.read_uint32()
|
||||
if !s.read_crc32() {
|
||||
return 0, TTA_FILE_ERROR
|
||||
}
|
||||
size += 22
|
||||
return size, nil
|
||||
}
|
||||
|
||||
func (s *tta_fifo) get_value(rice *tta_adapt) (value int32) {
|
||||
if s.bcache^bit_mask[s.bcount] == 0 {
|
||||
value += int32(s.bcount)
|
||||
|
@ -221,46 +200,6 @@ func (s *tta_fifo) write_skip_bytes(size uint32) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *tta_fifo) write_tta_header(info *tta_info) (size uint32, err error) {
|
||||
s.reset()
|
||||
|
||||
// write TTA1 signature
|
||||
if err = s.write_byte('T'); err != nil {
|
||||
return
|
||||
}
|
||||
if err = s.write_byte('T'); err != nil {
|
||||
return
|
||||
}
|
||||
if err = s.write_byte('A'); err != nil {
|
||||
return
|
||||
}
|
||||
if err = s.write_byte('1'); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.write_uint16(uint16(info.format)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = s.write_uint16(uint16(info.nch)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = s.write_uint16(uint16(info.bps)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = s.write_uint32(info.sps); err != nil {
|
||||
return
|
||||
}
|
||||
if err = s.write_uint32(info.samples); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.write_crc32(); err != nil {
|
||||
return
|
||||
}
|
||||
size = 22
|
||||
return
|
||||
}
|
||||
|
||||
func (s *tta_fifo) put_value(rice *tta_adapt, value int32) {
|
||||
var k, unary, outval uint32
|
||||
if value > 0 {
|
||||
|
|
Loading…
Reference in a new issue