ilimination of system code, removal of x-watcher and replacement of it by dmon, fixes in audio code, dynamic asset reload
This commit is contained in:
@ -29,6 +29,7 @@ static const uint8_t audio_exts_len[AUDIO_FILE_TYPE_COUNT] = {
|
||||
};
|
||||
|
||||
/* TODO: allow for vectorization and packed vectors (alignment care and alike) */
|
||||
/* TODO: free channel name duplicates */
|
||||
|
||||
/* TODO: count frames without use, free the memory when threshold is met */
|
||||
/* TODO: count repeated usages for sound effect cases with rendering to ram? */
|
||||
@ -212,6 +213,7 @@ static void free_audio_channel(AudioChannel channel) {
|
||||
SDL_assert_always(false);
|
||||
break;
|
||||
}
|
||||
SDL_free(channel.path);
|
||||
}
|
||||
|
||||
|
||||
@ -283,32 +285,42 @@ void audio_play(const char *path,
|
||||
/* create a channel if it doesn't exist */
|
||||
if (!pair) {
|
||||
AudioFileType const file_type = infer_audio_file_type(path);
|
||||
AudioChannel new_channel = {
|
||||
AudioChannel const new_channel = {
|
||||
.file_type = file_type,
|
||||
.context = init_audio_context(path, file_type),
|
||||
.path = path,
|
||||
.name = channel,
|
||||
.path = SDL_strdup(path),
|
||||
.repeat = repeat,
|
||||
.volume = volume,
|
||||
.panning = panning,
|
||||
};
|
||||
shput(ctx.audio_channels, channel, new_channel);
|
||||
shput(ctx.audio_channels, SDL_strdup(channel), new_channel);
|
||||
pair = shgetp_null(ctx.audio_channels, channel);
|
||||
}
|
||||
|
||||
/* TODO: destroy and create new context when channel is reused for different file */
|
||||
|
||||
/* works for both restarts and new audio */
|
||||
if (strcmp(pair->value.path, path) == 0)
|
||||
/* repeat if so */
|
||||
else if (strcmp(pair->value.path, path) == 0)
|
||||
repeat_audio(&pair->value);
|
||||
else {
|
||||
/* start anew, reuse channel name */
|
||||
free_audio_channel(pair->value);
|
||||
AudioFileType const file_type = infer_audio_file_type(path);
|
||||
AudioChannel const new_channel = {
|
||||
.file_type = file_type,
|
||||
.context = init_audio_context(path, file_type),
|
||||
.path = SDL_strdup(path),
|
||||
.repeat = repeat,
|
||||
.volume = volume,
|
||||
.panning = panning,
|
||||
};
|
||||
pair->value = new_channel;
|
||||
}
|
||||
} else {
|
||||
/* audio without channel plays without repeat and ability to change parameters over its course, nor stop it */
|
||||
AudioFileType const file_type = infer_audio_file_type(path);
|
||||
AudioChannel new_channel = {
|
||||
.file_type = file_type,
|
||||
.context = init_audio_context(path, file_type),
|
||||
.path = path,
|
||||
.name = NULL,
|
||||
.path = SDL_strdup(path),
|
||||
.repeat = false,
|
||||
.volume = volume,
|
||||
.panning = panning,
|
||||
@ -506,12 +518,12 @@ static void audio_sample_and_mixin_channel(AudioChannel *channel,
|
||||
}
|
||||
|
||||
|
||||
static void sanity_check_channel(const AudioChannel *channel) {
|
||||
if (channel->volume < 0.0f || channel->volume > 1.0f)
|
||||
log_warn("Volume argument is out of range for channel (%s)", channel->name);
|
||||
static void sanity_check_channel(const AudioChannelItem channel) {
|
||||
if (channel.value.volume < 0.0f || channel.value.volume > 1.0f)
|
||||
log_warn("Volume argument is out of range for channel (%s)", channel.key ? channel.key : "unnamed");
|
||||
|
||||
if (channel->panning < -1.0f || channel->panning > 1.0f)
|
||||
log_warn("Panning argument is out of range for channel (%s)", channel->name);
|
||||
if (channel.value.panning < -1.0f || channel.value.panning > 1.0f)
|
||||
log_warn("Panning argument is out of range for channel (%s)", channel.key ? channel.key : "unnamed");
|
||||
}
|
||||
|
||||
|
||||
@ -523,7 +535,7 @@ void audio_callback(void *userdata, uint8_t *stream, int len) {
|
||||
|
||||
size_t const audio_channels_len = shlen(ctx.audio_channels);
|
||||
for (size_t i = 0; i < audio_channels_len; ++i) {
|
||||
sanity_check_channel(&ctx.audio_channels[i].value);
|
||||
sanity_check_channel(ctx.audio_channels[i]);
|
||||
audio_sample_and_mixin_channel(&ctx.audio_channels[i].value,
|
||||
stream, len,
|
||||
i == audio_channels_len - 1);
|
||||
@ -531,7 +543,7 @@ void audio_callback(void *userdata, uint8_t *stream, int len) {
|
||||
|
||||
size_t const unnamed_audio_channels_len = shlen(ctx.unnamed_audio_channels);
|
||||
for (size_t i = 0; i < unnamed_audio_channels_len; ++i) {
|
||||
sanity_check_channel(&ctx.unnamed_audio_channels[i]);
|
||||
sanity_check_channel((AudioChannelItem){NULL, ctx.unnamed_audio_channels[i]});
|
||||
audio_sample_and_mixin_channel(&ctx.unnamed_audio_channels[i],
|
||||
stream, len,
|
||||
i == unnamed_audio_channels_len - 1);
|
||||
|
Reference in New Issue
Block a user