Ejemplo n.º 1
0
func loadRnd(fn string) ([2][][]float32, error) {
	var r [2][][]float32

	f, err := os.Open(fn)
	if err != nil {
		return r, err
	}
	defer f.Close()

	t, err := CreateTable(f, 0)
	if err != nil {
		return r, err
	}

	r[0] = make([][]float32, t.NFrames())
	r[1] = make([][]float32, t.NFrames())

	rand.Seed(42)
	for _, i := range rand.Perm(t.NFrames()) {
		x := t.FindSample(int64(i) * int64(t.SamplesPerFrame()))
		if _, err := f.Seek(x.Offset, 0); err != nil {
			return r, err
		}

		d := mpa.Decoder{Input: f}
		for k := 0; k < x.WarmUp; k++ {
			d.DecodeFrame()
		}
		if err := d.DecodeFrame(); err != nil {
			return r, err
		}
		for ch := 0; ch < 2; ch++ {
			s := make([]float32, d.NSamples())
			d.ReadSamples(ch, s)
			r[ch][i] = s
		}
	}

	return r, nil
}
Ejemplo n.º 2
0
func loadSeq(fn string) ([2][][]float32, error) {
	var r [2][][]float32

	f, err := os.Open(fn)
	if err != nil {
		return r, err
	}
	defer f.Close()

	d := mpa.Decoder{Input: f}
	for {
		if err := d.DecodeFrame(); err != nil {
			if err == io.EOF {
				err = nil
			}
			return r, err
		}
		for ch := 0; ch < 2; ch++ {
			s := make([]float32, d.NSamples())
			d.ReadSamples(ch, s)
			r[ch] = append(r[ch], s)
		}
	}
}