diff options
author | XANTRONIX Development | 2022-03-08 19:51:59 -0500 |
---|---|---|
committer | XANTRONIX Development | 2022-03-08 19:51:59 -0500 |
commit | d46847852d1446f4b64a0fd424cdea5fa1c0dbd4 (patch) | |
tree | e17acc9e2efe6e631108bdf2798bb5eec58ed071 /src | |
parent | aaff62e728a269893ef378534f6aca71643fe4cc (diff) | |
download | xas-d46847852d1446f4b64a0fd424cdea5fa1c0dbd4.tar.gz xas-d46847852d1446f4b64a0fd424cdea5fa1c0dbd4.tar.bz2 xas-d46847852d1446f4b64a0fd424cdea5fa1c0dbd4.zip |
Implement setting square wave duty cycle
Diffstat (limited to 'src')
-rw-r--r-- | src/synth.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/synth.c b/src/synth.c index b01ebc8..0be572d 100644 --- a/src/synth.c +++ b/src/synth.c @@ -27,8 +27,10 @@ static int16_t sample_square(xas_synth *synth) { int16_t ret; static float tau = 2.0f * M_PI; + float duty = synth->duty; + if (synth->state == XAS_SYNTH_ACTIVE) { - ret = (synth->phase - M_PI) > 0.0? + ret = ((duty * synth->phase) - M_PI) > 0.0? (int16_t)roundf(synth->gain * (INT16_MAX / 4)): (int16_t)roundf(synth->gain * (INT16_MIN / 4)); @@ -156,6 +158,7 @@ xas_synth *xas_synth_new(xas_audio_format format, synth->state = XAS_SYNTH_IDLE; synth->phase = 0.0f; synth->gain = XAS_SYNTH_DEFAULT_GAIN; + synth->duty = XAS_SYNTH_DEFAULT_DUTY; synth->frequency = XAS_SYNTH_DEFAULT_FREQUENCY; synth->format.channels = XAS_AUDIO_MONO; @@ -184,6 +187,10 @@ void xas_synth_set_gain(xas_synth *synth, float gain) { synth->gain = gain; } +void xas_synth_set_duty(xas_synth *synth, float duty) { + synth->duty = duty; +} + void xas_synth_set_type(xas_synth *synth, enum xas_synth_type type) { set_type(synth, type); } |