sfx normalization

normalized sound effects, converted them to ogg vorbis. there's now a
global config file sfx/volumes.conf, where the volumes of sound effects
can be adjusted. the default volume is 100, the max is 128.
This commit is contained in:
Andrei Alexeyev 2017-10-02 09:02:06 +03:00
parent d545852b0e
commit ee753f053e
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
29 changed files with 65 additions and 7 deletions

Binary file not shown.

Binary file not shown.

BIN
resources/sfx/death.ogg Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
resources/sfx/graze.ogg Normal file

Binary file not shown.

Binary file not shown.

BIN
resources/sfx/hit.ogg Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
resources/sfx/laser1.ogg Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
resources/sfx/shot1.ogg Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,14 @@
# The range is [0, 128]
charge_generic = 128
death = 100
enemydeath = 50
generic_shot = 10
graze = 20
hit = 100
item_generic = 70
laser1 = 100
masterspark = 128
shot1 = 50
shot1_loop = 40
shot_special1 = 50

View file

@ -12,6 +12,7 @@
#include "resource/bgm.h"
#define LOOPTIMEOUTFRAMES 10
#define DEFAULT_SFX_VOLUME 100
typedef struct CurrentBGM {
char *name;
@ -35,7 +36,6 @@ void audio_backend_music_stop(void);
void audio_backend_music_pause(void);
bool audio_backend_music_play(void *impl);
bool audio_backend_sound_play(void *impl);
bool audio_backend_sound_loop(void *impl);
bool audio_backend_sound_stop_loop(void *impl);
@ -50,6 +50,8 @@ void reset_sounds(void);
void update_sounds(void); // checks if loops need to be stopped
int get_default_sfx_volume(const char *sfx);
Sound* get_sound(const char *name);
Music* get_music(const char *music);

View file

@ -15,6 +15,7 @@
static char *saved_bgm;
static Hashtable *bgm_descriptions;
static Hashtable *sfx_volumes;
CurrentBGM current_bgm = { .name = NULL };
static void play_sound_internal(const char *name, bool unconditional, int cooldown) {
@ -104,9 +105,25 @@ static void bgm_cfg_volume_callback(ConfigIndex idx, ConfigValue v) {
audio_backend_set_bgm_volume(config_set_float(idx, v.f));
}
static void load_bgm_descriptions(void) {
static void store_sfx_volume(const char *key, const char *val, Hashtable *ht) {
int vol = atoi(val);
if(vol < 0 || vol > 128) {
log_warn("Volume %i for sfx %s is out of range; must be within [0, 128]", vol, key);
vol = vol < 0 ? 0 : 128;
}
log_debug("Default volume for %s is now %i", key, vol);
if(vol != DEFAULT_SFX_VOLUME) {
hashtable_set_string(ht, key, (void*)(intptr_t)vol);
}
}
static void load_config_files(void) {
bgm_descriptions = parse_keyvalue_file(BGM_PATH_PREFIX "bgm.conf", HT_DYNAMIC_SIZE);
return;
sfx_volumes = hashtable_new_stringkeys(HT_DYNAMIC_SIZE);
parse_keyvalue_file_cb(SFX_PATH_PREFIX "volumes.conf", (KVCallback)store_sfx_volume, sfx_volumes);
}
static inline char* get_bgm_desc(char *name) {
@ -120,6 +137,16 @@ static inline char* get_bgm_desc(char *name) {
return bgm_descriptions ? (char*)hashtable_get_string(bgm_descriptions, name) : NULL;
}
int get_default_sfx_volume(const char *sfx) {
void *v = hashtable_get_string(sfx_volumes, sfx);
if(v != NULL) {
return (intptr_t)v;
}
return DEFAULT_SFX_VOLUME;
}
void resume_bgm(void) {
start_bgm(current_bgm.name); // In most cases it just unpauses existing music.
}
@ -201,8 +228,8 @@ void start_bgm(const char *name) {
}
void audio_init(void) {
load_config_files();
audio_backend_init();
load_bgm_descriptions();
config_set_callback(CONFIG_SFX_VOLUME, sfx_cfg_volume_callback);
config_set_callback(CONFIG_BGM_VOLUME, bgm_cfg_volume_callback);
}
@ -213,5 +240,11 @@ void audio_shutdown(void) {
if(bgm_descriptions) {
hashtable_foreach(bgm_descriptions, hashtable_iter_free_data, NULL);
hashtable_free(bgm_descriptions);
bgm_descriptions = NULL;
}
if(sfx_volumes) {
hashtable_free(sfx_volumes);
sfx_volumes = NULL;
}
}

View file

@ -36,8 +36,17 @@ void* load_sound_begin(const char *path, unsigned int flags) {
return NULL;
}
char resname[strlen(path) - sizeof(SFX_PATH_PREFIX) + 1];
strcpy(resname, path + sizeof(SFX_PATH_PREFIX) - 1);
char *dot = strrchr(resname, '.');
assert(dot != NULL);
*dot = 0;
Mix_VolumeChunk(sound, get_default_sfx_volume(resname));
log_debug("%s volume: %i", resname, Mix_VolumeChunk(sound, -1));
Sound *snd = calloc(1, sizeof(Sound));
snd->impl = calloc(1,sizeof(MixerInternalSound));
snd->impl = calloc(1, sizeof(MixerInternalSound));
((MixerInternalSound*)snd->impl)->ch = sound;
((MixerInternalSound*)snd->impl)->loopchan = -1;
return snd;

View file

@ -475,7 +475,7 @@ Hashtable* parse_keyvalue_stream(SDL_RWops *strm, size_t tablesize) {
Hashtable *ht = hashtable_new_stringkeys(tablesize);
if(!parse_keyvalue_stream_cb(strm, (KVCallback)kvcallback_hashtable, ht)) {
free(ht);
hashtable_free(ht);
ht = NULL;
}
@ -486,7 +486,7 @@ Hashtable* parse_keyvalue_file(const char *filename, size_t tablesize) {
Hashtable *ht = hashtable_new_stringkeys(tablesize);
if(!parse_keyvalue_file_cb(filename, (KVCallback)kvcallback_hashtable, ht)) {
free(ht);
hashtable_free(ht);
ht = NULL;
}