From eb572423da5a84898a4cf9810dccf8fe363dc6fc Mon Sep 17 00:00:00 2001 From: h3llll Date: Wed, 5 Nov 2025 21:51:47 +0200 Subject: [PATCH] feat(audio): add audio module and audio/audio.h Signed-off-by: Lorenzo Torres --- audio/audio.h | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 audio/audio.h diff --git a/audio/audio.h b/audio/audio.h new file mode 100644 index 0000000..5579afd --- /dev/null +++ b/audio/audio.h @@ -0,0 +1,87 @@ +#ifndef AUDIO_H +#define AUDIO_H + +#include "../core/linear.h" + +enum audio_filetype { + AUDIO_FILETYPE_WAV, + AUDIO_FILETYPE_MP3, +}; + +/* + * The context object stores data related to audio, implementation + * depends on backend. + */ +struct audio_context; + +/* + * The resource object stores the read sound data + * loaded from a file and extra options. + */ +struct audio_resource; + +/* + * The source object represents an audio producing + * object with a position, an orientation and a velocity. + * A source must have a resource or multiple + * resources attached to it to be usable. (see audio_source_attach_resource) + */ +struct audio_source; + +/* + * The listener object represents the client's camera(i.e. ears), + * also having a position, an orientation and a velocity. + */ +struct audio_listener; + +/* + * This struct contains the flags with which + * audio files will be loaded. + */ +struct audio_resource_opts { + enum audio_filetype type; +}; + +struct audio_source_play_opts { int dummy; }; + +struct audio_listener_opts { int dummy; }; + +struct audio_context *audio_context_init(void); +void audio_context_deinit(struct audio_context *context); + +/* + * Creates a resource object from 'path' using specified options + */ +struct audio_resource *audio_resource_load(const char *path, struct audio_resource_opts opts); +void audio_resource_free(struct audio_resource *resource); + +struct audio_source *audio_source_init(vec3 pos, vec3 vel, vec3 ori); +void audio_source_deinit(struct audio_source *source); +/* + * Attaches 'resource' to 'source'. + * Returns a source-specific index which is used to play the resource via 'source'. + */ +u16 audio_source_attach_resource(struct audio_source *source, struct audio_resource *resource); +/* + * Plays 'index'th audio resource via 'source' using 'opts'. + * Will use default options if 'opts' is NULL. + * defaults: + * TODO + */ +void audio_source_play(struct audio_source *source, struct audio_source_play_opts *opts, u16 index); +/* + * Attaches 'resource' to 'source' at given 'index' overwriting whatever was there first. + */ +void audio_source_attach_resource_index(struct audio_source *source, struct audio_resource *resource, u16 index); + +struct audio_listener *audio_listener_init(vec3 pos, vec3 vel, vec3 ori); +void audio_listener_deinit(struct audio_listener *listener); +/* + * Applies 'opts' to 'listener'. + * Will use defaults if 'opts' was NULL. + * defaults: + * TODO + */ +void audio_listener_apply_opts(struct audio_listener *listener, struct audio_listener_opts *opts); + +#endif