summaryrefslogtreecommitdiff
path: root/src/audio/gen.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-01 00:58:20 +0100
committerskal <pascal.massimino@gmail.com>2026-02-01 01:13:53 +0100
commit18eb8a07ba39a8aad1c75521cee027b9c9c72e40 (patch)
tree87e498dbaffdd591eb94fddca315f6ba28756a32 /src/audio/gen.cc
parent03cd94817097e59a0809b222e0e1e74dd9a8ede7 (diff)
clang-format
Diffstat (limited to 'src/audio/gen.cc')
-rw-r--r--src/audio/gen.cc41
1 files changed, 26 insertions, 15 deletions
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 <stdlib.h>
#include <string.h>
-std::vector<float> generate_note_spectrogram(const NoteParams &params,
- int *out_num_frames) {
+std::vector<float> 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<float> spec_data(num_frames * DCT_SIZE, 0.0f);
@@ -32,7 +33,9 @@ std::vector<float> generate_note_spectrogram(const NoteParams &params,
// 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<float> generate_note_spectrogram(const NoteParams &params,
}
// 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<float> generate_note_spectrogram(const NoteParams &params,
return spec_data;
}
-void paste_spectrogram(std::vector<float> &dest_data, int *dest_num_frames,
- const std::vector<float> &src_data, int src_num_frames,
+void paste_spectrogram(std::vector<float>& dest_data, int* dest_num_frames,
+ const std::vector<float>& 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<float> &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<float> &dest_data, int *dest_num_frames,
}
}
-void apply_spectral_noise(std::vector<float> &data, int num_frames,
+void apply_spectral_noise(std::vector<float>& 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<float> &data, int num_frames,
}
}
-void apply_spectral_lowpass(std::vector<float> &data, int num_frames,
+void apply_spectral_lowpass(std::vector<float>& 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<float> &data, int num_frames,
}
}
-void apply_spectral_comb(std::vector<float> &data, int num_frames,
+void apply_spectral_comb(std::vector<float>& 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;
+ }
}
}