From 04c8d83b4ce0a9dcf16c7ca4aa26723db86780bc Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Sat, 8 Mar 2025 04:16:24 -0500 Subject: [PATCH] cleanup imports --- include/osc.h | 5 ----- src/osc.c | 1 + src/state.c | 1 - tests/test_vec.c | 9 ++------- tests/test_vec_macro.c | 5 ----- 5 files changed, 3 insertions(+), 18 deletions(-) diff --git a/include/osc.h b/include/osc.h index 9b57b88..43e54e8 100644 --- a/include/osc.h +++ b/include/osc.h @@ -1,5 +1,4 @@ #pragma once -#include "config.h" typedef struct { double phase; // current phase (in table index units) @@ -7,10 +6,6 @@ typedef struct { int wt_index; // index into the shared wavetable array } Osc; -// Create an oscillator (here, allocation is done in State_create) Osc Osc_create(int wt_index, double freq); -// Update an oscillator's frequency. void Osc_set_freq(Osc *osc, double freq); - -// (No Osc_destroy is needed since the array is owned by State.) diff --git a/src/osc.c b/src/osc.c index c8d24c2..2f5ea24 100644 --- a/src/osc.c +++ b/src/osc.c @@ -1,4 +1,5 @@ #include "osc.h" +#include "config.h" Osc Osc_create(int wt_index, double freq) { Osc osc; diff --git a/src/state.c b/src/state.c index fea41bd..a885882 100644 --- a/src/state.c +++ b/src/state.c @@ -90,7 +90,6 @@ float State_mix_sample(State *state) { if (osc->phase >= len) osc->phase -= len; } - // Average the oscillators in this voice. voice_sum /= NUM_OSCS; mix += voice_sum; } diff --git a/tests/test_vec.c b/tests/test_vec.c index 7a8ee1a..ec20ca4 100644 --- a/tests/test_vec.c +++ b/tests/test_vec.c @@ -13,7 +13,7 @@ Test(vec, int) { cr_assert_eq(vec->size, (size_t)(i + 1), "After push %d, vec size should be %d", i + 1, i + 1); } - // Verify that each stored int matches its expected value. + // Verify each stored int matches its expected value. for (size_t i = 0; i < vec->size; i++) { int value = 0; Vec_get(vec, i, &value); @@ -24,28 +24,23 @@ Test(vec, int) { } Test(vec, osc) { - // Create a vector for Osc pointers. - // We are storing Osc* elements, so the element size is sizeof(Osc*). - // The destroy function is set to Osc_destroy so that each Osc is cleaned up. Vec *vec = Vec_create(sizeof(Osc*), (ElemDestroyFunc)Osc_destroy); cr_assert_not_null(vec, "Vec_create returned NULL for Osc vector"); cr_assert_eq(vec->size, 0, "Initial Osc vector size should be 0"); const int numOsc = 1; for (int i = 0; i < numOsc; i++) { - // Create an oscillator with varying parameters. Osc *osc = Osc_create(WAVEFORM_SINE + (i % 2), 256 * (i + 1), 220.0 + (i * 10)); Vec_push_back(vec, &osc); cr_assert_eq(vec->size, (size_t)(i + 1), "After push %d, Osc vector size should be %d", i + 1, i + 1); } - // Verify that each stored Osc pointer is not NULL. + // Verify each stored Osc pointer is not NULL. for (size_t i = 0; i < vec->size; i++) { Osc *osc_ptr = NULL; Vec_get(vec, i, &osc_ptr); cr_assert_not_null(osc_ptr, "Osc element at index %zu should not be NULL", i); - // Optionally, you can add more detailed tests of the Osc's properties here. } Vec_destroy(vec); diff --git a/tests/test_vec_macro.c b/tests/test_vec_macro.c index 11cec55..9cd6147 100644 --- a/tests/test_vec_macro.c +++ b/tests/test_vec_macro.c @@ -8,32 +8,27 @@ Test(VecOscPtr, create_push_get_destroy) { cr_assert_not_null(ov, "Vec_OscPtr_create returned NULL"); cr_assert_eq(ov->vec->size, 0, "Initial vector size should be 0"); - // Create two oscillators with different properties. Osc *osc1 = Osc_create(WAVEFORM_SINE, 256, 440.0); cr_assert_not_null(osc1, "Osc_create returned NULL for osc1"); Osc *osc2 = Osc_create(WAVEFORM_SAW, 512, 220.0); cr_assert_not_null(osc2, "Osc_create returned NULL for osc2"); - // Push the oscillators into the typed vector. Vec_OscPtr_push_back(ov, osc1); cr_assert_eq(ov->vec->size, 1, "After pushing osc1, size should be 1"); Vec_OscPtr_push_back(ov, osc2); cr_assert_eq(ov->vec->size, 2, "After pushing osc2, size should be 2"); - // Retrieve the stored oscillators. Osc *retrieved1 = Vec_OscPtr_get(ov, 0); Osc *retrieved2 = Vec_OscPtr_get(ov, 1); cr_assert_not_null(retrieved1, "Retrieved oscillator 1 should not be NULL"); cr_assert_not_null(retrieved2, "Retrieved oscillator 2 should not be NULL"); - // Check that the retrieved oscillators have the expected properties. cr_assert_eq(retrieved1->wt->type, WAVEFORM_SINE, "Expected osc1 to have WAVEFORM_SINE"); cr_assert_eq(retrieved1->wt->length, 256, "Expected osc1 wavetable length to be 256"); cr_assert_eq(retrieved2->wt->type, WAVEFORM_SAW, "Expected osc2 to have WAVEFORM_SAW"); cr_assert_eq(retrieved2->wt->length, 512, "Expected osc2 wavetable length to be 512"); - // Verify phase and phase_inc for osc1. cr_assert_float_eq(retrieved1->phase, 0.0, 0.0001, "Initial phase for osc1 should be 0"); double expected_phase_inc1 = (TABLE_SIZE * 440.0) / SAMPLE_RATE; cr_assert_float_eq(retrieved1->phase_inc, expected_phase_inc1, 0.0001,