diff options
Diffstat (limited to 'src/audio/synth.cc')
| -rw-r--r-- | src/audio/synth.cc | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/audio/synth.cc b/src/audio/synth.cc index 2072bb4..d66c502 100644 --- a/src/audio/synth.cc +++ b/src/audio/synth.cc @@ -30,6 +30,8 @@ struct Voice { int buffer_pos; float fractional_pos; // Fractional sample position for tempo scaling + int start_sample_offset; // Samples to wait before producing audio output + const volatile float* active_spectral_data; }; @@ -152,7 +154,8 @@ void synth_commit_update(int spectrogram_id) { new_active_ptr, __ATOMIC_RELEASE); } -void synth_trigger_voice(int spectrogram_id, float volume, float pan) { +void synth_trigger_voice(int spectrogram_id, float volume, float pan, + int start_offset_samples) { if (spectrogram_id < 0 || spectrogram_id >= MAX_SPECTROGRAMS || !g_synth_data.spectrogram_registered[spectrogram_id]) { #if defined(DEBUG_LOG_SYNTH) @@ -174,6 +177,11 @@ void synth_trigger_voice(int spectrogram_id, float volume, float pan) { pan, spectrogram_id); pan = (pan < -1.0f) ? -1.0f : 1.0f; } + if (start_offset_samples < 0) { + DEBUG_SYNTH("[SYNTH WARNING] Negative start_offset=%d, clamping to 0\n", + start_offset_samples); + start_offset_samples = 0; + } #endif for (int i = 0; i < MAX_VOICES; ++i) { @@ -193,6 +201,7 @@ void synth_trigger_voice(int spectrogram_id, float volume, float pan) { v.buffer_pos = DCT_SIZE; // Force IDCT on first render v.fractional_pos = 0.0f; // Initialize fractional position for tempo scaling + v.start_sample_offset = start_offset_samples; // NEW: Sample-accurate timing v.active_spectral_data = g_synth_data.active_spectrogram_data[spectrogram_id]; @@ -223,6 +232,12 @@ void synth_render(float* output_buffer, int num_frames) { if (!v.active) continue; + // NEW: Skip this sample if we haven't reached the trigger offset yet + if (v.start_sample_offset > 0) { + v.start_sample_offset--; + continue; // Don't produce audio until offset elapsed + } + if (v.buffer_pos >= DCT_SIZE) { if (v.current_spectral_frame >= v.total_spectral_frames) { v.active = false; |
