diff options
Diffstat (limited to 'src/audio/tracker.cc')
| -rw-r--r-- | src/audio/tracker.cc | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/audio/tracker.cc b/src/audio/tracker.cc index 67c197f..1c0a9b2 100644 --- a/src/audio/tracker.cc +++ b/src/audio/tracker.cc @@ -5,6 +5,7 @@ #include "util/debug.h" #include "util/fatal_error.h" #include <cstring> +#include <random> #include <vector> static uint32_t g_last_trigger_idx = 0; @@ -190,8 +191,9 @@ static int get_free_pattern_slot() { // Helper to trigger a single note event (OPTIMIZED with caching) // start_offset_samples: How many samples into the future to trigger (for // sample-accurate timing) +// volume_mult: Additional volume multiplier (for humanization) static void trigger_note_event(const TrackerEvent& event, - int start_offset_samples) { + int start_offset_samples, float volume_mult = 1.0f) { #if defined(DEBUG_LOG_TRACKER) // VALIDATION: Check sample_id bounds if (event.sample_id >= g_tracker_samples_count) { @@ -227,7 +229,7 @@ static void trigger_note_event(const TrackerEvent& event, } // Trigger voice with sample-accurate offset - synth_trigger_voice(cached_synth_id, event.volume, event.pan, + synth_trigger_voice(cached_synth_id, event.volume * volume_mult, event.pan, start_offset_samples); } @@ -287,7 +289,32 @@ void tracker_update(float music_time_sec, float dt_music_sec) { (int)((event_music_time - music_time_sec) / tempo_scale * 32000.0f); } - trigger_note_event(event, sample_offset); + // Apply humanization if enabled + float volume_mult = 1.0f; + if (g_tracker_score.humanize_seed != 0) { + // Deterministic per-event RNG: hash seed with pattern/event indices + uint32_t event_hash = g_tracker_score.humanize_seed ^ + (active.pattern_id << 16) ^ active.next_event_idx; + std::minstd_rand rng(event_hash); + std::uniform_real_distribution<float> dist(-1.0f, 1.0f); + + // Timing variation: jitter by % of beat duration + if (g_tracker_score.timing_variation_pct > 0.0f) { + float beat_sec = 60.0f / g_tracker_score.bpm; + float jitter = dist(rng) * + (g_tracker_score.timing_variation_pct / 100.0f) * + beat_sec; + sample_offset += (int)(jitter / tempo_scale * 32000.0f); + } + + // Volume variation: vary by % + if (g_tracker_score.volume_variation_pct > 0.0f) { + volume_mult += + dist(rng) * (g_tracker_score.volume_variation_pct / 100.0f); + } + } + + trigger_note_event(event, sample_offset, volume_mult); active.next_event_idx++; } |
