summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2020-09-17 22:27:11 -0700
committer Aaron Giles <aaron@aarongiles.com>2020-09-17 22:27:31 -0700
commitacd6195487291f1b7107bc9012198fb8f91af5a0 (patch)
tree71bdc8b6bea41e2e3b11625658020b6102dcb9fa
parentb506c0a7a1d223cd5df8894d6d4cbc3d82ea38b9 (diff)
flt_rc/flt_vol: update to new stream callbacks
-rw-r--r--src/devices/sound/flt_rc.cpp45
-rw-r--r--src/devices/sound/flt_rc.h9
-rw-r--r--src/devices/sound/flt_vol.cpp16
-rw-r--r--src/devices/sound/flt_vol.h4
4 files changed, 40 insertions, 34 deletions
diff --git a/src/devices/sound/flt_rc.cpp b/src/devices/sound/flt_rc.cpp
index 8de64b37a40..cb6b4940681 100644
--- a/src/devices/sound/flt_rc.cpp
+++ b/src/devices/sound/flt_rc.cpp
@@ -23,6 +23,7 @@ filter_rc_device::filter_rc_device(const machine_config &mconfig, const char *ta
m_k(0),
m_memory(0),
m_type(LOWPASS),
+ m_last_sample_rate(0),
m_R1(1),
m_R2(1),
m_R3(1),
@@ -37,8 +38,8 @@ filter_rc_device::filter_rc_device(const machine_config &mconfig, const char *ta
void filter_rc_device::device_start()
{
- m_stream = stream_alloc_legacy(1, 1, machine().sample_rate());
- recalc();
+ m_stream = stream_alloc(1, 1, SAMPLE_RATE_OUTPUT_ADAPTIVE);
+ m_last_sample_rate = 0;
save_item(NAME(m_k));
save_item(NAME(m_memory));
@@ -54,28 +55,34 @@ void filter_rc_device::device_start()
// sound_stream_update_legacy - handle a stream update
//-------------------------------------------------
-void filter_rc_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void filter_rc_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
- stream_sample_t const *src = inputs[0];
- stream_sample_t *dst = outputs[0];
- int memory = m_memory;
+ auto &src = inputs[0];
+ auto &dst = outputs[0];
+ stream_buffer::sample_t memory = m_memory;
+
+ if (m_last_sample_rate != m_stream->sample_rate())
+ {
+ recalc();
+ m_last_sample_rate = m_stream->sample_rate();
+ }
switch (m_type)
{
case LOWPASS:
case LOWPASS_2C:
- while (samples--)
+ for (int sampindex = 0; sampindex < dst.samples(); sampindex++)
{
- memory += ((*src++ - memory) * m_k) / 0x10000;
- *dst++ = memory;
+ memory += (src.get(sampindex) - memory) * m_k;
+ dst.put(sampindex, memory);
}
break;
case HIGHPASS:
case AC:
- while (samples--)
+ for (int sampindex = 0; sampindex < dst.samples(); sampindex++)
{
- *dst++ = *src - memory;
- memory += ((*src++ - memory) * m_k) / 0x10000;
+ dst.put(sampindex, src.get(sampindex) - memory);
+ memory += (src.get(sampindex) - memory) * m_k;
}
break;
}
@@ -93,8 +100,8 @@ void filter_rc_device::recalc()
if (m_C == 0.0)
{
/* filter disabled */
- m_k = 0x10000;
- m_memory = 0x0;
+ m_k = 1.0;
+ m_memory = 0;
return;
}
Req = (m_R1 * (m_R2 + m_R3)) / (m_R1 + m_R2 + m_R3);
@@ -103,8 +110,8 @@ void filter_rc_device::recalc()
if (m_C == 0.0)
{
/* filter disabled */
- m_k = 0x10000;
- m_memory = 0x0;
+ m_k = 1.0;
+ m_memory = 0;
return;
}
Req = m_R1;
@@ -114,8 +121,8 @@ void filter_rc_device::recalc()
if (m_C == 0.0)
{
/* filter disabled */
- m_k = 0x0;
- m_memory = 0x0;
+ m_k = 0;
+ m_memory = 0;
return;
}
Req = m_R1;
@@ -126,5 +133,5 @@ void filter_rc_device::recalc()
/* Cut Frequency = 1/(2*Pi*Req*C) */
/* k = (1-(EXP(-TIMEDELTA/RC))) */
- m_k = 0x10000 - 0x10000 * (exp(-1 / (Req * m_C) / machine().sample_rate()));
+ m_k = 1.0 - exp(-1 / (Req * m_C) / m_stream->sample_rate());
}
diff --git a/src/devices/sound/flt_rc.h b/src/devices/sound/flt_rc.h
index 9c1bc7f3381..d06d0ff75d1 100644
--- a/src/devices/sound/flt_rc.h
+++ b/src/devices/sound/flt_rc.h
@@ -95,7 +95,7 @@ public:
{
m_stream->update();
set_rc(type, R1, R2, R3, C);
- recalc();
+ m_last_sample_rate = 0;
return *this;
}
@@ -109,16 +109,17 @@ protected:
virtual void device_start() override;
// sound stream update overrides
- virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override;
+ virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
private:
void recalc();
private:
sound_stream* m_stream;
- int m_k;
- int m_memory;
+ stream_buffer::sample_t m_k;
+ stream_buffer::sample_t m_memory;
int m_type;
+ int m_last_sample_rate;
double m_R1;
double m_R2;
double m_R3;
diff --git a/src/devices/sound/flt_vol.cpp b/src/devices/sound/flt_vol.cpp
index 8b8438f9b94..e43da0a1ee6 100644
--- a/src/devices/sound/flt_vol.cpp
+++ b/src/devices/sound/flt_vol.cpp
@@ -27,21 +27,19 @@ filter_volume_device::filter_volume_device(const machine_config &mconfig, const
void filter_volume_device::device_start()
{
m_gain = 0x100;
- m_stream = stream_alloc_legacy(1, 1, machine().sample_rate());
+ m_stream = stream_alloc(1, 1, SAMPLE_RATE_OUTPUT_ADAPTIVE);
}
//-------------------------------------------------
-// sound_stream_update_legacy - handle a stream update
+// sound_stream_update - handle a stream update
//-------------------------------------------------
-void filter_volume_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void filter_volume_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
- stream_sample_t const *src = inputs[0];
- stream_sample_t *dst = outputs[0];
-
- while (samples--)
- *dst++ = (*src++ * m_gain) >> 8;
+ // no need to work here; just copy input stream to output and apply gain
+ outputs[0] = inputs[0];
+ outputs[0].apply_gain(m_gain);
}
@@ -49,5 +47,5 @@ void filter_volume_device::sound_stream_update_legacy(sound_stream &stream, stre
void filter_volume_device::flt_volume_set_volume(float volume)
{
m_stream->update();
- m_gain = int(volume * 256);
+ m_gain = volume;
}
diff --git a/src/devices/sound/flt_vol.h b/src/devices/sound/flt_vol.h
index 034c3a3cf79..6a3bdab17d5 100644
--- a/src/devices/sound/flt_vol.h
+++ b/src/devices/sound/flt_vol.h
@@ -24,11 +24,11 @@ protected:
virtual void device_start() override;
// sound stream update overrides
- virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override;
+ virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
private:
sound_stream* m_stream;
- int m_gain;
+ stream_buffer::sample_t m_gain;
};
DECLARE_DEVICE_TYPE(FILTER_VOLUME, filter_volume_device)