diff --git a/docs/man/mame.6 b/docs/man/mame.6 index 3466ceef343..acb1d058625 100644 --- a/docs/man/mame.6 +++ b/docs/man/mame.6 @@ -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., diff --git a/docs/man/mess.6 b/docs/man/mess.6 index ec6a16b6ab5..d39926a18cb 100644 --- a/docs/man/mess.6 +++ b/docs/man/mess.6 @@ -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: diff --git a/docs/source/commandline/commandline-all.rst b/docs/source/commandline/commandline-all.rst index de46760271a..afe7cc2a72a 100644 --- a/docs/source/commandline/commandline-all.rst +++ b/docs/source/commandline/commandline-all.rst @@ -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** ** diff --git a/docs/source/commandline/commandline-index.rst b/docs/source/commandline/commandline-index.rst index c2cb93efbf1..b0cd9a51170 100644 --- a/docs/source/commandline/commandline-index.rst +++ b/docs/source/commandline/commandline-index.rst @@ -237,9 +237,9 @@ Core Video OpenGL GLSL Options Core Sound Options ~~~~~~~~~~~~~~~~~~ - | :ref:`samplerate ` | :ref:`[no]samples ` +| :ref:`[no]compressor ` | :ref:`volume ` | :ref:`sound ` | :ref:`audio_latency ` diff --git a/src/emu/emuopts.cpp b/src/emu/emuopts.cpp index ed614ecaa77..44f775dedfa 100644 --- a/src/emu/emuopts.cpp +++ b/src/emu/emuopts.cpp @@ -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" }, diff --git a/src/emu/emuopts.h b/src/emu/emuopts.h index 4d92ce5371c..3df399ce8d6 100644 --- a/src/emu/emuopts.h +++ b/src/emu/emuopts.h @@ -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 diff --git a/src/emu/sound.cpp b/src/emu/sound.cpp index 8260762d1f8..56b7d7ef071 100644 --- a/src/emu/sound.cpp +++ b/src/emu/sound.cpp @@ -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) diff --git a/src/emu/sound.h b/src/emu/sound.h index fab06bbcea8..c1e66808ae6 100644 --- a/src/emu/sound.h +++ b/src/emu/sound.h @@ -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 diff --git a/src/frontend/mame/ui/sndmenu.cpp b/src/frontend/mame/ui/sndmenu.cpp index a3c65e7f6c9..52948c8bca2 100644 --- a/src/frontend/mame/ui/sndmenu.cpp +++ b/src/frontend/mame/ui/sndmenu.cpp @@ -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); diff --git a/src/frontend/mame/ui/sndmenu.h b/src/frontend/mame/ui/sndmenu.h index 4cecc5dc165..2684f9c7854 100644 --- a/src/frontend/mame/ui/sndmenu.h +++ b/src/frontend/mame/ui/sndmenu.h @@ -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