twn_audio: rework interface

This commit is contained in:
2024-10-07 15:21:44 +03:00
parent cc1e64531c
commit ae8cc5f50b
5 changed files with 96 additions and 94 deletions

View File

@ -2,37 +2,45 @@
#define TWN_AUDIO_H
#include "twn_engine_api.h"
#include "twn_option.h"
#include <stdbool.h>
/* plays audio file at specified channel or at scratch channel if NULL is passed, without ability to refer to it later */
/* path path must contain valid file extension to infer which file format it is */
/* supported formats: .ogg, .xm */
TWN_API void audio_play(const char *path,
const char *channel, /* optional */
bool repeat, /* default: false */
float volume, /* default: 1.0f, range: 0.0f to 1.0f */
float panning); /* default: 0.0f, range: -1.0 to 1.0f */
typedef enum {
AUDIO_PARAM_REPEAT,
AUDIO_PARAM_VOLUME,
AUDIO_PARAM_PANNING,
} AudioParam;
TWN_API void audio_set(const char *channel, AudioParam param, float value);
/* TODO */
// TWN_API bool audio_ended(const char *channel);
#ifndef TWN_NOT_C
typedef struct PlayAudioArgs {
/* default: false */
bool repeat;
/* crossfade between already playing audio on a given channel, if any */
/* default: false */
bool crossfade;
/* range: 0.0f to 1.0f */
/* default: 1.0f */
float volume;
/* range: -1.0 to 1.0f */
/* default: 0.0f */
float panning;
char *path;
m_option_list(
char *, channel,
bool, repeat,
float, volume,
float, panning )
} PlayAudioArgs;
/* plays audio file at specified channel or anywhere if NULL is passed */
/* path must contain valid file extension to infer which file format it is */
/* supported formats: .ogg, .xm */
/* preserves args that are already specified on the channel */
TWN_API void audio_play(const char *path, const char *channel);
TWN_API void audio_play_ex(const char *path, const char *channel, PlayAudioArgs args);
/* could be used for modifying args */
/* warn: is only valid if no other calls to audio are made */
TWN_API PlayAudioArgs *audio_get_args(const char *channel);
TWN_API PlayAudioArgs audio_get_default_args(void);
TWN_API void audio_play_args(PlayAudioArgs args);
#define m_audio(...) (audio_play_args((PlayAudioArgs){__VA_ARGS__}))
#endif
#endif