示例#1
0
文件: mpg123.go 项目: Wessie/audec
// NewDecoder returns a new decoder to be used for decoding mp3 audio data
//
// The Close method should be called when finished with the decoder so as to
// not leak resources.
func NewDecoder(r io.Reader) (*Decoder, error) {
	var e C.int
	mh := C.mpg123_new(nil, &e)
	if mh == nil || e != 0 {
		return nil, toError(e)
	}

	err := toError(C.mpg123_open_feed(mh))
	if err != nil {
		return nil, err
	}

	C.mpg123_format_none(mh)
	C.mpg123_format(mh, 44100, C.MPG123_STEREO, C.MPG123_ENC_FLOAT_32)

	buf := make([]byte, ReadBufferSize)
	return &Decoder{mh: mh, src: r, buf: buf}, nil
}
示例#2
0
// Set the audio output format for decoder
func (d *Decoder) Format(rate int64, channels int, encodings int) {
	C.mpg123_format(d.handle, C.long(rate), C.int(channels), C.int(encodings))
}