mirror of
https://github.com/holub/mame
synced 2025-04-19 23:12:11 +03:00
Use std::clamp in more source files
This commit is contained in:
parent
08a0e5af5b
commit
0298e5d6c3
@ -128,8 +128,8 @@ uint8_t sns_rom21_srtc_device::srtc_weekday( uint32_t year, uint32_t month, uint
|
||||
uint32_t sum = 0; // Number of days passed since epoch
|
||||
|
||||
year = std::max(1900U, year);
|
||||
month = std::max(1U, std::min(12U, month));
|
||||
day = std::max(1U, std::min(31U, day));
|
||||
month = std::clamp(month, 1U, 12U);
|
||||
day = std::clamp(day, 1U, 31U);
|
||||
|
||||
while (y < year)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ INPUT_PORTS_END
|
||||
|
||||
uint8_t extract_delta_byte(int32_t &delta)
|
||||
{
|
||||
int32_t const result(std::min<int32_t>(std::max<int32_t>(delta, -120), 127));
|
||||
int32_t const result(std::clamp<int32_t>(delta, -120, 127));
|
||||
delta -= result;
|
||||
return uint8_t(int8_t(result));
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ INPUT_CHANGED_MEMBER( alto2_cpu_device::mouse_motion_x )
|
||||
{
|
||||
int16_t ox = static_cast<int16_t>(oldval);
|
||||
int16_t nx = static_cast<int16_t>(newval);
|
||||
m_mouse.dx = std::min(std::max(0, m_mouse.dx + (nx - ox)), 639);
|
||||
m_mouse.dx = std::clamp(m_mouse.dx + (nx - ox), 0, 639);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,7 +162,7 @@ INPUT_CHANGED_MEMBER( alto2_cpu_device::mouse_motion_y )
|
||||
{
|
||||
int16_t oy = static_cast<int16_t>(oldval);
|
||||
int16_t ny = static_cast<int16_t>(newval);
|
||||
m_mouse.dy = std::min(std::max(0, m_mouse.dy + (ny - oy)), 824);
|
||||
m_mouse.dy = std::clamp(m_mouse.dy + (ny - oy), 0, 824);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1778,7 +1778,7 @@ s64 dsp16_device_base::dau_saturate(u16 a) const
|
||||
if (m_core->dau_auc_sat(a))
|
||||
return m_core->dau_a[a];
|
||||
else
|
||||
return std::min<s64>(std::max<s64>(m_core->dau_a[a], std::numeric_limits<s32>::min()), std::numeric_limits<s32>::max());
|
||||
return std::clamp<s64>(m_core->dau_a[a], std::numeric_limits<s32>::min(), std::numeric_limits<s32>::max());
|
||||
}
|
||||
|
||||
inline bool dsp16_device_base::op_dau_con(u16 op, bool inc)
|
||||
|
@ -22,8 +22,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
static constexpr s32 clip16(int x) { return std::min(32767, std::max(-32768, x)); }
|
||||
static constexpr s32 clip18(int x) { return std::min(131071, std::max(-131072, x)); }
|
||||
static constexpr s32 clip16(int x) { return std::clamp(x, -32768, 32767); }
|
||||
static constexpr s32 clip18(int x) { return std::clamp(x, -131072, 131071); }
|
||||
|
||||
#define SHIFT 12
|
||||
#define FIX(v) ((u32)((float)(1 << SHIFT) * (v)))
|
||||
|
@ -214,9 +214,9 @@ void AICADSP::step()
|
||||
//Shifter
|
||||
s32 SHIFTED = 0; //24 bit
|
||||
if (SHIFT == 0)
|
||||
SHIFTED = std::max<s32>(std::min<s32>(ACC, 0x007FFFFF), -0x00800000);
|
||||
SHIFTED = std::clamp<s32>(ACC, -0x00800000, 0x007FFFFF);
|
||||
else if (SHIFT == 1)
|
||||
SHIFTED = std::max<s32>(std::min<s32>(ACC * 2, 0x007FFFFF), -0x00800000);
|
||||
SHIFTED = std::clamp<s32>(ACC * 2, -0x00800000, 0x007FFFFF);
|
||||
else if (SHIFT == 2)
|
||||
{
|
||||
SHIFTED = ACC * 2;
|
||||
|
@ -171,7 +171,7 @@ double cem3394_device::filter(double input, double cutoff)
|
||||
double cem3394_device::filter(double input, double cutoff)
|
||||
{
|
||||
// clamp cutoff to useful range, 50Hz-20kHz
|
||||
cutoff = std::min(std::max(cutoff, 50.0), 20000.0);
|
||||
cutoff = std::clamp(cutoff, 50.0, 20000.0);
|
||||
|
||||
// clamp resonance to below 1.0 to prevent runaway behavior; when clamping,
|
||||
// also apply an (arbitrary) scale factor to the output since we're close
|
||||
@ -222,7 +222,7 @@ double cem3394_device::filter(double input, double cutoff)
|
||||
double cem3394_device::filter(double input, double cutoff)
|
||||
{
|
||||
// clamp cutoff to useful range, 50Hz-20kHz
|
||||
cutoff = std::min(std::max(cutoff, 50.0), 20000.0);
|
||||
cutoff = std::clamp(cutoff, 50.0, 20000.0);
|
||||
|
||||
// clamp resonance to 0.95 to prevent infinite gain
|
||||
double r = 4.0 * std::min(res, 0.95);
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "emu.h"
|
||||
#include "huc6230.h"
|
||||
|
||||
constexpr int clamp(int val, int min, int max) { return std::min(max, std::max(min, val)); }
|
||||
|
||||
|
||||
void huc6230_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
|
||||
{
|
||||
@ -35,8 +33,8 @@ void huc6230_device::sound_stream_update(sound_stream &stream, std::vector<read_
|
||||
if (!channel->m_playing)
|
||||
continue;
|
||||
|
||||
samp0 = clamp(samp0 + ((channel->m_output * channel->m_lvol) >> 3), -32768, 32767);
|
||||
samp1 = clamp(samp1 + ((channel->m_output * channel->m_rvol) >> 3), -32768, 32767);
|
||||
samp0 = std::clamp(samp0 + ((channel->m_output * channel->m_lvol) >> 3), -32768, 32767);
|
||||
samp1 = std::clamp(samp1 + ((channel->m_output * channel->m_rvol) >> 3), -32768, 32767);
|
||||
}
|
||||
|
||||
outputs[0].put_int(i, samp0, 32768);
|
||||
|
@ -416,7 +416,7 @@ int16_t qsound_hle_device::qsound_voice::update(qsound_hle_device &dsp, int32_t
|
||||
if ((new_phase >> 12) >= m_end_addr)
|
||||
new_phase -= (m_loop_len << 12);
|
||||
|
||||
new_phase = std::min<int32_t>(std::max<int32_t>(new_phase, -0x8000000), 0x7FFFFFF);
|
||||
new_phase = std::clamp<int32_t>(new_phase, -0x8000000, 0x7FFFFFF);
|
||||
m_addr = new_phase >> 12;
|
||||
m_phase = (new_phase << 4)&0xffff;
|
||||
|
||||
@ -465,10 +465,10 @@ int16_t qsound_hle_device::qsound_adpcm::update(qsound_hle_device &dsp, int16_t
|
||||
if (step <= 0)
|
||||
delta = -delta;
|
||||
delta += curr_sample;
|
||||
delta = std::min<int32_t>(std::max<int32_t>(delta, -32768), 32767);
|
||||
delta = std::clamp<int32_t>(delta, -32768, 32767);
|
||||
|
||||
m_step_size = (dsp.read_dsp_rom(DATA_ADPCM_TAB + 8 + step) * m_step_size) >> 6;
|
||||
m_step_size = std::min<int16_t>(std::max<int16_t>(m_step_size, 1), 2000);
|
||||
m_step_size = std::clamp<int16_t>(m_step_size, 1, 2000);
|
||||
|
||||
return (delta * m_cur_vol) >> 16;
|
||||
}
|
||||
@ -504,7 +504,7 @@ void qsound_hle_device::state_normal_update()
|
||||
else
|
||||
m_echo.m_length = m_echo.m_end_pos - DELAY_BASE_OFFSET;
|
||||
|
||||
m_echo.m_length = std::min<int16_t>(std::max<int16_t>(m_echo.m_length, 0), 1024);
|
||||
m_echo.m_length = std::clamp<int16_t>(m_echo.m_length, 0, 1024);
|
||||
|
||||
// update PCM voices
|
||||
int32_t echo_input = 0;
|
||||
@ -534,8 +534,8 @@ void qsound_hle_device::state_normal_update()
|
||||
wet -= (m_voice_output[i] * (int16_t)read_dsp_rom(pan_index + PAN_TABLE_WET));
|
||||
}
|
||||
// Saturate accumulated voices
|
||||
dry = (std::min<int32_t>(std::max<int32_t>(dry, -0x1fffffff), 0x1fffffff)) << 2;
|
||||
wet = (std::min<int32_t>(std::max<int32_t>(wet, -0x1fffffff), 0x1fffffff)) << 2;
|
||||
dry = std::clamp<int32_t>(dry, -0x1fffffff, 0x1fffffff) << 2;
|
||||
wet = std::clamp<int32_t>(wet, -0x1fffffff, 0x1fffffff) << 2;
|
||||
|
||||
// Apply FIR filter on 'wet' input
|
||||
wet = m_filter[ch].apply(wet >> 16);
|
||||
@ -549,7 +549,7 @@ void qsound_hle_device::state_normal_update()
|
||||
|
||||
// DSP round function
|
||||
output = (output + 0x2000) & ~0x3fff;
|
||||
m_out[ch] = (std::min<int32_t>(std::max<int32_t>(output >> 14, -0x7fff), 0x7fff));
|
||||
m_out[ch] = std::clamp<int32_t>(output >> 14, -0x7fff, 0x7fff);
|
||||
|
||||
if (m_delay_update)
|
||||
{
|
||||
|
@ -24,9 +24,6 @@
|
||||
#include "rolandpcm.h"
|
||||
|
||||
|
||||
constexpr int clamp16(int16_t val, int16_t min, int16_t max) { return std::min(max, std::max(min, val)); }
|
||||
|
||||
|
||||
DEFINE_DEVICE_TYPE(MB87419_MB87420, mb87419_mb87420_device, "mb87419_mb87420", "Roland MB87419/MB87420 PCM")
|
||||
|
||||
mb87419_mb87420_device::mb87419_mb87420_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
|
||||
@ -307,7 +304,7 @@ void mb87419_mb87420_device::sound_stream_update(sound_stream &stream, std::vect
|
||||
chn.smpl_nxt += decode_sample((int8_t)read_byte(addr)); // This was verified to be independent from play_dir.
|
||||
|
||||
// until the decoding is fixed, we prevent overflow bugs (due to DC offsets when looping) this way
|
||||
chn.smpl_nxt = clamp16(chn.smpl_nxt, -0x7FF, +0x7FF);
|
||||
chn.smpl_nxt = std::clamp<int16_t>(chn.smpl_nxt, -0x7FF, +0x7FF);
|
||||
}
|
||||
|
||||
bool reachedEnd = false;
|
||||
|
@ -436,13 +436,13 @@ TIMER_CALLBACK_MEMBER(scsp_device::timerC_cb)
|
||||
int scsp_device::Get_AR(int base, int R)
|
||||
{
|
||||
int Rate = base + (R << 1);
|
||||
return m_ARTABLE[std::min(63, std::max(0, Rate))];
|
||||
return m_ARTABLE[std::clamp(Rate, 0, 63)];
|
||||
}
|
||||
|
||||
int scsp_device::Get_DR(int base, int R)
|
||||
{
|
||||
int Rate = base + (R << 1);
|
||||
return m_DRTABLE[std::min(63, std::max(0, Rate))];
|
||||
return m_DRTABLE[std::clamp(Rate, 0, 63)];
|
||||
}
|
||||
|
||||
void scsp_device::Compute_EG(SCSP_SLOT *slot)
|
||||
|
@ -224,9 +224,9 @@ void SCSPDSP::Step()
|
||||
//Shifter
|
||||
s32 SHIFTED = 0; //24 bit
|
||||
if (SHIFT == 0)
|
||||
SHIFTED = std::max<s32>(std::min<s32>(ACC, 0x007FFFFF), -0x00800000);
|
||||
SHIFTED = std::clamp<s32>(ACC, -0x00800000, 0x007FFFFF);
|
||||
else if (SHIFT == 1)
|
||||
SHIFTED = std::max<s32>(std::min<s32>(ACC * 2, 0x007FFFFF), -0x00800000);
|
||||
SHIFTED = std::clamp<s32>(ACC * 2, -0x00800000, 0x007FFFFF);
|
||||
else if (SHIFT == 2)
|
||||
{
|
||||
SHIFTED = ACC * 2;
|
||||
|
@ -2207,7 +2207,7 @@ bool spu_device::update_envelope(const int v)
|
||||
break;
|
||||
|
||||
case 4: // release
|
||||
voice[v].env_level=(std::min)(1.0f,(std::max)(0.0f,voice[v].env_level));
|
||||
voice[v].env_level=std::clamp(voice[v].env_level,0.0f,1.0f);
|
||||
voice[v].env_delta=voice[v].env_rr;
|
||||
if (voice[v].env_rr == -0.0f) // 0.0 release means infinite time
|
||||
{
|
||||
|
@ -275,7 +275,7 @@ void zsg2_device::filter_samples(zchan *ch)
|
||||
ch->emphasis_filter_state += raw_samples[i]-((ch->emphasis_filter_state+EMPHASIS_ROUNDING)>>EMPHASIS_FILTER_SHIFT);
|
||||
|
||||
int32_t sample = ch->emphasis_filter_state >> EMPHASIS_OUTPUT_SHIFT;
|
||||
ch->samples[i+1] = std::min<int32_t>(std::max<int32_t>(sample, -32768), 32767);
|
||||
ch->samples[i+1] = std::clamp<int32_t>(sample, -32768, 32767);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ void vector_device::add_point(int x, int y, rgb_t color, int intensity)
|
||||
{
|
||||
point *newpoint;
|
||||
|
||||
intensity = std::max(0, std::min(255, intensity));
|
||||
intensity = std::clamp(intensity, 0, 255);
|
||||
|
||||
m_min_intensity = intensity > 0 ? std::min(m_min_intensity, intensity) : m_min_intensity;
|
||||
m_max_intensity = intensity > 0 ? std::max(m_max_intensity, intensity) : m_max_intensity;
|
||||
@ -119,7 +119,7 @@ void vector_device::add_point(int x, int y, rgb_t color, int intensity)
|
||||
|
||||
intensity -= (int)(intensity * random * vector_options::s_flicker);
|
||||
|
||||
intensity = std::max(0, std::min(255, intensity));
|
||||
intensity = std::clamp(intensity, 0, 255);
|
||||
}
|
||||
|
||||
newpoint = &m_vector_list[m_vector_index];
|
||||
|
@ -1264,7 +1264,8 @@ std::string &cheat_manager::get_output_string(int row, ui::text_layout::text_jus
|
||||
row = (row < 0) ? (m_numlines + row) : (row - 1);
|
||||
|
||||
// clamp within range
|
||||
row = std::min(std::max(row, 0), m_numlines - 1);
|
||||
assert(m_numlines > 0);
|
||||
row = std::clamp(row, 0, m_numlines - 1);
|
||||
|
||||
// return the appropriate string
|
||||
m_justify[row] = justify;
|
||||
|
@ -306,7 +306,7 @@ protected:
|
||||
// try to load filters from a file
|
||||
if (value && file)
|
||||
{
|
||||
unsigned const cnt(unsigned((std::max)(std::min(int(MAX), std::atoi(value)), 0)));
|
||||
unsigned const cnt(std::clamp<int>(std::atoi(value), 0, MAX));
|
||||
for (unsigned i = 0; cnt > i; ++i)
|
||||
{
|
||||
typename Base::ptr flt(static_cast<Impl &>(*this).create(*file, indent + 1));
|
||||
|
@ -181,13 +181,10 @@ private:
|
||||
|
||||
static int clamp_or_throw(int value, int minimum, int maximum, bool clamp, const char *out_of_range_message)
|
||||
{
|
||||
if (value < minimum || value > maximum)
|
||||
{
|
||||
if (clamp)
|
||||
value = std::min(std::max(value, minimum), maximum);
|
||||
else
|
||||
throw std::out_of_range(out_of_range_message);
|
||||
}
|
||||
if (clamp)
|
||||
value = std::clamp(value, minimum, maximum);
|
||||
else if (value < minimum || value > maximum)
|
||||
throw std::out_of_range(out_of_range_message);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ INPUT_CHANGED_MEMBER(ceres1_state::mouse_x)
|
||||
else if (delta < -0x80)
|
||||
delta += 0x100;
|
||||
|
||||
m_mouse_x = std::max(0, std::min(m_mouse_x + delta, 1023));
|
||||
m_mouse_x = std::clamp(m_mouse_x + delta, 0, 1023);
|
||||
}
|
||||
|
||||
INPUT_CHANGED_MEMBER(ceres1_state::mouse_y)
|
||||
@ -294,7 +294,7 @@ INPUT_CHANGED_MEMBER(ceres1_state::mouse_y)
|
||||
else if (delta < -0x80)
|
||||
delta += 0x100;
|
||||
|
||||
m_mouse_y = std::max(0, std::min(m_mouse_y - delta, 799));
|
||||
m_mouse_y = std::clamp(m_mouse_y - delta, 0, 799);
|
||||
}
|
||||
|
||||
static INPUT_PORTS_START(ceres1)
|
||||
|
@ -164,7 +164,7 @@ static inline u8 get_fade(int c, int f) // same as CPS3?
|
||||
{
|
||||
f &= 0x3f;
|
||||
c = (f & 0x20) ? (c + (((0x1f - c) * (f & 0x1f)) / 0x1f)) : ((c * f) / 0x1f);
|
||||
c = std::max(0, std::min(0x1f, c));
|
||||
c = std::clamp(c, 0, 0x1f);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
@ -113,9 +113,9 @@ void astrocde_state::astrocade_palette(palette_device &palette) const
|
||||
int b = (by + y) * 255;
|
||||
|
||||
// clamp and store
|
||||
r = (std::min)((std::max)(r, 0), 255);
|
||||
g = (std::min)((std::max)(g, 0), 255);
|
||||
b = (std::min)((std::max)(b, 0), 255);
|
||||
r = std::clamp(r, 0, 255);
|
||||
g = std::clamp(g, 0, 255);
|
||||
b = std::clamp(b, 0, 255);
|
||||
palette.set_pen_color(color * 16 + luma, rgb_t(r, g, b));
|
||||
}
|
||||
}
|
||||
|
@ -4319,7 +4319,7 @@ float nv2a_renderer::combiner_map_input_function(Combiner::MapFunction code, flo
|
||||
case 0: // unsigned identity
|
||||
return std::max(0.0f, value);
|
||||
case 1: // unsigned invert
|
||||
return 1.0f - std::min(std::max(value, 0.0f), 1.0f);
|
||||
return 1.0f - std::clamp(value, 0.0f, 1.0f);
|
||||
case 2: // expand normal
|
||||
return 2.0f * std::max(0.0f, value) - 1.0f;
|
||||
case 3: // expand negate
|
||||
@ -4348,9 +4348,9 @@ void nv2a_renderer::combiner_map_input_function_array(Combiner::MapFunction code
|
||||
data[2] = std::max(0.0f, data[2]);
|
||||
break;
|
||||
case 1:
|
||||
data[0] = 1.0f - std::min(std::max(data[0], 0.0f), 1.0f);
|
||||
data[1] = 1.0f - std::min(std::max(data[1], 0.0f), 1.0f);
|
||||
data[2] = 1.0f - std::min(std::max(data[2], 0.0f), 1.0f);
|
||||
data[0] = 1.0f - std::clamp(data[0], 0.0f, 1.0f);
|
||||
data[1] = 1.0f - std::clamp(data[1], 0.0f, 1.0f);
|
||||
data[2] = 1.0f - std::clamp(data[2], 0.0f, 1.0f);
|
||||
break;
|
||||
case 2:
|
||||
data[0] = 2.0f * std::max(0.0f, data[0]) - 1.0f;
|
||||
@ -4697,9 +4697,9 @@ void nv2a_renderer::combiner_compute_rgb_outputs(int id, int stage_number)
|
||||
m = 0;
|
||||
combiner_function_AB(id, combiner.work[id].functions.RGBop1);
|
||||
}
|
||||
combiner.work[id].functions.RGBop1[0] = std::max(std::min((combiner.work[id].functions.RGBop1[0] + bias) * scale, 1.0f), -1.0f);
|
||||
combiner.work[id].functions.RGBop1[1] = std::max(std::min((combiner.work[id].functions.RGBop1[1] + bias) * scale, 1.0f), -1.0f);
|
||||
combiner.work[id].functions.RGBop1[2] = std::max(std::min((combiner.work[id].functions.RGBop1[2] + bias) * scale, 1.0f), -1.0f);
|
||||
combiner.work[id].functions.RGBop1[0] = std::clamp((combiner.work[id].functions.RGBop1[0] + bias) * scale, -1.0f, 1.0f);
|
||||
combiner.work[id].functions.RGBop1[1] = std::clamp((combiner.work[id].functions.RGBop1[1] + bias) * scale, -1.0f, 1.0f);
|
||||
combiner.work[id].functions.RGBop1[2] = std::clamp((combiner.work[id].functions.RGBop1[2] + bias) * scale, -1.0f, 1.0f);
|
||||
// second
|
||||
if (combiner.setup.stage[n].mapout_rgb.CD_dotproduct) {
|
||||
m = m | 1;
|
||||
@ -4707,18 +4707,18 @@ void nv2a_renderer::combiner_compute_rgb_outputs(int id, int stage_number)
|
||||
}
|
||||
else
|
||||
combiner_function_CD(id, combiner.work[id].functions.RGBop2);
|
||||
combiner.work[id].functions.RGBop2[0] = std::max(std::min((combiner.work[id].functions.RGBop2[0] + bias) * scale, 1.0f), -1.0f);
|
||||
combiner.work[id].functions.RGBop2[1] = std::max(std::min((combiner.work[id].functions.RGBop2[1] + bias) * scale, 1.0f), -1.0f);
|
||||
combiner.work[id].functions.RGBop2[2] = std::max(std::min((combiner.work[id].functions.RGBop2[2] + bias) * scale, 1.0f), -1.0f);
|
||||
combiner.work[id].functions.RGBop2[0] = std::clamp((combiner.work[id].functions.RGBop2[0] + bias) * scale, -1.0f, 1.0f);
|
||||
combiner.work[id].functions.RGBop2[1] = std::clamp((combiner.work[id].functions.RGBop2[1] + bias) * scale, -1.0f, 1.0f);
|
||||
combiner.work[id].functions.RGBop2[2] = std::clamp((combiner.work[id].functions.RGBop2[2] + bias) * scale, -1.0f, 1.0f);
|
||||
// third
|
||||
if (m == 0) {
|
||||
if (combiner.setup.stage[n].mapout_rgb.muxsum)
|
||||
combiner_function_ABmuxCD(id, combiner.work[id].functions.RGBop3);
|
||||
else
|
||||
combiner_function_ABsumCD(id, combiner.work[id].functions.RGBop3);
|
||||
combiner.work[id].functions.RGBop3[0] = std::max(std::min((combiner.work[id].functions.RGBop3[0] + bias) * scale, 1.0f), -1.0f);
|
||||
combiner.work[id].functions.RGBop3[1] = std::max(std::min((combiner.work[id].functions.RGBop3[1] + bias) * scale, 1.0f), -1.0f);
|
||||
combiner.work[id].functions.RGBop3[2] = std::max(std::min((combiner.work[id].functions.RGBop3[2] + bias) * scale, 1.0f), -1.0f);
|
||||
combiner.work[id].functions.RGBop3[0] = std::clamp((combiner.work[id].functions.RGBop3[0] + bias) * scale, -1.0f, 1.0f);
|
||||
combiner.work[id].functions.RGBop3[1] = std::clamp((combiner.work[id].functions.RGBop3[1] + bias) * scale, -1.0f, 1.0f);
|
||||
combiner.work[id].functions.RGBop3[2] = std::clamp((combiner.work[id].functions.RGBop3[2] + bias) * scale, -1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4749,10 +4749,10 @@ void nv2a_renderer::combiner_compute_alpha_outputs(int id, int stage_number)
|
||||
}
|
||||
// first
|
||||
combiner.work[id].functions.Aop1 = combiner.work[id].variables.A[3] * combiner.work[id].variables.B[3];
|
||||
combiner.work[id].functions.Aop1 = std::max(std::min((combiner.work[id].functions.Aop1 + bias) * scale, 1.0f), -1.0f);
|
||||
combiner.work[id].functions.Aop1 = std::clamp((combiner.work[id].functions.Aop1 + bias) * scale, -1.0f, 1.0f);
|
||||
// second
|
||||
combiner.work[id].functions.Aop2 = combiner.work[id].variables.C[3] * combiner.work[id].variables.D[3];
|
||||
combiner.work[id].functions.Aop2 = std::max(std::min((combiner.work[id].functions.Aop2 + bias) * scale, 1.0f), -1.0f);
|
||||
combiner.work[id].functions.Aop2 = std::clamp((combiner.work[id].functions.Aop2 + bias) * scale, -1.0f, 1.0f);
|
||||
// third
|
||||
if (combiner.setup.stage[n].mapout_alpha.muxsum) {
|
||||
if (combiner.work[id].registers.spare0[3] >= 0.5f)
|
||||
@ -4762,7 +4762,7 @@ void nv2a_renderer::combiner_compute_alpha_outputs(int id, int stage_number)
|
||||
}
|
||||
else
|
||||
combiner.work[id].functions.Aop3 = combiner.work[id].variables.A[3] * combiner.work[id].variables.B[3] + combiner.work[id].variables.C[3] * combiner.work[id].variables.D[3];
|
||||
combiner.work[id].functions.Aop3 = std::max(std::min((combiner.work[id].functions.Aop3 + bias) * scale, 1.0f), -1.0f);
|
||||
combiner.work[id].functions.Aop3 = std::clamp((combiner.work[id].functions.Aop3 + bias) * scale, -1.0f, 1.0f);
|
||||
}
|
||||
|
||||
WRITE_LINE_MEMBER(nv2a_renderer::vblank_callback)
|
||||
|
@ -1098,9 +1098,9 @@ rgb_t shaders::apply_color_convolution(rgb_t color)
|
||||
b = chroma[2] * saturation + luma;
|
||||
|
||||
return rgb_t(
|
||||
std::max(0, std::min(255, int(r * 255.0f))),
|
||||
std::max(0, std::min(255, int(g * 255.0f))),
|
||||
std::max(0, std::min(255, int(b * 255.0f))));
|
||||
std::clamp(int(r * 255.0f), 0, 255),
|
||||
std::clamp(int(g * 255.0f), 0, 255),
|
||||
std::clamp(int(b * 255.0f), 0, 255));
|
||||
}
|
||||
|
||||
int shaders::color_convolution_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
|
||||
|
@ -83,7 +83,7 @@ private:
|
||||
EFFECT_COUNT_MAX = 10
|
||||
};
|
||||
|
||||
uint32_t clamped_latency() const { return unsigned(std::max(std::min(m_audio_latency, int(LATENCY_MAX)), int(LATENCY_MIN))); }
|
||||
uint32_t clamped_latency() const { return unsigned(std::clamp<int>(m_audio_latency, LATENCY_MIN, LATENCY_MAX)); }
|
||||
uint32_t buffer_avail() const { return ((m_writepos >= m_playpos) ? m_buffer_size : 0) + m_playpos - m_writepos; }
|
||||
uint32_t buffer_used() const { return ((m_playpos > m_writepos) ? m_buffer_size : 0) + m_writepos - m_playpos; }
|
||||
|
||||
@ -320,7 +320,7 @@ void sound_coreaudio::update_audio_stream(bool is_throttled, int16_t const *buff
|
||||
|
||||
void sound_coreaudio::set_mastervolume(int attenuation)
|
||||
{
|
||||
int const clamped_attenuation = std::max(std::min(attenuation, 0), -32);
|
||||
int const clamped_attenuation = std::clamp(attenuation, -32, 0);
|
||||
m_scale = (-32 == clamped_attenuation) ? 0 : (int32_t)(pow(10.0, clamped_attenuation / 20.0) * 128);
|
||||
}
|
||||
|
||||
|
@ -359,7 +359,7 @@ void sound_direct_sound::update_audio_stream(
|
||||
void sound_direct_sound::set_mastervolume(int attenuation)
|
||||
{
|
||||
// clamp the attenuation to 0-32 range
|
||||
attenuation = std::max(std::min(attenuation, 0), -32);
|
||||
attenuation = std::clamp(attenuation, -32, 0);
|
||||
|
||||
// set the master volume
|
||||
if (m_stream_buffer)
|
||||
|
@ -192,7 +192,7 @@ int sound_pa::init(osd_options const &options)
|
||||
m_skip_threshold_ticks = 0;
|
||||
m_osd_tps = osd_ticks_per_second();
|
||||
m_buffer_min_ct = INT_MAX;
|
||||
m_audio_latency = std::min<int>(std::max<int>(m_audio_latency, LATENCY_MIN), LATENCY_MAX);
|
||||
m_audio_latency = std::clamp<int>(m_audio_latency, LATENCY_MIN, LATENCY_MAX);
|
||||
|
||||
try {
|
||||
m_ab = new audio_buffer<s16>(m_sample_rate, 2);
|
||||
|
@ -284,7 +284,7 @@ void sound_sdl::update_audio_stream(bool is_throttled, const int16_t *buffer, in
|
||||
void sound_sdl::set_mastervolume(int _attenuation)
|
||||
{
|
||||
// clamp the attenuation to 0-32 range
|
||||
attenuation = std::max(std::min(_attenuation, 0), -32);
|
||||
attenuation = std::clamp(_attenuation, -32, 0);
|
||||
|
||||
if (stream_in_initialized)
|
||||
{
|
||||
@ -373,7 +373,7 @@ int sound_sdl::init(const osd_options &options)
|
||||
sdl_xfer_samples = obtained.samples;
|
||||
|
||||
// pin audio latency
|
||||
audio_latency = std::max(std::min(m_audio_latency, MAX_AUDIO_LATENCY), 1);
|
||||
audio_latency = std::clamp(m_audio_latency, 1, MAX_AUDIO_LATENCY);
|
||||
|
||||
// compute the buffer sizes
|
||||
stream_buffer_size = (sample_rate() * 2 * sizeof(int16_t) * (2 + audio_latency)) / 30;
|
||||
|
@ -419,7 +419,7 @@ void sound_xaudio2::set_mastervolume(int attenuation)
|
||||
HRESULT result;
|
||||
|
||||
// clamp the attenuation to 0-32 range
|
||||
attenuation = std::max(std::min(attenuation, 0), -32);
|
||||
attenuation = std::clamp(attenuation, -32, 0);
|
||||
|
||||
// Ranges from 1.0 to XAUDIO2_MAX_VOLUME_LEVEL indicate additional gain
|
||||
// Ranges from 0 to 1.0 indicate a reduced volume level
|
||||
|
Loading…
Reference in New Issue
Block a user