Skip to content

Commit

Permalink
lichen-community-systemsgh-52: Updates examples, tests, and wasm bind…
Browse files Browse the repository at this point in the history
…ings to Oscillator API.
  • Loading branch information
colinbdclark committed Sep 13, 2022
1 parent 3f28d46 commit 8f21ae5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion libsignaletic/examples/console/src/print-sine.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) {
&settings, 0.0f)
};

struct sig_dsp_Sine* sine = sig_dsp_Sine_new(&allocator,
struct sig_dsp_Oscillator* sine = sig_dsp_Sine_new(&allocator,
&settings, &inputs);

puts("Sine wave (three blocks): ");
Expand Down
22 changes: 11 additions & 11 deletions libsignaletic/tests/test-libsignaletic.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ void test_sig_dsp_Sine(void) {

struct sig_dsp_Oscillator_Inputs* inputs = createSineInputs(
&allocator, &audioSettings, 440.0f, 0.0f, 1.0f, 0.0f);
struct sig_dsp_Sine* sine = sig_dsp_Sine_new(&allocator,
struct sig_dsp_Oscillator* sine = sig_dsp_Sine_new(&allocator,
&audioSettings, inputs);

sig_dsp_Sine_generate(sine);
sine->signal.generate(sine);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(
expected,
sine->signal.output,
Expand All @@ -469,10 +469,10 @@ void test_test_sig_dsp_Sine_isOffset(void) {

struct sig_dsp_Oscillator_Inputs* inputs = createSineInputs(
&allocator, &audioSettings, 440.0f, 0.0f, 1.0f, 1.0f);
struct sig_dsp_Sine* sine = sig_dsp_Sine_new(&allocator,
struct sig_dsp_Oscillator* sine = sig_dsp_Sine_new(&allocator,
&audioSettings, inputs);

sig_dsp_Sine_generate(sine);
sine->signal.generate(sine);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(
expected,
sine->signal.output,
Expand All @@ -485,21 +485,21 @@ void test_test_sig_dsp_Sine_isOffset(void) {
void test_sig_dsp_Sine_accumulatesPhase(void) {
struct sig_dsp_Oscillator_Inputs* inputs = createSineInputs(
&allocator, audioSettings, 440.0f, 0.0f, 1.0f, 0.0f);
struct sig_dsp_Sine* sine = sig_dsp_Sine_new(&allocator,
struct sig_dsp_Oscillator* sine = sig_dsp_Sine_new(&allocator,
audioSettings, inputs);

// 440 Hz frequency at 48 KHz sample rate.
float phaseStep = 0.05759586393833160400390625f;

sig_dsp_Sine_generate(sine);
sine->signal.generate(sine);
TEST_ASSERT_FLOAT_WITHIN_MESSAGE(
0.000001,
phaseStep * 48.0,
sine->phaseAccumulator,
"The phase accumulator should have been incremented for each sample in the block."
);

sig_dsp_Sine_generate(sine);
sine->signal.generate(sine);
TEST_ASSERT_FLOAT_WITHIN_MESSAGE(
0.000001,
phaseStep * 96.0,
Expand All @@ -514,12 +514,12 @@ void test_sig_dsp_Sine_accumulatesPhase(void) {
void test_sig_dsp_Sine_phaseWrapsAt2PI(void) {
struct sig_dsp_Oscillator_Inputs* inputs = createSineInputs(
&allocator, audioSettings, 440.0f, 0.0f, 1.0f, 0.0f);
struct sig_dsp_Sine* sine = sig_dsp_Sine_new(&allocator,
struct sig_dsp_Oscillator* sine = sig_dsp_Sine_new(&allocator,
audioSettings, inputs);

sig_dsp_Sine_generate(sine);
sig_dsp_Sine_generate(sine);
sig_dsp_Sine_generate(sine);
sine->signal.generate(sine);
sine->signal.generate(sine);
sine->signal.generate(sine);

TEST_ASSERT_TRUE_MESSAGE(
sine->phaseAccumulator <= sig_TWOPI &&
Expand Down
7 changes: 4 additions & 3 deletions libsignaletic/wasm/bindings/libsignaletic-web-bindings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ interface Signals {
void Sine_destroy(sig_Allocator allocator,
sig_dsp_Oscillator sine);

sig_dsp_Oscillator_Inputs Sine_Inputs_new(sig_Allocator allocator,
any freq, any phaseOffset, any mul, any add);
sig_dsp_Oscillator_Inputs Oscillator_Inputs_new(
sig_Allocator allocator, any freq, any phaseOffset, any mul,
any add);

void Sine_Inputs_destroy(sig_Allocator allocator,
void Oscillator_Inputs_destroy(sig_Allocator allocator,
sig_dsp_Oscillator_Inputs inputs);


Expand Down
2 changes: 1 addition & 1 deletion libsignaletic/wasm/bindings/src/libsignaletic-web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Signals {
return inputs;
}

void Sine_Inputs_destroy(struct sig_Allocator* allocator,
void Oscillator_Inputs_destroy(struct sig_Allocator* allocator,
struct sig_dsp_Oscillator_Inputs* self) {
allocator->impl->free(allocator, self);
}
Expand Down

0 comments on commit 8f21ae5

Please sign in to comment.