diff --git a/include/osc.h b/include/osc.h index 43d5708..a182621 100644 --- a/include/osc.h +++ b/include/osc.h @@ -8,16 +8,16 @@ typedef struct { Wavetable *wt; // pointer to this oscillator's wavetable } Osc; -Osc *osc_create(Waveform type, size_t length, double freq); -void osc_set_freq(Osc *osc, double freq); -void osc_destroy(Osc *osc); +Osc *Osc_create(Waveform type, size_t length, double freq); +void Osc_set_freq(Osc *osc, double freq); +void Osc_destroy(Osc *osc); typedef struct { Vec *vec; } OscVec; -OscVec *oscvec_create(void); -void oscvec_push(OscVec *ov, Osc *osc); -Osc *oscvec_get(const OscVec *ov, size_t index); -size_t oscvec_size(const OscVec *ov); -void oscvec_destroy(OscVec *ov); +OscVec *OscVec_create(void); +void OscVec_push(OscVec *ov, Osc *osc); +Osc *OscVec_get(const OscVec *ov, size_t index); +size_t OscVec_size(const OscVec *ov); +void OscVec_destroy(OscVec *ov); diff --git a/include/vec.h b/include/vec.h index 3130bd1..e5854c7 100644 --- a/include/vec.h +++ b/include/vec.h @@ -13,9 +13,9 @@ typedef struct { ElemDestroyFunc destroy_func; // Function pointer for element deletion } Vec; -Vec *vec_create(size_t element_size, ElemDestroyFunc destroy_func); -void vec_push_back(Vec *vec, const void *element); -void vec_get(const Vec *vec, size_t index, void *out_element); -void vec_set(Vec *vec, size_t index, const void *element); -void vec_pop_back(Vec *vec); -void vec_destroy(Vec *vec); +Vec *Vec_create(size_t element_size, ElemDestroyFunc destroy_func); +void Vec_push_back(Vec *vec, const void *element); +void Vec_get(const Vec *vec, size_t index, void *out_element); +void Vec_set(Vec *vec, size_t index, const void *element); +void Vec_pop_back(Vec *vec); +void Vec_destroy(Vec *vec); diff --git a/include/wavetable.h b/include/wavetable.h index 4407fe0..17cec45 100644 --- a/include/wavetable.h +++ b/include/wavetable.h @@ -16,9 +16,9 @@ typedef struct { Waveform type; } Wavetable; -Wavetable *wavetable_create(Waveform type, size_t length); -void wavetable_set_custom(Wavetable *wt, float *data, size_t length); -void wavetable_destroy(Wavetable *wt); +Wavetable *Wavetable_create(Waveform type, size_t length); +void Wavetable_set_custom(Wavetable *wt, float *data, size_t length); +void Wavetable_destroy(Wavetable *wt); typedef struct { Vec *vec; diff --git a/src/main.c b/src/main.c index ca16751..bc64033 100644 --- a/src/main.c +++ b/src/main.c @@ -11,14 +11,14 @@ #include "vec.h" // Global mutex to protect oscillator state. -static pthread_mutex_t osc_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t Osc_mutex = PTHREAD_MUTEX_INITIALIZER; // The write callback: libsoundio calls this when it needs more audio samples. // Now we use each oscillator's own wavetable length. static void write_callback(struct SoundIoOutStream *outstream, int frame_count_min, int frame_count_max) { (void)frame_count_min; - Vec *osc_vec = (Vec *)outstream->userdata; + Vec *Osc_vec = (Vec *)outstream->userdata; int frames_left = frame_count_max; while (frames_left > 0) { @@ -35,31 +35,31 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m for (int frame = 0; frame < frame_count; frame++) { float sample = 0.0f; - pthread_mutex_lock(&osc_mutex); + pthread_mutex_lock(&Osc_mutex); // Mix output from each oscillator. - for (size_t i = 0; i < osc_vec->size; i++) { + for (size_t i = 0; i < Osc_vec->size; i++) { // Retrieve the Osc* stored at index i. - Osc *osc = ((Osc **)(osc_vec->data))[i]; + Osc *osc = ((Osc **)(Osc_vec->data))[i]; // Use the actual wavetable length for indexing. size_t wt_length = osc->wt->length; double pos = osc->phase; int index0 = (int)pos; int index1 = (index0 + 1) % wt_length; double frac = pos - index0; - float osc_sample = + float Osc_sample = (float)((1.0 - frac) * osc->wt->data[index0] + frac * osc->wt->data[index1]); - sample += osc_sample; + sample += Osc_sample; // Increment phase and wrap around using the actual wavetable length. osc->phase += osc->phase_inc; if (osc->phase >= wt_length) osc->phase -= wt_length; } - pthread_mutex_unlock(&osc_mutex); + pthread_mutex_unlock(&Osc_mutex); // Average the mixed sample. - if (osc_vec->size > 0) - sample /= osc_vec->size; + if (Osc_vec->size > 0) + sample /= Osc_vec->size; // Write the sample to all output channels. for (int ch = 0; ch < outstream->layout.channel_count; ch++) { @@ -81,8 +81,8 @@ int main(int argc, char **argv) { (void)argc; (void)argv; // Create a vector for Osc pointers. - // We pass osc_destroy as the element destroy function so that each Osc is properly freed. - Vec *osc_vec = vec_create(sizeof(Osc *), (ElemDestroyFunc)osc_destroy); + // We pass Osc_destroy as the element destroy function so that each Osc is properly freed. + Vec *Osc_vec = Vec_create(sizeof(Osc *), (ElemDestroyFunc)Osc_destroy); double freq0 = 440.0, freq1 = 550.0, freq2 = 660.0; // Create oscillators with different wavetable resolutions. @@ -90,14 +90,14 @@ int main(int argc, char **argv) { // - A high-resolution sine (1024 samples), // - A medium-resolution saw (256 samples), // - A low-resolution square (16 samples) for a bitcrushed effect. - Osc *tempA = osc_create(WAVEFORM_SINE, 1024, freq0); - Osc *tempB = osc_create(WAVEFORM_SAW, 256, freq1); - Osc *tempC = osc_create(WAVEFORM_SQUARE, 16, freq2); + Osc *tempA = Osc_create(WAVEFORM_SINE, 1024, freq0); + Osc *tempB = Osc_create(WAVEFORM_SAW, 256, freq1); + Osc *tempC = Osc_create(WAVEFORM_SQUARE, 16, freq2); // Push the Osc pointers into the vector. - vec_push_back(osc_vec, &tempA); - vec_push_back(osc_vec, &tempB); - vec_push_back(osc_vec, &tempC); + Vec_push_back(Osc_vec, &tempA); + Vec_push_back(Osc_vec, &tempB); + Vec_push_back(Osc_vec, &tempC); // Initialize libsoundio. struct SoundIo *soundio = soundio_create(); @@ -148,7 +148,7 @@ int main(int argc, char **argv) { } // Set our oscillator vector as userdata and assign the callback. - outstream->userdata = osc_vec; + outstream->userdata = Osc_vec; outstream->write_callback = write_callback; // Open and start the output stream. @@ -178,50 +178,50 @@ int main(int argc, char **argv) { // Adjust oscillator 0 with UP/DOWN keys. if (IsKeyPressed(KEY_UP)) { - pthread_mutex_lock(&osc_mutex); + pthread_mutex_lock(&Osc_mutex); freq0 += 10.0; - osc_set_freq(((Osc **)(osc_vec->data))[0], freq0); - pthread_mutex_unlock(&osc_mutex); + Osc_set_freq(((Osc **)(Osc_vec->data))[0], freq0); + pthread_mutex_unlock(&Osc_mutex); } if (IsKeyPressed(KEY_DOWN)) { - pthread_mutex_lock(&osc_mutex); + pthread_mutex_lock(&Osc_mutex); freq0 -= 10.0; if (freq0 < 1.0) freq0 = 1.0; - osc_set_freq(((Osc **)(osc_vec->data))[0], freq0); - pthread_mutex_unlock(&osc_mutex); + Osc_set_freq(((Osc **)(Osc_vec->data))[0], freq0); + pthread_mutex_unlock(&Osc_mutex); } // Adjust oscillator 1 with RIGHT/LEFT keys. if (IsKeyPressed(KEY_RIGHT)) { - pthread_mutex_lock(&osc_mutex); + pthread_mutex_lock(&Osc_mutex); freq1 += 10.0; - osc_set_freq(((Osc **)(osc_vec->data))[1], freq1); - pthread_mutex_unlock(&osc_mutex); + Osc_set_freq(((Osc **)(Osc_vec->data))[1], freq1); + pthread_mutex_unlock(&Osc_mutex); } if (IsKeyPressed(KEY_LEFT)) { - pthread_mutex_lock(&osc_mutex); + pthread_mutex_lock(&Osc_mutex); freq1 -= 10.0; if (freq1 < 1.0) freq1 = 1.0; - osc_set_freq(((Osc **)(osc_vec->data))[1], freq1); - pthread_mutex_unlock(&osc_mutex); + Osc_set_freq(((Osc **)(Osc_vec->data))[1], freq1); + pthread_mutex_unlock(&Osc_mutex); } // Adjust oscillator 2 with W/S keys. if (IsKeyPressed(KEY_W)) { - pthread_mutex_lock(&osc_mutex); + pthread_mutex_lock(&Osc_mutex); freq2 += 10.0; - osc_set_freq(((Osc **)(osc_vec->data))[2], freq2); - pthread_mutex_unlock(&osc_mutex); + Osc_set_freq(((Osc **)(Osc_vec->data))[2], freq2); + pthread_mutex_unlock(&Osc_mutex); } if (IsKeyPressed(KEY_S)) { - pthread_mutex_lock(&osc_mutex); + pthread_mutex_lock(&Osc_mutex); freq2 -= 10.0; if (freq2 < 1.0) freq2 = 1.0; - osc_set_freq(((Osc **)(osc_vec->data))[2], freq2); - pthread_mutex_unlock(&osc_mutex); + Osc_set_freq(((Osc **)(Osc_vec->data))[2], freq2); + pthread_mutex_unlock(&Osc_mutex); } EndDrawing(); @@ -232,7 +232,7 @@ int main(int argc, char **argv) { soundio_outstream_destroy(outstream); soundio_device_unref(device); soundio_destroy(soundio); - vec_destroy(osc_vec); + Vec_destroy(Osc_vec); return 0; } diff --git a/src/osc.c b/src/osc.c index ea775ad..b09628e 100644 --- a/src/osc.c +++ b/src/osc.c @@ -3,39 +3,39 @@ #include #include -Osc *osc_create(Waveform type, size_t length, double freq) { +Osc *Osc_create(Waveform type, size_t length, double freq) { Osc *osc = malloc(sizeof(Osc)); osc->phase = 0.0; osc->phase_inc = (TABLE_SIZE * freq) / SAMPLE_RATE; - osc->wt = wavetable_create(type, length); + osc->wt = Wavetable_create(type, length); return osc; } -void osc_set_freq(Osc *osc, double freq) { +void Osc_set_freq(Osc *osc, double freq) { assert(freq > 0); assert(freq < SAMPLE_RATE / 2.0); // nyquist osc->phase_inc = (TABLE_SIZE * freq) / SAMPLE_RATE; } -void osc_destroy(Osc *osc) { +void Osc_destroy(Osc *osc) { assert(osc); - wavetable_destroy(osc->wt); + Wavetable_destroy(osc->wt); free(osc); } -OscVec *oscvec_create(void) { +OscVec *OscVec_create(void) { OscVec *ov = malloc(sizeof(OscVec)); - ov->vec = vec_create(sizeof(Osc *), (ElemDestroyFunc)osc_destroy); + ov->vec = Vec_create(sizeof(Osc *), (ElemDestroyFunc)Osc_destroy); return ov; } -void oscvec_push(OscVec *ov, Osc *osc) { vec_push_back(ov->vec, &osc); } +void OscVec_push(OscVec *ov, Osc *osc) { Vec_push_back(ov->vec, &osc); } -Osc *oscvec_get(const OscVec *ov, size_t index) { return ((Osc **)(ov->vec->data))[index]; } +Osc *OscVec_get(const OscVec *ov, size_t index) { return ((Osc **)(ov->vec->data))[index]; } -size_t oscvec_size(const OscVec *ov) { return ov->vec->size; } +size_t OscVec_size(const OscVec *ov) { return ov->vec->size; } -void oscvec_destroy(OscVec *ov) { - vec_destroy(ov->vec); +void OscVec_destroy(OscVec *ov) { + Vec_destroy(ov->vec); free(ov); } diff --git a/src/vec.c b/src/vec.c index ca78868..2ebd43d 100644 --- a/src/vec.c +++ b/src/vec.c @@ -5,7 +5,7 @@ #include #include -Vec *vec_create(size_t element_size, ElemDestroyFunc destroy_func) { +Vec *Vec_create(size_t element_size, ElemDestroyFunc destroy_func) { assert(element_size > 0); Vec *vec = malloc(sizeof(Vec)); @@ -26,7 +26,7 @@ Vec *vec_create(size_t element_size, ElemDestroyFunc destroy_func) { return vec; } -void vec_destroy(Vec *vec) { +void Vec_destroy(Vec *vec) { assert(vec); if (vec->destroy_func) { @@ -39,7 +39,7 @@ void vec_destroy(Vec *vec) { free(vec); } -void vec_push_back(Vec *vec, const void *element) { +void Vec_push_back(Vec *vec, const void *element) { assert(vec); assert(element); @@ -57,14 +57,14 @@ void vec_push_back(Vec *vec, const void *element) { vec->size++; } -void vec_get(const Vec *vec, size_t index, void *out_element) { +void Vec_get(const Vec *vec, size_t index, void *out_element) { cr_assert(vec); cr_assert(index < vec->size); memcpy(out_element, (char *)vec->data + index * vec->element_size, vec->element_size); } -void vec_set(Vec *vec, size_t index, const void *element) { +void Vec_set(Vec *vec, size_t index, const void *element) { assert(vec); assert(element); assert(index < vec->size); @@ -72,7 +72,7 @@ void vec_set(Vec *vec, size_t index, const void *element) { memcpy((char *)vec->data + index * vec->element_size, element, vec->element_size); } -void vec_pop_back(Vec *vec) { +void Vec_pop_back(Vec *vec) { assert(vec); assert(vec->size > 0); diff --git a/src/wavetable.c b/src/wavetable.c index f9e83f6..bcab9ae 100644 --- a/src/wavetable.c +++ b/src/wavetable.c @@ -6,7 +6,7 @@ #include #include -Wavetable *wavetable_create(Waveform type, size_t length) { +Wavetable *Wavetable_create(Waveform type, size_t length) { cr_assert(length > 0); Wavetable *wt = malloc(sizeof(Wavetable)); @@ -50,7 +50,7 @@ Wavetable *wavetable_create(Waveform type, size_t length) { return wt; } -void wavetable_destroy(Wavetable *wt) { +void Wavetable_destroy(Wavetable *wt) { cr_assert(wt); free(wt->data); free(wt); @@ -58,11 +58,11 @@ void wavetable_destroy(Wavetable *wt) { WtVec *WtVec_create(void) { WtVec *ov = malloc(sizeof(WtVec)); - ov->vec = vec_create(sizeof(Wavetable *), (ElemDestroyFunc)wavetable_destroy); + ov->vec = Vec_create(sizeof(Wavetable *), (ElemDestroyFunc)Wavetable_destroy); return ov; } -void WtVec_push(WtVec *ov, Wavetable *osc) { vec_push_back(ov->vec, &osc); } +void WtVec_push(WtVec *ov, Wavetable *osc) { Vec_push_back(ov->vec, &osc); } Wavetable *WtVec_get(const WtVec *ov, size_t index) { return ((Wavetable **)(ov->vec->data))[index]; @@ -71,6 +71,6 @@ Wavetable *WtVec_get(const WtVec *ov, size_t index) { size_t WtVec_size(const WtVec *ov) { return ov->vec->size; } void WtVec_destroy(WtVec *ov) { - vec_destroy(ov->vec); + Vec_destroy(ov->vec); free(ov); } diff --git a/tests/test_osc.c b/tests/test_osc.c index 2b2df34..be10d7d 100644 --- a/tests/test_osc.c +++ b/tests/test_osc.c @@ -6,8 +6,8 @@ Test(oscillator, create_and_frequency) { double freq = 440.0; size_t wt_length = 1024; - Osc *osc = osc_create(WAVEFORM_SINE, wt_length, freq); - cr_assert_not_null(osc, "osc_create returned NULL"); + Osc *osc = Osc_create(WAVEFORM_SINE, wt_length, freq); + cr_assert_not_null(osc, "Osc_create returned NULL"); cr_assert_float_eq(osc->phase, 0.0, 0.0001, "Initial phase should be 0"); double expected_phase_inc = (TABLE_SIZE * freq) / SAMPLE_RATE; @@ -18,9 +18,9 @@ Test(oscillator, create_and_frequency) { cr_assert_eq(osc->wt->length, wt_length, "Wavetable length incorrect"); /* Update oscillator frequency */ - osc_set_freq(osc, 880.0); + Osc_set_freq(osc, 880.0); double new_expected_phase_inc = (TABLE_SIZE * 880.0) / SAMPLE_RATE; cr_assert_float_eq(osc->phase_inc, new_expected_phase_inc, 0.0001, "Phase increment after frequency update incorrect"); - osc_destroy(osc); + Osc_destroy(osc); } diff --git a/tests/test_osvec.c b/tests/test_osvec.c index 4b33d42..6e55714 100644 --- a/tests/test_osvec.c +++ b/tests/test_osvec.c @@ -2,28 +2,28 @@ #include "config.h" #include "osc.h" -Test(oscvec, create_push_get_destroy) { +Test(OscVec, create_push_get_destroy) { // Create a new OscVec. - OscVec *ov = oscvec_create(); - cr_assert_not_null(ov, "oscvec_create returned NULL"); - cr_assert_eq(oscvec_size(ov), 0, "Initial oscvec size should be 0"); + OscVec *ov = OscVec_create(); + cr_assert_not_null(ov, "OscVec_create returned NULL"); + cr_assert_eq(OscVec_size(ov), 0, "Initial OscVec 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"); + 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 OscVec. - oscvec_push(ov, osc1); - cr_assert_eq(oscvec_size(ov), 1, "After pushing osc1, size should be 1"); + OscVec_push(ov, osc1); + cr_assert_eq(OscVec_size(ov), 1, "After pushing osc1, size should be 1"); - oscvec_push(ov, osc2); - cr_assert_eq(oscvec_size(ov), 2, "After pushing osc2, size should be 2"); + OscVec_push(ov, osc2); + cr_assert_eq(OscVec_size(ov), 2, "After pushing osc2, size should be 2"); // Retrieve the stored oscillators. - Osc *retrieved1 = oscvec_get(ov, 0); - Osc *retrieved2 = oscvec_get(ov, 1); + Osc *retrieved1 = OscVec_get(ov, 0); + Osc *retrieved2 = OscVec_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"); @@ -41,5 +41,5 @@ Test(oscvec, create_push_get_destroy) { "Phase increment for osc1 is incorrect"); // Destroy the OscVec (this will clean up both oscillators). - oscvec_destroy(ov); + OscVec_destroy(ov); } diff --git a/tests/test_vec.c b/tests/test_vec.c index cd24765..7a8ee1a 100644 --- a/tests/test_vec.c +++ b/tests/test_vec.c @@ -3,39 +3,39 @@ #include "osc.h" Test(vec, int) { - Vec *vec = vec_create(sizeof(int), NULL); - cr_assert_not_null(vec, "vec_create returned NULl"); + Vec *vec = Vec_create(sizeof(int), NULL); + cr_assert_not_null(vec, "Vec_create returned NULl"); cr_assert_eq(vec->size, 0, "initial vec size should be 0"); const int numInts = 10; for (int i = 0; i < numInts; i++) { - vec_push_back(vec, &i); + Vec_push_back(vec, &i); 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. for (size_t i = 0; i < vec->size; i++) { int value = 0; - vec_get(vec, i, &value); + Vec_get(vec, i, &value); cr_assert_eq(value, (int)i, "Expected element at index %zu to be %d", i, (int)i); } - vec_destroy(vec); + Vec_destroy(vec); } 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"); + // 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); + 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); } @@ -43,10 +43,10 @@ Test(vec, osc) { // Verify that 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); + 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); + Vec_destroy(vec); } diff --git a/tests/test_wavetable.c b/tests/test_wavetable.c index 173645b..83df51d 100644 --- a/tests/test_wavetable.c +++ b/tests/test_wavetable.c @@ -4,47 +4,47 @@ Test(wavetable, sine_generation) { size_t length = 100; - Wavetable *wt = wavetable_create(WAVEFORM_SINE, length); - cr_assert_not_null(wt, "wavetable_create returned NULL for sine"); + Wavetable *wt = Wavetable_create(WAVEFORM_SINE, length); + cr_assert_not_null(wt, "Wavetable_create returned NULL for sine"); cr_assert_eq(wt->length, length, "Expected wavetable length %zu, got %zu", length, wt->length); for (size_t i = 0; i < length; i++) { float expected = (float)sin(2.0 * M_PI * i / length); cr_assert_float_eq(wt->data[i], expected, 0.0001, "Sine sample at index %zu incorrect", i); } - wavetable_destroy(wt); + Wavetable_destroy(wt); } Test(wavetable, square_generation) { size_t length = 10; - Wavetable *wt = wavetable_create(WAVEFORM_SQUARE, length); - cr_assert_not_null(wt, "wavetable_create returned NULL for square"); + Wavetable *wt = Wavetable_create(WAVEFORM_SQUARE, length); + cr_assert_not_null(wt, "Wavetable_create returned NULL for square"); cr_assert_eq(wt->length, length, "Expected wavetable length %zu", length); for (size_t i = 0; i < length; i++) { float expected = (i < length / 2) ? 1.0f : -1.0f; cr_assert_float_eq(wt->data[i], expected, 0.0001, "Square sample at index %zu incorrect", i); } - wavetable_destroy(wt); + Wavetable_destroy(wt); } Test(wavetable, saw_generation) { size_t length = 10; - Wavetable *wt = wavetable_create(WAVEFORM_SAW, length); - cr_assert_not_null(wt, "wavetable_create returned NULL for saw"); + Wavetable *wt = Wavetable_create(WAVEFORM_SAW, length); + cr_assert_not_null(wt, "Wavetable_create returned NULL for saw"); cr_assert_eq(wt->length, length, "Expected wavetable length %zu", length); for (size_t i = 0; i < length; i++) { float expected = 2.0f * i / length - 1.0f; cr_assert_float_eq(wt->data[i], expected, 0.0001, "Saw sample at index %zu incorrect", i); } - wavetable_destroy(wt); + Wavetable_destroy(wt); } Test(wavetable, triangle_generation) { size_t length = 10; - Wavetable *wt = wavetable_create(WAVEFORM_TRIANGLE, length); - cr_assert_not_null(wt, "wavetable_create returned NULL for triangle"); + Wavetable *wt = Wavetable_create(WAVEFORM_TRIANGLE, length); + cr_assert_not_null(wt, "Wavetable_create returned NULL for triangle"); cr_assert_eq(wt->length, length, "Expected wavetable length %zu", length); for (size_t i = 0; i < length; i++) { @@ -56,22 +56,22 @@ Test(wavetable, triangle_generation) { } cr_assert_float_eq(wt->data[i], expected, 0.0001, "Triangle sample at index %zu incorrect", i); } - wavetable_destroy(wt); + Wavetable_destroy(wt); } // Test(wavetable, custom_waveform) { // size_t length = 5; -// Wavetable *wt = wavetable_create(WAVEFORM_SINE, length); -// /* Assume wavetable_set_custom replaces the data and sets type to WAVEFORM_CUSTOM */ +// Wavetable *wt = Wavetable_create(WAVEFORM_SINE, length); +// /* Assume Wavetable_set_custom replaces the data and sets type to WAVEFORM_CUSTOM */ // float custom_data[5] = { 0.0f, 0.25f, 0.5f, 0.75f, 1.0f }; -// wavetable_set_custom(wt, custom_data, length); +// Wavetable_set_custom(wt, custom_data, length); // for (size_t i = 0; i < length; i++) { // cr_assert_float_eq(wt->data[i], custom_data[i], 0.0001, "Custom sample at index %zu incorrect", i); // } // cr_assert_eq(wt->type, WAVEFORM_CUSTOM, "Expected wavetable type WAVEFORM_CUSTOM"); // -// wavetable_destroy(wt); +// Wavetable_destroy(wt); // } Test(wtvec, push_get_and_destroy) { @@ -80,14 +80,14 @@ Test(wtvec, push_get_and_destroy) { cr_assert_eq(WtVec_size(wv), 0, "Initial WtVec size should be 0"); size_t length1 = 100; - Wavetable *wt1 = wavetable_create(WAVEFORM_SINE, length1); - cr_assert_not_null(wt1, "wavetable_create returned NULL for sine"); + Wavetable *wt1 = Wavetable_create(WAVEFORM_SINE, length1); + cr_assert_not_null(wt1, "Wavetable_create returned NULL for sine"); WtVec_push(wv, wt1); cr_assert_eq(WtVec_size(wv), 1, "After pushing sine wavetable, size should be 1"); size_t length2 = 50; - Wavetable *wt2 = wavetable_create(WAVEFORM_SAW, length2); - cr_assert_not_null(wt2, "wavetable_create returned NULL for saw"); + Wavetable *wt2 = Wavetable_create(WAVEFORM_SAW, length2); + cr_assert_not_null(wt2, "Wavetable_create returned NULL for saw"); WtVec_push(wv, wt2); cr_assert_eq(WtVec_size(wv), 2, "After pushing saw wavetable, size should be 2");