Beispiel #1
0
// Prepare for direct feeding via Feed
func (d *Decoder) OpenFeed() error {
	err := C.mpg123_open_feed(d.handle)
	if err != C.MPG123_OK {
		return fmt.Errorf("mpg123 error: %s", d.strerror())
	}
	return nil
}
Beispiel #2
0
// 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
}