test(02-01): add failing tests for synth config, oscillator, and layer
- TestAllClassesHaveConfig, TestFrequenciesInRange, TestFrequenciesUnique - TestHarmonicsNonEmpty, TestPanPositionsInRange - TestOscillatorAdvance, TestOscillatorPhaseWrap, TestOscillatorDistinctFreqs - TestEMAAmplitudeRise, TestEMAAmplitudeDecay, TestWhisperFloor, TestWhisperFloorNotSeenIsZero
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package synth_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/netsynth/netsynth/synth"
|
||||
)
|
||||
|
||||
func TestOscillatorAdvance(t *testing.T) {
|
||||
harmonics := []synth.HarmonicDef{{Ratio: 1, Amplitude: 1.0}, {Ratio: 2, Amplitude: 0.5}}
|
||||
osc := synth.NewOscillator(440.0, synth.SampleRate)
|
||||
|
||||
hasPos := false
|
||||
hasNeg := false
|
||||
for i := 0; i < 100; i++ {
|
||||
s := osc.Advance(harmonics)
|
||||
if s > 0 {
|
||||
hasPos = true
|
||||
}
|
||||
if s < 0 {
|
||||
hasNeg = true
|
||||
}
|
||||
}
|
||||
if !hasPos || !hasNeg {
|
||||
t.Errorf("expected both positive and negative samples; hasPos=%v hasNeg=%v", hasPos, hasNeg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOscillatorPhaseWrap(t *testing.T) {
|
||||
harmonics := []synth.HarmonicDef{{Ratio: 1, Amplitude: 1.0}}
|
||||
osc := synth.NewOscillator(440.0, synth.SampleRate)
|
||||
|
||||
for i := 0; i < synth.SampleRate; i++ {
|
||||
osc.Advance(harmonics)
|
||||
}
|
||||
p := osc.Phase()
|
||||
if p < 0 || p >= 1.0 {
|
||||
t.Errorf("expected phase in [0, 1), got %.6f", p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOscillatorDistinctFreqs(t *testing.T) {
|
||||
harmonics := []synth.HarmonicDef{{Ratio: 1, Amplitude: 1.0}}
|
||||
osc65 := synth.NewOscillator(65.0, synth.SampleRate)
|
||||
osc440 := synth.NewOscillator(440.0, synth.SampleRate)
|
||||
|
||||
same := true
|
||||
for i := 0; i < 100; i++ {
|
||||
s65 := osc65.Advance(harmonics)
|
||||
s440 := osc440.Advance(harmonics)
|
||||
if s65 != s440 {
|
||||
same = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if same {
|
||||
t.Error("expected oscillators at 65 Hz and 440 Hz to produce different sample sequences")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user