From 18eb8a07ba39a8aad1c75521cee027b9c9c72e40 Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 1 Feb 2026 00:58:20 +0100 Subject: clang-format --- src/audio/audio.cc | 15 ++++++++------- src/audio/audio.h | 4 ++-- src/audio/dct.h | 4 ++-- src/audio/fdct.cc | 2 +- src/audio/gen.cc | 41 ++++++++++++++++++++++++++--------------- src/audio/gen.h | 14 +++++++------- src/audio/idct.cc | 2 +- src/audio/synth.cc | 41 +++++++++++++++++++++++------------------ src/audio/synth.h | 10 +++++----- src/audio/window.cc | 2 +- src/audio/window.h | 2 +- 11 files changed, 77 insertions(+), 60 deletions(-) (limited to 'src/audio') diff --git a/src/audio/audio.cc b/src/audio/audio.cc index b482e64..e4abbf8 100644 --- a/src/audio/audio.cc +++ b/src/audio/audio.cc @@ -4,12 +4,12 @@ #include "audio.h" -#ifndef DEMO_BUILD_TOOLS +#if !defined(DEMO_BUILD_TOOLS) #define MA_NO_FLAC #define MA_NO_ENCODING #define MA_NO_MP3 #define MA_NO_WAV -#endif +#endif /* !defined(DEMO_BUILD_TOOLS) */ #define MINIAUDIO_IMPLEMENTATION #include "miniaudio.h" #include "synth.h" @@ -18,10 +18,10 @@ static ma_device g_device; -void audio_data_callback(ma_device *pDevice, void *pOutput, const void *pInput, +void audio_data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { (void)pInput; - float *fOutput = (float *)pOutput; + float* fOutput = (float*)pOutput; synth_render(fOutput, (int)frameCount); } @@ -48,7 +48,7 @@ void audio_start() { } } -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) void audio_render_silent(float duration_sec) { const int sample_rate = 32000; const int chunk_size = 512; @@ -62,9 +62,10 @@ void audio_render_silent(float duration_sec) { total_frames -= frames_to_render; } } -#endif +#endif /* !defined(STRIP_ALL) */ -void audio_update() {} +void audio_update() { +} void audio_shutdown() { ma_device_stop(&g_device); diff --git a/src/audio/audio.h b/src/audio/audio.h index 1fb53b6..24db18f 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -6,8 +6,8 @@ void audio_init(); void audio_start(); // Starts the audio device callback -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) void audio_render_silent(float duration_sec); // Fast-forwards audio state -#endif +#endif /* !defined(STRIP_ALL) */ void audio_update(); void audio_shutdown(); diff --git a/src/audio/dct.h b/src/audio/dct.h index b6b7126..ee3e9b3 100644 --- a/src/audio/dct.h +++ b/src/audio/dct.h @@ -7,5 +7,5 @@ #define DCT_SIZE 512 // Forward declarations -void fdct_512(const float *input, float *output); -void idct_512(const float *input, float *output); +void fdct_512(const float* input, float* output); +void idct_512(const float* input, float* output); diff --git a/src/audio/fdct.cc b/src/audio/fdct.cc index 3541e9c..78973a3 100644 --- a/src/audio/fdct.cc +++ b/src/audio/fdct.cc @@ -5,7 +5,7 @@ #include "dct.h" #include -void fdct_512(const float *input, float *output) { +void fdct_512(const float* input, float* output) { const float PI = 3.14159265358979323846f; for (int k = 0; k < DCT_SIZE; ++k) { float sum = 0.0f; diff --git a/src/audio/gen.cc b/src/audio/gen.cc index ddc4fa6..148fc68 100644 --- a/src/audio/gen.cc +++ b/src/audio/gen.cc @@ -9,10 +9,11 @@ #include #include -std::vector generate_note_spectrogram(const NoteParams ¶ms, - int *out_num_frames) { +std::vector generate_note_spectrogram(const NoteParams& params, + int* out_num_frames) { int num_frames = (int)(params.duration_sec * 32000.0f / DCT_SIZE); - if (num_frames < 1) num_frames = 1; + if (num_frames < 1) + num_frames = 1; *out_num_frames = num_frames; std::vector spec_data(num_frames * DCT_SIZE, 0.0f); @@ -32,7 +33,9 @@ std::vector generate_note_spectrogram(const NoteParams ¶ms, // Envelope (Simple Attack) float env = 1.0f; - if (t < params.attack_sec) { env = t / params.attack_sec; } + if (t < params.attack_sec) { + env = t / params.attack_sec; + } // Vibrato float vib = sinf(t * params.vibrato_rate * 2.0f * 3.14159f) * @@ -58,7 +61,9 @@ std::vector generate_note_spectrogram(const NoteParams ¶ms, } // Apply window - for (int i = 0; i < DCT_SIZE; ++i) { pcm_chunk[i] *= window[i]; } + for (int i = 0; i < DCT_SIZE; ++i) { + pcm_chunk[i] *= window[i]; + } // Apply FDCT float dct_chunk[DCT_SIZE]; @@ -73,10 +78,11 @@ std::vector generate_note_spectrogram(const NoteParams ¶ms, return spec_data; } -void paste_spectrogram(std::vector &dest_data, int *dest_num_frames, - const std::vector &src_data, int src_num_frames, +void paste_spectrogram(std::vector& dest_data, int* dest_num_frames, + const std::vector& src_data, int src_num_frames, int frame_offset) { - if (src_num_frames <= 0) return; + if (src_num_frames <= 0) + return; int needed_frames = frame_offset + src_num_frames; if (needed_frames > *dest_num_frames) { @@ -86,7 +92,8 @@ void paste_spectrogram(std::vector &dest_data, int *dest_num_frames, for (int f = 0; f < src_num_frames; ++f) { int dst_frame_idx = frame_offset + f; - if (dst_frame_idx < 0) continue; + if (dst_frame_idx < 0) + continue; for (int i = 0; i < DCT_SIZE; ++i) { dest_data[dst_frame_idx * DCT_SIZE + i] += src_data[f * DCT_SIZE + i]; @@ -94,7 +101,7 @@ void paste_spectrogram(std::vector &dest_data, int *dest_num_frames, } } -void apply_spectral_noise(std::vector &data, int num_frames, +void apply_spectral_noise(std::vector& data, int num_frames, float amount) { for (int f = 0; f < num_frames; ++f) { for (int i = 0; i < DCT_SIZE; ++i) { @@ -104,11 +111,13 @@ void apply_spectral_noise(std::vector &data, int num_frames, } } -void apply_spectral_lowpass(std::vector &data, int num_frames, +void apply_spectral_lowpass(std::vector& data, int num_frames, float cutoff_ratio) { int cutoff_bin = (int)(cutoff_ratio * DCT_SIZE); - if (cutoff_bin < 0) cutoff_bin = 0; - if (cutoff_bin >= DCT_SIZE) return; + if (cutoff_bin < 0) + cutoff_bin = 0; + if (cutoff_bin >= DCT_SIZE) + return; for (int f = 0; f < num_frames; ++f) { for (int i = cutoff_bin; i < DCT_SIZE; ++i) { @@ -117,11 +126,13 @@ void apply_spectral_lowpass(std::vector &data, int num_frames, } } -void apply_spectral_comb(std::vector &data, int num_frames, +void apply_spectral_comb(std::vector& data, int num_frames, float period_bins, float depth) { for (int i = 0; i < DCT_SIZE; ++i) { float mod = 1.0f - depth * (0.5f + 0.5f * cosf((float)i / period_bins * 6.28318f)); - for (int f = 0; f < num_frames; ++f) { data[f * DCT_SIZE + i] *= mod; } + for (int f = 0; f < num_frames; ++f) { + data[f * DCT_SIZE + i] *= mod; + } } } diff --git a/src/audio/gen.h b/src/audio/gen.h index f490115..94f4ee3 100644 --- a/src/audio/gen.h +++ b/src/audio/gen.h @@ -20,19 +20,19 @@ struct NoteParams { }; // Generates a single note into a new spectrogram buffer -std::vector generate_note_spectrogram(const NoteParams ¶ms, - int *out_num_frames); +std::vector generate_note_spectrogram(const NoteParams& params, + int* out_num_frames); // Pastes a source spectrogram into a destination spectrogram at a given frame // offset Expands destination if necessary -void paste_spectrogram(std::vector &dest_data, int *dest_num_frames, - const std::vector &src_data, int src_num_frames, +void paste_spectrogram(std::vector& dest_data, int* dest_num_frames, + const std::vector& src_data, int src_num_frames, int frame_offset); // Post-processing effects -void apply_spectral_noise(std::vector &data, int num_frames, +void apply_spectral_noise(std::vector& data, int num_frames, float amount); -void apply_spectral_lowpass(std::vector &data, int num_frames, +void apply_spectral_lowpass(std::vector& data, int num_frames, float cutoff_ratio); -void apply_spectral_comb(std::vector &data, int num_frames, +void apply_spectral_comb(std::vector& data, int num_frames, float period_bins, float depth); diff --git a/src/audio/idct.cc b/src/audio/idct.cc index 6235950..f8e8769 100644 --- a/src/audio/idct.cc +++ b/src/audio/idct.cc @@ -5,7 +5,7 @@ #include "dct.h" #include -void idct_512(const float *input, float *output) { +void idct_512(const float* input, float* output) { const float PI = 3.14159265358979323846f; for (int n = 0; n < DCT_SIZE; ++n) { float sum = input[0] / 2.0f; diff --git a/src/audio/synth.cc b/src/audio/synth.cc index b4aaf53..db5a96c 100644 --- a/src/audio/synth.cc +++ b/src/audio/synth.cc @@ -23,12 +23,12 @@ struct Voice { float time_domain_buffer[DCT_SIZE]; int buffer_pos; - const volatile float *active_spectral_data; + const volatile float* active_spectral_data; }; static struct { Spectrogram spectrograms[MAX_SPECTROGRAMS]; - const volatile float *active_spectrogram_data[MAX_SPECTROGRAMS]; + const volatile float* active_spectrogram_data[MAX_SPECTROGRAMS]; bool spectrogram_registered[MAX_SPECTROGRAMS]; } g_synth_data; @@ -49,7 +49,7 @@ void synth_shutdown() { // Nothing to do here since we are not allocating memory } -int synth_register_spectrogram(const Spectrogram *spec) { +int synth_register_spectrogram(const Spectrogram* spec) { for (int i = 0; i < MAX_SPECTROGRAMS; ++i) { if (!g_synth_data.spectrogram_registered[i]) { g_synth_data.spectrograms[i] = *spec; @@ -67,19 +67,19 @@ void synth_unregister_spectrogram(int spectrogram_id) { } } -float *synth_begin_update(int spectrogram_id) { +float* synth_begin_update(int spectrogram_id) { if (spectrogram_id < 0 || spectrogram_id >= MAX_SPECTROGRAMS || !g_synth_data.spectrogram_registered[spectrogram_id]) { return nullptr; } - const volatile float *active_ptr = + const volatile float* active_ptr = g_synth_data.active_spectrogram_data[spectrogram_id]; if (active_ptr == g_synth_data.spectrograms[spectrogram_id].spectral_data_a) { - return (float *)(g_synth_data.spectrograms[spectrogram_id].spectral_data_b); + return (float*)(g_synth_data.spectrograms[spectrogram_id].spectral_data_b); } else { - return (float *)(g_synth_data.spectrograms[spectrogram_id].spectral_data_a); + return (float*)(g_synth_data.spectrograms[spectrogram_id].spectral_data_a); } } @@ -89,9 +89,9 @@ void synth_commit_update(int spectrogram_id) { return; } - const volatile float *old_active_ptr = + const volatile float* old_active_ptr = g_synth_data.active_spectrogram_data[spectrogram_id]; - const float *new_active_ptr = + const float* new_active_ptr = (old_active_ptr == g_synth_data.spectrograms[spectrogram_id].spectral_data_a) ? g_synth_data.spectrograms[spectrogram_id].spectral_data_b @@ -99,7 +99,7 @@ void synth_commit_update(int spectrogram_id) { // Atomic swap using GCC/Clang builtins for thread safety __atomic_store_n( - (const float **)&g_synth_data.active_spectrogram_data[spectrogram_id], + (const float**)&g_synth_data.active_spectrogram_data[spectrogram_id], new_active_ptr, __ATOMIC_RELEASE); } @@ -111,7 +111,7 @@ void synth_trigger_voice(int spectrogram_id, float volume, float pan) { for (int i = 0; i < MAX_VOICES; ++i) { if (!g_voices[i].active) { - Voice &v = g_voices[i]; + Voice& v = g_voices[i]; v.active = true; v.spectrogram_id = spectrogram_id; v.volume = volume; @@ -132,7 +132,7 @@ void synth_trigger_voice(int spectrogram_id, float volume, float pan) { } } -void synth_render(float *output_buffer, int num_frames) { +void synth_render(float* output_buffer, int num_frames) { // Use the pre-calculated window // float window[WINDOW_SIZE]; // hamming_window_512(window); @@ -145,8 +145,9 @@ void synth_render(float *output_buffer, int num_frames) { float right_sample = 0.0f; for (int v_idx = 0; v_idx < MAX_VOICES; ++v_idx) { - Voice &v = g_voices[v_idx]; - if (!v.active) continue; + Voice& v = g_voices[v_idx]; + if (!v.active) + continue; if (v.buffer_pos >= DCT_SIZE) { if (v.current_spectral_frame >= v.total_spectral_frames) { @@ -158,7 +159,7 @@ void synth_render(float *output_buffer, int num_frames) { v.active_spectral_data = g_synth_data.active_spectrogram_data[v.spectrogram_id]; - const float *spectral_frame = (const float *)v.active_spectral_data + + const float* spectral_frame = (const float*)v.active_spectral_data + (v.current_spectral_frame * DCT_SIZE); float windowed_frame[DCT_SIZE]; @@ -170,7 +171,7 @@ void synth_render(float *output_buffer, int num_frames) { idct_512(windowed_frame, v.time_domain_buffer); v.buffer_pos = 0; - v.current_spectral_frame++; + ++v.current_spectral_frame; } float voice_sample = v.time_domain_buffer[v.buffer_pos] * v.volume; @@ -192,9 +193,13 @@ void synth_render(float *output_buffer, int num_frames) { int synth_get_active_voice_count() { int count = 0; for (int i = 0; i < MAX_VOICES; ++i) { - if (g_voices[i].active) { count++; } + if (g_voices[i].active) { + ++count; + } } return count; } -float synth_get_output_peak() { return g_current_output_peak; } +float synth_get_output_peak() { + return g_current_output_peak; +} diff --git a/src/audio/synth.h b/src/audio/synth.h index 45a9410..a0720f2 100644 --- a/src/audio/synth.h +++ b/src/audio/synth.h @@ -11,8 +11,8 @@ #define MAX_SPECTROGRAMS 8 struct Spectrogram { - const float *spectral_data_a; // Front buffer - const float *spectral_data_b; // Back buffer (for double-buffering) + const float* spectral_data_a; // Front buffer + const float* spectral_data_b; // Back buffer (for double-buffering) int num_frames; }; @@ -20,15 +20,15 @@ void synth_init(); void synth_shutdown(); // Register a spectrogram for playback. Returns an ID or -1. -int synth_register_spectrogram(const Spectrogram *spec); +int synth_register_spectrogram(const Spectrogram* spec); void synth_unregister_spectrogram(int spectrogram_id); // Double-buffering API for thread-safe updates -float *synth_begin_update(int spectrogram_id); +float* synth_begin_update(int spectrogram_id); void synth_commit_update(int spectrogram_id); void synth_trigger_voice(int spectrogram_id, float volume, float pan); -void synth_render(float *output_buffer, int num_frames); +void synth_render(float* output_buffer, int num_frames); int synth_get_active_voice_count(); float synth_get_output_peak(); diff --git a/src/audio/window.cc b/src/audio/window.cc index e5dfdec..b68c747 100644 --- a/src/audio/window.cc +++ b/src/audio/window.cc @@ -5,7 +5,7 @@ #include "window.h" #include -void hamming_window_512(float *window) { +void hamming_window_512(float* window) { const float PI = 3.14159265358979323846f; for (int i = 0; i < WINDOW_SIZE; ++i) { window[i] = diff --git a/src/audio/window.h b/src/audio/window.h index 99ac209..c3b583a 100644 --- a/src/audio/window.h +++ b/src/audio/window.h @@ -6,4 +6,4 @@ #define WINDOW_SIZE 512 -void hamming_window_512(float *window); +void hamming_window_512(float* window); -- cgit v1.2.3