diff options
author | 2020-09-20 19:40:21 -0700 | |
---|---|---|
committer | 2020-09-20 19:40:21 -0700 | |
commit | 4849a5aebaf94b0ee95293308309bf43a5ff8da6 (patch) | |
tree | 4700e4cb5e458f84c923708d045b5f8d547c2625 /src | |
parent | 6eaa5f09467165e144da9369dc51aa6cfc500cd0 (diff) |
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
Diffstat (limited to 'src')
39 files changed, 132 insertions, 191 deletions
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<read si[2] = s32(inputs[2].get(0) * in_scale) & 0xffffff; si[3] = s32(inputs[3].get(0) * in_scale) & 0xffffff; - stream_buffer::sample_t out_scale = 1.0 / (32768.0 * 65536.0); - outputs[0].put(0, stream_buffer::sample_t(s32(so[0] << 8)) * out_scale); - outputs[1].put(0, stream_buffer::sample_t(s32(so[1] << 8)) * out_scale); - outputs[2].put(0, stream_buffer::sample_t(s32(so[2] << 8)) * out_scale); - outputs[3].put(0, stream_buffer::sample_t(s32(so[3] << 8)) * out_scale); + outputs[0].put_int(0, s32(so[0] << 8) >> 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<read_stream_view> 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<read_stream_view> 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::vector<read_stre case 1: // FIFO mode { - constexpr stream_buffer::sample_t sample_scale = 64.0 / 32768.0; for (i = 0; i < outL.samples(); i++) { int8_t smpll, smplr; @@ -234,15 +233,14 @@ void asc_device::sound_stream_update(sound_stream &stream, std::vector<read_stre break; } - outL.put(i, stream_buffer::sample_t(smpll) * sample_scale); - outR.put(i, stream_buffer::sample_t(smplr) * sample_scale); + outL.put_int(i, smpll, 32768 / 64); + outR.put_int(i, smplr, 32768 / 64); } break; } case 2: // wavetable mode { - constexpr stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * 4.0); for (i = 0; i < outL.samples(); i++) { int32_t mixL, mixR; @@ -269,8 +267,8 @@ void asc_device::sound_stream_update(sound_stream &stream, std::vector<read_stre mixR += smpl*256; } - outL.put(i, stream_buffer::sample_t(mixL) * sample_scale); - outR.put(i, stream_buffer::sample_t(mixR) * sample_scale); + outL.put_int(i, mixL, 32768 * 4); + outR.put_int(i, mixR, 32768 * 4); } break; } diff --git a/src/devices/sound/awacs.cpp b/src/devices/sound/awacs.cpp index 19f734cd468..72cf31d7589 100644 --- a/src/devices/sound/awacs.cpp +++ b/src/devices/sound/awacs.cpp @@ -93,13 +93,12 @@ void awacs_device::sound_stream_update(sound_stream &stream, std::vector<read_st auto &outL = outputs[0]; auto &outR = outputs[1]; - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; if (m_playback_enable) { for (int i = 0; i < outL.samples(); i++) { - outL.put(i, stream_buffer::sample_t(s16(m_dma_space->read_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<read_str { auto &dest1 = outputs[0]; auto &dest2 = outputs[1]; - constexpr stream_buffer::sample_t sample_scale = 8.0 / 32768.0; for (int i = 0; i < samples; i++) { - stream_buffer::sample_t val; - - val = stream_buffer::sample_t(*lmix++) * sample_scale; - dest1.put(i, limit(val)); - val = stream_buffer::sample_t(*rmix++) * sample_scale; - dest2.put(i, limit(val)); + dest1.put_int_clamp(i, *lmix++, 32768 / 8); + dest2.put_int_clamp(i, *rmix++, 32768 / 8); } } } @@ -465,15 +454,10 @@ void c219_device::sound_stream_update(sound_stream &stream, std::vector<read_str { auto &dest1 = outputs[0]; auto &dest2 = outputs[1]; - constexpr stream_buffer::sample_t sample_scale = 8.0 / 32768.0; for (int i = 0; i < samples; i++) { - stream_buffer::sample_t val; - - val = stream_buffer::sample_t(*lmix++) * sample_scale; - dest1.put(i, limit(val)); - val = stream_buffer::sample_t(*rmix++) * sample_scale; - dest2.put(i, limit(val)); + dest1.put_int_clamp(i, *lmix++, 32768 / 8); + dest2.put_int_clamp(i, *rmix++, 32768 / 8); } } } diff --git a/src/devices/sound/c352.cpp b/src/devices/sound/c352.cpp index 826f194437a..bea5a561b59 100644 --- a/src/devices/sound/c352.cpp +++ b/src/devices/sound/c352.cpp @@ -129,7 +129,6 @@ void c352_device::sound_stream_update(sound_stream &stream, std::vector<read_str auto &buffer_rl = outputs[2]; auto &buffer_rr = outputs[3]; - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (int i = 0; i < buffer_fl.samples(); i++) { int out[4] = { 0, 0, 0, 0 }; @@ -174,10 +173,10 @@ void c352_device::sound_stream_update(sound_stream &stream, std::vector<read_str out[3] += (((v.flags & C352_FLG_PHASEFR) ? -s : s) * v.curr_vol[3]) >> 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::vector<read_st outputs[0].fill(0); outputs[1].fill(0); - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (int ch = 0; ch < 6; ch++) { channel *chan = &m_channel[ch]; @@ -88,8 +87,8 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vector<read_st // based on Charles MacDonald's research chan->noise_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::vector<read_st /* DDA mode */ for (int i = 0; i < outputs[0].samples(); i++) { - outputs[0].add(i, stream_buffer::sample_t(s16(vll * (chan->dda - 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::vector<read_st lfo_dstchan->tick = 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::vector<read_st chan->tick = 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<read_str auto &buffer1 = outputs[0]; auto &buffer2 = outputs[1]; - constexpr stream_buffer::sample_t sample_scale = 1.0 / (4.0 * 32768.0); for (int sampindex = 0; sampindex < buffer1.samples(); sampindex++) { int vol[4]; @@ -264,8 +263,8 @@ void dave_device::sound_stream_update(sound_stream &stream, std::vector<read_str left_volume = output_volumes[0] + output_volumes[2] + output_volumes[4] + output_volumes[6]; right_volume = output_volumes[1] + output_volumes[3] + output_volumes[5] + output_volumes[7]; - buffer1.put(sampindex, stream_buffer::sample_t(left_volume) * sample_scale); - buffer2.put(sampindex, stream_buffer::sample_t(right_volume) * sample_scale); + buffer1.put_int(sampindex, left_volume, 32768 * 4); + buffer2.put_int(sampindex, right_volume, 32768 * 4); } } diff --git a/src/devices/sound/digitalk.cpp b/src/devices/sound/digitalk.cpp index 9ca0e6fa5f0..2bff98478e5 100644 --- a/src/devices/sound/digitalk.cpp +++ b/src/devices/sound/digitalk.cpp @@ -548,7 +548,6 @@ void digitalker_device::sound_stream_update(sound_stream &stream, std::vector<re { auto &sout = outputs[0]; int cpos = 0; - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; while(cpos != sout.samples()) { if(m_zero_count == 0 && m_dac_index == 128) digitalker_step(); @@ -563,10 +562,10 @@ void digitalker_device::sound_stream_update(sound_stream &stream, std::vector<re } else if(m_dac_index != 128) { while(cpos != sout.samples() && m_dac_index != 128) { - stream_buffer::sample_t v = stream_buffer::sample_t(m_dac[m_dac_index]) * sample_scale; + s32 v = m_dac[m_dac_index]; int pp = m_pitch_pos; while(cpos != sout.samples() && pp != m_pitch) { - sout.put(cpos++, v); + sout.put_int(cpos++, v, 32768); pp++; } if(pp == m_pitch) { diff --git a/src/devices/sound/es1373.cpp b/src/devices/sound/es1373.cpp index 5ab2d1f0fe6..a7a86de22d6 100644 --- a/src/devices/sound/es1373.cpp +++ b/src/devices/sound/es1373.cpp @@ -306,7 +306,6 @@ void es1373_device::send_audio_out(chan_info& chan, uint32_t intr_mask, write_st //uint32_t sample_size = calc_size(chan.format); // Send data to sound stream bool buf_row_done; - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (int i=0; i<outL.samples(); i++) { buf_row_done = false; int16_t lsamp = 0, rsamp = 0; @@ -374,8 +373,8 @@ void es1373_device::send_audio_out(chan_info& chan, uint32_t intr_mask, write_st chan.buf_rptr -= 0x10; } } - outL.put(i, stream_buffer::sample_t(lsamp) * sample_scale); - outR.put(i, stream_buffer::sample_t(rsamp) * sample_scale); + outL.put_int(i, lsamp, 32768); + outR.put_int(i, rsamp, 32768); } } diff --git a/src/devices/sound/es5503.cpp b/src/devices/sound/es5503.cpp index 4ffc0d263a3..0d727fc77bf 100644 --- a/src/devices/sound/es5503.cpp +++ b/src/devices/sound/es5503.cpp @@ -199,9 +199,8 @@ void es5503_device::sound_stream_update(sound_stream &stream, std::vector<read_s } mixp = &m_mix_buffer[0]; - constexpr stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * 8.0); for (i = 0; i < outputs[chan].samples(); i++) - outputs[chan].put(i, stream_buffer::sample_t(*mixp++) * sample_scale); + outputs[chan].put_int(i, *mixp++, 32768 * 8); } } diff --git a/src/devices/sound/es5506.cpp b/src/devices/sound/es5506.cpp index 746518a3c81..aa266b4a620 100644 --- a/src/devices/sound/es5506.cpp +++ b/src/devices/sound/es5506.cpp @@ -1042,9 +1042,8 @@ void es5506_device::generate_samples(std::vector<write_stream_view> &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<write_stream_view> &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<read_stream_view> const &inputs, std::vector<write_stream_view> &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<r #endif /* now that we have computed all channels, save current data to the output buffer */ - outputs[0].put(j, stream_buffer::sample_t(output_l) * sample_scale); - outputs[1].put(j, stream_buffer::sample_t(output_r) * sample_scale); + outputs[0].put_int(j, output_l, 32768); + outputs[1].put_int(j, output_r, 32768); } // if (wavraw) diff --git a/src/devices/sound/gb.cpp b/src/devices/sound/gb.cpp index 9fd9d8d333b..cb4ba86fe36 100644 --- a/src/devices/sound/gb.cpp +++ b/src/devices/sound/gb.cpp @@ -1218,7 +1218,6 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, std::vector { 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++) { s32 sample; @@ -1271,7 +1270,7 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, std::vector right *= m_snd_control.vol_right; /* Update the buffers */ - outputl.put(sampindex, stream_buffer::sample_t(left) * sample_scale); - outputr.put(sampindex, stream_buffer::sample_t(right) * sample_scale); + outputl.put_int(sampindex, left, 32768 / 64); + outputr.put_int(sampindex, right, 32768 / 64); } } diff --git a/src/devices/sound/huc6230.cpp b/src/devices/sound/huc6230.cpp index 8c7e9bd91a7..31e143fea8c 100644 --- a/src/devices/sound/huc6230.cpp +++ b/src/devices/sound/huc6230.cpp @@ -23,7 +23,6 @@ constexpr int clamp(int val, int min, int max) { return std::min(max, std::max(m void huc6230_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &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::vector<read_ 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); + 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<read_stream_view> const &inputs, std::vector<write_stream_view> &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<read mix_l += m_channels[ch].output_l; } - outputs[0].put(i, stream_buffer::sample_t(mix_r) * sample_scale); - outputs[1].put(i, stream_buffer::sample_t(mix_l) * sample_scale); + outputs[0].put_int(i, mix_r, 32768 * 16); + outputs[1].put_int(i, mix_l, 32768 * 16); } } diff --git a/src/devices/sound/ics2115.cpp b/src/devices/sound/ics2115.cpp index 98c5916c253..80e4aa9cd09 100644 --- a/src/devices/sound/ics2115.cpp +++ b/src/devices/sound/ics2115.cpp @@ -391,7 +391,6 @@ int ics2115_device::fill_output(ics2115_voice& voice, std::vector<write_stream_v const u16 fine = 1 << (3*(voice.vol.incr >> 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<write_stream_v { /*if (voice.playing()) {*/ - outputs[0].add(i, stream_buffer::sample_t(sample * vleft) * sample_scale); - outputs[1].add(i, stream_buffer::sample_t(sample * vright) * sample_scale); + outputs[0].add_int(i, (sample * vleft) >> (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<read auto &outL = outputs[0]; auto &outR = outputs[1]; - stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * 4.0); for (int i = 0; i < outL.samples(); i++) { s32 sampleout = 0; @@ -159,9 +158,8 @@ void iremga20_device::sound_stream_update(sound_stream &stream, std::vector<read } } - stream_buffer::sample_t final = stream_buffer::sample_t(sampleout) * sample_scale; - outL.put(i, final); - outR.put(i, final); + outL.put_int(i, sampleout, 32768 * 4); + outR.put_int(i, sampleout, 32768 * 4); } } diff --git a/src/devices/sound/k007232.cpp b/src/devices/sound/k007232.cpp index 5d7d20dc6d8..a8b6c135a51 100644 --- a/src/devices/sound/k007232.cpp +++ b/src/devices/sound/k007232.cpp @@ -236,7 +236,6 @@ void k007232_device::sound_stream_update(sound_stream &stream, std::vector<read_ } } - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (int j = 0; j < outputs[0].samples(); j++) { s32 lsum = 0, rsum = 0; @@ -282,7 +281,7 @@ void k007232_device::sound_stream_update(sound_stream &stream, std::vector<read_ rsum += out * vol_b; } } - outputs[0].put(j, stream_buffer::sample_t(lsum) * sample_scale); - outputs[1].put(j, stream_buffer::sample_t(rsum) * sample_scale); + outputs[0].put_int(j, lsum, 32768); + outputs[1].put_int(j, rsum, 32768); } } diff --git a/src/devices/sound/k053260.cpp b/src/devices/sound/k053260.cpp index 4158e5a11e7..619313c9c99 100644 --- a/src/devices/sound/k053260.cpp +++ b/src/devices/sound/k053260.cpp @@ -301,14 +301,6 @@ void k053260_device::write(offs_t offset, u8 data) } } -static inline int limit(int val, int max, int min) -{ - return std::max(min, std::min(max, val)); -} - -static constexpr s32 MAXOUT = 0x7fff; -static constexpr s32 MINOUT = -0x8000; - //------------------------------------------------- // sound_stream_update - handle a stream update //------------------------------------------------- @@ -317,7 +309,6 @@ void k053260_device::sound_stream_update(sound_stream &stream, std::vector<read_ { if (m_mode & 2) { - constexpr stream_buffer::sample_t sample_scale = 1.0f / stream_buffer::sample_t(MAXOUT); for ( int j = 0; j < outputs[0].samples(); j++ ) { stream_sample_t buffer[2] = {0, 0}; @@ -328,8 +319,8 @@ void k053260_device::sound_stream_update(sound_stream &stream, std::vector<read_ voice.play(buffer); } - outputs[0].put(j, stream_buffer::sample_t(limit( buffer[0], MAXOUT, MINOUT )) * sample_scale); - outputs[1].put(j, stream_buffer::sample_t(limit( buffer[1], MAXOUT, MINOUT )) * sample_scale); + outputs[0].put_int_clamp(j, buffer[0], 32768); + outputs[1].put_int_clamp(j, buffer[1], 32768); } } else diff --git a/src/devices/sound/k054539.cpp b/src/devices/sound/k054539.cpp index b1aa643d994..8d1b368e9ad 100644 --- a/src/devices/sound/k054539.cpp +++ b/src/devices/sound/k054539.cpp @@ -124,7 +124,6 @@ void k054539_device::sound_stream_update(sound_stream &stream, std::vector<read_ return; } - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for(int sample = 0; sample != outputs[0].samples(); sample++) { double lval, rval; if(!(flags & DISABLE_REVERB)) @@ -303,8 +302,8 @@ void k054539_device::sound_stream_update(sound_stream &stream, std::vector<read_ } } reverb_pos = (reverb_pos + 1) & 0x1fff; - outputs[0].put(sample, stream_buffer::sample_t(lval) * sample_scale); - outputs[1].put(sample, stream_buffer::sample_t(rval) * sample_scale); + outputs[0].put_int(sample, lval, 32768); + outputs[1].put_int(sample, rval, 32768); } } diff --git a/src/devices/sound/ks0164.cpp b/src/devices/sound/ks0164.cpp index ac1579280b0..2086b014478 100644 --- a/src/devices/sound/ks0164.cpp +++ b/src/devices/sound/ks0164.cpp @@ -370,7 +370,6 @@ u16 ks0164_device::uncomp_8_16(u8 value) void ks0164_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &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::vector<read_s sumr += samp; } } - outputs[0].put(sample, stream_buffer::sample_t(suml) * sample_scale); - outputs[1].put(sample, stream_buffer::sample_t(sumr) * sample_scale); + outputs[0].put_int(sample, suml, 32768 * 32); + outputs[1].put_int(sample, sumr, 32768 * 32); } } diff --git a/src/devices/sound/l7a1045_l6028_dsp_a.cpp b/src/devices/sound/l7a1045_l6028_dsp_a.cpp index 16c45121378..7f567f86cbb 100644 --- a/src/devices/sound/l7a1045_l6028_dsp_a.cpp +++ b/src/devices/sound/l7a1045_l6028_dsp_a.cpp @@ -152,7 +152,6 @@ void l7a1045_sound_device::sound_stream_update(sound_stream &stream, std::vector outputs[0].fill(0); outputs[1].fill(0); - constexpr stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * 512.0); for (int i = 0; i < 32; i++) { if (m_key & (1 << i)) @@ -193,8 +192,8 @@ void l7a1045_sound_device::sound_stream_update(sound_stream &stream, std::vector sample = ((int8_t)(data & 0xfc)) << (3 - (data & 3)); frac += step; - outputs[0].add(j, stream_buffer::sample_t(sample * vptr->l_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<write_stream_view> &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<s1; i++) { - stream_buffer::sample_t v = stream_buffer::sample_t(samples[i]) * sample_scale; - outputs[0].put(i+pos, v); - outputs[1].put(i+pos, v); + outputs[0].put_int(i+pos, samples[i], 32768); + outputs[1].put_int(i+pos, samples[i], 32768); } } else { for(int i=0; i<s1; i++) { - outputs[0].put(i+pos, stream_buffer::sample_t(samples[i*2]) * sample_scale); - outputs[1].put(i+pos, stream_buffer::sample_t(samples[i*2+1]) * sample_scale); + outputs[0].put_int(i+pos, samples[i*2], 32768); + outputs[1].put_int(i+pos, samples[i*2+1], 32768); } } diff --git a/src/devices/sound/mos6560.cpp b/src/devices/sound/mos6560.cpp index 8522a9b8b6d..be66c4c4703 100644 --- a/src/devices/sound/mos6560.cpp +++ b/src/devices/sound/mos6560.cpp @@ -892,7 +892,6 @@ void mos6560_device::sound_stream_update(sound_stream &stream, std::vector<read_ int i, v; auto &buffer = outputs[0]; - constexpr stream_buffer::sample_t sample_scale = 1.0 / 8192.0; for (i = 0; i < buffer.samples(); i++) { v = 0; @@ -958,6 +957,6 @@ void mos6560_device::sound_stream_update(sound_stream &stream, std::vector<read_ v = 8191; else if (v < -8191) v = -8191; - buffer.put(i, stream_buffer::sample_t(v) * sample_scale); + buffer.put_int(i, v, 8192); } } diff --git a/src/devices/sound/mos7360.cpp b/src/devices/sound/mos7360.cpp index 3ca5e48ef8f..993cade8ec2 100644 --- a/src/devices/sound/mos7360.cpp +++ b/src/devices/sound/mos7360.cpp @@ -463,7 +463,6 @@ void mos7360_device::sound_stream_update(sound_stream &stream, std::vector<read_ int i, v, a; auto &buffer = outputs[0]; - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (i = 0; i < buffer.samples(); i++) { v = 0; @@ -507,7 +506,7 @@ void mos7360_device::sound_stream_update(sound_stream &stream, std::vector<read_ v = v * a; - buffer.put(i, stream_buffer::sample_t(v) * sample_scale); + buffer.put_int(i, v, 32768); } } diff --git a/src/devices/sound/msm5232.cpp b/src/devices/sound/msm5232.cpp index 43d02d542e7..972b83a8c53 100644 --- a/src/devices/sound/msm5232.cpp +++ b/src/devices/sound/msm5232.cpp @@ -743,17 +743,16 @@ void msm5232_device::sound_stream_update(sound_stream &stream, std::vector<read_ auto &bufnoise = outputs[10]; int i; - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (i=0; i<buf1.samples(); i++) { /* calculate all voices' envelopes */ EG_voices_advance(); TG_group_advance(0); /* calculate tones group 1 */ - buf1.put(i, stream_buffer::sample_t(o2) * sample_scale); - buf2.put(i, stream_buffer::sample_t(o4) * sample_scale); - buf3.put(i, stream_buffer::sample_t(o8) * sample_scale); - buf4.put(i, stream_buffer::sample_t(o16) * sample_scale); + buf1.put_int(i, o2, 32768); + buf2.put_int(i, o4, 32768); + buf3.put_int(i, o8, 32768); + buf4.put_int(i, o16, 32768); SAVE_SINGLE_CHANNEL(0,o2) SAVE_SINGLE_CHANNEL(1,o4) @@ -761,13 +760,13 @@ void msm5232_device::sound_stream_update(sound_stream &stream, std::vector<read_ SAVE_SINGLE_CHANNEL(3,o16) TG_group_advance(1); /* calculate tones group 2 */ - buf5.put(i, stream_buffer::sample_t(o2) * sample_scale); - buf6.put(i, stream_buffer::sample_t(o4) * sample_scale); - buf7.put(i, stream_buffer::sample_t(o8) * sample_scale); - buf8.put(i, stream_buffer::sample_t(o16) * sample_scale); + buf5.put_int(i, o2, 32768); + buf6.put_int(i, o4, 32768); + buf7.put_int(i, o8, 32768); + buf8.put_int(i, o16, 32768); - bufsolo1.put(i, stream_buffer::sample_t(solo8) * sample_scale); - bufsolo2.put(i, stream_buffer::sample_t(solo16) * sample_scale); + bufsolo1.put_int(i, solo8, 32768); + bufsolo2.put_int(i, solo16, 32768); SAVE_SINGLE_CHANNEL(4,o2) SAVE_SINGLE_CHANNEL(5,o4) diff --git a/src/devices/sound/multipcm.cpp b/src/devices/sound/multipcm.cpp index 150cbd73301..2c30aeadc38 100644 --- a/src/devices/sound/multipcm.cpp +++ b/src/devices/sound/multipcm.cpp @@ -632,19 +632,6 @@ void multipcm_device::device_clock_changed() // 16 bits and convert to a stream_buffer::sample_t //----------------------------------------------------- -stream_buffer::sample_t multipcm_device::convert_to_stream_sample(int32_t value) -{ - if (value < -32768) - { - return -1.0; - } - else if (value > 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<read } } - outputs[0].put(i, convert_to_stream_sample(smpl)); - outputs[1].put(i, convert_to_stream_sample(smpr)); + outputs[0].put_int_clamp(i, smpl, 32768); + outputs[1].put_int_clamp(i, smpr, 32768); } } diff --git a/src/devices/sound/namco.cpp b/src/devices/sound/namco.cpp index 830f3713b45..46f04d4c34d 100644 --- a/src/devices/sound/namco.cpp +++ b/src/devices/sound/namco.cpp @@ -43,8 +43,6 @@ /* a position of waveform sample */ #define WAVEFORM_POSITION(n) (((n) >> 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::vector<r if (voice->noise_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::vector<r int cnt; if (voice->noise_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<read_s int accum; auto &output = outputs[0]; - constexpr stream_buffer::sample_t sample_scale = 1.0 / 128.0; for (int sampindex = 0; sampindex < output.samples(); sampindex++) { accum = apu_square(&m_APU.squ[0]); @@ -742,12 +741,6 @@ void nesapu_device::sound_stream_update(sound_stream &stream, std::vector<read_s accum += apu_noise(&m_APU.noi); accum += apu_dpcm(&m_APU.dpcm); - /* 8-bit clamps */ - if (accum > 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<read_str } } mixp = &mix[0]; - constexpr stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * 16.0); for (i = 0; i < outputs[0].samples(); i++) { - outputs[0].put(i, stream_buffer::sample_t(*mixp++) * sample_scale); - outputs[1].put(i, stream_buffer::sample_t(*mixp++) * sample_scale); + outputs[0].put_int(i, *mixp++, 32768 * 16); + outputs[1].put_int(i, *mixp++, 32768 * 16); } } diff --git a/src/devices/sound/okim6295.cpp b/src/devices/sound/okim6295.cpp index c3aee26e52e..a6acbe12e9b 100644 --- a/src/devices/sound/okim6295.cpp +++ b/src/devices/sound/okim6295.cpp @@ -344,7 +344,6 @@ void okim6295_device::okim_voice::generate_adpcm(device_rom_interface &rom, writ return; // loop while we still have samples to generate - constexpr stream_buffer::sample_t sample_scale = 1.0 / 2048.0; for (int sampindex = 0; sampindex < buffer.samples(); sampindex++) { // fetch the next sample byte @@ -352,7 +351,7 @@ void okim6295_device::okim_voice::generate_adpcm(device_rom_interface &rom, writ // output to the buffer, scaling by the volume // signal in range -2048..2047 - buffer.add(sampindex, m_adpcm.clock(nibble) * sample_scale * m_volume); + buffer.add_int(sampindex, m_adpcm.clock(nibble) * m_volume, 2048); // next! if (++m_sample >= 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<read_s if (!m_pwm_mode) { - constexpr stream_buffer::sample_t sample_scale = 1.0 / 128.0; for (int sampindex = 0; sampindex < output.samples(); sampindex++) - output.put(sampindex, stream_buffer::sample_t(next()) * sample_scale); + output.put_int(sampindex, next(), 128); } else { diff --git a/src/devices/sound/tms5220.cpp b/src/devices/sound/tms5220.cpp index 9c4974c34e2..d0afb710f46 100644 --- a/src/devices/sound/tms5220.cpp +++ b/src/devices/sound/tms5220.cpp @@ -2061,7 +2061,6 @@ void tms5220_device::sound_stream_update(sound_stream &stream, std::vector<read_ auto &output = outputs[0]; /* loop while we still have samples to generate */ - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (int sampindex = 0; sampindex < output.samples(); ) { int length = (output.samples() > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : output.samples(); @@ -2069,7 +2068,7 @@ void tms5220_device::sound_stream_update(sound_stream &stream, std::vector<read_ /* generate the samples and copy to the target buffer */ process(sample_data, length); for (int index = 0; index < length; index++) - output.put(sampindex++, sample_data[index] * sample_scale); + output.put_int(sampindex++, sample_data[index], 32768); } } diff --git a/src/devices/sound/ym2151.cpp b/src/devices/sound/ym2151.cpp index b519d9a1224..74cfa9643ae 100644 --- a/src/devices/sound/ym2151.cpp +++ b/src/devices/sound/ym2151.cpp @@ -1845,7 +1845,6 @@ void ym2151_device::sound_stream_update(sound_stream &stream, std::vector<read_s return; } - constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (int sampindex=0; sampindex<outputs[0].samples(); sampindex++) { advance_eg(); @@ -1864,16 +1863,8 @@ void ym2151_device::sound_stream_update(sound_stream &stream, std::vector<read_s outr += chanout[ch] & pan[2*ch+1]; } - if (outl > 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(); } diff --git a/src/emu/sound.h b/src/emu/sound.h index c3027b28ba6..03c5ccb335e 100644 --- a/src/emu/sound.h +++ b/src/emu/sound.h @@ -346,6 +346,7 @@ protected: class write_stream_view : public read_stream_view { + public: // empty constructor so we can live in an array or vector write_stream_view() @@ -364,7 +365,7 @@ public: { } - // safely write a gain-applied sample to the buffer + // safely write a sample to the buffer void put(s32 index, sample_t sample) { sound_assert(u32(index) < samples()); @@ -374,7 +375,33 @@ public: m_buffer->put(index, sample); } - // safely add a gain-applied sample to the buffer + // write a sample to the buffer, clamping to +/- the clamp value + void put_clamp(s32 index, sample_t sample, sample_t clamp = 1.0) + { + if (sample > clamp) + sample = clamp; + if (sample < -clamp) + sample = -clamp; + put(index, sample); + } + + // write a sample to the buffer, converting from an integer with the given maximum + void put_int(s32 index, s32 sample, s32 max) + { + put(index, sample_t(sample) * (1.0f / sample_t(max))); + } + + // write a sample to the buffer, converting from an integer with the given maximum + void put_int_clamp(s32 index, s32 sample, s32 maxclamp) + { + if (sample > maxclamp) + sample = maxclamp; + else if (sample < -maxclamp) + sample = -maxclamp; + put_int(index, sample, maxclamp); + } + + // safely add a sample to the buffer void add(s32 index, sample_t sample) { sound_assert(u32(index) < samples()); @@ -384,6 +411,12 @@ public: m_buffer->put(index, m_buffer->get(index) + sample); } + // add a sample to the buffer, converting from an integer with the given maximum + void add_int(s32 index, s32 sample, s32 max) + { + add(index, sample_t(sample) * (1.0f / sample_t(max))); + } + // fill part of the view with the given value void fill(sample_t value, s32 start, s32 count) { |