feat(05-01): wire waveform resolution into NewLayer at construction time

- NewLayer resolves WaveformPresetHarmonics when cfg.WaveformType != WaveformCustom
- Preset harmonics stored in Layer.Config so AdvanceSample uses them unchanged
- WaveformCustom path preserves existing hand-tuned harmonics (backward compatible)
- TestNewLayerResolvesWaveformPreset: verifies preset fills harmonics on construction
- TestNewLayerPreservesCustomHarmonics: verifies hand-tuned harmonics are untouched
- TestSineRegressionVsCustomHarmonics: verifies WaveformSine == {Ratio:1,Amp:1.0}
- All 41 synth tests pass, encode tests unaffected
This commit is contained in:
2026-03-26 17:34:45 +01:00
parent 82d1e37d0f
commit 7f6471426f
2 changed files with 69 additions and 0 deletions
+4
View File
@@ -20,7 +20,11 @@ type Layer struct {
}
// NewLayer creates a Layer for the given config using the specified sample rate and EMA time constant (tau in seconds).
// If cfg.WaveformType is not WaveformCustom, harmonics are resolved from the preset at construction time.
func NewLayer(cfg FreqConfig, sampleRate int, tau float64) *Layer {
if cfg.WaveformType != WaveformCustom {
cfg.Harmonics = WaveformPresetHarmonics(cfg.WaveformType, cfg.BaseHz, sampleRate)
}
return &Layer{
Config: cfg,
Osc: NewOscillator(cfg.BaseHz, sampleRate),