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/gen.cc | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'src/audio/gen.cc') 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; + } } } -- cgit v1.2.3