sound: make the compressor optional (clamp overdrive to -1.0-1.0 when off)

This commit is contained in:
hap 2021-09-24 19:40:10 +02:00
parent 3a2ab1a6c6
commit c9c3cac6c2
10 changed files with 54 additions and 9 deletions

View File

@ -938,6 +938,9 @@ cause higher audio quality but slower emulation speed. The default is
.B \-[no]samples
Use samples if available. The default is ON (\-samples).
.TP
.B \-[no]compressor
Use compressor for sound. The default is ON (\-compressor).
.TP
.B \-volume, \-vol \fIvalue
Sets the startup volume. It can later be changed with the user interface
(see Keys section). The volume is an attenuation in dB: e.g.,

View File

@ -969,6 +969,9 @@ cause higher audio quality but slower emulation speed. The default is
.B \-[no]samples
Use samples if available. The default is ON (\-samples).
.TP
.B \-[no]compressor
Use compressor for sound. The default is ON (\-compressor).
.TP
.B \-volume, \-vol \fIvalue
Sets the startup volume. It can later be changed with the user interface
(see Keys section). The volume is an attenuation in dB:

View File

@ -2824,6 +2824,19 @@ Core Sound Options
mame qbert -nosamples
.. _mame-commandline-nocompressor:
**-[no]compressor**
Use compressor for sound.
The default is ON (**-compressor**).
Example:
.. code-block:: bash
mame popeye -nocompressor
.. _mame-commandline-volume:
**-volume** / **-vol** *<value>*

View File

@ -237,9 +237,9 @@ Core Video OpenGL GLSL Options
Core Sound Options
~~~~~~~~~~~~~~~~~~
| :ref:`samplerate <mame-commandline-samplerate>`
| :ref:`[no]samples <mame-commandline-nosamples>`
| :ref:`[no]compressor <mame-commandline-nocompressor>`
| :ref:`volume <mame-commandline-volume>`
| :ref:`sound <mame-commandline-sound>`
| :ref:`audio_latency <mame-commandline-audiolatency>`

View File

@ -141,7 +141,8 @@ const options_entry emu_options::s_option_entries[] =
{ OPTION_SAMPLERATE ";sr(1000-1000000)", "48000", OPTION_INTEGER, "set sound output sample rate" },
{ OPTION_SAMPLES, "1", OPTION_BOOLEAN, "enable the use of external samples if available" },
{ OPTION_VOLUME ";vol", "0", OPTION_INTEGER, "sound volume in decibels (-32 min, 0 max)" },
{ OPTION_SPEAKER_REPORT, "0", OPTION_INTEGER, "print report of speaker ouput maxima (0=none, or 1-4 for more detail)" },
{ OPTION_COMPRESSOR, "1", OPTION_BOOLEAN, "enable compressor for sound" },
{ OPTION_SPEAKER_REPORT "(0-4)", "0", OPTION_INTEGER, "print report of speaker ouput maxima (0=none, or 1-4 for more detail)" },
// input options
{ nullptr, nullptr, OPTION_HEADER, "CORE INPUT OPTIONS" },

View File

@ -120,6 +120,7 @@
#define OPTION_SAMPLERATE "samplerate"
#define OPTION_SAMPLES "samples"
#define OPTION_VOLUME "volume"
#define OPTION_COMPRESSOR "compressor"
#define OPTION_SPEAKER_REPORT "speaker_report"
// core input options
@ -405,6 +406,7 @@ public:
int sample_rate() const { return int_value(OPTION_SAMPLERATE); }
bool samples() const { return bool_value(OPTION_SAMPLES); }
int volume() const { return int_value(OPTION_VOLUME); }
bool compressor() const { return bool_value(OPTION_COMPRESSOR); }
int speaker_report() const { return int_value(OPTION_SPEAKER_REPORT); }
// core input options

View File

@ -1068,6 +1068,7 @@ sound_manager::sound_manager(running_machine &machine) :
m_rightmix(machine.sample_rate()),
m_compressor_scale(1.0),
m_compressor_counter(0),
m_compressor_enabled(machine.options().compressor()),
m_muted(0),
m_nosound_mode(machine.osd().no_sound()),
m_attenuation(0),
@ -1543,8 +1544,11 @@ void sound_manager::update(void *ptr, int param)
if (lscale != m_compressor_scale && sample != m_finalmix_leftover)
lscale = adjust_toward_compressor_scale(lscale, lprev, lsamp);
lprev = lsamp * lscale;
if (m_compressor_enabled)
lsamp = lprev;
// clamp the left side
lprev = lsamp *= lscale;
if (lsamp > 1.0)
lsamp = 1.0;
else if (lsamp < -1.0)
@ -1556,8 +1560,11 @@ void sound_manager::update(void *ptr, int param)
if (rscale != m_compressor_scale && sample != m_finalmix_leftover)
rscale = adjust_toward_compressor_scale(rscale, rprev, rsamp);
// clamp the left side
rprev = rsamp *= rscale;
rprev = rsamp * rscale;
if (m_compressor_enabled)
rsamp = rprev;
// clamp the right side
if (rsamp > 1.0)
rsamp = 1.0;
else if (rsamp < -1.0)

View File

@ -833,6 +833,7 @@ private:
stream_buffer::sample_t m_compressor_scale; // current compressor scale factor
int m_compressor_counter; // compressor update counter for backoff
bool m_compressor_enabled; // enable compressor (it will still be calculated for detecting overdrive)
u8 m_muted; // bitmask of muting reasons
bool m_nosound_mode; // true if we're in "nosound" mode

View File

@ -28,6 +28,7 @@ menu_sound_options::menu_sound_options(mame_ui_manager &mui, render_container &c
m_sample_rate = mui.machine().options().sample_rate();
m_sound = (strcmp(options.sound(), OSDOPTVAL_NONE) && strcmp(options.sound(), "0"));
m_samples = mui.machine().options().samples();
m_compressor = mui.machine().options().compressor();
int total = std::size(m_sound_rate);
@ -47,15 +48,19 @@ menu_sound_options::~menu_sound_options()
{
emu_options &moptions = machine().options();
if (strcmp(moptions.value(OSDOPTION_SOUND),m_sound ? OSDOPTVAL_AUTO : OSDOPTVAL_NONE)!=0)
if (strcmp(moptions.value(OSDOPTION_SOUND), m_sound ? OSDOPTVAL_AUTO : OSDOPTVAL_NONE) != 0)
{
moptions.set_value(OSDOPTION_SOUND, m_sound ? OSDOPTVAL_AUTO : OSDOPTVAL_NONE, OPTION_PRIORITY_CMDLINE);
}
if (moptions.int_value(OPTION_SAMPLERATE)!=m_sound_rate[m_cur_rates])
if (moptions.bool_value(OPTION_COMPRESSOR) != m_compressor)
{
moptions.set_value(OPTION_COMPRESSOR, m_compressor, OPTION_PRIORITY_CMDLINE);
}
if (moptions.int_value(OPTION_SAMPLERATE) != m_sound_rate[m_cur_rates])
{
moptions.set_value(OPTION_SAMPLERATE, m_sound_rate[m_cur_rates], OPTION_PRIORITY_CMDLINE);
}
if (moptions.bool_value(OPTION_SAMPLES)!=m_samples)
if (moptions.bool_value(OPTION_SAMPLES) != m_samples)
{
moptions.set_value(OPTION_SAMPLES, m_samples, OPTION_PRIORITY_CMDLINE);
}
@ -84,6 +89,14 @@ void menu_sound_options::handle()
}
break;
case ENABLE_COMPRESSOR:
if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT || menu_event->iptkey == IPT_UI_SELECT)
{
m_compressor = !m_compressor;
changed = true;
}
break;
case SAMPLE_RATE:
if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT)
{
@ -133,6 +146,7 @@ void menu_sound_options::populate(float &customtop, float &custombottom)
// add options items
item_append_on_off(_("Sound"), m_sound, 0, (void *)(uintptr_t)ENABLE_SOUND);
item_append_on_off(_("Compressor"), m_compressor, 0, (void *)(uintptr_t)ENABLE_COMPRESSOR);
item_append(_("Sample Rate"), string_format("%d", m_sample_rate), arrow_flags, (void *)(uintptr_t)SAMPLE_RATE);
item_append_on_off(_("Use External Samples"), m_samples, 0, (void *)(uintptr_t)ENABLE_SAMPLES);
item_append(menu_item_type::SEPARATOR);

View File

@ -32,6 +32,7 @@ private:
enum
{
ENABLE_SOUND = 1,
ENABLE_COMPRESSOR,
SAMPLE_RATE,
ENABLE_SAMPLES
};
@ -42,7 +43,7 @@ private:
uint16_t m_cur_rates;
static const int m_sound_rate[];
int m_sample_rate;
bool m_samples, m_sound;
bool m_samples, m_sound, m_compressor;
};
} // namespace ui