Make info struct public
This commit is contained in:
parent
d845324160
commit
d708a9de89
10
codec.go
10
codec.go
|
@ -5,11 +5,11 @@ import (
|
|||
)
|
||||
|
||||
type Info struct {
|
||||
format uint32 // audio format
|
||||
nch uint32 // number of channels
|
||||
bps uint32 // bits per sample
|
||||
sps uint32 // samplerate (sps)
|
||||
samples uint32 // data length in samples
|
||||
Format uint32 // audio format
|
||||
Nch uint32 // number of channels
|
||||
Bps uint32 // bits per sample
|
||||
Sps uint32 // samplerate (sps)
|
||||
Samples uint32 // data length in samples
|
||||
}
|
||||
|
||||
type adapter struct {
|
||||
|
|
38
decoder.go
38
decoder.go
|
@ -37,9 +37,9 @@ func Decompress(infile io.ReadWriteSeeker, outfile io.WriteSeeker, passwd string
|
|||
if err = decoder.GetInfo(&info, 0); err != nil {
|
||||
return
|
||||
}
|
||||
smpSize := info.nch * ((info.bps + 7) / 8)
|
||||
dataSize := info.samples * smpSize
|
||||
waveHdr := wave.NewHeader(dataSize, uint16(info.nch), info.sps, uint16(info.bps), uint16(smpSize))
|
||||
smpSize := info.Nch * ((info.Bps + 7) / 8)
|
||||
dataSize := info.Samples * smpSize
|
||||
waveHdr := wave.NewHeader(dataSize, uint16(info.Nch), info.Sps, uint16(info.Bps), uint16(smpSize))
|
||||
if _, err = waveHdr.WriteTo(outfile); err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -262,11 +262,11 @@ func (d *Decoder) ReadHeader(info *Info) (uint32, error) {
|
|||
'1' != d.fifo.readByte() {
|
||||
return 0, errFormat
|
||||
}
|
||||
info.format = uint32(d.fifo.readUint16())
|
||||
info.nch = uint32(d.fifo.readUint16())
|
||||
info.bps = uint32(d.fifo.readUint16())
|
||||
info.sps = d.fifo.readUint32()
|
||||
info.samples = d.fifo.readUint32()
|
||||
info.Format = uint32(d.fifo.readUint16())
|
||||
info.Nch = uint32(d.fifo.readUint16())
|
||||
info.Bps = uint32(d.fifo.readUint16())
|
||||
info.Sps = d.fifo.readUint32()
|
||||
info.Samples = d.fifo.readUint32()
|
||||
if !d.fifo.readCrc32() {
|
||||
return 0, errFile
|
||||
}
|
||||
|
@ -286,13 +286,13 @@ func (d *Decoder) GetInfo(info *Info, pos int64) (err error) {
|
|||
if p, err = d.ReadHeader(info); err != nil {
|
||||
return
|
||||
}
|
||||
if info.format > 2 ||
|
||||
info.bps < minBPS ||
|
||||
info.bps > maxBPS ||
|
||||
info.nch > maxNCH {
|
||||
if info.Format > 2 ||
|
||||
info.Bps < minBPS ||
|
||||
info.Bps > maxBPS ||
|
||||
info.Nch > maxNCH {
|
||||
return errFormat
|
||||
}
|
||||
if info.format == formatEncrypted {
|
||||
if info.Format == formatEncrypted {
|
||||
if !d.passwordSet {
|
||||
return errPassword
|
||||
}
|
||||
|
@ -302,11 +302,11 @@ func (d *Decoder) GetInfo(info *Info, pos int64) (err error) {
|
|||
d.data = [8]byte{}
|
||||
}
|
||||
d.offset = uint64(pos) + uint64(p)
|
||||
d.format = info.format
|
||||
d.depth = (info.bps + 7) / 8
|
||||
d.flenStd = (256 * (info.sps) / 245)
|
||||
d.flenLast = info.samples % d.flenStd
|
||||
d.frames = info.samples / d.flenStd
|
||||
d.format = info.Format
|
||||
d.depth = (info.Bps + 7) / 8
|
||||
d.flenStd = (256 * (info.Sps) / 245)
|
||||
d.flenLast = info.Samples % d.flenStd
|
||||
d.frames = info.Samples / d.flenStd
|
||||
if d.flenLast != 0 {
|
||||
d.frames++
|
||||
} else {
|
||||
|
@ -315,7 +315,7 @@ func (d *Decoder) GetInfo(info *Info, pos int64) (err error) {
|
|||
d.rate = 0
|
||||
d.seekTable = make([]uint64, d.frames)
|
||||
d.seekAllowed = d.readSeekTable()
|
||||
d.channels = int(info.nch)
|
||||
d.channels = int(info.Nch)
|
||||
d.frameInit(0, false)
|
||||
return
|
||||
}
|
||||
|
|
42
encoder.go
42
encoder.go
|
@ -43,15 +43,15 @@ func Compress(infile io.ReadSeeker, outfile io.ReadWriteSeeker, passwd string, c
|
|||
encoder := NewEncoder(outfile)
|
||||
smpSize := uint32(waveHdr.NumChannels * ((waveHdr.BitsPerSample + 7) / 8))
|
||||
info := Info{
|
||||
nch: uint32(waveHdr.NumChannels),
|
||||
bps: uint32(waveHdr.BitsPerSample),
|
||||
sps: waveHdr.SampleRate,
|
||||
format: formatSimple,
|
||||
samples: dataSize / smpSize,
|
||||
Nch: uint32(waveHdr.NumChannels),
|
||||
Bps: uint32(waveHdr.BitsPerSample),
|
||||
Sps: waveHdr.SampleRate,
|
||||
Format: formatSimple,
|
||||
Samples: dataSize / smpSize,
|
||||
}
|
||||
if len(passwd) > 0 {
|
||||
encoder.SetPassword(passwd)
|
||||
info.format = formatEncrypted
|
||||
info.Format = formatEncrypted
|
||||
}
|
||||
bufSize := pcmBufferLength * smpSize
|
||||
buffer := make([]byte, bufSize)
|
||||
|
@ -257,19 +257,19 @@ func (e *Encoder) WriteHeader(info *Info) (size uint32, err error) {
|
|||
if err = e.fifo.writeByte('1'); err != nil {
|
||||
return
|
||||
}
|
||||
if err = e.fifo.writeUint16(uint16(info.format)); err != nil {
|
||||
if err = e.fifo.writeUint16(uint16(info.Format)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = e.fifo.writeUint16(uint16(info.nch)); err != nil {
|
||||
if err = e.fifo.writeUint16(uint16(info.Nch)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = e.fifo.writeUint16(uint16(info.bps)); err != nil {
|
||||
if err = e.fifo.writeUint16(uint16(info.Bps)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = e.fifo.writeUint32(info.sps); err != nil {
|
||||
if err = e.fifo.writeUint32(info.Sps); err != nil {
|
||||
return
|
||||
}
|
||||
if err = e.fifo.writeUint32(info.samples); err != nil {
|
||||
if err = e.fifo.writeUint32(info.Samples); err != nil {
|
||||
return
|
||||
}
|
||||
if err = e.fifo.writeCrc32(); err != nil {
|
||||
|
@ -281,10 +281,10 @@ func (e *Encoder) WriteHeader(info *Info) (size uint32, err error) {
|
|||
}
|
||||
|
||||
func (e *Encoder) SetInfo(info *Info) (err error) {
|
||||
if info.format > 2 ||
|
||||
info.bps < minBPS ||
|
||||
info.bps > maxBPS ||
|
||||
info.nch > maxNCH {
|
||||
if info.Format > 2 ||
|
||||
info.Bps < minBPS ||
|
||||
info.Bps > maxBPS ||
|
||||
info.Nch > maxNCH {
|
||||
return errFormat
|
||||
}
|
||||
var p uint32
|
||||
|
@ -292,11 +292,11 @@ func (e *Encoder) SetInfo(info *Info) (err error) {
|
|||
return
|
||||
}
|
||||
e.offset = uint64(p)
|
||||
e.format = info.format
|
||||
e.depth = (info.bps + 7) / 8
|
||||
e.flenStd = (256 * (info.sps) / 245)
|
||||
e.flenLast = info.samples % e.flenStd
|
||||
e.frames = info.samples / e.flenStd
|
||||
e.format = info.Format
|
||||
e.depth = (info.Bps + 7) / 8
|
||||
e.flenStd = (256 * (info.Sps) / 245)
|
||||
e.flenLast = info.Samples % e.flenStd
|
||||
e.frames = info.Samples / e.flenStd
|
||||
if e.flenLast != 0 {
|
||||
e.frames++
|
||||
} else {
|
||||
|
@ -305,7 +305,7 @@ func (e *Encoder) SetInfo(info *Info) (err error) {
|
|||
e.rate = 0
|
||||
e.fifo.writeSkipBytes((e.frames + 1) * 4)
|
||||
e.seekTable = make([]uint64, e.frames)
|
||||
e.channels = int(info.nch)
|
||||
e.channels = int(info.Nch)
|
||||
e.shiftBits = (4 - e.depth) << 3
|
||||
e.frameInit(0)
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue