summaryrefslogtreecommitdiff
path: root/src/dft.h
diff options
context:
space:
mode:
authorsteven-na <noreply.github@stvnc.dev>2026-08-01 16:19:10 -0700
committersteven-na <noreply.github@stvnc.dev>2026-08-01 16:19:10 -0700
commit1ccc16dd584e95038b22264451315b44227bf321 (patch)
tree724cf2e86132e165dee88d314b0686ed2bc732cf /src/dft.h
parent584d166c4ebf2768825e6719f461fd91c3dd4555 (diff)
Discrete Fourier Transform impl
Diffstat (limited to 'src/dft.h')
-rw-r--r--src/dft.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/dft.h b/src/dft.h
new file mode 100644
index 0000000..982cc6f
--- /dev/null
+++ b/src/dft.h
@@ -0,0 +1,48 @@
+#pragma once
+
+#include "common.h"
+#include "smrt_arena.h"
+#include "wav.h"
+
+typedef struct {
+ f64 *frequencies;
+ f64 * amplitudes;
+ f64 * phases;
+ u64 freq_count;
+} dft_data_t;
+
+/// Run DFT algorithm on samples
+dft_data_t discrete_fourier_transform(smrt_arena_t * arena ,
+ f64 * samples ,
+ u64 sample_count ,
+ u64 sample_rate);
+
+/// Convert DFT frequency data to unsigned 8-bit PCM WAV amplitude data
+wav_data_t dft_data_to_wav(smrt_arena_t * arena ,
+ dft_data_t dft ,
+ u64 sample_rate ,
+ f64 duration);
+
+typedef struct {
+ dft_data_t data;
+ u64 sample_count;
+ u64 start_index;
+} stft_segment_t;
+
+typedef struct {
+ stft_segment_t * segments;
+ u64 segment_count;
+ u64 sample_rate;
+} stft_data_t;
+
+/// Run STFT algorithm on samples.
+stft_data_t short_time_fourier_transform(smrt_arena_t * arena ,
+ u64 samples_per_segment ,
+ f64 * samples ,
+ u64 sample_count ,
+ u64 sample_rate);
+
+/// Convert STFT frequency data to unsigned 8-bit PCM WAV amplitude data
+wav_data_t stft_data_to_wav(smrt_arena_t * arena ,
+ stft_data_t stft ,
+ u64 sample_count);