Skip to content

Commit

Permalink
Made it possible to increase the volume slider setting (e.g. using th…
Browse files Browse the repository at this point in the history
…e Tilde key) above 0db (for now on windows only)

fixes #167 and remainder of #155
  • Loading branch information
toxieainc committed Oct 3, 2023
1 parent 9370d24 commit 2e9701e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
2 changes: 2 additions & 0 deletions release/whatsnew.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Implemented fast flips for avr_120h, avs_170h, im_186, im_186ve, mt_145, mt_145h
Fixed crash of Mustang Boss mt_145hb
Fixed regressions by reducing the pre-shutdown time for Joctronic, NSM, Juegos Populares, after fixing timeslice issue related to the VGM file dump feature (which uses a fast timer)
Added support for the old SC-01 Votrax ROM version (wired only to the Mars - God of War Prototype so far)
Made it possible to increase the volume slider setting (e.g. using the Tilde key) above 0db (for now on windows only)
try to avoid it though, as it can result in sound clipping artifacts!
Fixed regression/crashes for Elvis and Monopoly (introduced in 3.1)
Improved emulation robustness when running multiple machines from the same generation (e.g. System11) one after another (e.g. from within VPX)
or when resetting certain machines
Expand Down
11 changes: 6 additions & 5 deletions src/usrintrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3319,14 +3319,15 @@ static void onscrd_volume(struct mame_bitmap *bitmap,int increment,int arg)
{
attenuation = osd_get_mastervolume();
attenuation += increment;
if (attenuation > 0) attenuation = 0;
//if (attenuation > 0) attenuation = 0; // gain is now handled, at least in the windows sound module
if (attenuation > 32) attenuation = 32;
if (attenuation < -32) attenuation = -32;
osd_set_mastervolume(attenuation);
}
attenuation = osd_get_mastervolume();

sprintf(buf,"%s %3ddB", ui_getstring (UI_volume), attenuation);
displayosd(bitmap,buf,100 * (attenuation + 32) / 32,100);
sprintf(buf,"%s %3ddB", ui_getstring(UI_volume), attenuation);
displayosd(bitmap,buf,100 * (attenuation + 32) / 64,100);
}

static void onscrd_mixervol(struct mame_bitmap *bitmap,int increment,int arg)
Expand Down Expand Up @@ -3570,7 +3571,7 @@ static void onscrd_init(void)
if (Machine->drv->sound[soundnum].sound_type == SOUND_DISCRETE)
{
/* For each DISCRETE_ADJUST node then there is a slider, there can only be one SOUND_DISCRETE */
/* in the machinbe sound delcaration so this WONT trigger more than once */
/* in the machine sound declaration so this WONT trigger more than once */
{
int count;
count=discrete_sh_adjuster_count((struct discrete_sound_block*)Machine->drv->sound[soundnum].sound_interface);
Expand All @@ -3585,7 +3586,7 @@ static void onscrd_init(void)
}
}
#endif /* HAS_DISCRETE */
/* K.Wilkins Feb2003 Additional of Disrete Sound System ADJUSTMENT sliders */
/* K.Wilkins Feb2003 Additional of Discrete Sound System ADJUSTMENT sliders */
}

if (options.cheat)
Expand Down
47 changes: 42 additions & 5 deletions src/windows/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
#include "video.h"
#include "rc.h"

#include "../../ext/libsamplerate/config.h"
#ifdef RESAMPLER_SSE_OPT
#if (defined(_M_IX86_FP) && _M_IX86_FP >= 2) || defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || defined(__ia64__) || defined(__x86_64__)
#include <xmmintrin.h>
#include <emmintrin.h>
#else // Arm Neon
#include "../sse2neon.h"
#endif
#endif


//============================================================
Expand Down Expand Up @@ -64,6 +73,7 @@ extern int verbose;

// global parameters
int attenuation = 0;
double volume_gain = 1.;



Expand Down Expand Up @@ -373,6 +383,28 @@ int osd_update_audio_stream(INT16 *buffer)
buffer = mix_buffer;
}

if(volume_gain > 1.)
{
const float vgf = volume_gain;
int i;
for (i = 0; i < input_bytes; ++i)
{
#if defined(RESAMPLER_SSE_OPT)
const INT16 samplei = (INT16)_mm_cvtss_si32(_mm_max_ss(_mm_min_ss(_mm_mul_ss(_mm_cvtsi32_ss(_mm_setzero_ps(), buffer[i]), _mm_set_ss(vgf)), _mm_set_ss(32767.f)), _mm_set_ss(-32768.f)));
#else
const float sample = (float)buffer[i] * vgf;
INT16 samplei;
if (sample <= -32768.f)
samplei = -32768;
else if (sample >= 32767.f)
samplei = 32767;
else
samplei = (INT16)(lrintf(sample));
#endif
buffer[i] = samplei;
}
}

// copy data into the sound buffer
copy_sample_data(buffer, input_bytes);

Expand Down Expand Up @@ -423,16 +455,21 @@ int osd_update_audio_stream(INT16 *buffer)

void osd_set_mastervolume(int _attenuation)
{
// clamp the attenuation to 0-32 range
if (_attenuation > 0)
_attenuation = 0;
volume_gain = 1.;

// clamp the attenuation to -32 - 32 range
if (_attenuation < -32)
_attenuation = -32;
if (_attenuation > 32)
_attenuation = 32;
attenuation = _attenuation;

while (_attenuation-- > 0)
volume_gain *= 1.1220184543019634355910389464779; // = (10 ^ (1/20)) = 1dB

// set the master volume
if (stream_buffer && is_enabled)
IDirectSoundBuffer_SetVolume(stream_buffer, (attenuation == -32) ? DSBVOLUME_MIN : attenuation * 100);
IDirectSoundBuffer_SetVolume(stream_buffer, (attenuation == -32) ? DSBVOLUME_MIN : min(attenuation,0) * 100);
}


Expand All @@ -457,7 +494,7 @@ void osd_sound_enable(int enable_it)
if (stream_buffer)
{
if (enable_it)
IDirectSoundBuffer_SetVolume(stream_buffer, attenuation * 100);
IDirectSoundBuffer_SetVolume(stream_buffer, min(attenuation,0) * 100);
else
IDirectSoundBuffer_SetVolume(stream_buffer, DSBVOLUME_MIN);

Expand Down

3 comments on commit 2e9701e

@passionforpins
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THANK YOU!! Just raising the master volume to 5db now I can hear the speech in Earthshaker! This should rescue many system 11 titles with low speech volumes. Great work @toxieainc !

@toxieainc
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@passionforpins Note though that the re-balancing of speech, music and sfx for sys11 is still ongoing at the moment. (due to the recent ym2151 and hc555XX updates)

@passionforpins
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@passionforpins Note though that the re-balancing of speech, music and sfx for sys11 is still ongoing at the moment. (due to the recent ym2151 and hc555XX updates)

Yes I've been watching :) and thrilled with the progress so far. Thank you!

Please sign in to comment.