speaker: set pan range to -1 to 1,

sliders: show channel volume in percentage and increase maximum to 400%
This commit is contained in:
hap 2023-09-10 12:23:29 +02:00
parent 04aac6dc77
commit 1ea07622d1
4 changed files with 78 additions and 59 deletions

View File

@ -1382,6 +1382,7 @@ void sound_manager::config_load(config_type cfg_type, config_level cfg_level, ut
mixer_input info;
if (indexed_mixer_input(node->get_attribute_int("index", -1), info))
{
// note that this doesn't disallow out-of-range values
float value = node->get_attribute_float("value", std::nanf(""));
if (std::isnan(value))

View File

@ -37,8 +37,8 @@ speaker_device::speaker_device(const machine_config &mconfig, const char *tag, d
, m_x(0.0)
, m_y(0.0)
, m_z(0.0)
, m_pan(1.0)
, m_defpan(1.0)
, m_pan(0.0)
, m_defpan(0.0)
, m_current_max(0)
, m_samples_this_bucket(0)
{
@ -67,18 +67,17 @@ speaker_device &speaker_device::set_position(double x, double y, double z)
// hard pan to left
if (m_x < 0.0)
set_pan(0.0f);
set_pan(-1.0f);
// hard pan to right
else if (m_x > 0.0)
set_pan(2.0f);
set_pan(1.0f);
// center (mono)
else
set_pan(1.0f);
set_pan(0.0f);
m_defpan = m_pan;
return *this;
}
@ -121,20 +120,20 @@ void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample
if (!suppress)
{
// if the speaker is hard panned to the left, send only to the left
if (m_pan == 0.0f)
if (m_pan == -1.0f)
for (int sample = 0; sample < expected_samples; sample++)
leftmix[sample] += view.get(sample);
// if the speaker is hard panned to the right, send only to the right
else if (m_pan == 2.0f)
else if (m_pan == 1.0f)
for (int sample = 0; sample < expected_samples; sample++)
rightmix[sample] += view.get(sample);
// otherwise, send to both
else
{
const float leftpan = (m_pan <= 1.0f) ? 1.0f : 2.0f - m_pan;
const float rightpan = (m_pan >= 1.0f) ? 1.0f : m_pan;
const float leftpan = (m_pan <= 0.0f) ? 1.0f : 1.0f - m_pan;
const float rightpan = (m_pan >= 0.0f) ? 1.0f : 1.0f + m_pan;
for (int sample = 0; sample < expected_samples; sample++)
{

View File

@ -71,8 +71,8 @@ public:
// internally for use by the sound system
void mix(stream_buffer::sample_t *leftmix, stream_buffer::sample_t *rightmix, attotime start, attotime end, int expected_samples, bool suppress);
// panning
void set_pan(double pan) { m_pan = std::clamp(pan, 0.0, 2.0); }
// user panning configuration
void set_pan(float pan) { m_pan = std::clamp(pan, -1.0f, 1.0f); }
float pan() { return m_pan; }
float defpan() { return m_defpan; }

View File

@ -741,15 +741,15 @@ float mame_ui_manager::get_line_height(float scale)
if (raw_font_pixel_height < 24)
{
// do we want to scale smaller? only do so if we exceed the threshold
if (scale_factor <= 1.0F)
if (scale_factor <= 1.0f)
{
if (one_to_one_line_height < UI_MAX_FONT_HEIGHT || raw_font_pixel_height < 12)
scale_factor = 1.0F;
scale_factor = 1.0f;
}
else
{
// otherwise, just ensure an integral scale factor
scale_factor = floor(scale_factor);
scale_factor = floorf(scale_factor);
}
}
else
@ -1479,14 +1479,15 @@ std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine
for (int item = 0; machine.sound().indexed_mixer_input(item, info); item++)
{
std::string str = string_format(_("%1$s Volume"), info.stream->input(info.inputnum).name());
slider_alloc(std::move(str), 0, 1000, 2000, 20, std::bind(&mame_ui_manager::slider_mixervol, this, item, _1, _2));
slider_alloc(std::move(str), 0, 1000, 4000, 20, std::bind(&mame_ui_manager::slider_mixervol, this, item, _1, _2));
}
// add speaker panning
for (speaker_device &speaker : speaker_device_enumerator(machine.root_device()))
{
int defpan = floorf(speaker.defpan() * 1000.0f + 0.5f);
std::string str = string_format(_("%s '%s' Panning"), speaker.name(), speaker.tag());
slider_alloc(std::move(str), 0, floor(speaker.defpan() * 1000.0 + 0.5), 2000, 20, std::bind(&mame_ui_manager::slider_panning, this, std::ref(speaker), _1, _2));
slider_alloc(std::move(str), -1000, defpan, 1000, 20, std::bind(&mame_ui_manager::slider_panning, this, std::ref(speaker), _1, _2));
}
// add analog adjusters
@ -1524,10 +1525,10 @@ std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine
screen_device_enumerator scriter(machine.root_device());
for (screen_device &screen : scriter)
{
int defxscale = floor(screen.xscale() * 1000.0f + 0.5f);
int defyscale = floor(screen.yscale() * 1000.0f + 0.5f);
int defxoffset = floor(screen.xoffset() * 1000.0f + 0.5f);
int defyoffset = floor(screen.yoffset() * 1000.0f + 0.5f);
int defxscale = floorf(screen.xscale() * 1000.0f + 0.5f);
int defyscale = floorf(screen.yscale() * 1000.0f + 0.5f);
int defxoffset = floorf(screen.xoffset() * 1000.0f + 0.5f);
int defyoffset = floorf(screen.yoffset() * 1000.0f + 0.5f);
std::string screen_desc = machine_info().get_screen_desc(screen);
// add refresh rate tweaker
@ -1562,10 +1563,10 @@ std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine
{
laserdisc_overlay_config config;
laserdisc.get_overlay_config(config);
int defxscale = floor(config.m_overscalex * 1000.0f + 0.5f);
int defyscale = floor(config.m_overscaley * 1000.0f + 0.5f);
int defxoffset = floor(config.m_overposx * 1000.0f + 0.5f);
int defyoffset = floor(config.m_overposy * 1000.0f + 0.5f);
int defxscale = floorf(config.m_overscalex * 1000.0f + 0.5f);
int defyscale = floorf(config.m_overscaley * 1000.0f + 0.5f);
int defxoffset = floorf(config.m_overposx * 1000.0f + 0.5f);
int defyoffset = floorf(config.m_overposy * 1000.0f + 0.5f);
// add scale and offset controls per-overlay
std::string str = string_format(_("Laserdisc '%1$s' Horiz Stretch"), laserdisc.tag());
@ -1630,9 +1631,12 @@ int32_t mame_ui_manager::slider_volume(std::string *str, int32_t newval)
{
if (newval != SLIDER_NOCHANGE)
machine().sound().set_attenuation(newval);
int32_t curval = machine().sound().attenuation();
if (str)
*str = string_format(_("%1$3ddB"), machine().sound().attenuation());
return machine().sound().attenuation();
*str = string_format(_("%1$3d" UTF8_NBSP "dB"), curval);
return curval;
}
@ -1646,15 +1650,22 @@ int32_t mame_ui_manager::slider_mixervol(int item, std::string *str, int32_t new
mixer_input info;
if (!machine().sound().indexed_mixer_input(item, info))
return 0;
if (newval != SLIDER_NOCHANGE)
{
int32_t curval = floor(info.stream->input(info.inputnum).user_gain() * 1000.0f + 0.5f);
if (newval > curval && (newval - curval) <= 4) newval += 4; // round up on increment
info.stream->input(info.inputnum).set_user_gain(float(newval) * 0.001f);
}
int32_t curval = floorf(info.stream->input(info.inputnum).user_gain() * 1000.0f + 0.5f);
if (str)
*str = string_format("%1.2f", info.stream->input(info.inputnum).user_gain());
return floorf(info.stream->input(info.inputnum).user_gain() * 1000.0f + 0.5f);
{
if (curval == 0)
*str = _("Mute");
else if (curval % 10)
*str = string_format(_("%1$.1f%%"), float(curval) * 0.1f);
else
*str = string_format(_("%1$3d%%"), curval / 10);
}
return curval;
}
@ -1668,27 +1679,27 @@ int32_t mame_ui_manager::slider_panning(speaker_device &speaker, std::string *st
if (newval != SLIDER_NOCHANGE)
speaker.set_pan(float(newval) * 0.001f);
int32_t curval = floor(speaker.pan() * 1000.0f + 0.5f);
int32_t curval = floorf(speaker.pan() * 1000.0f + 0.5f);
if (str)
{
switch (curval)
{
// preset strings for exact center/left/right
case 1000:
case 0:
*str = _("Center");
break;
case 0:
case -1000:
*str = _("Left");
break;
case 2000:
case 1000:
*str = _("Right");
break;
// otherwise show as floating point
default:
*str = string_format("%1.2f", float(curval) * 0.001f);
*str = string_format(_("%1$.3f"), float(curval) * 0.001f);
break;
}
}
@ -1713,7 +1724,7 @@ int32_t mame_ui_manager::slider_adjuster(ioport_field &field, std::string *str,
field.set_user_settings(settings);
}
if (str)
*str = string_format(_("%1$d%%"), settings.value);
*str = string_format(_("%1$3d%%"), settings.value);
return settings.value;
}
@ -1726,10 +1737,18 @@ int32_t mame_ui_manager::slider_adjuster(ioport_field &field, std::string *str,
int32_t mame_ui_manager::slider_overclock(device_t &device, std::string *str, int32_t newval)
{
if (newval != SLIDER_NOCHANGE)
device.set_clock_scale(float(newval) * 0.001f);
device.set_clock_scale(double(newval) * 0.001);
int32_t curval = floor(device.clock_scale() * 1000.0 + 0.5);
if (str)
*str = string_format(_("%1$3.0f%%"), floor(device.clock_scale() * 100.0 + 0.5));
return floor(device.clock_scale() * 1000.0 + 0.5);
{
if (curval % 10)
*str = string_format(_("%1$.1f%%"), float(curval) * 0.1f);
else
*str = string_format(_("%1$3d%%"), curval / 10);
}
return curval;
}
@ -1772,7 +1791,7 @@ int32_t mame_ui_manager::slider_brightness(screen_device &screen, std::string *s
}
if (str)
*str = string_format(_("%1$.3f"), settings.m_brightness);
return floor(settings.m_brightness * 1000.0f + 0.5f);
return floorf(settings.m_brightness * 1000.0f + 0.5f);
}
@ -1791,7 +1810,7 @@ int32_t mame_ui_manager::slider_contrast(screen_device &screen, std::string *str
}
if (str)
*str = string_format(_("%1$.3f"), settings.m_contrast);
return floor(settings.m_contrast * 1000.0f + 0.5f);
return floorf(settings.m_contrast * 1000.0f + 0.5f);
}
@ -1809,7 +1828,7 @@ int32_t mame_ui_manager::slider_gamma(screen_device &screen, std::string *str, i
}
if (str)
*str = string_format(_("%1$.3f"), settings.m_gamma);
return floor(settings.m_gamma * 1000.0f + 0.5f);
return floorf(settings.m_gamma * 1000.0f + 0.5f);
}
@ -1828,7 +1847,7 @@ int32_t mame_ui_manager::slider_xscale(screen_device &screen, std::string *str,
}
if (str)
*str = string_format(_("%1$.3f"), settings.m_xscale);
return floor(settings.m_xscale * 1000.0f + 0.5f);
return floorf(settings.m_xscale * 1000.0f + 0.5f);
}
@ -1847,7 +1866,7 @@ int32_t mame_ui_manager::slider_yscale(screen_device &screen, std::string *str,
}
if (str)
*str = string_format(_("%1$.3f"), settings.m_yscale);
return floor(settings.m_yscale * 1000.0f + 0.5f);
return floorf(settings.m_yscale * 1000.0f + 0.5f);
}
@ -1866,7 +1885,7 @@ int32_t mame_ui_manager::slider_xoffset(screen_device &screen, std::string *str,
}
if (str)
*str = string_format(_("%1$.3f"), settings.m_xoffset);
return floor(settings.m_xoffset * 1000.0f + 0.5f);
return floorf(settings.m_xoffset * 1000.0f + 0.5f);
}
@ -1885,7 +1904,7 @@ int32_t mame_ui_manager::slider_yoffset(screen_device &screen, std::string *str,
}
if (str)
*str = string_format(_("%1$.3f"), settings.m_yoffset);
return floor(settings.m_yoffset * 1000.0f + 0.5f);
return floorf(settings.m_yoffset * 1000.0f + 0.5f);
}
@ -1906,7 +1925,7 @@ int32_t mame_ui_manager::slider_overxscale(laserdisc_device &laserdisc, std::str
}
if (str)
*str = string_format(_("%1$.3f"), settings.m_overscalex);
return floor(settings.m_overscalex * 1000.0f + 0.5f);
return floorf(settings.m_overscalex * 1000.0f + 0.5f);
}
@ -1927,7 +1946,7 @@ int32_t mame_ui_manager::slider_overyscale(laserdisc_device &laserdisc, std::str
}
if (str)
*str = string_format(_("%1$.3f"), settings.m_overscaley);
return floor(settings.m_overscaley * 1000.0f + 0.5f);
return floorf(settings.m_overscaley * 1000.0f + 0.5f);
}
@ -1948,7 +1967,7 @@ int32_t mame_ui_manager::slider_overxoffset(laserdisc_device &laserdisc, std::st
}
if (str)
*str = string_format(_("%1$.3f"), settings.m_overposx);
return floor(settings.m_overposx * 1000.0f + 0.5f);
return floorf(settings.m_overposx * 1000.0f + 0.5f);
}
@ -1969,7 +1988,7 @@ int32_t mame_ui_manager::slider_overyoffset(laserdisc_device &laserdisc, std::st
}
if (str)
*str = string_format(_("%1$.3f"), settings.m_overposy);
return floor(settings.m_overposy * 1000.0f + 0.5f);
return floorf(settings.m_overposy * 1000.0f + 0.5f);
}
@ -1984,7 +2003,7 @@ int32_t mame_ui_manager::slider_flicker([[maybe_unused]] screen_device &screen,
vector_options::s_flicker = float(newval) * 0.001f;
if (str)
*str = string_format(_("%1$1.2f"), vector_options::s_flicker);
return floor(vector_options::s_flicker * 1000.0f + 0.5f);
return floorf(vector_options::s_flicker * 1000.0f + 0.5f);
}
@ -1999,7 +2018,7 @@ int32_t mame_ui_manager::slider_beam_width_min([[maybe_unused]] screen_device &s
vector_options::s_beam_width_min = std::min(float(newval) * 0.01f, vector_options::s_beam_width_max);
if (str != nullptr)
*str = string_format(_("%1$1.2f"), vector_options::s_beam_width_min);
return floor(vector_options::s_beam_width_min * 100.0f + 0.5f);
return floorf(vector_options::s_beam_width_min * 100.0f + 0.5f);
}
@ -2014,7 +2033,7 @@ int32_t mame_ui_manager::slider_beam_width_max([[maybe_unused]] screen_device &s
vector_options::s_beam_width_max = std::max(float(newval) * 0.01f, vector_options::s_beam_width_min);
if (str != nullptr)
*str = string_format(_("%1$1.2f"), vector_options::s_beam_width_max);
return floor(vector_options::s_beam_width_max * 100.0f + 0.5f);
return floorf(vector_options::s_beam_width_max * 100.0f + 0.5f);
}
@ -2029,7 +2048,7 @@ int32_t mame_ui_manager::slider_beam_dot_size([[maybe_unused]] screen_device &sc
vector_options::s_beam_dot_size = std::max(float(newval) * 0.01f, 0.1f);
if (str != nullptr)
*str = string_format(_("%1$1.2f"), vector_options::s_beam_dot_size);
return floor(vector_options::s_beam_dot_size * 100.0f + 0.5f);
return floorf(vector_options::s_beam_dot_size * 100.0f + 0.5f);
}
@ -2044,7 +2063,7 @@ int32_t mame_ui_manager::slider_beam_intensity_weight([[maybe_unused]] screen_de
vector_options::s_beam_intensity_weight = float(newval) * 0.001f;
if (str != nullptr)
*str = string_format(_("%1$1.2f"), vector_options::s_beam_intensity_weight);
return floor(vector_options::s_beam_intensity_weight * 1000.0f + 0.5f);
return floorf(vector_options::s_beam_intensity_weight * 1000.0f + 0.5f);
}
@ -2060,7 +2079,7 @@ int32_t mame_ui_manager::slider_crossscale(ioport_field &field, std::string *str
field.set_crosshair_scale(float(newval) * 0.001);
if (str)
*str = string_format((field.crosshair_axis() == CROSSHAIR_AXIS_X) ? _("Crosshair Scale X %1$1.3f") : _("Crosshair Scale Y %1$1.3f"), float(newval) * 0.001f);
return floor(field.crosshair_scale() * 1000.0f + 0.5f);
return floorf(field.crosshair_scale() * 1000.0f + 0.5f);
}
#endif