Fixed: Non-spatial sound does not obey global sound effect's volume. Spatial sound is either too loud or to quiet. (#400)
This commit is contained in:
parent
ec04a9c111
commit
90971e9e56
|
@ -350,9 +350,7 @@ int S3SyncSampleVolumeAndPan(tS3_channel* chan) {
|
||||||
float pan_ratio; // [esp+38h] [ebp-8h]
|
float pan_ratio; // [esp+38h] [ebp-8h]
|
||||||
float total_vol; // [esp+3Ch] [ebp-4h]
|
float total_vol; // [esp+3Ch] [ebp-4h]
|
||||||
|
|
||||||
int volume_db;
|
|
||||||
int pan;
|
int pan;
|
||||||
float linear_volume;
|
|
||||||
|
|
||||||
if (chan->type != eS3_ST_sample) {
|
if (chan->type != eS3_ST_sample) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -362,12 +360,8 @@ int S3SyncSampleVolumeAndPan(tS3_channel* chan) {
|
||||||
total_vol = 1.0f;
|
total_vol = 1.0f;
|
||||||
}
|
}
|
||||||
if (chan->descriptor && chan->descriptor->type == chan->type) {
|
if (chan->descriptor && chan->descriptor->type == chan->type) {
|
||||||
volume_db = 510.0f / total_vol * -5.0f - 350.0f;
|
|
||||||
if (volume_db >= 0) {
|
|
||||||
volume_db = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AudioBackend_SetVolume(chan->type_struct_sample, volume_db) == eAB_success && chan->spatial_sound) {
|
if (AudioBackend_SetVolume(chan->type_struct_sample, total_vol) == eAB_success && chan->spatial_sound) {
|
||||||
|
|
||||||
if (chan->left_volume != 0 && chan->right_volume > chan->left_volume) {
|
if (chan->left_volume != 0 && chan->right_volume > chan->left_volume) {
|
||||||
pan_ratio = chan->right_volume / (float)chan->left_volume;
|
pan_ratio = chan->right_volume / (float)chan->left_volume;
|
||||||
|
|
|
@ -27,6 +27,9 @@ static int kMem_S3_DOS_SOS_channel = 234;
|
||||||
typedef struct tMiniaudio_sample {
|
typedef struct tMiniaudio_sample {
|
||||||
ma_audio_buffer_ref buffer_ref;
|
ma_audio_buffer_ref buffer_ref;
|
||||||
ma_sound sound;
|
ma_sound sound;
|
||||||
|
int init_volume;
|
||||||
|
int init_pan;
|
||||||
|
int init_new_rate;
|
||||||
int initialized;
|
int initialized;
|
||||||
} tMiniaudio_sample;
|
} tMiniaudio_sample;
|
||||||
|
|
||||||
|
@ -158,6 +161,12 @@ tAudioBackend_error_code AudioBackend_PlaySample(void* type_struct_sample, int c
|
||||||
}
|
}
|
||||||
miniaudio->initialized = 1;
|
miniaudio->initialized = 1;
|
||||||
|
|
||||||
|
if (miniaudio->init_volume > 0) {
|
||||||
|
AudioBackend_SetVolume(type_struct_sample, miniaudio->init_volume);
|
||||||
|
AudioBackend_SetPan(type_struct_sample, miniaudio->init_pan);
|
||||||
|
AudioBackend_SetFrequency(type_struct_sample, rate, miniaudio->init_new_rate);
|
||||||
|
}
|
||||||
|
|
||||||
ma_sound_set_looping(&miniaudio->sound, loop);
|
ma_sound_set_looping(&miniaudio->sound, loop);
|
||||||
ma_sound_start(&miniaudio->sound);
|
ma_sound_start(&miniaudio->sound);
|
||||||
return eAB_success;
|
return eAB_success;
|
||||||
|
@ -175,15 +184,19 @@ int AudioBackend_SoundIsPlaying(void* type_struct_sample) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
tAudioBackend_error_code AudioBackend_SetVolume(void* type_struct_sample, int volume_db) {
|
tAudioBackend_error_code AudioBackend_SetVolume(void* type_struct_sample, int volume) {
|
||||||
tMiniaudio_sample* miniaudio;
|
tMiniaudio_sample* miniaudio;
|
||||||
float linear_volume;
|
float linear_volume;
|
||||||
|
|
||||||
miniaudio = (tMiniaudio_sample*)type_struct_sample;
|
miniaudio = (tMiniaudio_sample*)type_struct_sample;
|
||||||
assert(miniaudio != NULL);
|
assert(miniaudio != NULL);
|
||||||
|
|
||||||
// convert from directsound -10000 - 0 decibel volume scale
|
if (!miniaudio->initialized) {
|
||||||
linear_volume = ma_volume_db_to_linear(volume_db / 100.0f);
|
miniaudio->init_volume = volume;
|
||||||
|
return eAB_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
linear_volume = volume / 510.0f;
|
||||||
ma_sound_set_volume(&miniaudio->sound, linear_volume);
|
ma_sound_set_volume(&miniaudio->sound, linear_volume);
|
||||||
return eAB_success;
|
return eAB_success;
|
||||||
}
|
}
|
||||||
|
@ -194,6 +207,11 @@ tAudioBackend_error_code AudioBackend_SetPan(void* type_struct_sample, int pan)
|
||||||
miniaudio = (tMiniaudio_sample*)type_struct_sample;
|
miniaudio = (tMiniaudio_sample*)type_struct_sample;
|
||||||
assert(miniaudio != NULL);
|
assert(miniaudio != NULL);
|
||||||
|
|
||||||
|
if (!miniaudio->initialized) {
|
||||||
|
miniaudio->init_pan = pan;
|
||||||
|
return eAB_success;
|
||||||
|
}
|
||||||
|
|
||||||
// convert from directsound -10000 - 10000 pan scale
|
// convert from directsound -10000 - 10000 pan scale
|
||||||
ma_sound_set_pan(&miniaudio->sound, pan / 10000.0f);
|
ma_sound_set_pan(&miniaudio->sound, pan / 10000.0f);
|
||||||
return eAB_success;
|
return eAB_success;
|
||||||
|
@ -205,6 +223,11 @@ tAudioBackend_error_code AudioBackend_SetFrequency(void* type_struct_sample, int
|
||||||
miniaudio = (tMiniaudio_sample*)type_struct_sample;
|
miniaudio = (tMiniaudio_sample*)type_struct_sample;
|
||||||
assert(miniaudio != NULL);
|
assert(miniaudio != NULL);
|
||||||
|
|
||||||
|
if (!miniaudio->initialized) {
|
||||||
|
miniaudio->init_new_rate = new_rate;
|
||||||
|
return eAB_success;
|
||||||
|
}
|
||||||
|
|
||||||
// convert from directsound frequency to linear pitch scale
|
// convert from directsound frequency to linear pitch scale
|
||||||
ma_sound_set_pitch(&miniaudio->sound, (new_rate / (float)original_rate));
|
ma_sound_set_pitch(&miniaudio->sound, (new_rate / (float)original_rate));
|
||||||
return eAB_success;
|
return eAB_success;
|
||||||
|
|
Loading…
Reference in New Issue