summaryrefslogtreecommitdiff
path: root/src/audio
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/audio.cc34
-rw-r--r--src/audio/tracker.cc19
2 files changed, 15 insertions, 38 deletions
diff --git a/src/audio/audio.cc b/src/audio/audio.cc
index f5bc4ab..a220fbb 100644
--- a/src/audio/audio.cc
+++ b/src/audio/audio.cc
@@ -78,9 +78,9 @@ void audio_start() {
#if !defined(STRIP_ALL)
if (!audio_is_prefilled()) {
const int buffered = g_ring_buffer.available_read();
- const float buffered_ms =
- (float)buffered / (RING_BUFFER_SAMPLE_RATE * RING_BUFFER_CHANNELS) *
- 1000.0f;
+ const float buffered_ms = (float)buffered /
+ (RING_BUFFER_SAMPLE_RATE * RING_BUFFER_CHANNELS) *
+ 1000.0f;
printf("WARNING: Audio buffer not pre-filled (%.1fms < %.1fms)\n",
buffered_ms, audio_get_required_prefill_time() * 1000.0f);
}
@@ -97,21 +97,18 @@ void audio_render_ahead(float music_time, float dt, float target_fill) {
// Render in small chunks to keep synth time synchronized with tracker
// Chunk size: one frame's worth of audio (~16.6ms @ 60fps)
- // TODO(timing): CRITICAL BUG - Truncation here may cause 180ms drift over 63 beats
- // (int) cast loses fractional samples: 0.333 samples/frame * 2560 frames = 853 samples = 27ms
- // But observed drift is 180ms, so this is not the only source (27ms < 180ms)
- // NOTE: This is NOT a float vs double precision issue - floats handle <500s times fine
- // See also: tracker.cc BPM timing calculation
+ // TODO(timing): CRITICAL BUG - Truncation here may cause 180ms drift over 63
+ // beats (int) cast loses fractional samples: 0.333 samples/frame * 2560
+ // frames = 853 samples = 27ms But observed drift is 180ms, so this is not the
+ // only source (27ms < 180ms) NOTE: This is NOT a float vs double precision
+ // issue - floats handle <500s times fine See also: tracker.cc BPM timing
+ // calculation
const int chunk_frames = (int)(dt * RING_BUFFER_SAMPLE_RATE);
const int chunk_samples = chunk_frames * RING_BUFFER_CHANNELS;
if (chunk_frames <= 0)
return;
- static int64_t g_total_render_calls = 0;
- static int64_t g_total_frames_rendered = 0;
- const int64_t frames_before = g_ring_buffer.get_total_written() / RING_BUFFER_CHANNELS;
-
// Keep rendering small chunks until buffer is full enough
while (true) {
// First, try to flush any pending samples from previous partial writes
@@ -228,19 +225,6 @@ void audio_render_ahead(float music_time, float dt, float target_fill) {
}
}
}
-
- // DEBUG: Track actual frames rendered vs expected
- const int64_t frames_after = g_ring_buffer.get_total_written() / RING_BUFFER_CHANNELS;
- const int64_t actual_rendered = frames_after - frames_before;
- g_total_render_calls++;
- g_total_frames_rendered += actual_rendered;
-
- if (g_total_render_calls % 600 == 0) { // Every 10 seconds at 60fps
- const float expected_frames = g_total_render_calls * (float)(chunk_frames);
- const float drift_ms = (expected_frames - g_total_frames_rendered) / RING_BUFFER_SAMPLE_RATE * 1000.0f;
- printf("[RENDER_DRIFT] calls=%lld expect=%.1f actual=%lld drift=%.2fms\n",
- g_total_render_calls, expected_frames, g_total_frames_rendered, drift_ms);
- }
}
float audio_get_playback_time() {
diff --git a/src/audio/tracker.cc b/src/audio/tracker.cc
index 00c31e9..38c814d 100644
--- a/src/audio/tracker.cc
+++ b/src/audio/tracker.cc
@@ -193,7 +193,8 @@ static int get_free_pattern_slot() {
// sample-accurate timing)
// volume_mult: Additional volume multiplier (for humanization)
static void trigger_note_event(const TrackerEvent& event,
- int start_offset_samples, float volume_mult = 1.0f) {
+ 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) {
@@ -234,10 +235,10 @@ static void trigger_note_event(const TrackerEvent& event,
}
void tracker_update(float music_time_sec, float dt_music_sec) {
- // TODO(timing): CRITICAL BUG - Events trigger ~180ms early over 63 beats @ BPM=90
- // Observed: Beat 63 snare at 41.82s in WAV, should be at 42.00s (180ms drift)
- // NOTE: This is NOT a float vs double precision issue - floats handle <500s times fine
- // Root cause unknown - suspects:
+ // TODO(timing): CRITICAL BUG - Events trigger ~180ms early over 63 beats @
+ // BPM=90 Observed: Beat 63 snare at 41.82s in WAV, should be at 42.00s (180ms
+ // drift) NOTE: This is NOT a float vs double precision issue - floats handle
+ // <500s times fine Root cause unknown - suspects:
// 1. Systematic bias in time calculation (not random accumulation)
// 2. Truncation in audio.cc:103 chunk_frames = (int)(dt * sample_rate)
// 3. BPM calculation precision below (unit_duration_sec)
@@ -324,14 +325,6 @@ void tracker_update(float music_time_sec, float dt_music_sec) {
}
}
- // DEBUG: Track kick/snare timing for drift investigation
- if (event.sample_id == 0 || event.sample_id == 1) { // Assuming kick=0, snare=1
- const char* name = (event.sample_id == 0) ? "KICK " : "SNARE";
- const float delta_ms = (event_music_time - music_time_sec) * 1000.0f;
- printf("[DRIFT] %s: music=%.4f expect=%.4f delta=%.2fms offset=%d\n",
- name, music_time_sec, event_music_time, delta_ms, sample_offset);
- }
-
trigger_note_event(event, sample_offset, volume_mult);
active.next_event_idx++;
}