summaryrefslogtreecommitdiff
path: root/src/wav.h
diff options
context:
space:
mode:
authorsteven-na <noreply.github@stvnc.dev>2026-07-30 13:58:06 -0700
committersteven-na <noreply.github@stvnc.dev>2026-07-30 13:58:06 -0700
commita1af7db3ecf1863c77e69aa432e6fb2694ec3f95 (patch)
tree1109813dfd46c2db628eb9d03c861dddf41b2a4b /src/wav.h
parent62ae217a27531d9767bcdda0e7ff6c4368ed857e (diff)
Wav file loading
Diffstat (limited to 'src/wav.h')
-rw-r--r--src/wav.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/wav.h b/src/wav.h
new file mode 100644
index 0000000..dd85ccd
--- /dev/null
+++ b/src/wav.h
@@ -0,0 +1,46 @@
+#pragma once
+
+#include "common.h"
+#include "smrt_arena.h"
+
+#define WAV_DATA_BASE_POS sizeof(wav_data_t)
+
+typedef struct {
+ u64 sample_count;
+} wav_data_t;
+
+// [Master RIFF chunk]
+// FileTypeBlocID (4 bytes) : Identifier « RIFF » (0x52, 0x49, 0x46, 0x46)
+// FileSize (4 bytes) : Overall file size minus 8 bytes
+// FileFormatID (4 bytes) : Format = « WAVE » (0x57, 0x41, 0x56, 0x45)
+#pragma pack(push, 1)
+typedef struct {
+ u8 chunk_id[4];
+ u32 file_size;
+ u8 file_format_id[4];
+} wav_master_chunk_t;
+
+// [Chunk describing the data format]
+// FormatBlocID (4 bytes) : Identifier « fmt␣ » (0x66, 0x6D, 0x74, 0x20)
+// BlocSize (4 bytes) : Chunk size minus 8 bytes
+// AudioFormat (2 bytes) : Audio format (1: PCM integer, 3: IEEE 754 float)
+// NbrChannels (2 bytes) : Number of channels
+// Frequency (4 bytes) : Sample rate (in hertz)
+// BytePerSec (4 bytes) : Number of bytes to read per second (Frequency * BytePerBloc).
+// BytePerBloc (2 bytes) : Number of bytes per block (NbrChannels * BitsPerSample / 8).
+// BitsPerSample (2 bytes) : Number of bits per sample
+typedef struct {
+ u8 chunk_id[4];
+ u32 chunk_size;
+ u16 audio_format;
+ u16 num_channels;
+ u32 sample_rate;
+ u32 byter_per_sec;
+ u16 bytes_per_block;
+ u16 bits_per_sample;
+} wav_fmt_chunk_t;
+#pragma pack(pop)
+
+ wav_data_t *load_wav_file(smrt_arena_t *arena, char *filename, wav_master_chunk_t *master_o, wav_fmt_chunk_t *format_o);
+ void write_wav_file(char *filename, wav_fmt_chunk_t *header_i, wav_data_t *data_i);
+wav_fmt_chunk_t make_wav_fmt_chunk(u32 num_channels, u32 sample_rate, u16 bits_per_sample, wav_data_t *data_i);