summaryrefslogtreecommitdiff
path: root/src/audio/synth.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio/synth.cc')
-rw-r--r--src/audio/synth.cc38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/audio/synth.cc b/src/audio/synth.cc
index 617ff2f..ada46fd 100644
--- a/src/audio/synth.cc
+++ b/src/audio/synth.cc
@@ -28,7 +28,7 @@ struct Voice {
float time_domain_buffer[DCT_SIZE];
int buffer_pos;
- float fractional_pos; // Fractional sample position for tempo scaling
+ float fractional_pos; // Fractional sample position for tempo scaling
const volatile float* active_spectral_data;
};
@@ -47,7 +47,7 @@ static float g_tempo_scale = 1.0f; // Playback speed multiplier
#if !defined(STRIP_ALL)
static float g_elapsed_time_sec = 0.0f; // Tracks elapsed time for event hooks
-#endif /* !defined(STRIP_ALL) */
+#endif /* !defined(STRIP_ALL) */
void synth_init() {
memset(&g_synth_data, 0, sizeof(g_synth_data));
@@ -72,22 +72,23 @@ int synth_register_spectrogram(const Spectrogram* spec) {
#if defined(DEBUG_LOG_SYNTH)
// VALIDATION: Check spectrogram pointer and data
if (spec == nullptr) {
- DEBUG_SYNTH( "[SYNTH ERROR] Null spectrogram pointer\n");
+ DEBUG_SYNTH("[SYNTH ERROR] Null spectrogram pointer\n");
return -1;
}
if (spec->spectral_data_a == nullptr || spec->spectral_data_b == nullptr) {
- DEBUG_SYNTH( "[SYNTH ERROR] Null spectral data pointers\n");
+ DEBUG_SYNTH("[SYNTH ERROR] Null spectral data pointers\n");
return -1;
}
if (spec->num_frames <= 0 || spec->num_frames > 10000) {
- DEBUG_SYNTH( "[SYNTH ERROR] Invalid num_frames=%d (must be 1-10000)\n",
- spec->num_frames);
+ DEBUG_SYNTH("[SYNTH ERROR] Invalid num_frames=%d (must be 1-10000)\n",
+ spec->num_frames);
return -1;
}
// VALIDATION: Check spectral data isn't all zeros (common corruption symptom)
bool all_zero = true;
const float* data = spec->spectral_data_a;
- const int samples_to_check = (spec->num_frames > 10) ? 10 * DCT_SIZE : spec->num_frames * DCT_SIZE;
+ const int samples_to_check =
+ (spec->num_frames > 10) ? 10 * DCT_SIZE : spec->num_frames * DCT_SIZE;
for (int j = 0; j < samples_to_check; ++j) {
if (data[j] != 0.0f) {
all_zero = false;
@@ -95,8 +96,9 @@ int synth_register_spectrogram(const Spectrogram* spec) {
}
}
if (all_zero) {
- DEBUG_SYNTH( "[SYNTH WARNING] Spectrogram appears to be all zeros (num_frames=%d)\n",
- spec->num_frames);
+ DEBUG_SYNTH(
+ "[SYNTH WARNING] Spectrogram appears to be all zeros (num_frames=%d)\n",
+ spec->num_frames);
}
#endif
@@ -157,8 +159,8 @@ void synth_trigger_voice(int spectrogram_id, float volume, float pan) {
if (spectrogram_id < 0 || spectrogram_id >= MAX_SPECTROGRAMS ||
!g_synth_data.spectrogram_registered[spectrogram_id]) {
#if defined(DEBUG_LOG_SYNTH)
- DEBUG_SYNTH( "[SYNTH ERROR] Invalid spectrogram_id=%d in trigger_voice\n",
- spectrogram_id);
+ DEBUG_SYNTH("[SYNTH ERROR] Invalid spectrogram_id=%d in trigger_voice\n",
+ spectrogram_id);
#endif
return;
}
@@ -166,12 +168,13 @@ void synth_trigger_voice(int spectrogram_id, float volume, float pan) {
#if defined(DEBUG_LOG_SYNTH)
// VALIDATION: Check volume and pan ranges
if (volume < 0.0f || volume > 2.0f) {
- DEBUG_SYNTH( "[SYNTH WARNING] Unusual volume=%.2f for spectrogram_id=%d\n",
- volume, spectrogram_id);
+ DEBUG_SYNTH("[SYNTH WARNING] Unusual volume=%.2f for spectrogram_id=%d\n",
+ volume, spectrogram_id);
}
if (pan < -1.0f || pan > 1.0f) {
- DEBUG_SYNTH( "[SYNTH WARNING] Invalid pan=%.2f (clamping) for spectrogram_id=%d\n",
- pan, spectrogram_id);
+ DEBUG_SYNTH(
+ "[SYNTH WARNING] Invalid pan=%.2f (clamping) for spectrogram_id=%d\n",
+ pan, spectrogram_id);
pan = (pan < -1.0f) ? -1.0f : 1.0f;
}
#endif
@@ -191,7 +194,8 @@ void synth_trigger_voice(int spectrogram_id, float volume, float pan) {
v.total_spectral_frames =
g_synth_data.spectrograms[spectrogram_id].num_frames;
v.buffer_pos = DCT_SIZE; // Force IDCT on first render
- v.fractional_pos = 0.0f; // Initialize fractional position for tempo scaling
+ v.fractional_pos =
+ 0.0f; // Initialize fractional position for tempo scaling
v.active_spectral_data =
g_synth_data.active_spectrogram_data[spectrogram_id];
@@ -200,7 +204,7 @@ void synth_trigger_voice(int spectrogram_id, float volume, float pan) {
AudioBackend* backend = audio_get_backend();
if (backend != nullptr) {
backend->on_voice_triggered(g_elapsed_time_sec, spectrogram_id, volume,
- pan);
+ pan);
}
#endif /* !defined(STRIP_ALL) */