From 7dac325122067bd8b453c0ec60fc1a768bb6f934 Mon Sep 17 00:00:00 2001 From: stefonzo Date: Mon, 5 Sep 2022 20:17:22 -0500 Subject: adds libwav --- 3rdparty/libwav/tests/write_f32/CMakeLists.txt | 13 +++++++++++++ 3rdparty/libwav/tests/write_f32/main.c | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 3rdparty/libwav/tests/write_f32/CMakeLists.txt create mode 100644 3rdparty/libwav/tests/write_f32/main.c (limited to '3rdparty/libwav/tests/write_f32') diff --git a/3rdparty/libwav/tests/write_f32/CMakeLists.txt b/3rdparty/libwav/tests/write_f32/CMakeLists.txt new file mode 100644 index 0000000..cca1ecf --- /dev/null +++ b/3rdparty/libwav/tests/write_f32/CMakeLists.txt @@ -0,0 +1,13 @@ +add_executable(write-f32 main.c) +target_link_libraries(write-f32 + wav::wav + $<$:m> + ) +target_include_directories(write-f32 PRIVATE ${CMAKE_SOURCE_DIR}/include) +target_compile_features(write-f32 PRIVATE ${wav_compile_features}) +target_compile_definitions(write-f32 PRIVATE ${wav_compile_definitions}) +target_compile_options(write-f32 PRIVATE + ${wav_c_flags} + $<$:${wav_compile_options_release}> + $<$:${wav_compile_options_release}> + ) 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 +#include +#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; +} -- cgit v1.2.1