summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2020-09-18 01:09:47 -0700
committer Aaron Giles <aaron@aarongiles.com>2020-09-18 01:09:47 -0700
commit63939050194d3acfdd699e0be0e6da777ddc6ce6 (patch)
tree9ec99afbd191eb106ffcf5973fa29f1734ffa7bb /src/devices/sound
parent13dca2492996bfc8308502abffe9baaf99bb7505 (diff)
gaelco/gb/hc55516/huc620: update to new stream callback
Diffstat (limited to 'src/devices/sound')
-rw-r--r--src/devices/sound/gaelco.cpp15
-rw-r--r--src/devices/sound/gaelco.h2
-rw-r--r--src/devices/sound/gb.cpp25
-rw-r--r--src/devices/sound/gb.h2
-rw-r--r--src/devices/sound/hc55516.cpp40
-rw-r--r--src/devices/sound/hc55516.h10
-rw-r--r--src/devices/sound/huc6230.cpp18
-rw-r--r--src/devices/sound/huc6230.h2
8 files changed, 56 insertions, 58 deletions
diff --git a/src/devices/sound/gaelco.cpp b/src/devices/sound/gaelco.cpp
index 41fbfc0a4c4..d672154b6e9 100644
--- a/src/devices/sound/gaelco.cpp
+++ b/src/devices/sound/gaelco.cpp
@@ -76,10 +76,11 @@ gaelco_gae1_device::gaelco_gae1_device(const machine_config &mconfig, device_typ
Writes length bytes to the sound buffer
============================================================================*/
-void gaelco_gae1_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void gaelco_gae1_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
/* fill all data needed */
- for (int j = 0; j < samples; j++)
+ constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0;
+ for (int j = 0; j < outputs[0].samples(); j++)
{
int output_l = 0, output_r = 0;
@@ -177,12 +178,12 @@ void gaelco_gae1_device::sound_stream_update_legacy(sound_stream &stream, stream
#endif
/* now that we have computed all channels, save current data to the output buffer */
- outputs[0][j] = output_l;
- outputs[1][j] = output_r;
+ outputs[0].put(j, stream_buffer::sample_t(output_l) * sample_scale);
+ outputs[1].put(j, stream_buffer::sample_t(output_r) * sample_scale);
}
- if (wavraw)
- wav_add_data_32lr(wavraw, outputs[0], outputs[1], samples, 0);
+// if (wavraw)
+// wav_add_data_buffer(wavraw, outputs[0], outputs[1]);
}
/*============================================================================
@@ -253,7 +254,7 @@ void gaelco_gae1_device::gaelcosnd_w(offs_t offset, uint16_t data, uint16_t mem_
void gaelco_gae1_device::device_start()
{
u32 rate = clock() / 128;
- m_stream = stream_alloc_legacy(0, 2, rate);
+ m_stream = stream_alloc(0, 2, rate);
/* init volume table */
for (int vol = 0; vol < VOLUME_LEVELS; vol++)
diff --git a/src/devices/sound/gaelco.h b/src/devices/sound/gaelco.h
index 4f7eeaeb7a7..a598c64345d 100644
--- a/src/devices/sound/gaelco.h
+++ b/src/devices/sound/gaelco.h
@@ -43,7 +43,7 @@ protected:
virtual void device_clock_changed() 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;
// device_rom_interface overrides
virtual void rom_bank_updated() override;
diff --git a/src/devices/sound/gb.cpp b/src/devices/sound/gb.cpp
index 42944daf152..9fd9d8d333b 100644
--- a/src/devices/sound/gb.cpp
+++ b/src/devices/sound/gb.cpp
@@ -142,7 +142,7 @@ cgb04_apu_device::cgb04_apu_device(const machine_config &mconfig, const char *ta
void gameboy_sound_device::device_start()
{
- m_channel = stream_alloc_legacy(0, 2, machine().sample_rate());
+ m_channel = stream_alloc(0, 2, SAMPLE_RATE_OUTPUT_ADAPTIVE);
m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gameboy_sound_device::timer_callback),this));
m_timer->adjust(clocks_to_attotime(FRAME_CYCLES/128), 0, clocks_to_attotime(FRAME_CYCLES/128));
@@ -1214,15 +1214,16 @@ void cgb04_apu_device::apu_power_off()
// sound_stream_update_legacy - handle a stream update
//-------------------------------------------------
-void gameboy_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void gameboy_sound_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
- stream_sample_t *outputl = outputs[0];
- stream_sample_t *outputr = outputs[1];
- while (samples-- > 0)
+ auto &outputl = outputs[0];
+ auto &outputr = outputs[1];
+ constexpr stream_buffer::sample_t sample_scale = 1.0 / (32768.0 / 64.0);
+ for (int sampindex = 0; sampindex < outputl.samples(); sampindex++)
{
- stream_sample_t sample;
- stream_sample_t left = 0;
- stream_sample_t right = 0;
+ s32 sample;
+ s32 left = 0;
+ s32 right = 0;
/* Mode 1 - Wave with Envelope and Sweep */
if (m_snd_1.on)
@@ -1269,12 +1270,8 @@ void gameboy_sound_device::sound_stream_update_legacy(sound_stream &stream, stre
left *= m_snd_control.vol_left;
right *= m_snd_control.vol_right;
- /* pump up the volume */
- left <<= 6;
- right <<= 6;
-
/* Update the buffers */
- *outputl++ = left;
- *outputr++ = right;
+ outputl.put(sampindex, stream_buffer::sample_t(left) * sample_scale);
+ outputr.put(sampindex, stream_buffer::sample_t(right) * sample_scale);
}
}
diff --git a/src/devices/sound/gb.h b/src/devices/sound/gb.h
index a0ea67ed0a8..fee26bd8a74 100644
--- a/src/devices/sound/gb.h
+++ b/src/devices/sound/gb.h
@@ -25,7 +25,7 @@ protected:
virtual void device_reset() 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;
protected:
enum
diff --git a/src/devices/sound/hc55516.cpp b/src/devices/sound/hc55516.cpp
index 6397d2c927c..d01c3b86c0c 100644
--- a/src/devices/sound/hc55516.cpp
+++ b/src/devices/sound/hc55516.cpp
@@ -18,7 +18,7 @@
#define FILTER_CHARGE_TC 0.004
#define FILTER_MIN 0.0416
#define FILTER_MAX 1.0954
-#define SAMPLE_GAIN 10000.0
+#define SAMPLE_GAIN (10000.0 / 32768.0)
@@ -115,7 +115,7 @@ void hc55516_device::start_common(uint8_t _shiftreg_mask, int _active_clock_hi)
m_last_clock_state = 0;
/* create the stream */
- m_channel = stream_alloc_legacy(0, 1, SAMPLE_RATE);
+ m_channel = stream_alloc(0, 1, SAMPLE_RATE);
save_item(NAME(m_last_clock_state));
save_item(NAME(m_digit));
@@ -186,11 +186,12 @@ void hc55516_device::process_digit()
temp = integrator * SAMPLE_GAIN;
m_integrator = integrator;
+ m_next_sample = temp;
/* compress the sample range to fit better in a 16-bit word */
- if (temp < 0)
+/* if (temp < 0)
m_next_sample = (int)(temp / (-temp * (1.0 / 32768.0) + 1.0));
else
- m_next_sample = (int)(temp / (temp * (1.0 / 32768.0) + 1.0));
+ m_next_sample = (int)(temp / (temp * (1.0 / 32768.0) + 1.0));*/
}
void hc55516_device::clock_w(int state)
@@ -244,20 +245,15 @@ int hc55516_device::clock_state_r()
// sound_stream_update_legacy - handle a stream update
//-------------------------------------------------
-void hc55516_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void hc55516_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
- stream_sample_t *buffer = outputs[0];
+ auto &buffer = outputs[0];
int i;
- int32_t sample, slope;
-
- /* zero-length? bail */
- if (samples == 0)
- return;
if (!is_external_oscillator())
{
/* track how many samples we've updated without a clock */
- m_update_count += samples;
+ m_update_count += buffer.samples();
if (m_update_count > SAMPLE_RATE / 32)
{
m_update_count = SAMPLE_RATE;
@@ -266,18 +262,18 @@ void hc55516_device::sound_stream_update_legacy(sound_stream &stream, stream_sam
}
/* compute the interpolation slope */
- sample = m_curr_sample;
- slope = ((int32_t)m_next_sample - sample) / samples;
+ stream_buffer::sample_t sample = m_curr_sample;
+ stream_buffer::sample_t slope = (m_next_sample - sample) / buffer.samples();
m_curr_sample = m_next_sample;
if (is_external_oscillator())
{
/* external oscillator */
- for (i = 0; i < samples; i++, sample += slope)
+ for (i = 0; i < buffer.samples(); i++, sample += slope)
{
uint8_t clock_state;
- *buffer++ = sample;
+ buffer.put(i, stream_buffer::sample_t(sample));
m_update_count++;
@@ -297,16 +293,16 @@ void hc55516_device::sound_stream_update_legacy(sound_stream &stream, stream_sam
/* software driven clock */
else
- for (i = 0; i < samples; i++, sample += slope)
- *buffer++ = sample;
+ for (i = 0; i < buffer.samples(); i++, sample += slope)
+ buffer.put(i, stream_buffer::sample_t(sample));
}
-void mc3417_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void mc3417_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
- hc55516_device::sound_stream_update_legacy(stream, inputs, outputs, samples);
+ hc55516_device::sound_stream_update(stream, inputs, outputs);
}
-void mc3418_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void mc3418_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
- hc55516_device::sound_stream_update_legacy(stream, inputs, outputs, samples);
+ hc55516_device::sound_stream_update(stream, inputs, outputs);
}
diff --git a/src/devices/sound/hc55516.h b/src/devices/sound/hc55516.h
index 96284167c52..0948ce025a4 100644
--- a/src/devices/sound/hc55516.h
+++ b/src/devices/sound/hc55516.h
@@ -27,7 +27,7 @@ protected:
virtual void device_reset() 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;
void start_common(uint8_t _shiftreg_mask, int _active_clock_hi);
@@ -41,8 +41,8 @@ protected:
uint8_t m_new_digit;
uint8_t m_shiftreg;
- int16_t m_curr_sample;
- int16_t m_next_sample;
+ stream_buffer::sample_t m_curr_sample;
+ stream_buffer::sample_t m_next_sample;
uint32_t m_update_count;
@@ -70,7 +70,7 @@ 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;
};
@@ -84,7 +84,7 @@ 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;
};
diff --git a/src/devices/sound/huc6230.cpp b/src/devices/sound/huc6230.cpp
index fd2ef5b9689..8c7e9bd91a7 100644
--- a/src/devices/sound/huc6230.cpp
+++ b/src/devices/sound/huc6230.cpp
@@ -21,12 +21,13 @@
constexpr int clamp(int val, int min, int max) { return std::min(max, std::max(min, val)); }
-void huc6230_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void huc6230_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
- for (int i = 0; i < samples; i++)
+ constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0;
+ for (int i = 0; i < outputs[0].samples(); i++)
{
- outputs[0][i] = inputs[0][i];
- outputs[1][i] = inputs[1][i];
+ s32 samp0 = inputs[0].get(i) * 32768.0;
+ s32 samp1 = inputs[1].get(i) * 32768.0;
for (int adpcm = 0; adpcm < 2; adpcm++)
{
@@ -35,9 +36,12 @@ void huc6230_device::sound_stream_update_legacy(sound_stream &stream, stream_sam
if (!channel->m_playing)
continue;
- outputs[0][i] = clamp(outputs[0][i] + ((channel->m_output * channel->m_lvol) >> 3), -32768, 32767);
- outputs[1][i] = clamp(outputs[1][i] + ((channel->m_output * channel->m_rvol) >> 3), -32768, 32767);
+ samp0 = clamp(samp0 + ((channel->m_output * channel->m_lvol) >> 3), -32768, 32767);
+ samp1 = clamp(samp1 + ((channel->m_output * channel->m_rvol) >> 3), -32768, 32767);
}
+
+ outputs[0].put(i, stream_buffer::sample_t(samp0) * sample_scale);
+ outputs[1].put(i, stream_buffer::sample_t(samp1) * sample_scale);
}
}
@@ -172,7 +176,7 @@ void huc6230_device::device_start()
m_vca_cb.resolve_safe();
- m_stream = stream_alloc_legacy(2, 2, clock() / 6);
+ m_stream = stream_alloc(2, 2, clock() / 6);
m_adpcm_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(huc6230_device::adpcm_timer),this));
for (int i = 0; i < 2; i++)
diff --git a/src/devices/sound/huc6230.h b/src/devices/sound/huc6230.h
index 27e67ce41a3..a2ca7824617 100644
--- a/src/devices/sound/huc6230.h
+++ b/src/devices/sound/huc6230.h
@@ -28,7 +28,7 @@ protected:
virtual void device_clock_changed() 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:
struct adpcm_channel {