From 4849a5aebaf94b0ee95293308309bf43a5ff8da6 Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Sun, 20 Sep 2020 19:40:21 -0700 Subject: sound: Add a few new helpers to write_stream_view * put_clamp - clamps the input value before writing * put_int - takes an integer and coverts it to float * put_int_clamp - converts and clamps an integer * add_int - converts an int and adds to the current sample --- src/devices/cpu/tms57002/tms57002.cpp | 9 ++++----- src/devices/sound/aica.cpp | 5 ++--- src/devices/sound/asc.cpp | 10 ++++------ src/devices/sound/awacs.cpp | 5 ++--- src/devices/sound/c140.cpp | 24 ++++-------------------- src/devices/sound/c352.cpp | 9 ++++----- src/devices/sound/c6280.cpp | 17 ++++++++--------- src/devices/sound/cdda.cpp | 5 ++--- src/devices/sound/dave.cpp | 5 ++--- src/devices/sound/digitalk.cpp | 5 ++--- src/devices/sound/es1373.cpp | 5 ++--- src/devices/sound/es5503.cpp | 3 +-- src/devices/sound/es5506.cpp | 6 ++---- src/devices/sound/gaelco.cpp | 5 ++--- src/devices/sound/gb.cpp | 5 ++--- src/devices/sound/huc6230.cpp | 5 ++--- src/devices/sound/i5000.cpp | 5 ++--- src/devices/sound/ics2115.cpp | 5 ++--- src/devices/sound/iremga20.cpp | 6 ++---- src/devices/sound/k007232.cpp | 5 ++--- src/devices/sound/k053260.cpp | 13 ++----------- src/devices/sound/k054539.cpp | 5 ++--- src/devices/sound/ks0164.cpp | 5 ++--- src/devices/sound/l7a1045_l6028_dsp_a.cpp | 5 ++--- src/devices/sound/mas3507d.cpp | 10 ++++------ src/devices/sound/mos6560.cpp | 3 +-- src/devices/sound/mos7360.cpp | 3 +-- src/devices/sound/msm5232.cpp | 21 ++++++++++----------- src/devices/sound/multipcm.cpp | 17 ++--------------- src/devices/sound/namco.cpp | 16 +++++++--------- src/devices/sound/namco_163.cpp | 3 +-- src/devices/sound/nes_apu.cpp | 9 +-------- src/devices/sound/nile.cpp | 5 ++--- src/devices/sound/okim6295.cpp | 3 +-- src/devices/sound/sn76496.cpp | 5 ++--- src/devices/sound/sp0250.cpp | 3 +-- src/devices/sound/tms5220.cpp | 3 +-- src/devices/sound/ym2151.cpp | 13 ++----------- 38 files changed, 97 insertions(+), 189 deletions(-) (limited to 'src/devices') diff --git a/src/devices/cpu/tms57002/tms57002.cpp b/src/devices/cpu/tms57002/tms57002.cpp index c2cf28f3f92..da29f23fbcd 100644 --- a/src/devices/cpu/tms57002/tms57002.cpp +++ b/src/devices/cpu/tms57002/tms57002.cpp @@ -929,11 +929,10 @@ void tms57002_device::sound_stream_update(sound_stream &stream, std::vector> 1, 32768 * 32768); + outputs[1].put_int(0, s32(so[1] << 8) >> 1, 32768 * 32768); + outputs[2].put_int(0, s32(so[2] << 8) >> 1, 32768 * 32768); + outputs[3].put_int(0, s32(so[3] << 8) >> 1, 32768 * 32768); sync_w(1); } diff --git a/src/devices/sound/aica.cpp b/src/devices/sound/aica.cpp index 7bedf5d660a..21d5fa081d0 100644 --- a/src/devices/sound/aica.cpp +++ b/src/devices/sound/aica.cpp @@ -1233,7 +1233,6 @@ void aica_device::DoMasterSamples(std::vector const &inputs, w { int i; - constexpr stream_buffer::sample_t sample_scale = 1.0 / stream_buffer::sample_t(32768 << SHIFT); for (int s = 0; s < bufl.samples(); ++s) { s32 smpl = 0, smpr = 0; @@ -1293,8 +1292,8 @@ void aica_device::DoMasterSamples(std::vector const &inputs, w smpr = clip16(smpr >> 3); } - bufl.put(s, stream_buffer::sample_t(smpl * m_LPANTABLE[MVOL() << 0xd]) * sample_scale); - bufr.put(s, stream_buffer::sample_t(smpr * m_LPANTABLE[MVOL() << 0xd]) * sample_scale); + bufl.put_int(s, smpl * m_LPANTABLE[MVOL() << 0xd], 32768 << SHIFT); + bufr.put_int(s, smpr * m_LPANTABLE[MVOL() << 0xd], 32768 << SHIFT); } } diff --git a/src/devices/sound/asc.cpp b/src/devices/sound/asc.cpp index e03494040ab..23ec35a2766 100644 --- a/src/devices/sound/asc.cpp +++ b/src/devices/sound/asc.cpp @@ -148,7 +148,6 @@ void asc_device::sound_stream_update(sound_stream &stream, std::vectorread_word(offset + m_play_ptr))) * sample_scale); - outR.put(i, stream_buffer::sample_t(s16(m_dma_space->read_word(offset + m_play_ptr + 2))) * sample_scale); + outL.put_int(i, s16(m_dma_space->read_word(offset + m_play_ptr)), 32768); + outR.put_int(i, s16(m_dma_space->read_word(offset + m_play_ptr + 2)), 32768); m_play_ptr += 4; } diff --git a/src/devices/sound/c140.cpp b/src/devices/sound/c140.cpp index 0edb1920a8c..5d0b0811854 100644 --- a/src/devices/sound/c140.cpp +++ b/src/devices/sound/c140.cpp @@ -77,12 +77,6 @@ DEFINE_DEVICE_TYPE(C219, c219_device, "c219", "Namco C219") // LIVE DEVICE //************************************************************************** -static inline stream_buffer::sample_t limit(stream_buffer::sample_t in) -{ - return std::max(-1.0f, std::min(1.0f, in)); -} - - //------------------------------------------------- // c140_device - constructor //------------------------------------------------- @@ -326,15 +320,10 @@ void c140_device::sound_stream_update(sound_stream &stream, std::vector> 8; } - buffer_fl.put(i, stream_buffer::sample_t(s16(out[0] >> 3)) * sample_scale); - buffer_fr.put(i, stream_buffer::sample_t(s16(out[1] >> 3)) * sample_scale); - buffer_rl.put(i, stream_buffer::sample_t(s16(out[2] >> 3)) * sample_scale); - buffer_rr.put(i, stream_buffer::sample_t(s16(out[3] >> 3)) * sample_scale); + buffer_fl.put_int(i, s16(out[0] >> 3), 32768); + buffer_fr.put_int(i, s16(out[1] >> 3), 32768); + buffer_rl.put_int(i, s16(out[2] >> 3), 32768); + buffer_rr.put_int(i, s16(out[3] >> 3), 32768); } } diff --git a/src/devices/sound/c6280.cpp b/src/devices/sound/c6280.cpp index d01dd74125a..1b6666455c9 100644 --- a/src/devices/sound/c6280.cpp +++ b/src/devices/sound/c6280.cpp @@ -51,7 +51,6 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectornoise_seed = (seed >> 1) | ((BIT(seed, 0) ^ BIT(seed, 1) ^ BIT(seed, 11) ^ BIT(seed, 12) ^ BIT(seed, 17)) << 17); } - outputs[0].add(i, stream_buffer::sample_t(s16(vll * (data - 16))) * sample_scale); - outputs[1].add(i, stream_buffer::sample_t(s16(vlr * (data - 16))) * sample_scale); + outputs[0].add_int(i, s16(vll * (data - 16)), 32768); + outputs[1].add_int(i, s16(vlr * (data - 16)), 32768); } } else @@ -98,8 +97,8 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectordda - 16))) * sample_scale); - outputs[1].add(i, stream_buffer::sample_t(s16(vlr * (chan->dda - 16))) * sample_scale); + outputs[0].add_int(i, s16(vll * (chan->dda - 16)), 32768); + outputs[1].add_int(i, s16(vlr * (chan->dda - 16)), 32768); } } else @@ -138,8 +137,8 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectortick = step; lfo_dstchan->index = (lfo_dstchan->index + 1) & 0x1f; } - outputs[0].add(i, stream_buffer::sample_t(s16(vll * (data - 16))) * sample_scale); - outputs[1].add(i, stream_buffer::sample_t(s16(vlr * (data - 16))) * sample_scale); + outputs[0].add_int(i, s16(vll * (data - 16)), 32768); + outputs[1].add_int(i, s16(vlr * (data - 16)), 32768); } } } @@ -156,8 +155,8 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectortick = step; chan->index = (chan->index + 1) & 0x1f; } - outputs[0].add(i, stream_buffer::sample_t(s16(vll * (data - 16))) * sample_scale); - outputs[1].add(i, stream_buffer::sample_t(s16(vlr * (data - 16))) * sample_scale); + outputs[0].add_int(i, s16(vll * (data - 16)), 32768); + outputs[1].add_int(i, s16(vlr * (data - 16)), 32768); } } } diff --git a/src/devices/sound/cdda.cpp b/src/devices/sound/cdda.cpp index ca2bd280de8..e208847510e 100644 --- a/src/devices/sound/cdda.cpp +++ b/src/devices/sound/cdda.cpp @@ -164,7 +164,6 @@ void cdda_device::get_audio_data(write_stream_view &bufL, write_stream_view &buf int i; int16_t *audio_cache = (int16_t *) m_audio_cache.get(); - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (int sampindex = 0; sampindex < bufL.samples(); ) { /* if no file, audio not playing, audio paused, or out of disc data, @@ -191,8 +190,8 @@ void cdda_device::get_audio_data(write_stream_view &bufL, write_stream_view &buf for (i = 0; i < samples; i++) { /* CD-DA data on the disc is big-endian */ - bufL.put(sampindex + i, stream_buffer::sample_t(s16(big_endianize_int16( audio_cache[ m_audio_bptr ] ))) * sample_scale); m_audio_bptr++; - bufR.put(sampindex + i, stream_buffer::sample_t(s16(big_endianize_int16( audio_cache[ m_audio_bptr ] ))) * sample_scale); m_audio_bptr++; + bufL.put_int(sampindex + i, s16(big_endianize_int16( audio_cache[ m_audio_bptr ] )), 32768); m_audio_bptr++; + bufR.put_int(sampindex + i, s16(big_endianize_int16( audio_cache[ m_audio_bptr ] )), 32768); m_audio_bptr++; } sampindex += samples; diff --git a/src/devices/sound/dave.cpp b/src/devices/sound/dave.cpp index f26ea891879..b7f1487c025 100644 --- a/src/devices/sound/dave.cpp +++ b/src/devices/sound/dave.cpp @@ -205,7 +205,6 @@ void dave_device::sound_stream_update(sound_stream &stream, std::vector &outputs) generate_irq(voice, v); } - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (int c = 0; c < outputs.size(); c++) - outputs[c].put(sampindex, stream_buffer::sample_t(cursample[c]) * sample_scale); + outputs[c].put_int(sampindex, cursample[c], 32768); } } @@ -1081,9 +1080,8 @@ void es5505_device::generate_samples(std::vector &outputs) generate_irq(voice, v); } - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (int c = 0; c < outputs.size(); c++) - outputs[c].put(sampindex, stream_buffer::sample_t(cursample[c]) * sample_scale); + outputs[c].put_int(sampindex, cursample[c], 32768); } } diff --git a/src/devices/sound/gaelco.cpp b/src/devices/sound/gaelco.cpp index d672154b6e9..52e71a606c6 100644 --- a/src/devices/sound/gaelco.cpp +++ b/src/devices/sound/gaelco.cpp @@ -79,7 +79,6 @@ gaelco_gae1_device::gaelco_gae1_device(const machine_config &mconfig, device_typ void gaelco_gae1_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { /* fill all data needed */ - 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; @@ -178,8 +177,8 @@ void gaelco_gae1_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (int i = 0; i < outputs[0].samples(); i++) { s32 samp0 = inputs[0].get(i) * 32768.0; @@ -40,8 +39,8 @@ void huc6230_device::sound_stream_update(sound_stream &stream, std::vectorm_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); + outputs[0].put_int(i, samp0, 32768); + outputs[1].put_int(i, samp1, 32768); } } diff --git a/src/devices/sound/i5000.cpp b/src/devices/sound/i5000.cpp index 033da94049d..6978b9336f3 100644 --- a/src/devices/sound/i5000.cpp +++ b/src/devices/sound/i5000.cpp @@ -116,7 +116,6 @@ bool i5000snd_device::read_sample(int ch) void i5000snd_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - constexpr stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * 16.0); for (int i = 0; i < outputs[0].samples(); i++) { int32_t mix_l = 0; @@ -158,8 +157,8 @@ void i5000snd_device::sound_stream_update(sound_stream &stream, std::vector> 6)); voice.vol.add = (voice.vol.incr & 0x3f)<< (10 - fine); - constexpr stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * (1 << (5 + volume_bits))); for (int i = 0; i < outputs[0].samples(); i++) { const u32 volacc = (voice.vol.acc >> 10) & 0xffff; @@ -411,8 +410,8 @@ int ics2115_device::fill_output(ics2115_voice& voice, std::vector> (5 + volume_bits), 32768); + outputs[1].add_int(i, (sample * vright) >> (5 + volume_bits), 32768); } voice.update_ramp(); diff --git a/src/devices/sound/iremga20.cpp b/src/devices/sound/iremga20.cpp index 3c5ac7dfe0f..3ec07d3de35 100644 --- a/src/devices/sound/iremga20.cpp +++ b/src/devices/sound/iremga20.cpp @@ -134,7 +134,6 @@ void iremga20_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - constexpr stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * 32.0); for(int sample = 0; sample != outputs[0].samples(); sample++) { s32 suml = 0, sumr = 0; for(int voice = 0; voice < 0x20; voice++) { @@ -416,7 +415,7 @@ void ks0164_device::sound_stream_update(sound_stream &stream, std::vectorl_volume) * sample_scale); - outputs[1].add(j, stream_buffer::sample_t(sample * vptr->r_volume) * sample_scale); + outputs[0].add_int(j, sample * vptr->l_volume, 32768 * 512); + outputs[1].add_int(j, sample * vptr->r_volume, 32768 * 512); } vptr->pos = pos; diff --git a/src/devices/sound/mas3507d.cpp b/src/devices/sound/mas3507d.cpp index b024b6408cd..a5b7a7917d2 100644 --- a/src/devices/sound/mas3507d.cpp +++ b/src/devices/sound/mas3507d.cpp @@ -367,17 +367,15 @@ void mas3507d_device::append_buffer(std::vector &outputs, int if(s1 > sample_count) s1 = sample_count; - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; if(mp3_info.channels == 1) { for(int i=0; i 32767) - { - return 1.0; - } - return stream_buffer::sample_t(value) * (1.0 / 32768.0); -} - #if MULTIPCM_LOG_SAMPLES void multipcm_device::dump_sample(slot_t &slot) { @@ -734,8 +721,8 @@ void multipcm_device::sound_stream_update(sound_stream &stream, std::vector> m_f_fracbits) & 0x1f) -static constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; - DEFINE_DEVICE_TYPE(NAMCO, namco_device, "namco", "Namco") DEFINE_DEVICE_TYPE(NAMCO_15XX, namco_15xx_device, "namco_15xx", "Namco 15xx") DEFINE_DEVICE_TYPE(NAMCO_CUS30, namco_cus30_device, "namco_cus30", "Namco CUS30") @@ -239,7 +237,7 @@ uint32_t namco_audio_device::namco_update_one(write_stream_view &buffer, const i { for (int sampindex = 0; sampindex < buffer.samples(); sampindex++) { - buffer.add(sampindex, stream_buffer::sample_t(wave[WAVEFORM_POSITION(counter)]) * sample_scale); + buffer.add_int(sampindex, wave[WAVEFORM_POSITION(counter)], 32768); counter += freq; } @@ -699,13 +697,13 @@ void namco_audio_device::sound_stream_update(sound_stream &stream, std::vectornoise_state) { - lmix.add(i, stream_buffer::sample_t(l_noise_data) * sample_scale); - rmix.add(i, stream_buffer::sample_t(r_noise_data) * sample_scale); + lmix.add_int(i, l_noise_data, 32768); + rmix.add_int(i, r_noise_data, 32768); } else { - lmix.add(i, stream_buffer::sample_t(-l_noise_data) * sample_scale); - rmix.add(i, stream_buffer::sample_t(-r_noise_data) * sample_scale); + lmix.add_int(i, -l_noise_data, 32768); + rmix.add_int(i, -r_noise_data, 32768); } if (hold) @@ -799,9 +797,9 @@ void namco_audio_device::sound_stream_update(sound_stream &stream, std::vectornoise_state) - buffer.add(i, stream_buffer::sample_t(noise_data) * sample_scale); + buffer.add_int(i, noise_data, 32768); else - buffer.add(i, stream_buffer::sample_t(-noise_data) * sample_scale); + buffer.add_int(i, -noise_data, 32768); if (hold) { diff --git a/src/devices/sound/namco_163.cpp b/src/devices/sound/namco_163.cpp index d23c6e14693..87cd82a03eb 100644 --- a/src/devices/sound/namco_163.cpp +++ b/src/devices/sound/namco_163.cpp @@ -151,7 +151,6 @@ void namco_163_sound_device::sound_stream_update(sound_stream &stream, std::vect } // Slightly noisy but closer to real hardware behavior - constexpr stream_buffer::sample_t sample_scale = 1.0 / 128.0; for (int s = 0; s < outputs[0].samples(); s++) { u32 phase = (m_ram[m_reg_addr + 5] << 16) | (m_ram[m_reg_addr + 3] << 8) | m_ram[m_reg_addr + 1]; @@ -172,6 +171,6 @@ void namco_163_sound_device::sound_stream_update(sound_stream &stream, std::vect { m_reg_addr = 0x78 - ((m_ram[0x7f] & 0x70) >> 1); } - outputs[0].put(s, stream_buffer::sample_t(output) * sample_scale); + outputs[0].put_int(s, output, 128); } } diff --git a/src/devices/sound/nes_apu.cpp b/src/devices/sound/nes_apu.cpp index f5f7352bc56..f7b4772ddb7 100644 --- a/src/devices/sound/nes_apu.cpp +++ b/src/devices/sound/nes_apu.cpp @@ -733,7 +733,6 @@ void nesapu_device::sound_stream_update(sound_stream &stream, std::vector 127) - accum = 127; - else if (accum < -128) - accum = -128; - - output.put(sampindex, stream_buffer::sample_t(accum) * sample_scale); + output.put_int_clamp(sampindex, accum, 128); } } diff --git a/src/devices/sound/nile.cpp b/src/devices/sound/nile.cpp index 83e6b4316a7..345c88f2bf0 100644 --- a/src/devices/sound/nile.cpp +++ b/src/devices/sound/nile.cpp @@ -160,11 +160,10 @@ void nile_device::sound_stream_update(sound_stream &stream, std::vector= m_count) diff --git a/src/devices/sound/sn76496.cpp b/src/devices/sound/sn76496.cpp index 9bc686dedb2..eac04a2d99f 100644 --- a/src/devices/sound/sn76496.cpp +++ b/src/devices/sound/sn76496.cpp @@ -378,7 +378,6 @@ void sn76496_base_device::sound_stream_update(sound_stream &stream, std::vector< int16_t out; int16_t out2 = 0; - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (int sampindex = 0; sampindex < lbuffer->samples(); sampindex++) { // clock chip once @@ -445,9 +444,9 @@ void sn76496_base_device::sound_stream_update(sound_stream &stream, std::vector< if (m_negate) { out = -out; out2 = -out2; } - lbuffer->put(sampindex, stream_buffer::sample_t(out) * sample_scale); + lbuffer->put_int(sampindex, out, 32768); if (m_stereo) - rbuffer->put(sampindex, stream_buffer::sample_t(out2) * sample_scale); + rbuffer->put_int(sampindex, out2, 32768); } } diff --git a/src/devices/sound/sp0250.cpp b/src/devices/sound/sp0250.cpp index e18143a29b0..862b3781a7c 100644 --- a/src/devices/sound/sp0250.cpp +++ b/src/devices/sound/sp0250.cpp @@ -258,9 +258,8 @@ void sp0250_device::sound_stream_update(sound_stream &stream, std::vector MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : output.samples(); @@ -2069,7 +2068,7 @@ void tms5220_device::sound_stream_update(sound_stream &stream, std::vector 32767) - outl = 32767; - else if (outl < -32768) - outl = -32768; - if (outr > 32767) - outr = 32767; - else if (outr < -32768) - outr = -32768; - outputs[0].put(sampindex, stream_buffer::sample_t(outl) * sample_scale); - outputs[1].put(sampindex, stream_buffer::sample_t(outr) * sample_scale); + outputs[0].put_int_clamp(sampindex, outl, 32768); + outputs[1].put_int_clamp(sampindex, outr, 32768); advance(); } -- cgit v1.2.3