diff options
author | XANTRONIX Development | 2022-03-15 18:35:39 -0400 |
---|---|---|
committer | XANTRONIX Development | 2022-03-15 18:35:39 -0400 |
commit | 7f4b113f8dd3b42016a4c9b9efa3ea3b2ea3fce9 (patch) | |
tree | c9eb81354a6dfe02031417efbb3b26b0aa8b2625 /src | |
parent | 1bbe0659cfc4f1ea17e2c05869578959cc11fdfc (diff) | |
download | xas-7f4b113f8dd3b42016a4c9b9efa3ea3b2ea3fce9.tar.gz xas-7f4b113f8dd3b42016a4c9b9efa3ea3b2ea3fce9.tar.bz2 xas-7f4b113f8dd3b42016a4c9b9efa3ea3b2ea3fce9.zip |
Impleemnt xas_mixer_object_add()
Impleemnt xas_mixer_object_add() as a convenience method to create an
audio stream from an object given; ensure audio streams instantiated in
this manner are destroyed upon mixer destruction
Diffstat (limited to 'src')
-rw-r--r-- | src/mixer.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/mixer.c b/src/mixer.c index 8fe53cb..a60118d 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -176,6 +176,10 @@ void xas_mixer_destroy(xas_mixer *mixer) { while (input) { xas_mixer_input *next = input->next; + if (input->flags & XAS_MIXER_INPUT_STREAM_MANAGED) { + xas_audio_stream_destroy(input->stream); + } + free(input); input = next; @@ -231,6 +235,7 @@ xas_mixer_input *xas_mixer_input_add(xas_mixer *mixer, input->stream = stream; input->gain = gain; + input->flags = 0; input->next = NULL; input_set_pan(input, pan); @@ -250,6 +255,32 @@ error_invalid_stream: return NULL; } +xas_mixer_input *xas_mixer_object_add(xas_mixer *mixer, + xas_object *object, + float gain, + float pan) { + xas_mixer_input *input; + xas_audio_stream *stream; + + if ((stream = xas_object_stream_new(object)) == NULL) { + goto error_object_stream_new; + } + + if ((input = xas_mixer_input_add(mixer, stream, gain, pan)) == NULL) { + goto error_input_add; + } + + input->flags |= XAS_MIXER_INPUT_STREAM_MANAGED; + + return input; + +error_input_add: + xas_audio_stream_destroy(stream); + +error_object_stream_new: + return NULL; +} + void xas_mixer_input_set_gain(xas_mixer_input *input, float gain) { if (gain < 0.0 || gain > 1.0) { return; |