summaryrefslogtreecommitdiff
path: root/src/audio/audio.cpp
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-01-27 22:16:23 +0100
committerskal <pascal.massimino@gmail.com>2026-01-27 22:16:23 +0100
commitad4f87e0ebfd361c69c7ba9adc29292305f21f7c (patch)
tree7e3d4feffce3cac26139df1ace2f879e62bfc00c /src/audio/audio.cpp
parent2f68b86ba403fdae97c00569b6bb9b58ad1f33a6 (diff)
feat(audio): Implement real-time spectrogram synthesizer
Adds a multi-voice, real-time audio synthesis engine that generates sound from spectrogram data using an Inverse Discrete Cosine Transform (IDCT). Key features: - A thread-safe, double-buffered system for dynamically updating spectrograms in real-time without interrupting audio playback. - Core DSP components: FDCT, IDCT, and Hamming window functions. - A simple sequencer in the main loop to demonstrate scripted audio events and dynamic updates. - Unit tests for the new synth engine and Hamming window, integrated with CTest. - A file documenting the build process, features, and how to run tests.
Diffstat (limited to 'src/audio/audio.cpp')
-rw-r--r--src/audio/audio.cpp23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp
index 9e778f1..318ccb8 100644
--- a/src/audio/audio.cpp
+++ b/src/audio/audio.cpp
@@ -1,27 +1,19 @@
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"
+#include "synth.h"
#include <math.h>
static ma_device device;
-static float phase = 0.0f;
static void audio_callback(ma_device*, void* output, const void*, ma_uint32 frames) {
- int16_t* out = (int16_t*)output;
- const float freq = 440.0f;
- const float sr = 32000.0f;
-
- for (ma_uint32 i = 0; i < frames; i++) {
- float s = sinf(phase) * 0.2f;
- phase += 2.0f * 3.14159265f * freq / sr;
- if (phase > 2.0f * 3.14159265f) phase -= 2.0f * 3.14159265f;
- out[i] = (int16_t)(s * 32767.0f);
- }
+ synth_render((float*)output, frames);
}
void audio_init() {
+ synth_init();
ma_device_config cfg = ma_device_config_init(ma_device_type_playback);
- cfg.playback.format = ma_format_s16;
- cfg.playback.channels = 1;
+ cfg.playback.format = ma_format_f32;
+ cfg.playback.channels = 2;
cfg.sampleRate = 32000;
cfg.dataCallback = audio_callback;
@@ -30,4 +22,7 @@ void audio_init() {
}
void audio_update() {}
-void audio_shutdown() { ma_device_uninit(&device); }
+void audio_shutdown() {
+ synth_shutdown();
+ ma_device_uninit(&device);
+}