audio.c: sanity checking with warnings
This commit is contained in:
parent
6cb8736fc1
commit
eba3f0a2d5
11
src/audio.c
11
src/audio.c
@ -177,6 +177,7 @@ void play_audio_ex(const char *path, const char *channel, t_play_audio_args args
|
|||||||
.file_type = file_type,
|
.file_type = file_type,
|
||||||
.context = init_audio_context(path, file_type),
|
.context = init_audio_context(path, file_type),
|
||||||
.path = path,
|
.path = path,
|
||||||
|
.name = channel,
|
||||||
};
|
};
|
||||||
shput(ctx.audio_channels, channel, new_channel);
|
shput(ctx.audio_channels, channel, new_channel);
|
||||||
pair = shgetp_null(ctx.audio_channels, channel);
|
pair = shgetp_null(ctx.audio_channels, channel);
|
||||||
@ -324,6 +325,15 @@ static void audio_sample_and_mixin_channel(const struct audio_channel *channel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void sanity_check_channel(const struct audio_channel *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);
|
||||||
|
|
||||||
|
if (channel->args.panning < -1.0f || channel->args.panning > 1.0f)
|
||||||
|
log_warn("panning argument is out of range for channel (%s)", channel->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void audio_callback(void *userdata, uint8_t *stream, int len) {
|
void audio_callback(void *userdata, uint8_t *stream, int len) {
|
||||||
(void)userdata;
|
(void)userdata;
|
||||||
|
|
||||||
@ -331,6 +341,7 @@ void audio_callback(void *userdata, uint8_t *stream, int len) {
|
|||||||
SDL_memset(stream, sizeof (uint16_t), len * ctx.audio_stream_channel_count);
|
SDL_memset(stream, sizeof (uint16_t), len * ctx.audio_stream_channel_count);
|
||||||
|
|
||||||
for (int i = 0; i < shlen(ctx.audio_channels); ++i) {
|
for (int i = 0; i < shlen(ctx.audio_channels); ++i) {
|
||||||
|
sanity_check_channel(&ctx.audio_channels[i].value);
|
||||||
audio_sample_and_mixin_channel(&ctx.audio_channels[i].value, stream, len);
|
audio_sample_and_mixin_channel(&ctx.audio_channels[i].value, stream, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ struct audio_channel {
|
|||||||
enum audio_file_type file_type;
|
enum audio_file_type file_type;
|
||||||
union audio_context context; /* interpreted by `file_type` value */
|
union audio_context context; /* interpreted by `file_type` value */
|
||||||
const char *path;
|
const char *path;
|
||||||
|
const char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user