Beispiel #1
0
// Open reads the vorbis headers from an ogg.Reader and performs the setup needed to decode the data.
func OpenOgg(in *ogg.Reader) (*Vorbis, error) {
	v := new(Vorbis)
	v.reader = in
	r, err := ogg.NewBitReaderErr(v.reader.NextPacket())
	if err != nil {
		return nil, err
	}
	err = v.header.ReadFrom(r)
	if err != nil {
		return nil, err
	}
	b, err := v.reader.NextPacket()
	if err != nil {
		return nil, err
	}
	v.comments.ReadFrom(b)
	r, err = ogg.NewBitReaderErr(v.reader.NextPacket())
	if err != nil {
		return nil, err
	}
	v.setup.init(&v.header)
	err = v.setup.ReadFrom(r)
	if err != nil {
		return nil, err
	}
	return v, nil
}
Beispiel #2
0
// DecodePacket decodes a packet from the input.
// The result is a two-dimensional array, the first index corresponds to the channel, the second to the sample position.
// The number of samples decoded can vary, but will never exceed MaxBlockSize()
func (v *Vorbis) DecodePacket() ([][]float32, error) {
	var out [][]float32
	if v.overlap == nil {
		r, err := ogg.NewBitReaderErr(v.reader.NextPacket())
		if err != nil {
			return nil, err
		}
		out, v.overlap, err = v.setup.decodePacket(r, nil)
		v.position += uint64(len(out[0]))
	}
	r, err := ogg.NewBitReaderErr(v.reader.NextPacket())
	if err != nil {
		return nil, err
	}
	out, v.overlap, err = v.setup.decodePacket(r, v.overlap)
	v.position += uint64(len(out[0]))
	return out, err
}