diff options
author | stefonzo <stevester.robinson@gmail.com> | 2022-09-05 20:17:22 -0500 |
---|---|---|
committer | stefonzo <stevester.robinson@gmail.com> | 2022-09-05 20:17:22 -0500 |
commit | 7dac325122067bd8b453c0ec60fc1a768bb6f934 (patch) | |
tree | aab7173f2c19eacaf433f443d2fc53e198ce89d7 /3rdparty/libwav/tests/write_f32/main.c | |
parent | 16431035f8e1c61e37adcceb8eab75e8d0dfed62 (diff) |
adds libwav
Diffstat (limited to '3rdparty/libwav/tests/write_f32/main.c')
-rw-r--r-- | 3rdparty/libwav/tests/write_f32/main.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/3rdparty/libwav/tests/write_f32/main.c b/3rdparty/libwav/tests/write_f32/main.c new file mode 100644 index 0000000..14f4f33 --- /dev/null +++ b/3rdparty/libwav/tests/write_f32/main.c @@ -0,0 +1,25 @@ +#include <math.h> +#include <stdlib.h> +#include "wav.h" + +void generate_sine_wave(float *x, int sample_rate, int len) +{ + for (int i = 0; i < len; ++i) { + x[i] = 0.5f * cosf(2 * 3.14159265358979323f * 440.0f * i / sample_rate); + } +} + +int main(void) +{ + float *buf = malloc(sizeof(float) * 10 * 44100); + generate_sine_wave(buf, 44100, 10 * 44100); + WavFile *fp = wav_open("out.wav", WAV_OPEN_WRITE); + wav_set_format(fp, WAV_FORMAT_IEEE_FLOAT); + /* wav_set_sample_size(fp, sizeof(float)); */ + wav_set_num_channels(fp, 1); + wav_set_sample_rate(fp, 44100); + wav_write(fp, buf, 10 * 44100); + wav_close(fp); + free(buf); + return 0; +} |