summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatarGravatar Aaron Giles <aaron@aarongiles.com>2020-09-30 21:12:20 -0700
committerGravatarGravatar Aaron Giles <aaron@aarongiles.com>2020-09-30 21:12:20 -0700
commit4b0e38daa2e74ad39888b0c675fd55d89721efaa (patch)
treeab90b0800d5b84f1e87601a82d01ba029df08497
parent21d4cfac03c2868201abe6b9b2a3db1a4a9ca0ab (diff)
ymfm: Take advantage of new stream callback features.fmrewrite
-rw-r--r--src/devices/sound/ym2151.cpp13
-rw-r--r--src/devices/sound/ym2203.cpp11
-rw-r--r--src/devices/sound/ym2608.cpp13
-rw-r--r--src/devices/sound/ym2610.cpp13
-rw-r--r--src/devices/sound/ym2612.cpp25
5 files changed, 19 insertions, 56 deletions
diff --git a/src/devices/sound/ym2151.cpp b/src/devices/sound/ym2151.cpp
index 9ea9f18b826..2917e24b5d7 100644
--- a/src/devices/sound/ym2151.cpp
+++ b/src/devices/sound/ym2151.cpp
@@ -49,14 +49,9 @@ inline s16 linear_to_fp(s32 value)
// clamping
//-------------------------------------------------
-inline stream_buffer::sample_t fp_to_linear(s16 value)
+inline s32 fp_to_linear(s16 value)
{
- s32 result = (value >> 3) << BIT(value, 0, 3);
- if (result < -32768)
- result = -32768;
- else if (result > 32767)
- result = 32767;
- return stream_buffer::sample_t(result) * (1.0 / 32768.0);
+ return (value >> 3) << BIT(value, 0, 3);
}
@@ -218,8 +213,8 @@ void ym2151_device::sound_stream_update(sound_stream &stream, std::vector<read_s
// convert to 10.3 floating point value for the DAC and back
// OPN is mono, so only the left sum matters
- outputs[0].put(sampindex, fp_to_linear(linear_to_fp(lsum)));
- outputs[1].put(sampindex, fp_to_linear(linear_to_fp(rsum)));
+ outputs[0].put_int_clamp(sampindex, fp_to_linear(linear_to_fp(lsum)), 32768);
+ outputs[1].put_int_clamp(sampindex, fp_to_linear(linear_to_fp(rsum)), 32768);
}
}
diff --git a/src/devices/sound/ym2203.cpp b/src/devices/sound/ym2203.cpp
index 4ef27f47a8d..949c281ee53 100644
--- a/src/devices/sound/ym2203.cpp
+++ b/src/devices/sound/ym2203.cpp
@@ -47,14 +47,9 @@ inline s16 linear_to_fp(s32 value)
// clamping
//-------------------------------------------------
-inline stream_buffer::sample_t fp_to_linear(s16 value)
+inline s32 fp_to_linear(s16 value)
{
- s32 result = (value >> 3) << BIT(value, 0, 3);
- if (result < -32768)
- result = -32768;
- else if (result > 32767)
- result = 32767;
- return stream_buffer::sample_t(result) * (1.0 / 32768.0);
+ return (value >> 3) << BIT(value, 0, 3);
}
@@ -213,7 +208,7 @@ void ym2203_device::sound_stream_update(sound_stream &stream, std::vector<read_s
// convert to 10.3 floating point value for the DAC and back
// OPN is mono, so only the left sum matters
- outputs[0].put(sampindex, fp_to_linear(linear_to_fp(lsum)));
+ outputs[0].put_int_clamp(sampindex, fp_to_linear(linear_to_fp(lsum)), 32768);
}
}
diff --git a/src/devices/sound/ym2608.cpp b/src/devices/sound/ym2608.cpp
index 9e39679185d..165fc6cc299 100644
--- a/src/devices/sound/ym2608.cpp
+++ b/src/devices/sound/ym2608.cpp
@@ -290,7 +290,6 @@ void ym2608_device::sound_stream_update(sound_stream &stream, std::vector<read_s
u8 opnmask = BIT(m_irq_enable, 7) ? 0x3f : 0x07;
// iterate over all target samples
- constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0;
for (int sampindex = 0; sampindex < outputs[0].samples(); sampindex++)
{
// clock the OPN
@@ -315,16 +314,8 @@ void ym2608_device::sound_stream_update(sound_stream &stream, std::vector<read_s
m_adpcm_b.output(lsum, rsum, 2, 0x01);
// YM2608 is stereo
- if (lsum < -32768)
- lsum = -32768;
- else if (lsum > 32767)
- lsum = 32767;
- if (rsum < -32768)
- rsum = -32768;
- else if (rsum > 32767)
- rsum = 32767;
- outputs[0].put(sampindex, lsum * sample_scale);
- outputs[1].put(sampindex, rsum * sample_scale);
+ outputs[0].put_int_clamp(sampindex, lsum, 32768);
+ outputs[1].put_int_clamp(sampindex, rsum, 32768);
}
}
diff --git a/src/devices/sound/ym2610.cpp b/src/devices/sound/ym2610.cpp
index f20c9ce8a00..f7fb266c43b 100644
--- a/src/devices/sound/ym2610.cpp
+++ b/src/devices/sound/ym2610.cpp
@@ -261,7 +261,6 @@ void ym2610_device::sound_stream_update(sound_stream &stream, std::vector<read_s
}
// iterate over all target samples
- constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0;
for (int sampindex = 0; sampindex < outputs[0].samples(); sampindex++)
{
// clock the OPN
@@ -287,16 +286,8 @@ void ym2610_device::sound_stream_update(sound_stream &stream, std::vector<read_s
m_adpcm_b.output(lsum, rsum, 2, 0x01);
// YM2608 is stereo
- if (lsum < -32768)
- lsum = -32768;
- else if (lsum > 32767)
- lsum = 32767;
- if (rsum < -32768)
- rsum = -32768;
- else if (rsum > 32767)
- rsum = 32767;
- outputs[0].put(sampindex, stream_buffer::sample_t(lsum) * sample_scale);
- outputs[1].put(sampindex, stream_buffer::sample_t(rsum) * sample_scale);
+ outputs[0].put_int_clamp(sampindex, lsum, 32768);
+ outputs[1].put_int_clamp(sampindex, rsum, 32768);
}
}
diff --git a/src/devices/sound/ym2612.cpp b/src/devices/sound/ym2612.cpp
index 348899af649..1d945978f54 100644
--- a/src/devices/sound/ym2612.cpp
+++ b/src/devices/sound/ym2612.cpp
@@ -188,8 +188,7 @@ void ym2612_device::sound_stream_update(sound_stream &stream, std::vector<read_s
void ym2612_device::sound_stream_update_common(write_stream_view &outl, write_stream_view &outr, bool discontinuity)
{
- constexpr stream_buffer::sample_t sample_divider = MULTIPLEX_YM2612_YM3438_OUTPUT ? 1.0 : 6.0;
- stream_buffer::sample_t sample_scale = 1.0 / (sample_divider * (discontinuity ? 260.0 : 256.0));
+ u32 const sample_divider = (discontinuity ? 260 : 256) * (MULTIPLEX_YM2612_YM3438_OUTPUT ? 1 : 6);
// iterate over all target samples
s32 lsum = 0, rsum = 0;
@@ -225,9 +224,10 @@ void ym2612_device::sound_stream_update_common(write_stream_view &outl, write_st
// if multiplexing, just scale to 16 bits and output
if (MULTIPLEX_YM2612_YM3438_OUTPUT)
{
- outl.put(sampindex, stream_buffer::sample_t(lchan) * sample_scale);
- outr.put(sampindex, stream_buffer::sample_t(rchan) * sample_scale);
+ outl.put_int(sampindex, lchan, sample_divider);
+ outr.put_int(sampindex, rchan, sample_divider);
sampindex++;
+ lsum = rsum = 0;
}
// if not, accumulate the sums
@@ -239,8 +239,8 @@ void ym2612_device::sound_stream_update_common(write_stream_view &outl, write_st
// on the last channel, output the average and reset the sums
if (m_channel == 5)
{
- outl.put(sampindex, stream_buffer::sample_t(lsum) * sample_scale);
- outr.put(sampindex, stream_buffer::sample_t(rsum) * sample_scale);
+ outl.put_int(sampindex, lsum, sample_divider);
+ outr.put_int(sampindex, rsum, sample_divider);
sampindex++;
lsum = rsum = 0;
}
@@ -314,7 +314,6 @@ void ymf276_device::sound_stream_update(sound_stream &stream, std::vector<read_s
u8 const opn_mask = m_dac_enable ? 0x1f : 0x3f;
// iterate over all target samples
- constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0;
for (int sampindex = 0; sampindex < outputs[0].samples(); sampindex++)
{
// clock the OPN
@@ -336,16 +335,8 @@ void ymf276_device::sound_stream_update(sound_stream &stream, std::vector<read_s
}
// YMF3438 is stereo
- if (lsum < -32768)
- lsum = -32768;
- else if (lsum > 32767)
- lsum = 32767;
- if (rsum < -32768)
- rsum = -32768;
- else if (rsum > 32767)
- rsum = 32767;
- outputs[0].put(sampindex, stream_buffer::sample_t(lsum) * sample_scale);
- outputs[1].put(sampindex, stream_buffer::sample_t(rsum) * sample_scale);
+ outputs[0].put_int_clamp(sampindex, lsum, 32768);
+ outputs[1].put_int_clamp(sampindex, rsum, 32768);
}
}