typedef & PascalCase for ALL structs and enums
This commit is contained in:
@ -24,9 +24,9 @@ static const char *audio_exts[audio_file_type_count] = {
|
||||
/* TODO: count frames without use, free the memory when threshold is met */
|
||||
/* TODO: count repeated usages for sound effect cases with rendering to ram? */
|
||||
/* stores path to data hash, useful for sound effects */
|
||||
static struct audio_file_cache {
|
||||
static struct AudioFileCache {
|
||||
char *key;
|
||||
struct audio_file_cache_value {
|
||||
struct AudioFileCacheValue {
|
||||
unsigned char *data;
|
||||
size_t len;
|
||||
} value;
|
||||
@ -34,7 +34,7 @@ static struct audio_file_cache {
|
||||
|
||||
|
||||
static int64_t get_audio_data(const char *path, unsigned char **data) {
|
||||
const struct audio_file_cache *cache = shgetp_null(audio_file_cache, path);
|
||||
const struct AudioFileCache *cache = shgetp_null(audio_file_cache, path);
|
||||
if (!cache) {
|
||||
unsigned char *file;
|
||||
int64_t len = file_to_bytes(path, &file);
|
||||
@ -43,7 +43,7 @@ static int64_t get_audio_data(const char *path, unsigned char **data) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const struct audio_file_cache_value value = { file, (size_t)len };
|
||||
const struct AudioFileCacheValue value = { file, (size_t)len };
|
||||
shput(audio_file_cache, path, value);
|
||||
|
||||
*data = file;
|
||||
@ -55,16 +55,16 @@ static int64_t get_audio_data(const char *path, unsigned char **data) {
|
||||
}
|
||||
|
||||
|
||||
void play_audio(const char *path, const char *channel) {
|
||||
const struct audio_channel_item *pair = shgetp_null(ctx.audio_channels, channel);
|
||||
void audio_play(const char *path, const char *channel) {
|
||||
const AudioChannelItem *pair = shgetp_null(ctx.audio_channels, channel);
|
||||
if (!pair)
|
||||
play_audio_ex(path, channel, get_default_audio_args());
|
||||
audio_play_ex(path, channel, audio_get_default_args());
|
||||
else
|
||||
play_audio_ex(path, channel, pair->value.args);
|
||||
audio_play_ex(path, channel, pair->value.args);
|
||||
}
|
||||
|
||||
|
||||
static t_audio_file_type infer_audio_file_type(const char *path) {
|
||||
static AudioFileType infer_audio_file_type(const char *path) {
|
||||
size_t path_len = strlen(path);
|
||||
|
||||
for (int i = 0; i < audio_file_type_count; ++i) {
|
||||
@ -73,7 +73,7 @@ static t_audio_file_type infer_audio_file_type(const char *path) {
|
||||
continue;
|
||||
|
||||
if (strcmp(&path[path_len - ext_length], audio_exts[i]) == 0)
|
||||
return (t_audio_file_type)i;
|
||||
return (AudioFileType)i;
|
||||
}
|
||||
|
||||
return audio_file_type_unknown;
|
||||
@ -82,7 +82,7 @@ static t_audio_file_type infer_audio_file_type(const char *path) {
|
||||
|
||||
/* TODO: error propagation and clearing of resources on partial success? */
|
||||
/* or should we expect things to simply fail? */
|
||||
static union audio_context init_audio_context(const char *path, t_audio_file_type type) {
|
||||
static union AudioContext init_audio_context(const char *path, AudioFileType type) {
|
||||
switch (type) {
|
||||
case audio_file_type_ogg: {
|
||||
unsigned char *data;
|
||||
@ -101,7 +101,7 @@ static union audio_context init_audio_context(const char *path, t_audio_file_typ
|
||||
|
||||
stb_vorbis_info info = stb_vorbis_get_info(handle);
|
||||
|
||||
return (union audio_context) {
|
||||
return (union AudioContext) {
|
||||
.vorbis = {
|
||||
.data = data,
|
||||
.handle = handle,
|
||||
@ -131,21 +131,21 @@ static union audio_context init_audio_context(const char *path, t_audio_file_typ
|
||||
|
||||
xm_set_max_loop_count(handle, 1);
|
||||
|
||||
return (union audio_context) {
|
||||
return (union AudioContext) {
|
||||
.xm = { .handle = handle }
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
CRY("Audio error", "Unhandled audio format (in init)");
|
||||
return (union audio_context){0};
|
||||
return (union AudioContext){0};
|
||||
}
|
||||
|
||||
return (union audio_context){0};
|
||||
return (union AudioContext){0};
|
||||
}
|
||||
|
||||
|
||||
static void repeat_audio(struct audio_channel *channel) {
|
||||
static void repeat_audio(AudioChannel *channel) {
|
||||
switch (channel->file_type) {
|
||||
case audio_file_type_ogg: {
|
||||
stb_vorbis_seek_start(channel->context.vorbis.handle);
|
||||
@ -164,13 +164,13 @@ static void repeat_audio(struct audio_channel *channel) {
|
||||
}
|
||||
|
||||
|
||||
void play_audio_ex(const char *path, const char *channel, t_play_audio_args args) {
|
||||
struct audio_channel_item *pair = shgetp_null(ctx.audio_channels, channel);
|
||||
void audio_play_ex(const char *path, const char *channel, PlayAudioArgs args) {
|
||||
AudioChannelItem *pair = shgetp_null(ctx.audio_channels, channel);
|
||||
|
||||
/* create a channel if it doesn't exist */
|
||||
if (!pair) {
|
||||
t_audio_file_type file_type = infer_audio_file_type(path);
|
||||
struct audio_channel new_channel = {
|
||||
AudioFileType file_type = infer_audio_file_type(path);
|
||||
AudioChannel new_channel = {
|
||||
.args = args,
|
||||
.file_type = file_type,
|
||||
.context = init_audio_context(path, file_type),
|
||||
@ -189,8 +189,8 @@ void play_audio_ex(const char *path, const char *channel, t_play_audio_args args
|
||||
}
|
||||
|
||||
|
||||
t_play_audio_args *get_audio_args(const char *channel) {
|
||||
struct audio_channel_item *pair = shgetp_null(ctx.audio_channels, channel);
|
||||
PlayAudioArgs *audio_get_args(const char *channel) {
|
||||
AudioChannelItem *pair = shgetp_null(ctx.audio_channels, channel);
|
||||
if (!pair)
|
||||
return NULL;
|
||||
|
||||
@ -198,8 +198,8 @@ t_play_audio_args *get_audio_args(const char *channel) {
|
||||
}
|
||||
|
||||
|
||||
t_play_audio_args get_default_audio_args(void) {
|
||||
return (t_play_audio_args){
|
||||
PlayAudioArgs audio_get_default_args(void) {
|
||||
return (PlayAudioArgs){
|
||||
.repeat = false,
|
||||
.crossfade = false,
|
||||
.volume = 1.0f,
|
||||
@ -209,7 +209,7 @@ t_play_audio_args get_default_audio_args(void) {
|
||||
|
||||
|
||||
/* this assumes int16_t based streams */
|
||||
static void audio_mixin_streams(const struct audio_channel *channel,
|
||||
static void audio_mixin_streams(const AudioChannel *channel,
|
||||
uint8_t *restrict a,
|
||||
uint8_t *restrict b,
|
||||
size_t frames)
|
||||
@ -236,7 +236,7 @@ static void audio_mixin_streams(const struct audio_channel *channel,
|
||||
|
||||
|
||||
/* remember: sample is data for all channels where frame is a part of it */
|
||||
static void audio_sample_and_mixin_channel(const struct audio_channel *channel,
|
||||
static void audio_sample_and_mixin_channel(const AudioChannel *channel,
|
||||
uint8_t *stream,
|
||||
int len)
|
||||
{
|
||||
@ -323,7 +323,7 @@ static void audio_sample_and_mixin_channel(const struct audio_channel *channel,
|
||||
}
|
||||
|
||||
|
||||
static void sanity_check_channel(const struct audio_channel *channel) {
|
||||
static void sanity_check_channel(const AudioChannel *channel) {
|
||||
if (channel->args.volume < 0.0f || channel->args.volume > 1.0f)
|
||||
log_warn("Volume argument is out of range for channel (%s)", channel->name);
|
||||
|
||||
|
Reference in New Issue
Block a user