diff options
author | XANTRONIX Development | 2022-02-27 21:29:32 -0500 |
---|---|---|
committer | XANTRONIX Development | 2022-02-27 21:29:32 -0500 |
commit | 718527b8f93ca893f996fdd1bf46063d1b5d3ecb (patch) | |
tree | d2de760106dc17bf5b54b3e0533018d0b23df562 /include/xas | |
parent | 1cc112d8ef190185c6c08989b97e534a1c3b63f4 (diff) | |
download | xas-718527b8f93ca893f996fdd1bf46063d1b5d3ecb.tar.gz xas-718527b8f93ca893f996fdd1bf46063d1b5d3ecb.tar.bz2 xas-718527b8f93ca893f996fdd1bf46063d1b5d3ecb.zip |
Refactor src/synth.c
Changes:
* Implement xas_synth type to consolidate synthesiser
implementation and different tone generator types
* Refactor examples/ code to remove duplicate synthesiser code
Diffstat (limited to 'include/xas')
-rw-r--r-- | include/xas/synth.h | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/include/xas/synth.h b/include/xas/synth.h index 20446cd..53f3343 100644 --- a/include/xas/synth.h +++ b/include/xas/synth.h @@ -6,23 +6,49 @@ #include <xas/audio.h> -typedef struct _xas_synth xas_synth; +#define XAS_SYNTH_DEFAULT_FREQUENCY 2600 /* Hz */ -typedef int16_t (*xas_synth_callback_sample)(xas_synth *synth, void *ctx); +enum xas_synth_type { + XAS_SYNTH_SINE, + XAS_SYNTH_SQUARE, + XAS_SYNTH_TRIANGLE, + XAS_SYNTH_SAWTOOTH +}; -typedef void (*xas_synth_callback_cleanup)(xas_synth *synth, void *ctx); +enum xas_synth_state { + XAS_SYNTH_IDLE, + XAS_SYNTH_ACTIVE +}; + +typedef struct _xas_synth xas_synth; + +typedef int16_t (*xas_synth_sample_callback)(xas_synth *synth); struct _xas_synth { + enum xas_synth_type type; + enum xas_synth_state state; + xas_audio_format format; - xas_synth_callback_sample sample; - xas_synth_callback_cleanup cleanup; - void *ctx; + size_t buffer_size; + + xas_synth_sample_callback sample; + + float phase; + size_t frequency; }; -xas_audio_stream *xas_synth_new(xas_synth_callback_sample sample, - xas_synth_callback_cleanup cleanup, - xas_audio_format format, - size_t buffer_size, - void *ctx); +xas_synth *xas_synth_new(xas_audio_format format, + size_t buffer_size, + enum xas_synth_type type); + +void xas_synth_destroy(xas_synth *synth); + +void xas_synth_set_frequency(xas_synth *synth, size_t frequency); + +void xas_synth_start(xas_synth *synth); + +void xas_synth_stop(xas_synth *synth); + +xas_audio_stream *xas_synth_new_stream(xas_synth *synth); #endif /* _XAS_SYNTH_H */ |