summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/wav.c25
-rw-r--r--src/wav.h7
2 files changed, 32 insertions, 0 deletions
diff --git a/src/wav.c b/src/wav.c
index 9796160..ab8919d 100644
--- a/src/wav.c
+++ b/src/wav.c
@@ -1,4 +1,5 @@
#include "wav.h"
+#include "common.h"
#include "smrt_arena.h"
#include <assert.h>
@@ -260,3 +261,27 @@ f64 *read_32bps_float_data(smrt_arena_t *arena, wav_data_t data, u16 num_channel
return vs;
}
+
+f64 *combine_channels(smrt_arena_t *arena, f64 **channels, u64 num_channels, u64 sample_count) {
+ assert(num_channels != 0 && "num_channels must be >0");
+
+ f64 *samples = SMRTA_ALLOC_ARRAY(arena, f64, num_channels * sample_count);
+
+ for (u64 s = 0; s < sample_count; s++) {
+ for (u64 c = 0; c < num_channels; c++) {
+ samples[s*num_channels + c] = channels[c][s];
+ }
+ }
+
+ return samples;
+}
+
+f32 *f64_to_f32(smrt_arena_t *arena, f64 *samples, u64 sample_count) {
+ f32 *o = SMRTA_ALLOC_ARRAY(arena, f32, sample_count);
+
+ for (u64 i = 0; i < sample_count; i++) {
+ o[i] = (f32)samples[i];
+ }
+
+ return o;
+}
diff --git a/src/wav.h b/src/wav.h
index 484c6da..00ab37d 100644
--- a/src/wav.h
+++ b/src/wav.h
@@ -62,6 +62,7 @@ wav_fmt_chunk_t make_wav_fmt_chunk(u32 num_channels ,
/// Load WAV data into [-1.0, 1.0] f64 amplitudes. Populates -o inputs with information.
/// samples will be amplitude data for each channel from the WAV file, of length sample_count.
+/// align_up_memoryn will align allocation up to nearest multiple (For FFT)
void wav_load(smrt_arena_t *arena, FILE *wav, f64 *** samples_o ,
u16 *channel_count_o ,
u64 * sample_count_o ,
@@ -73,3 +74,9 @@ f64 * read_8bps_data(smrt_arena_t *arena, wav_data_t data, u16 num_channel
f64 * read_16bps_data(smrt_arena_t *arena, wav_data_t data, u16 num_channels, u16 channel, u64 align_up_memoryn);
f64 * read_24bps_data(smrt_arena_t *arena, wav_data_t data, u16 num_channels, u16 channel, u64 align_up_memoryn);
f64 *read_32bps_float_data(smrt_arena_t *arena, wav_data_t data, u16 num_channels, u16 channel, u64 align_up_memoryn);
+
+/// Combine channel_count arrays of sample_count samples from **channels
+/// Interleaving for WAV format audio storage.
+f64 *combine_channels(smrt_arena_t *arena, f64 **channels, u64 channel_count, u64 sample_count);
+
+f32 *f64_to_f32(smrt_arena_t *arena, f64 *samples, u64 sample_count);