From 77976d03699f95ea28278b5fdbba392f198b5f52 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 9 Feb 2022 00:00:51 -0500 Subject: Implement xas_audio_format type Changes: * Implement xas_audio_format struct to provide sample size, channels, and sample rate * Refactor argument order for most functions to allow a reasonable reading of argument types, when replacing three separate size_t arguments with one xas_audio_format object --- include/xas/audio.h | 38 +++++++++++++++++++++++++------------- include/xas/bank.h | 13 ++++++------- include/xas/mixer.h | 5 +---- include/xas/riff.h | 4 +--- include/xas/synth.h | 11 ++++------- include/xas/vox.h | 12 ++++-------- 6 files changed, 41 insertions(+), 42 deletions(-) (limited to 'include/xas') diff --git a/include/xas/audio.h b/include/xas/audio.h index 5a92a50..b18a2d2 100644 --- a/include/xas/audio.h +++ b/include/xas/audio.h @@ -30,12 +30,16 @@ typedef ssize_t (*xas_audio_fill)(void *ctx, typedef void (*xas_audio_cleanup)(void *ctx, xas_audio_stream *stream); -struct _xas_audio_stream { - enum xas_audio_stream_type type; - +typedef struct _xas_audio_format { size_t channels, sample_size, sample_rate; +} xas_audio_format; + +struct _xas_audio_stream { + enum xas_audio_stream_type type; + + xas_audio_format format; size_t buffer_size, buffer_count; @@ -51,21 +55,29 @@ struct _xas_audio_stream { void *ctx; }; +void xas_audio_zero(xas_audio_format format, + void *dest, + size_t index, + size_t count); + +void xas_audio_copy(xas_audio_format format, + void *dest, + void *src, + size_t index_dest, + size_t index_src, + size_t count); + xas_audio_stream *xas_audio_stream_new_sink(xas_audio_drain drain, xas_audio_cleanup cleanup, - void *ctx, - size_t channels, - size_t sample_size, - size_t sample_rate, - size_t buffer_size); + xas_audio_format format, + size_t buffer_size, + void *ctx); xas_audio_stream *xas_audio_stream_new_source(xas_audio_fill fill, xas_audio_cleanup cleanup, - void *ctx, - size_t channels, - size_t sample_size, - size_t sample_rate, - size_t buffer_size); + xas_audio_format format, + size_t buffer_size, + void *ctx); void xas_audio_stream_destroy(xas_audio_stream *stream); diff --git a/include/xas/bank.h b/include/xas/bank.h index ec3cb99..9f877d0 100644 --- a/include/xas/bank.h +++ b/include/xas/bank.h @@ -13,26 +13,25 @@ typedef struct _xas_bank_entry { } xas_bank_entry; typedef struct _xas_bank { - size_t sample_size, - sample_rate, - entry_size, + xas_audio_format format; + + size_t entry_size, entry_count; int flags; - float force; + float gain; size_t entry, index; } xas_bank; -xas_bank *xas_bank_new(size_t sample_size, - size_t sample_rate, +xas_bank *xas_bank_new(xas_audio_format format, size_t entry_size, size_t entry_count); void xas_bank_destroy(xas_bank *bank); -int xas_bank_play(xas_bank *bank, size_t entry, float force); +int xas_bank_play(xas_bank *bank, size_t entry, float gain); void xas_bank_stop(xas_bank *bank); diff --git a/include/xas/mixer.h b/include/xas/mixer.h index 73fd363..3769272 100644 --- a/include/xas/mixer.h +++ b/include/xas/mixer.h @@ -25,10 +25,7 @@ typedef struct _xas_mixer { size_t buffer_size; } xas_mixer; -xas_mixer *xas_mixer_new(size_t channels, - size_t sample_size, - size_t sample_rate, - size_t buffer_size); +xas_mixer *xas_mixer_new(xas_audio_format format, size_t buffer_size); void xas_mixer_destroy(xas_mixer *mixer); diff --git a/include/xas/riff.h b/include/xas/riff.h index f78e9e9..5a5d4ed 100644 --- a/include/xas/riff.h +++ b/include/xas/riff.h @@ -50,9 +50,7 @@ typedef struct _xas_riff xas_riff; #pragma pack(pop) xas_audio_stream *xas_riff_new_file(const char *path, - size_t channels, - size_t sample_size, - size_t sample_rate, + xas_audio_format format, int flags); xas_audio_stream *xas_riff_open_file(const char *path, int flags); diff --git a/include/xas/synth.h b/include/xas/synth.h index 1d070aa..20446cd 100644 --- a/include/xas/synth.h +++ b/include/xas/synth.h @@ -13,19 +13,16 @@ typedef int16_t (*xas_synth_callback_sample)(xas_synth *synth, void *ctx); typedef void (*xas_synth_callback_cleanup)(xas_synth *synth, void *ctx); struct _xas_synth { - size_t sample_size, - sample_rate; - + xas_audio_format format; xas_synth_callback_sample sample; xas_synth_callback_cleanup cleanup; void *ctx; }; -xas_audio_stream *xas_synth_new(size_t sample_size, - size_t sample_rate, - size_t buffer_size, - xas_synth_callback_sample sample, +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); #endif /* _XAS_SYNTH_H */ diff --git a/include/xas/vox.h b/include/xas/vox.h index 85d8d20..fd442a8 100644 --- a/include/xas/vox.h +++ b/include/xas/vox.h @@ -13,11 +13,9 @@ typedef struct _xas_vox { const char *text2wave_path; - size_t sample_size, - sample_rate, - buffer_size; + xas_audio_format format; - void *ctx; + size_t buffer_size; int flags; @@ -29,10 +27,8 @@ typedef struct _xas_vox { } xas_vox; xas_vox *xas_vox_new(const char *text2wave_path, - size_t sample_size, - size_t sample_rate, - size_t buffer_size, - void *ctx); + xas_audio_format format, + size_t buffer_size); void xas_vox_destroy(xas_vox *vox); -- cgit v1.2.3