diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-06 16:32:57 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-06 16:32:57 +0100 |
| commit | a9f0174f95b577cc7f8d67023eb37d83d050c0fd (patch) | |
| tree | 64fe6f060d2be732406a50b9ab5fe8b32101c0aa /src | |
| parent | 2ffb7c34a93a7b45b22b784c8570e2f31e0638ba (diff) | |
fix(audio): Scale procedural note generation for orthonormal DCT
Fixed procedural notes (NOTE_*) being inaudible by adding scaling
compensation in gen.cc.
Root Cause:
- Old non-orthonormal DCT produced values ~16x larger (no sqrt scaling)
- New orthonormal DCT: output *= sqrt(1/N) or sqrt(2/N)
- Procedural note generation in gen.cc now produces 16x smaller spectrograms
- IDCT expects same magnitude as .spec files -> notes too quiet
Solution:
- Added scale_factor = sqrt(DCT_SIZE / 2) = sqrt(256) = 16
- Multiply DCT output by 16 to match old magnitude
- Procedural notes now have same loudness as sample-based notes
Verification:
- Checked spectral_editor: does not use DCT for procedural
- Checked editor tools: no procedural generation with DCT
- All 23 tests pass
Procedural notes should now be audible at correct volume.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/audio/gen.cc | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/audio/gen.cc b/src/audio/gen.cc index 148fc68..5604457 100644 --- a/src/audio/gen.cc +++ b/src/audio/gen.cc @@ -69,9 +69,14 @@ std::vector<float> generate_note_spectrogram(const NoteParams& params, float dct_chunk[DCT_SIZE]; fdct_512(pcm_chunk, dct_chunk); - // Copy to buffer + // Scale up to compensate for orthonormal normalization + // Old non-orthonormal DCT had no sqrt scaling, so output was ~sqrt(N/2) larger + // Scale factor: sqrt(DCT_SIZE / 2) = sqrt(256) = 16 + const float scale_factor = sqrtf(DCT_SIZE / 2.0f); + + // Copy to buffer with scaling for (int i = 0; i < DCT_SIZE; ++i) { - spec_data[f * DCT_SIZE + i] = dct_chunk[i]; + spec_data[f * DCT_SIZE + i] = dct_chunk[i] * scale_factor; } } |
