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 }
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) } } }