Compare commits
2 commits
4421c708d1
...
3d5460c48a
Author | SHA1 | Date | |
---|---|---|---|
DataHoarder | 3d5460c48a | ||
DataHoarder | d0c3e3e655 |
17
opus_test.go
17
opus_test.go
|
@ -86,6 +86,8 @@ func TestCodecFloat32(t *testing.T) {
|
|||
}
|
||||
addSineFloat32(pcm, SAMPLE_RATE, G4)
|
||||
err = enc.EncodeFloat32(pcm)
|
||||
enc.Close()
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't encode data: %v", err)
|
||||
}
|
||||
|
@ -95,11 +97,16 @@ func TestCodecFloat32(t *testing.T) {
|
|||
}
|
||||
// TODO: Uh-oh.. it looks like I forgot to put a data = data[:n] here, yet
|
||||
// the test is not failing. Why?
|
||||
n, err := dec.ReadFloat32(pcm)
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't decode data: %v", err)
|
||||
var out []float32
|
||||
buf := make([]float32, 120*SAMPLE_RATE)
|
||||
for {
|
||||
n, err := dec.ReadFloat32(pcm)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
out = append(out, buf[:n]...)
|
||||
}
|
||||
if len(pcm) != n {
|
||||
t.Fatalf("Length mismatch: %d samples in, %d out", len(pcm), n)
|
||||
if len(out) != len(pcm) {
|
||||
t.Fatalf("Length mismatch: %d samples in, %d out", len(out), len(pcm))
|
||||
}
|
||||
}
|
||||
|
|
53
stream.go
53
stream.go
|
@ -115,6 +115,59 @@ func (s *Stream) Init(read io.Reader) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
const ChannelCountMax = int(C.OPUS_CHANNEL_COUNT_MAX)
|
||||
|
||||
// Information a mapped OpusHead struct, see https://opus-codec.org/docs/opusfile_api-0.5/structOpusHead.html
|
||||
type Information struct {
|
||||
Version int
|
||||
ChannelCount int
|
||||
PreSkip uint
|
||||
InputSampleRate uint
|
||||
OutputGain int
|
||||
MappingFamily int
|
||||
StreamCount int
|
||||
CoupledCount int
|
||||
Mapping [ChannelCountMax]uint8
|
||||
}
|
||||
|
||||
//Info Returns the information of the current link
|
||||
func (s *Stream) Info() *Information {
|
||||
if s.oggfile == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
head := C.op_head(s.oggfile, C.int(-1))
|
||||
|
||||
if head == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
info := &Information{
|
||||
Version: int(head.version),
|
||||
ChannelCount: int(head.channel_count),
|
||||
PreSkip: uint(head.pre_skip),
|
||||
InputSampleRate: uint(head.input_sample_rate),
|
||||
OutputGain: int(head.output_gain),
|
||||
MappingFamily: int(head.mapping_family),
|
||||
StreamCount: int(head.stream_count),
|
||||
CoupledCount: int(head.coupled_count),
|
||||
}
|
||||
|
||||
copy(info.Mapping[:], unsafe.Slice((*uint8)(&head.mapping[0]), ChannelCountMax))
|
||||
|
||||
return info
|
||||
|
||||
}
|
||||
|
||||
//Channels Returns the channel count of the current link
|
||||
func (s *Stream) Channels() int {
|
||||
if s.oggfile == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return int(C.op_channel_count(s.oggfile, C.int(-1)))
|
||||
}
|
||||
|
||||
// Read a chunk of raw opus data from the stream and decode it. Returns the
|
||||
// number of decoded samples per channel. This means that a dual channel
|
||||
// (stereo) feed will have twice as many samples as the value returned.
|
||||
|
|
Loading…
Reference in a new issue