예제 #1
0
// NewDecoder creates a new Opus decoder with the given sample rate
// and number of channels.
func NewDecoder(sampleRate int, chanCount int) (dec *Decoder, err error) {
	dec = new(Decoder)

	// allocate Opus decoder
	ecode := C.opus_decoder_init(&dec.cee, C.opus_int32(sampleRate),
		C.int(chanCount))
	if ecode != C.OPUS_OK {
		dec = nil
		err = ErrUnspecified
	}
	dec.chcnt = chanCount
	return
}
예제 #2
0
func NewDecoder(sampleRate, channels int) (*Decoder, error) {
	decoder := &Decoder{}
	decoder.data = make([]byte, int(C.opus_decoder_get_size(C.int(channels))))
	decoder.cDecoder = (*C.struct_OpusDecoder)(unsafe.Pointer(&decoder.data[0]))

	ret := C.opus_decoder_init(decoder.cDecoder, C.opus_int32(sampleRate), C.int(channels))
	if err := getErr(ret); err != nil {
		return nil, err
	}
	decoder.channels = channels

	return decoder, nil
}
예제 #3
0
파일: decoder.go 프로젝트: fanzy618/opus
func (dec *Decoder) Init(sample_rate int, channels int) error {
	if dec.p != nil {
		return fmt.Errorf("opus decoder already initialized")
	}
	if channels != 1 && channels != 2 {
		return fmt.Errorf("Number of channels must be 1 or 2: %d", channels)
	}
	size := C.opus_decoder_get_size(C.int(channels))
	dec.sample_rate = sample_rate
	dec.mem = make([]byte, size)
	dec.p = (*C.OpusDecoder)(unsafe.Pointer(&dec.mem[0]))
	errno := C.opus_decoder_init(
		dec.p,
		C.opus_int32(sample_rate),
		C.int(channels))
	if errno != 0 {
		return opuserr(int(errno))
	}
	return nil
}