test: add debug counters to audio routing test
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
@@ -48,6 +48,11 @@ static float test_audio_input[MAX_CHANNELS][MAX_SAMPLES];
|
||||
static atomic_size_t test_audio_input_count[MAX_CHANNELS];
|
||||
static atomic_size_t test_audio_input_read[MAX_CHANNELS];
|
||||
|
||||
// Debug counters
|
||||
static atomic_ulong test_callback_count;
|
||||
static atomic_ulong test_midi_sent_count;
|
||||
static atomic_ulong test_audio_written_count;
|
||||
|
||||
// Shared MIDI buffer (written by test thread, read by JACK callback)
|
||||
static uint8_t test_midi_buffer[3]; // status, note, velocity
|
||||
static atomic_bool test_midi_pending;
|
||||
@@ -81,6 +86,8 @@ static int test_process_callback(jack_nframes_t nframes, void *arg) {
|
||||
(void)arg;
|
||||
if (!atomic_load(&test_running)) return 0;
|
||||
|
||||
atomic_fetch_add(&test_callback_count, 1);
|
||||
|
||||
pthread_mutex_lock(&test_buffer_mutex);
|
||||
|
||||
// Write test audio to output ports (to be sent to looper)
|
||||
@@ -91,14 +98,17 @@ static int test_process_callback(jack_nframes_t nframes, void *arg) {
|
||||
size_t read_pos = atomic_load(&test_audio_input_read[ch]);
|
||||
size_t count = atomic_load(&test_audio_input_count[ch]);
|
||||
|
||||
bool wrote_audio = false;
|
||||
for (jack_nframes_t i = 0; i < nframes; i++) {
|
||||
if (read_pos + i < count) {
|
||||
out[i] = test_audio_input[ch][read_pos + i];
|
||||
if (test_audio_input[ch][read_pos + i] != 0.0f) wrote_audio = true;
|
||||
} else {
|
||||
out[i] = 0.0f;
|
||||
}
|
||||
}
|
||||
atomic_store(&test_audio_input_read[ch], read_pos + nframes);
|
||||
if (wrote_audio) atomic_fetch_add(&test_audio_written_count, 1);
|
||||
}
|
||||
|
||||
// Read audio from looper outputs
|
||||
@@ -269,6 +279,10 @@ static void send_sine_wave(int channel, float frequency, float amplitude, jack_n
|
||||
// Wait for the JACK callback to consume the audio
|
||||
// (the callback runs in a separate thread)
|
||||
usleep(duration * 1000 + 300000); // duration ms + 300ms extra
|
||||
|
||||
unsigned long cb_count = atomic_load(&test_callback_count);
|
||||
unsigned long aw_count = atomic_load(&test_audio_written_count);
|
||||
printf(" [DEBUG] Callback count: %lu, Audio written: %lu\n", cb_count, aw_count);
|
||||
}
|
||||
|
||||
static void send_midi_note(int note, int velocity) {
|
||||
@@ -282,11 +296,16 @@ static void send_midi_note(int note, int velocity) {
|
||||
test_midi_buffer[1] = note & 0x7F;
|
||||
test_midi_buffer[2] = velocity & 0x7F;
|
||||
atomic_store(&test_midi_pending, true);
|
||||
atomic_fetch_add(&test_midi_sent_count, 1);
|
||||
|
||||
pthread_mutex_unlock(&test_buffer_mutex);
|
||||
|
||||
// Wait longer for JACK to process the MIDI message
|
||||
usleep(300000); // 300ms to let JACK process
|
||||
|
||||
unsigned long cb_count = atomic_load(&test_callback_count);
|
||||
unsigned long ms_count = atomic_load(&test_midi_sent_count);
|
||||
printf(" [DEBUG] Callback count: %lu, MIDI sent: %lu\n", cb_count, ms_count);
|
||||
}
|
||||
|
||||
static float get_channel_rms(int channel) {
|
||||
@@ -561,6 +580,9 @@ int main(void) {
|
||||
atomic_store(&tests_failed, 0);
|
||||
atomic_store(&test_running, true);
|
||||
atomic_store(&test_timeout, false);
|
||||
atomic_store(&test_callback_count, 0);
|
||||
atomic_store(&test_midi_sent_count, 0);
|
||||
atomic_store(&test_audio_written_count, 0);
|
||||
|
||||
// Start watchdog thread
|
||||
pthread_t watchdog;
|
||||
|
||||
Reference in New Issue
Block a user