Exemplo n.º 1
0
func TestNewClipFromWave(t *testing.T) {
	c, _ := NewClipFromWave(testSoundFilePath)
	w, _ := wave.OpenFile(testSoundFilePath)
	waveLen := len(w.Samples) / int(w.Header.NumChannels)
	for chanNum := 0; chanNum < len(c.Samples); chanNum++ {
		clipLen := len(c.Samples[chanNum])
		if clipLen != waveLen {
			t.Errorf("Expected %d samples instead of %d in clip on channel %d\n",
				waveLen, clipLen, chanNum)
		}
	}
}
Exemplo n.º 2
0
func TestNewWaveFromClip(t *testing.T) {
	c, _ := NewClipFromWave(testSoundFilePath)
	w, _ := wave.OpenFile(testSoundFilePath)
	w2 := NewWaveFromClip(c)
	if len(w.Samples) != len(w2.Samples) {
		t.Errorf("Expected length %d and have length %d\n",
			len(w.Samples), len(w2.Samples))
	}
	for i, sample := range w.Samples {
		if sample != w2.Samples[i] {
			t.Errorf("Expected %d instead of %d for sample offset %d\n",
				sample, w2.Samples[i], i)
		}
	}
}
Exemplo n.º 3
0
// Creates a new clip from a wave file name.
func NewClipFromWave(waveFileName string) (*Clip, error) {
	c := new(Clip)
	w, err := wave.OpenFile(waveFileName)
	if err != nil {
		return c, err
	}
	c.Name = w.FileName // TODO: Remove file extensions.
	numChannels := int(w.Header.NumChannels)
	c = NewClip(int(w.Header.NumChannels))
	c.SampleRate = int(w.Header.SampleRate)
	// Deinterlace the wave sample data into disparate slices.
	for i, sample := range w.Samples {
		c.Samples[i%numChannels] = append(c.Samples[i%numChannels], sample)
	}
	return c, nil
}