okim6258/okim6376/okim9810/pcd3311/qs1000/qsound: update to new stream callbacks

This commit is contained in:
Aaron Giles 2020-09-20 21:12:33 -07:00
parent 69cc7e883c
commit 7704e21dc6
12 changed files with 53 additions and 63 deletions

View File

@ -114,7 +114,7 @@ void okim6258_device::device_start()
m_divider = dividers[m_start_divider]; m_divider = dividers[m_start_divider];
m_stream = stream_alloc_legacy(0, 1, clock()/m_divider); m_stream = stream_alloc(0, 1, clock()/m_divider);
m_signal = -2; m_signal = -2;
m_step = 0; m_step = 0;
@ -141,17 +141,15 @@ void okim6258_device::device_reset()
// sound_stream_update_legacy - handle a stream update // sound_stream_update_legacy - handle a stream update
//------------------------------------------------- //-------------------------------------------------
void okim6258_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) void okim6258_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];
memset(outputs[0], 0, samples * sizeof(*outputs[0]));
if (m_status & STATUS_PLAYING) if (m_status & STATUS_PLAYING)
{ {
int nibble_shift = m_nibble_shift; int nibble_shift = m_nibble_shift;
while (samples) for (int sampindex = 0; sampindex < buffer.samples(); sampindex++)
{ {
/* Compute the new amplitude and update the current step */ /* Compute the new amplitude and update the current step */
int nibble = (m_data_in >> nibble_shift) & 0xf; int nibble = (m_data_in >> nibble_shift) & 0xf;
@ -161,8 +159,7 @@ void okim6258_device::sound_stream_update_legacy(sound_stream &stream, stream_sa
nibble_shift ^= 4; nibble_shift ^= 4;
*buffer++ = sample; buffer.put_int(sampindex, sample, 32768);
samples--;
} }
/* Update the parameters */ /* Update the parameters */
@ -170,9 +167,7 @@ void okim6258_device::sound_stream_update_legacy(sound_stream &stream, stream_sa
} }
else else
{ {
/* Fill with 0 */ buffer.fill(0);
while (samples--)
*buffer++ = 0;
} }
} }

View File

@ -47,7 +47,7 @@ protected:
virtual void device_clock_changed() override; virtual void device_clock_changed() override;
// sound stream update overrides // 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: private:
void state_save_register(); void state_save_register();

View File

@ -169,7 +169,7 @@ void okim6376_device::device_start()
m_ch2_update = 0; m_ch2_update = 0;
m_st_pulses = 0; m_st_pulses = 0;
/* generate the name and create the stream */ /* generate the name and create the stream */
m_stream = stream_alloc_legacy(0, 1, get_sample_rate()); m_stream = stream_alloc(0, 1, get_sample_rate());
/* initialize the voices */ /* initialize the voices */
for (voice = 0; voice < OKIM6376_VOICES; voice++) for (voice = 0; voice < OKIM6376_VOICES; voice++)
@ -578,21 +578,18 @@ void okim6376_device::write(uint8_t data)
} }
//------------------------------------------------- //-------------------------------------------------
// sound_stream_update_legacy - handle a stream update // sound_stream_update - handle a stream update
//------------------------------------------------- //-------------------------------------------------
void okim6376_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) void okim6376_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{ {
int i; outputs[0].fill(0);
memset(outputs[0], 0, samples * sizeof(*outputs[0])); for (int i = 0; i < OKIM6376_VOICES; i++)
for (i = 0; i < OKIM6376_VOICES; i++)
{ {
struct ADPCMVoice *voice = &m_voice[i]; struct ADPCMVoice *voice = &m_voice[i];
stream_sample_t *buffer = outputs[0]; auto &buffer = outputs[0];
int16_t sample_data[MAX_SAMPLE_CHUNK]; int16_t sample_data[MAX_SAMPLE_CHUNK];
int remaining = samples;
if (i == 0) //channel 1 is the only channel to affect NAR if (i == 0) //channel 1 is the only channel to affect NAR
{ {
if (m_nartimer > 0) if (m_nartimer > 0)
@ -606,16 +603,16 @@ void okim6376_device::sound_stream_update_legacy(sound_stream &stream, stream_sa
} }
/* loop while we have samples remaining */ /* loop while we have samples remaining */
while (remaining) for (int sampindex = 0; sampindex < buffer.samples(); )
{ {
int remaining = buffer.samples() - sampindex;
int samples = (remaining > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : remaining; int samples = (remaining > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : remaining;
int samp;
generate_adpcm(voice, sample_data, samples,i); generate_adpcm(voice, sample_data, samples,i);
for (samp = 0; samp < samples; samp++) for (int samp = 0; samp < samples; samp++)
*buffer++ += sample_data[samp]; buffer.add_int(sampindex + samp, sample_data[samp], 32768);
remaining -= samples; sampindex += samples;
} }
} }
} }

View File

@ -32,7 +32,7 @@ protected:
virtual void device_post_load() override; virtual void device_post_load() override;
// sound stream update overrides // 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 // device_rom_interface overrides
virtual void rom_bank_updated() override; virtual void rom_bank_updated() override;

View File

@ -112,7 +112,7 @@ okim9810_device::okim9810_device(const machine_config &mconfig, const char *tag,
void okim9810_device::device_start() void okim9810_device::device_start()
{ {
// create the stream // create the stream
m_stream = stream_alloc_legacy(0, 2, clock()); m_stream = stream_alloc(0, 2, clock());
// save state stuff // save state stuff
save_item(NAME(m_TMP_register)); save_item(NAME(m_TMP_register));
@ -214,15 +214,15 @@ void okim9810_device::rom_bank_updated()
// our sound stream // our sound stream
//------------------------------------------------- //-------------------------------------------------
void okim9810_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) void okim9810_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{ {
// reset the output streams // reset the output streams
memset(outputs[0], 0, samples * sizeof(*outputs[0])); outputs[0].fill(0);
memset(outputs[1], 0, samples * sizeof(*outputs[1])); outputs[1].fill(0);
// iterate over voices and accumulate sample data // iterate over voices and accumulate sample data
for (auto & elem : m_voice) for (auto & elem : m_voice)
elem.generate_audio(*this, outputs, samples, m_global_volume, m_filter_type); elem.generate_audio(*this, outputs, m_global_volume, m_filter_type);
} }
@ -613,8 +613,7 @@ okim9810_device::okim_voice::okim_voice()
//------------------------------------------------- //-------------------------------------------------
void okim9810_device::okim_voice::generate_audio(device_rom_interface &rom, void okim9810_device::okim_voice::generate_audio(device_rom_interface &rom,
stream_sample_t * const *buffers, std::vector<write_stream_view> &outputs,
int samples,
const uint8_t global_volume, const uint8_t global_volume,
const uint8_t filter_type) const uint8_t filter_type)
{ {
@ -623,8 +622,8 @@ void okim9810_device::okim_voice::generate_audio(device_rom_interface &rom,
return; return;
// separate out left and right channels // separate out left and right channels
stream_sample_t *outL = buffers[0]; auto &outL = outputs[0];
stream_sample_t *outR = buffers[1]; auto &outR = outputs[1];
// get left and right volumes // get left and right volumes
uint8_t volume_scale_left = volume_scale(global_volume, m_channel_volume, m_pan_volume_left); uint8_t volume_scale_left = volume_scale(global_volume, m_channel_volume, m_pan_volume_left);
@ -636,7 +635,7 @@ void okim9810_device::okim_voice::generate_audio(device_rom_interface &rom,
return; return;
// loop while we still have samples to generate // loop while we still have samples to generate
while (samples-- != 0) for (int sampindex = 0; sampindex < outL.samples(); sampindex++)
{ {
// If interpSampleNum == 0, we are at the beginning of a new interp chunk, gather data // If interpSampleNum == 0, we are at the beginning of a new interp chunk, gather data
if (m_interpSampleNum == 0) if (m_interpSampleNum == 0)
@ -747,11 +746,11 @@ void okim9810_device::okim_voice::generate_audio(device_rom_interface &rom,
// output to the stereo buffers, scaling by the volume // output to the stereo buffers, scaling by the volume
// signal in range -2048..2047, volume in range 2..128 => signal * volume / 8 in range -32768..32767 // signal in range -2048..2047, volume in range 2..128 => signal * volume / 8 in range -32768..32767
int32_t interpValueL = (interpValue * (int32_t)volume_scale_left) / 8; int32_t interpValueL = (interpValue * (int32_t)volume_scale_left);
*outL++ += interpValueL; outL.add_int(sampindex, interpValueL, 32768 * 8);
int32_t interpValueR = (interpValue * (int32_t)volume_scale_right) / 8; int32_t interpValueR = (interpValue * (int32_t)volume_scale_right);
*outR++ += interpValueR; outR.add_int(sampindex, interpValueR, 32768 * 8);
// if the interpsample has reached its end, move on to the next sample // if the interpsample has reached its end, move on to the next sample
m_interpSampleNum++; m_interpSampleNum++;

View File

@ -87,7 +87,7 @@ protected:
virtual void device_clock_changed() override; virtual void device_clock_changed() override;
// device_sound_interface overrides // device_sound_interface 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 // device_rom_interface overrides
virtual void rom_bank_updated() override; virtual void rom_bank_updated() override;
@ -98,8 +98,7 @@ protected:
public: public:
okim_voice(); okim_voice();
void generate_audio(device_rom_interface &rom, void generate_audio(device_rom_interface &rom,
stream_sample_t * const *buffers, std::vector<write_stream_view> &buffers,
int samples,
const uint8_t global_volume, const uint8_t global_volume,
const uint8_t filter_type); const uint8_t filter_type);

View File

@ -52,6 +52,6 @@ void pcd3311_device::device_start()
// our sound stream // our sound stream
//------------------------------------------------- //-------------------------------------------------
void pcd3311_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) void pcd3311_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{ {
} }

View File

@ -48,7 +48,7 @@ protected:
virtual void device_start() override; virtual void device_start() override;
// internal callbacks // internal callbacks
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: private:
int m_a0; int m_a0;

View File

@ -229,7 +229,7 @@ void qs1000_device::device_start()
// The QS1000 operates at 24MHz. Creating a stream at that rate // The QS1000 operates at 24MHz. Creating a stream at that rate
// would be overkill so we opt for a fraction of that rate which // would be overkill so we opt for a fraction of that rate which
// gives reasonable results // gives reasonable results
m_stream = stream_alloc_legacy(0, 2, clock() / 32); m_stream = stream_alloc(0, 2, clock() / 32);
// Resolve CPU port callbacks // Resolve CPU port callbacks
m_in_p1_cb.resolve_safe(0); m_in_p1_cb.resolve_safe(0);
@ -468,11 +468,11 @@ void qs1000_device::wave_w(offs_t offset, uint8_t data)
//------------------------------------------------- //-------------------------------------------------
// sound_stream_update_legacy - // sound_stream_update_legacy -
//------------------------------------------------- //-------------------------------------------------
void qs1000_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) void qs1000_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{ {
// Rset the output stream // Rset the output stream
memset(outputs[0], 0x0, samples * sizeof(*outputs[0])); outputs[0].fill(0);
memset(outputs[1], 0x0, samples * sizeof(*outputs[1])); outputs[1].fill(0);
// Iterate over voices and accumulate sample data // Iterate over voices and accumulate sample data
for (auto & chan : m_channels) for (auto & chan : m_channels)
@ -485,7 +485,7 @@ void qs1000_device::sound_stream_update_legacy(sound_stream &stream, stream_samp
{ {
if (chan.m_flags & QS1000_ADPCM) if (chan.m_flags & QS1000_ADPCM)
{ {
for (int samp = 0; samp < samples; samp++) for (int samp = 0; samp < outputs[0].samples(); samp++)
{ {
if (chan.m_addr >= chan.m_loop_end) if (chan.m_addr >= chan.m_loop_end)
{ {
@ -529,13 +529,13 @@ void qs1000_device::sound_stream_update_legacy(sound_stream &stream, stream_samp
chan.m_addr = (chan.m_addr + (chan.m_acc >> 18)) & QS1000_ADDRESS_MASK; chan.m_addr = (chan.m_addr + (chan.m_acc >> 18)) & QS1000_ADDRESS_MASK;
chan.m_acc &= ((1 << 18) - 1); chan.m_acc &= ((1 << 18) - 1);
outputs[0][samp] += (result * 4 * lvol * vol) >> 12; outputs[0].add_int(samp, result * 4 * lvol * vol, 32768 << 12);
outputs[1][samp] += (result * 4 * rvol * vol) >> 12; outputs[1].add_int(samp, result * 4 * rvol * vol, 32768 << 12);
} }
} }
else else
{ {
for (int samp = 0; samp < samples; samp++) for (int samp = 0; samp < outputs[0].samples(); samp++)
{ {
if (chan.m_addr >= chan.m_loop_end) if (chan.m_addr >= chan.m_loop_end)
{ {
@ -558,8 +558,8 @@ void qs1000_device::sound_stream_update_legacy(sound_stream &stream, stream_samp
chan.m_addr = (chan.m_addr + (chan.m_acc >> 18)) & QS1000_ADDRESS_MASK; chan.m_addr = (chan.m_addr + (chan.m_acc >> 18)) & QS1000_ADDRESS_MASK;
chan.m_acc &= ((1 << 18) - 1); chan.m_acc &= ((1 << 18) - 1);
outputs[0][samp] += (result * lvol * vol) >> 12; outputs[0].add_int(samp, result * lvol * vol, 32768 << 12);
outputs[1][samp] += (result * rvol * vol) >> 12; outputs[1].add_int(samp, result * rvol * vol, 32768 << 12);
} }
} }
} }

View File

@ -73,7 +73,7 @@ protected:
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
// device_sound_interface overrides // device_sound_interface 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 // device_rom_interface overrides
virtual void rom_bank_updated() override; virtual void rom_bank_updated() override;

View File

@ -207,7 +207,7 @@ void qsound_device::device_add_mconfig(machine_config &config)
void qsound_device::device_start() void qsound_device::device_start()
{ {
// hope we get good synchronisation between the DSP and the sound system // hope we get good synchronisation between the DSP and the sound system
m_stream = stream_alloc_legacy(0, 2, clock() / 2 / 1248); m_stream = stream_alloc(0, 2, clock() / 2 / 1248);
// save DSP communication state // save DSP communication state
save_item(NAME(m_rom_bank)); save_item(NAME(m_rom_bank));
@ -251,13 +251,13 @@ void qsound_device::device_reset()
//------------------------------------------------- //-------------------------------------------------
// sound_stream_update_legacy - handle a stream update // sound_stream_update - handle a stream update
//------------------------------------------------- //-------------------------------------------------
void qsound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) void qsound_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{ {
std::fill_n(outputs[0], samples, m_samples[0]); outputs[0].fill(stream_buffer::sample_t(m_samples[0]) * (1.0 / 32768.0));
std::fill_n(outputs[1], samples, m_samples[1]); outputs[1].fill(stream_buffer::sample_t(m_samples[1]) * (1.0 / 32768.0));
} }

View File

@ -32,7 +32,7 @@ protected:
virtual void device_reset() override; virtual void device_reset() override;
// device_sound_interface implementation // device_sound_interface implementation
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 implementation // device_rom_interface implementation
virtual void rom_bank_updated() override; virtual void rom_bank_updated() override;