Add Channels and Info methods on decoder
This commit is contained in:
parent
4421c708d1
commit
d0c3e3e655
53
stream.go
53
stream.go
|
@ -115,6 +115,59 @@ func (s *Stream) Init(read io.Reader) error {
|
||||||
return nil
|
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
|
// 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
|
// number of decoded samples per channel. This means that a dual channel
|
||||||
// (stereo) feed will have twice as many samples as the value returned.
|
// (stereo) feed will have twice as many samples as the value returned.
|
||||||
|
|
Loading…
Reference in a new issue