From c1bd56f0d318c71faac757d89c910c2682af6651 Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Sun, 13 Sep 2020 10:18:44 -0700 Subject: Significant internal changes to sound streams (#7169) Significant internal changes to sound streams: Abstracted buffers of sound data into an internal stream_buffer class, with helper classes read_stream_view and write_stream_view which offer readable/writable "views" into the buffers Internal sound calculations are all done using stream_buffer::sample_t, which is a 32-bit float; existing callbacks are supported through an adapter that converts to/from signed 32-bit integers Improved behavior of dynamic stream sample rate changes to resample a short runway of data to preserve continuity across transitions Created a new stream update callback which passes a std::vector of read_stream_views for inputs, and a std::vector of write_stream_views for outputs Updated core mixer and speaker devices to the new stream update callback Updated the following sound cores to the new stream update callback: ay8910, dac, k054539, msm5205, namco, netlist, okim6295, pokey, samples, sn76496, sp0250, tms5220, tms57002, upd7759, vgm_visualizer, volt_reg Changed existing stream update callback to make inputs explicitly const and the output pointers const as well, since they are re-used across calls; fixed several engines that violated this rule Sound_manager::stream_alloc can no longer automatically connect to a device's sound_stream_update callback; instead, the stream_alloc() on the sound_device_interface should be called; updated many violators of this rule Streams can be created with SAMPLE_RATE_OUTPUT_ADAPTIVE, which dynamically tracks the sample rate of its first downstream output, or with SAMPLE_RATE_INPUT_ADAPTIVE, which tracks the sample rate of its first input Changed resampling to be a separate sound_stream that is invoked as needed, opening the path for selectable resampling implementations Added a flags parameter to the new stream allocation method that allows you to specify a that input streams should not be resampled Exposed stream_input and stream_output classes directly, simplifying access to user gains and stream names Added a simple dynamic compressor to sound_manager to provide nicer results when overdriven sound happens; compression does not affect speaker_report results Improved verbose speaker_report to print a graph of peaks over time More aggressive debugging enabled for now even in release builds (should be disabled prior to next release) via SOUND_DEBUG define in sound.h; report any assertions for fixing --- src/devices/bus/a2bus/a2mcms.cpp | 4 +- src/devices/bus/a2bus/a2mcms.h | 2 +- src/devices/bus/coco/coco_ssc.cpp | 10 +- src/devices/bus/isa/gus.cpp | 4 +- src/devices/bus/isa/gus.h | 2 +- src/devices/cpu/tms57002/tms57002.cpp | 37 +- src/devices/cpu/tms57002/tms57002.h | 2 +- src/devices/imagedev/cassette.cpp | 4 +- src/devices/imagedev/cassette.h | 2 +- src/devices/imagedev/floppy.cpp | 6 +- src/devices/imagedev/floppy.h | 2 +- src/devices/machine/8364_paula.cpp | 6 +- src/devices/machine/8364_paula.h | 2 +- src/devices/machine/acorn_vidc.cpp | 2 +- src/devices/machine/laserdsc.cpp | 6 +- src/devices/machine/laserdsc.h | 2 +- src/devices/machine/netlist.cpp | 60 +- src/devices/machine/netlist.h | 23 +- src/devices/machine/s2636.cpp | 6 +- src/devices/machine/s2636.h | 2 +- src/devices/machine/spg2xx_audio.cpp | 4 +- src/devices/machine/spg2xx_audio.h | 2 +- src/devices/sound/2203intf.cpp | 6 +- src/devices/sound/2203intf.h | 2 +- src/devices/sound/2608intf.cpp | 6 +- src/devices/sound/2608intf.h | 2 +- src/devices/sound/2610intf.cpp | 10 +- src/devices/sound/2610intf.h | 4 +- src/devices/sound/2612intf.cpp | 8 +- src/devices/sound/2612intf.h | 2 +- src/devices/sound/262intf.cpp | 6 +- src/devices/sound/262intf.h | 2 +- src/devices/sound/3526intf.cpp | 6 +- src/devices/sound/3526intf.h | 2 +- src/devices/sound/3812intf.cpp | 6 +- src/devices/sound/3812intf.h | 2 +- src/devices/sound/8950intf.cpp | 6 +- src/devices/sound/8950intf.h | 2 +- src/devices/sound/aica.cpp | 8 +- src/devices/sound/aica.h | 6 +- src/devices/sound/asc.cpp | 6 +- src/devices/sound/asc.h | 2 +- src/devices/sound/astrocde.cpp | 6 +- src/devices/sound/astrocde.h | 2 +- src/devices/sound/awacs.cpp | 6 +- src/devices/sound/awacs.h | 2 +- src/devices/sound/ay8910.cpp | 60 +- src/devices/sound/ay8910.h | 10 +- src/devices/sound/beep.cpp | 6 +- src/devices/sound/beep.h | 2 +- src/devices/sound/bsmt2000.cpp | 6 +- src/devices/sound/bsmt2000.h | 2 +- src/devices/sound/c140.cpp | 8 +- src/devices/sound/c140.h | 4 +- src/devices/sound/c352.cpp | 6 +- src/devices/sound/c352.h | 2 +- src/devices/sound/c6280.cpp | 4 +- src/devices/sound/c6280.h | 2 +- src/devices/sound/cdda.cpp | 6 +- src/devices/sound/cdda.h | 2 +- src/devices/sound/cdp1863.cpp | 6 +- src/devices/sound/cdp1863.h | 2 +- src/devices/sound/cdp1864.cpp | 6 +- src/devices/sound/cdp1864.h | 2 +- src/devices/sound/cdp1869.cpp | 6 +- src/devices/sound/cdp1869.h | 2 +- src/devices/sound/cem3394.cpp | 6 +- src/devices/sound/cem3394.h | 2 +- src/devices/sound/dac.h | 77 +- src/devices/sound/dac76.cpp | 6 +- src/devices/sound/dac76.h | 2 +- src/devices/sound/dave.cpp | 6 +- src/devices/sound/dave.h | 2 +- src/devices/sound/digitalk.cpp | 6 +- src/devices/sound/digitalk.h | 2 +- src/devices/sound/disc_cls.h | 2 +- src/devices/sound/disc_inp.hxx | 4 +- src/devices/sound/discrete.cpp | 8 +- src/devices/sound/discrete.h | 2 +- src/devices/sound/dmadac.cpp | 6 +- src/devices/sound/dmadac.h | 2 +- src/devices/sound/dspv.cpp | 2 +- src/devices/sound/dspv.h | 2 +- src/devices/sound/es1373.cpp | 12 +- src/devices/sound/es1373.h | 2 +- src/devices/sound/es5503.cpp | 4 +- src/devices/sound/es5503.h | 2 +- src/devices/sound/es5506.cpp | 14 +- src/devices/sound/es5506.h | 8 +- src/devices/sound/esqpump.cpp | 4 +- src/devices/sound/esqpump.h | 2 +- src/devices/sound/flt_rc.cpp | 8 +- src/devices/sound/flt_rc.h | 2 +- src/devices/sound/flt_vol.cpp | 8 +- src/devices/sound/flt_vol.h | 2 +- src/devices/sound/fm.cpp | 6 +- src/devices/sound/fm.h | 8 +- src/devices/sound/fm2612.cpp | 2 +- src/devices/sound/gaelco.cpp | 4 +- src/devices/sound/gaelco.h | 2 +- src/devices/sound/gb.cpp | 12 +- src/devices/sound/gb.h | 2 +- src/devices/sound/hc55516.cpp | 14 +- src/devices/sound/hc55516.h | 6 +- src/devices/sound/huc6230.cpp | 4 +- src/devices/sound/huc6230.h | 2 +- src/devices/sound/i5000.cpp | 4 +- src/devices/sound/i5000.h | 2 +- src/devices/sound/ics2115.cpp | 6 +- src/devices/sound/ics2115.h | 4 +- src/devices/sound/iopspu.cpp | 2 +- src/devices/sound/iopspu.h | 2 +- src/devices/sound/iremga20.cpp | 6 +- src/devices/sound/iremga20.h | 2 +- src/devices/sound/k005289.cpp | 6 +- src/devices/sound/k005289.h | 2 +- src/devices/sound/k007232.cpp | 6 +- src/devices/sound/k007232.h | 2 +- src/devices/sound/k051649.cpp | 6 +- src/devices/sound/k051649.h | 2 +- src/devices/sound/k053260.cpp | 8 +- src/devices/sound/k053260.h | 2 +- src/devices/sound/k054539.cpp | 13 +- src/devices/sound/k054539.h | 2 +- src/devices/sound/ks0164.cpp | 4 +- src/devices/sound/ks0164.h | 2 +- src/devices/sound/l7a1045_l6028_dsp_a.cpp | 6 +- src/devices/sound/l7a1045_l6028_dsp_a.h | 2 +- src/devices/sound/lmc1992.cpp | 4 +- src/devices/sound/lmc1992.h | 2 +- src/devices/sound/mas3507d.cpp | 10 +- src/devices/sound/mas3507d.h | 4 +- src/devices/sound/mea8000.cpp | 4 +- src/devices/sound/mea8000.h | 2 +- src/devices/sound/mos6560.cpp | 6 +- src/devices/sound/mos6560.h | 2 +- src/devices/sound/mos6581.cpp | 6 +- src/devices/sound/mos6581.h | 2 +- src/devices/sound/mos7360.cpp | 6 +- src/devices/sound/mos7360.h | 2 +- src/devices/sound/msm5205.cpp | 23 +- src/devices/sound/msm5205.h | 4 +- src/devices/sound/msm5232.cpp | 6 +- src/devices/sound/msm5232.h | 2 +- src/devices/sound/multipcm.cpp | 6 +- src/devices/sound/multipcm.h | 2 +- src/devices/sound/n63701x.cpp | 6 +- src/devices/sound/n63701x.h | 2 +- src/devices/sound/namco.cpp | 139 ++- src/devices/sound/namco.h | 10 +- src/devices/sound/namco_163.cpp | 4 +- src/devices/sound/namco_163.h | 2 +- src/devices/sound/nes_apu.cpp | 11 +- src/devices/sound/nes_apu.h | 2 +- src/devices/sound/nile.cpp | 6 +- src/devices/sound/nile.h | 2 +- src/devices/sound/okim6258.cpp | 6 +- src/devices/sound/okim6258.h | 2 +- src/devices/sound/okim6295.cpp | 53 +- src/devices/sound/okim6295.h | 20 +- src/devices/sound/okim6376.cpp | 25 +- src/devices/sound/okim6376.h | 7 +- src/devices/sound/okim9810.cpp | 6 +- src/devices/sound/okim9810.h | 4 +- src/devices/sound/pcd3311.cpp | 4 +- src/devices/sound/pcd3311.h | 2 +- src/devices/sound/pokey.cpp | 47 +- src/devices/sound/pokey.h | 4 +- src/devices/sound/qs1000.cpp | 6 +- src/devices/sound/qs1000.h | 2 +- src/devices/sound/qsound.cpp | 6 +- src/devices/sound/qsound.h | 2 +- src/devices/sound/qsoundhle.cpp | 6 +- src/devices/sound/qsoundhle.h | 2 +- src/devices/sound/rf5c400.cpp | 6 +- src/devices/sound/rf5c400.h | 2 +- src/devices/sound/rf5c68.cpp | 6 +- src/devices/sound/rf5c68.h | 2 +- src/devices/sound/rolandpcm.cpp | 6 +- src/devices/sound/rolandpcm.h | 2 +- src/devices/sound/rp2c33_snd.cpp | 6 +- src/devices/sound/rp2c33_snd.h | 2 +- src/devices/sound/s14001a.cpp | 6 +- src/devices/sound/s14001a.h | 2 +- src/devices/sound/s_dsp.cpp | 10 +- src/devices/sound/s_dsp.h | 2 +- src/devices/sound/saa1099.cpp | 6 +- src/devices/sound/saa1099.h | 2 +- src/devices/sound/samples.cpp | 83 +- src/devices/sound/samples.h | 15 +- src/devices/sound/scsp.cpp | 16 +- src/devices/sound/scsp.h | 6 +- src/devices/sound/segapcm.cpp | 6 +- src/devices/sound/segapcm.h | 2 +- src/devices/sound/sn76477.cpp | 6 +- src/devices/sound/sn76477.h | 2 +- src/devices/sound/sn76496.cpp | 17 +- src/devices/sound/sn76496.h | 2 +- src/devices/sound/snkwave.cpp | 6 +- src/devices/sound/snkwave.h | 2 +- src/devices/sound/sp0250.cpp | 30 +- src/devices/sound/sp0250.h | 2 +- src/devices/sound/sp0256.cpp | 6 +- src/devices/sound/sp0256.h | 2 +- src/devices/sound/spkrdev.cpp | 6 +- src/devices/sound/spkrdev.h | 2 +- src/devices/sound/spu.cpp | 16 +- src/devices/sound/spu.h | 8 +- src/devices/sound/st0016.cpp | 6 +- src/devices/sound/st0016.h | 2 +- src/devices/sound/swp00.cpp | 4 +- src/devices/sound/swp00.h | 2 +- src/devices/sound/swp20.cpp | 2 +- src/devices/sound/swp20.h | 2 +- src/devices/sound/swp30.cpp | 4 +- src/devices/sound/swp30.h | 2 +- src/devices/sound/t6721a.cpp | 6 +- src/devices/sound/t6721a.h | 2 +- src/devices/sound/t6w28.cpp | 6 +- src/devices/sound/t6w28.h | 2 +- src/devices/sound/tc8830f.cpp | 4 +- src/devices/sound/tc8830f.h | 2 +- src/devices/sound/tiaintf.cpp | 6 +- src/devices/sound/tiaintf.h | 2 +- src/devices/sound/tms3615.cpp | 27 +- src/devices/sound/tms3615.h | 2 +- src/devices/sound/tms36xx.cpp | 6 +- src/devices/sound/tms36xx.h | 2 +- src/devices/sound/tms5110.cpp | 6 +- src/devices/sound/tms5110.h | 2 +- src/devices/sound/tms5220.cpp | 19 +- src/devices/sound/tms5220.h | 2 +- src/devices/sound/upd1771.cpp | 6 +- src/devices/sound/upd1771.h | 2 +- src/devices/sound/upd7752.cpp | 6 +- src/devices/sound/upd7752.h | 2 +- src/devices/sound/upd7759.cpp | 77 +- src/devices/sound/upd7759.h | 26 +- src/devices/sound/upd934g.cpp | 6 +- src/devices/sound/upd934g.h | 2 +- src/devices/sound/vgm_visualizer.cpp | 34 +- src/devices/sound/vgm_visualizer.h | 6 +- src/devices/sound/vlm5030.cpp | 6 +- src/devices/sound/vlm5030.h | 2 +- src/devices/sound/volt_reg.cpp | 11 +- src/devices/sound/volt_reg.h | 6 +- src/devices/sound/votrax.cpp | 6 +- src/devices/sound/votrax.h | 2 +- src/devices/sound/vrc6.cpp | 6 +- src/devices/sound/vrc6.h | 2 +- src/devices/sound/vrender0.cpp | 6 +- src/devices/sound/vrender0.h | 2 +- src/devices/sound/wave.cpp | 8 +- src/devices/sound/wave.h | 2 +- src/devices/sound/x1_010.cpp | 6 +- src/devices/sound/x1_010.h | 2 +- src/devices/sound/ym2151.cpp | 13 +- src/devices/sound/ym2151.h | 2 +- src/devices/sound/ym2413.cpp | 6 +- src/devices/sound/ym2413.h | 2 +- src/devices/sound/ymf262.cpp | 2 +- src/devices/sound/ymf262.h | 2 +- src/devices/sound/ymf271.cpp | 6 +- src/devices/sound/ymf271.h | 2 +- src/devices/sound/ymf278b.cpp | 6 +- src/devices/sound/ymf278b.h | 2 +- src/devices/sound/ymz280b.cpp | 6 +- src/devices/sound/ymz280b.h | 2 +- src/devices/sound/ymz770.cpp | 6 +- src/devices/sound/ymz770.h | 2 +- src/devices/sound/zsg2.cpp | 6 +- src/devices/sound/zsg2.h | 2 +- src/devices/video/i8244.cpp | 4 +- src/devices/video/i8244.h | 2 +- src/emu/disound.cpp | 98 +- src/emu/disound.h | 18 +- src/emu/sound.cpp | 1658 +++++++++++++++++++---------- src/emu/sound.h | 814 +++++++++++--- src/emu/speaker.cpp | 59 +- src/emu/speaker.h | 16 +- src/frontend/mame/ui/ui.cpp | 10 +- src/mame/audio/arcadia.cpp | 6 +- src/mame/audio/arcadia.h | 2 +- src/mame/audio/channelf.cpp | 6 +- src/mame/audio/channelf.h | 2 +- src/mame/audio/cheekyms.cpp | 2 +- src/mame/audio/cinemat.cpp | 26 +- src/mame/audio/cmi01a.cpp | 4 +- src/mame/audio/cmi01a.h | 2 +- src/mame/audio/cps3.cpp | 6 +- src/mame/audio/cps3.h | 2 +- src/mame/audio/dai_snd.cpp | 6 +- src/mame/audio/dai_snd.h | 2 +- src/mame/audio/dsbz80.cpp | 4 +- src/mame/audio/dsbz80.h | 2 +- src/mame/audio/elan_eu3a05.cpp | 6 +- src/mame/audio/elan_eu3a05.h | 2 +- src/mame/audio/exidy.cpp | 6 +- src/mame/audio/exidy.h | 2 +- src/mame/audio/exidy440.cpp | 6 +- src/mame/audio/exidy440.h | 2 +- src/mame/audio/flower.cpp | 4 +- src/mame/audio/flower.h | 2 +- src/mame/audio/geebee.cpp | 6 +- src/mame/audio/geebee.h | 2 +- src/mame/audio/gomoku.cpp | 6 +- src/mame/audio/gomoku.h | 2 +- src/mame/audio/gridlee.cpp | 6 +- src/mame/audio/hyprolyb.cpp | 6 +- src/mame/audio/hyprolyb.h | 2 +- src/mame/audio/irem.cpp | 6 +- src/mame/audio/lynx.cpp | 12 +- src/mame/audio/lynx.h | 4 +- src/mame/audio/mario.cpp | 2 +- src/mame/audio/micro3d.cpp | 6 +- src/mame/audio/micro3d.h | 2 +- src/mame/audio/mw8080bw.cpp | 6 +- src/mame/audio/phoenix.cpp | 6 +- src/mame/audio/phoenix.h | 2 +- src/mame/audio/pleiads.cpp | 14 +- src/mame/audio/pleiads.h | 6 +- src/mame/audio/polepos.cpp | 6 +- src/mame/audio/polepos.h | 2 +- src/mame/audio/redbaron.cpp | 6 +- src/mame/audio/redbaron.h | 2 +- src/mame/audio/segag80.cpp | 8 +- src/mame/audio/segag80r.cpp | 6 +- src/mame/audio/segausb.cpp | 6 +- src/mame/audio/segausb.h | 2 +- src/mame/audio/seibu.cpp | 6 +- src/mame/audio/seibu.h | 2 +- src/mame/audio/snk6502.cpp | 6 +- src/mame/audio/snk6502.h | 2 +- src/mame/audio/socrates.cpp | 6 +- src/mame/audio/socrates.h | 2 +- src/mame/audio/special.cpp | 6 +- src/mame/audio/special.h | 2 +- src/mame/audio/svis_snd.cpp | 6 +- src/mame/audio/svis_snd.h | 2 +- src/mame/audio/tiamc1.cpp | 6 +- src/mame/audio/tiamc1.h | 2 +- src/mame/audio/timeplt.cpp | 6 +- src/mame/audio/timeplt.h | 2 +- src/mame/audio/trackfld.cpp | 6 +- src/mame/audio/trackfld.h | 2 +- src/mame/audio/turrett.cpp | 6 +- src/mame/audio/tvc.cpp | 12 +- src/mame/audio/tvc.h | 2 +- src/mame/audio/tx1.cpp | 12 +- src/mame/audio/tx1.h | 4 +- src/mame/audio/vboy.cpp | 6 +- src/mame/audio/vboy.h | 2 +- src/mame/audio/vc4000.cpp | 6 +- src/mame/audio/vc4000.h | 2 +- src/mame/audio/warpwarp.cpp | 6 +- src/mame/audio/warpwarp.h | 2 +- src/mame/audio/wiping.cpp | 6 +- src/mame/audio/wiping.h | 2 +- src/mame/audio/wswan.cpp | 12 +- src/mame/audio/wswan.h | 2 +- src/mame/audio/xavix.cpp | 4 +- src/mame/audio/zaccaria.cpp | 6 +- src/mame/drivers/1942.cpp | 2 +- src/mame/drivers/carpolo.cpp | 2 +- src/mame/drivers/cocoloco.cpp | 2 +- src/mame/drivers/destroyr.cpp | 2 +- src/mame/drivers/esq1.cpp | 6 +- src/mame/drivers/flyball.cpp | 2 +- src/mame/drivers/galaxian.cpp | 4 +- src/mame/drivers/gamemachine.cpp | 2 +- src/mame/drivers/istrebiteli.cpp | 6 +- src/mame/drivers/milton6805.cpp | 6 +- src/mame/drivers/ninjaw.cpp | 6 +- src/mame/drivers/popeye.cpp | 2 +- src/mame/drivers/pv1000.cpp | 8 +- src/mame/drivers/segas16b.cpp | 8 +- src/mame/drivers/starcrus.cpp | 2 +- src/mame/drivers/starfire.cpp | 4 +- src/mame/drivers/tankbatt.cpp | 2 +- src/mame/includes/gridlee.h | 2 +- src/mame/includes/segag80r.h | 2 +- src/mame/includes/turrett.h | 2 +- src/mame/includes/xavix.h | 2 +- src/mame/machine/mega32x.cpp | 4 +- src/mame/machine/mega32x.h | 2 +- src/mame/video/gic.cpp | 4 +- src/mame/video/gic.h | 2 +- 387 files changed, 3133 insertions(+), 2023 deletions(-) diff --git a/src/devices/bus/a2bus/a2mcms.cpp b/src/devices/bus/a2bus/a2mcms.cpp index 7e2cab57b6b..f9de57897f8 100644 --- a/src/devices/bus/a2bus/a2mcms.cpp +++ b/src/devices/bus/a2bus/a2mcms.cpp @@ -206,7 +206,7 @@ mcms_device::mcms_device(const machine_config &mconfig, const char *tag, device_ void mcms_device::device_start() { m_write_irq.resolve(); - m_stream = machine().sound().stream_alloc(*this, 0, 2, 31250); + m_stream = stream_alloc_legacy(0, 2, 31250); m_timer = timer_alloc(0, nullptr); m_clrtimer = timer_alloc(1, nullptr); m_enabled = false; @@ -252,7 +252,7 @@ void mcms_device::device_timer(emu_timer &timer, device_timer_id tid, int param, } } -void mcms_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void mcms_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *outL, *outR; int i, v; diff --git a/src/devices/bus/a2bus/a2mcms.h b/src/devices/bus/a2bus/a2mcms.h index 9a183a9313d..11e8b332ee0 100644 --- a/src/devices/bus/a2bus/a2mcms.h +++ b/src/devices/bus/a2bus/a2mcms.h @@ -42,7 +42,7 @@ protected: virtual void device_reset() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream *m_stream; diff --git a/src/devices/bus/coco/coco_ssc.cpp b/src/devices/bus/coco/coco_ssc.cpp index 2f7a1793071..63f6e90fcc5 100644 --- a/src/devices/bus/coco/coco_ssc.cpp +++ b/src/devices/bus/coco/coco_ssc.cpp @@ -130,7 +130,7 @@ namespace virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream* m_stream; @@ -535,17 +535,17 @@ cocossc_sac_device::cocossc_sac_device(const machine_config &mconfig, const char void cocossc_sac_device::device_start() { - m_stream = stream_alloc(1, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(1, 1, machine().sample_rate()); } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void cocossc_sac_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void cocossc_sac_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { - stream_sample_t *src = inputs[0]; + stream_sample_t const *src = inputs[0]; stream_sample_t *dst = outputs[0]; double n = samples; diff --git a/src/devices/bus/isa/gus.cpp b/src/devices/bus/isa/gus.cpp index 239b8a6d2d2..a1c3f39612e 100644 --- a/src/devices/bus/isa/gus.cpp +++ b/src/devices/bus/isa/gus.cpp @@ -243,7 +243,7 @@ void gf1_device::device_timer(emu_timer &timer, device_timer_id id, int param, v } } -void gf1_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void gf1_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int x,y; //uint32_t count; @@ -403,7 +403,7 @@ void gf1_device::device_start() m_wave_ram.resize(1024*1024); memset(&m_wave_ram[0], 0, 1024*1024); - m_stream = stream_alloc(0,2,clock() / (14 * 16)); + m_stream = stream_alloc_legacy(0,2,clock() / (14 * 16)); // init timers m_timer1 = timer_alloc(ADLIB_TIMER1); diff --git a/src/devices/bus/isa/gus.h b/src/devices/bus/isa/gus.h index ec2e4168142..3f637bee84d 100644 --- a/src/devices/bus/isa/gus.h +++ b/src/devices/bus/isa/gus.h @@ -123,7 +123,7 @@ public: // optional information overrides virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; protected: // voice-specific registers diff --git a/src/devices/cpu/tms57002/tms57002.cpp b/src/devices/cpu/tms57002/tms57002.cpp index 8464a10e2f0..c2cf28f3f92 100644 --- a/src/devices/cpu/tms57002/tms57002.cpp +++ b/src/devices/cpu/tms57002/tms57002.cpp @@ -918,28 +918,22 @@ void tms57002_device::execute_run() icount = 0; } -void tms57002_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void tms57002_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - assert(samples == 1); + assert(inputs[0].samples() == 1); + assert(outputs[0].samples() == 1); - if (st0 & ST0_SIM) - { - si[0] = (inputs[0][0] << 8) & 0xffffff; - si[1] = (inputs[1][0] << 8) & 0xffffff; - si[2] = (inputs[2][0] << 8) & 0xffffff; - si[3] = (inputs[3][0] << 8) & 0xffffff; - } - else - { - si[0] = inputs[0][0] & 0xffffff; - si[1] = inputs[1][0] & 0xffffff; - si[2] = inputs[2][0] & 0xffffff; - si[3] = inputs[3][0] & 0xffffff; - } - outputs[0][0] = int16_t(so[0] >> 8); - outputs[1][0] = int16_t(so[1] >> 8); - outputs[2][0] = int16_t(so[2] >> 8); - outputs[3][0] = int16_t(so[3] >> 8); + stream_buffer::sample_t in_scale = 32768.0 * ((st0 & ST0_SIM) ? 256.0 : 1.0); + si[0] = s32(inputs[0].get(0) * in_scale) & 0xffffff; + si[1] = s32(inputs[1].get(0) * in_scale) & 0xffffff; + 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); sync_w(1); } @@ -981,8 +975,7 @@ void tms57002_device::device_start() state_add(TMS57002_HOST3, "HOST3", host[3]); set_icountptr(icount); - - stream_alloc(4, 4, STREAM_SYNC); + stream_alloc(4, 4, SAMPLE_RATE_INPUT_ADAPTIVE, STREAM_SYNCHRONOUS); save_item(NAME(macc)); save_item(NAME(macc_read)); diff --git a/src/devices/cpu/tms57002/tms57002.h b/src/devices/cpu/tms57002/tms57002.h index b1a96823b06..12bcd732120 100644 --- a/src/devices/cpu/tms57002/tms57002.h +++ b/src/devices/cpu/tms57002/tms57002.h @@ -36,7 +36,7 @@ protected: virtual void device_resolve_objects() override; virtual void device_start() override; virtual void device_reset() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; virtual space_config_vector memory_space_config() const override; virtual u32 execute_min_cycles() const noexcept override; virtual u32 execute_max_cycles() const noexcept override; diff --git a/src/devices/imagedev/cassette.cpp b/src/devices/imagedev/cassette.cpp index 473dfe0ce7b..c6e20ba66dd 100644 --- a/src/devices/imagedev/cassette.cpp +++ b/src/devices/imagedev/cassette.cpp @@ -236,7 +236,7 @@ void cassette_image_device::device_start() m_state = m_default_state; m_value = 0; - machine().sound().stream_alloc(*this, 0, (m_stereo? 2:1), machine().sample_rate()); + stream_alloc_legacy(0, (m_stereo? 2:1), machine().sample_rate()); } image_init_result cassette_image_device::call_create(int format_type, util::option_resolution *format_options) @@ -404,7 +404,7 @@ std::string cassette_image_device::call_display() // Cassette sound //------------------------------------------------- -void cassette_image_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void cassette_image_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *left_buffer = outputs[0]; stream_sample_t *right_buffer = nullptr; diff --git a/src/devices/imagedev/cassette.h b/src/devices/imagedev/cassette.h index 790b2e0d8c3..a661e8312a8 100644 --- a/src/devices/imagedev/cassette.h +++ b/src/devices/imagedev/cassette.h @@ -102,7 +102,7 @@ public: void seek(double time, int origin); // sound stream update overrides - void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; device_sound_interface& set_stereo() { m_stereo = true; return *this; } protected: diff --git a/src/devices/imagedev/floppy.cpp b/src/devices/imagedev/floppy.cpp index f725845fa0d..3dd96644f1a 100644 --- a/src/devices/imagedev/floppy.cpp +++ b/src/devices/imagedev/floppy.cpp @@ -1248,7 +1248,7 @@ void floppy_sound_device::device_start() // If we don't have all samples, don't allocate a stream or access sample data. if (m_loaded) { - m_sound = machine().sound().stream_alloc(*this, 0, 1, clock()); // per-floppy stream + m_sound = stream_alloc_legacy(0, 1, clock()); // per-floppy stream } register_for_save_states(); } @@ -1369,10 +1369,10 @@ void floppy_sound_device::step(int zone) } //------------------------------------------------- -// sound_stream_update - update the sound stream +// sound_stream_update_legacy - update the sound stream //------------------------------------------------- -void floppy_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void floppy_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // We are using only one stream, unlike the parent class // Also, there is no need for interpolation, as we only expect diff --git a/src/devices/imagedev/floppy.h b/src/devices/imagedev/floppy.h index 4fa16d3c338..d07a12c146c 100644 --- a/src/devices/imagedev/floppy.h +++ b/src/devices/imagedev/floppy.h @@ -294,7 +294,7 @@ protected: private: // device_sound_interface overrides - void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; sound_stream* m_sound; int m_step_base; diff --git a/src/devices/machine/8364_paula.cpp b/src/devices/machine/8364_paula.cpp index a340b5a523c..1e10ca55b3e 100644 --- a/src/devices/machine/8364_paula.cpp +++ b/src/devices/machine/8364_paula.cpp @@ -58,7 +58,7 @@ void paula_8364_device::device_start() } // create the stream - m_stream = machine().sound().stream_alloc(*this, 0, 4, clock() / CLOCK_DIVIDER); + m_stream = stream_alloc_legacy(0, 4, clock() / CLOCK_DIVIDER); } //------------------------------------------------- @@ -159,10 +159,10 @@ void paula_8364_device::dma_reload(audio_channel *chan) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void paula_8364_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void paula_8364_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int channum, sampoffs = 0; diff --git a/src/devices/machine/8364_paula.h b/src/devices/machine/8364_paula.h index 0a7016c4496..a2ac2feab26 100644 --- a/src/devices/machine/8364_paula.h +++ b/src/devices/machine/8364_paula.h @@ -68,7 +68,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: enum diff --git a/src/devices/machine/acorn_vidc.cpp b/src/devices/machine/acorn_vidc.cpp index 65487e2b63a..36733555e7d 100644 --- a/src/devices/machine/acorn_vidc.cpp +++ b/src/devices/machine/acorn_vidc.cpp @@ -416,7 +416,7 @@ inline void acorn_vidc10_device::refresh_stereo_image(u8 channel) m_lspeaker->set_input_gain(channel,left_gain[m_stereo_image[channel]]*m_sound_input_gain); m_rspeaker->set_input_gain(channel,right_gain[m_stereo_image[channel]]*m_sound_input_gain); - //printf("%d %f %f\n",channel,m_lspeaker->input_gain(channel),m_rspeaker->input_gain(channel)); + //printf("%d %f %f\n",channel,m_lspeaker->input(channel).gain(),m_rspeaker->input(channel).gain()); } diff --git a/src/devices/machine/laserdsc.cpp b/src/devices/machine/laserdsc.cpp index 8176ac14f29..ef3df359859 100644 --- a/src/devices/machine/laserdsc.cpp +++ b/src/devices/machine/laserdsc.cpp @@ -308,11 +308,11 @@ void laserdisc_device::device_timer(emu_timer &timer, device_timer_id id, int pa //------------------------------------------------- -// sound_stream_update - audio streamer for +// sound_stream_update_legacy - audio streamer for // laserdiscs //------------------------------------------------- -void laserdisc_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void laserdisc_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // compute AND values based on the squelch int16_t leftand = (m_audiosquelch & 1) ? 0x0000 : 0xffff; @@ -762,7 +762,7 @@ void laserdisc_device::init_audio() m_audio_callback.resolve(); // allocate a stream - m_stream = stream_alloc(0, 2, 48000); + m_stream = stream_alloc_legacy(0, 2, 48000); // allocate audio buffers m_audiomaxsamples = ((uint64_t)m_samplerate * 1000000 + m_fps_times_1million - 1) / m_fps_times_1million; diff --git a/src/devices/machine/laserdsc.h b/src/devices/machine/laserdsc.h index e2877a4a216..8ca3abad222 100644 --- a/src/devices/machine/laserdsc.h +++ b/src/devices/machine/laserdsc.h @@ -220,7 +220,7 @@ protected: virtual void device_validity_check(validity_checker &valid) const override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // subclass helpers void set_audio_squelch(bool squelchleft, bool squelchright) { m_stream->update(); m_audiosquelch = (squelchleft ? 1 : 0) | (squelchright ? 2 : 0); } diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index 10208d8e357..988c21c33e1 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -263,7 +263,7 @@ plib::istream_uptr netlist_data_memregions_t::stream(const pstring &name) // sound_in // ---------------------------------------------------------------------------------------- -using sound_in_type = netlist::interface::NETLIB_NAME(buffered_param_setter); +using sound_in_type = netlist::interface::NETLIB_NAME(buffered_param_setter); class NETLIB_NAME(sound_in) : public sound_in_type { @@ -820,17 +820,15 @@ void netlist_mame_stream_output_device::device_reset() #endif } -void netlist_mame_stream_output_device::sound_update_fill(std::size_t samples, stream_sample_t *target) +void netlist_mame_stream_output_device::sound_update_fill(write_stream_view &target) { - if (samples < m_buffer.size()) - osd_printf_warning("sound %s: samples %d less bufsize %d\n", name(), samples, m_buffer.size()); + if (target.samples() < m_buffer.size()) + osd_printf_warning("sound %s: samples %d less bufsize %d\n", name(), target.samples(), m_buffer.size()); - std::copy(m_buffer.begin(), m_buffer.end(), target); - std::size_t pos = m_buffer.size(); - while (pos < samples) - { - target[pos++] = m_cur; - } + int sampindex; + for (sampindex = 0; sampindex < m_buffer.size(); sampindex++) + target.put(sampindex, m_buffer[sampindex]); + target.fill(m_cur, sampindex); } @@ -868,19 +866,10 @@ void netlist_mame_stream_output_device::process(netlist::netlist_time_ext tim, n // throw emu_fatalerror("sound %s: pos %d exceeded bufsize %d\n", name().c_str(), pos, m_bufsize); while (m_buffer.size() < pos ) { - m_buffer.push_back(static_cast(m_cur)); + m_buffer.push_back(static_cast(m_cur)); } - // clamp to avoid spikes, but not too hard, as downstream processing, volume - // controls, etc may bring values above 32767 back down in range; some clamping - // is still useful, however, as the mixing is done with integral values - if (plib::abs(val) < 32767.0*256.0) - m_cur = val; - else if (val > 0.0) - m_cur = 32767.0*256.0; - else - m_cur = -32767.0*256.0; - + m_cur = val; } @@ -1409,8 +1398,10 @@ void netlist_mame_sound_device::device_start() if (e.first < 0 || e.first >= m_in.size()) fatalerror("illegal input channel number %d", e.first); } + m_inbuffer.resize(m_in.size()); + /* initialize the stream(s) */ - m_stream = machine().sound().stream_alloc(*this, m_in.size(), m_out.size(), m_sound_clock); + m_stream = stream_alloc(m_in.size(), m_out.size(), m_sound_clock, STREAM_DISABLE_INPUT_RESAMPLING); LOGDEVCALLS("sound device_start exit\n"); } @@ -1453,26 +1444,25 @@ void netlist_mame_sound_device::update_to_current_time() LOGTIMING("%s : %f us before machine time\n", this->name(), (cur - mtime).as_double() * 1000000.0); } -void netlist_mame_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void netlist_mame_sound_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - const auto mtime = machine().time(); - if (mtime < m_last_update_to_current_time) - LOGTIMING("machine.time() decreased 1\n"); - m_last_update_to_current_time = mtime; - LOGDEBUG("samples %d\n", samples); - for (auto &e : m_in) { - auto sample_time = netlist::netlist_time::from_raw(static_cast(nltime_from_attotime(m_attotime_per_clock).as_raw())); - e.second->buffer_reset(sample_time, samples, &inputs[e.first]); + auto clock_period = inputs[e.first].sample_period(); + auto sample_time = netlist::netlist_time::from_raw(static_cast(nltime_from_attotime(clock_period).as_raw())); + m_inbuffer[e.first] = netlist_mame_sound_input_buffer(inputs[e.first]); + e.second->buffer_reset(sample_time, m_inbuffer[e.first].samples(), &m_inbuffer[e.first]); } - m_cur_time += (samples * m_attotime_per_clock); + int samples = outputs[0].samples(); + LOGDEBUG("samples %d\n", samples); - auto nl_target_time = std::min(nltime_from_attotime(mtime), nltime_from_attotime(m_cur_time)); + // end_time() is the time at the END of the last sample we're generating + // however, the sample value is the value at the START of that last sample, + // so subtract one sample period so that we only process up to the minimum + auto nl_target_time = nltime_from_attotime(outputs[0].end_time() - outputs[0].sample_period()); auto nltime(netlist().exec().time()); - if (nltime < nl_target_time) { netlist().exec().process_queue(nl_target_time - nltime); @@ -1480,7 +1470,7 @@ void netlist_mame_sound_device::sound_stream_update(sound_stream &stream, stream for (auto &e : m_out) { - e.second->sound_update_fill(samples, outputs[e.first]); + e.second->sound_update_fill(outputs[e.first]); e.second->buffer_reset(nl_target_time); } diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index b7a78c0bd77..8b9e156adba 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -228,6 +228,22 @@ private: netlist_mame_cpu_device *m_dev; }; +// ---------------------------------------------------------------------------------------- +// netlist_mame_sound_input_buffer +// ---------------------------------------------------------------------------------------- + +class netlist_mame_sound_input_buffer : public read_stream_view +{ +public: + netlist_mame_sound_input_buffer() : + read_stream_view() { } + + netlist_mame_sound_input_buffer(read_stream_view const &src) : + read_stream_view(src) { } + + stream_buffer::sample_t operator[](std::size_t index) { return get(index); } +}; + // ---------------------------------------------------------------------------------------- // netlist_mame_sound_device // ---------------------------------------------------------------------------------------- @@ -266,13 +282,14 @@ protected: // device_t overrides virtual void device_start() override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; virtual void device_validity_check(validity_checker &valid) const override; //virtual void device_reset() override; private: std::map m_out; std::map m_in; + std::vector m_inbuffer; sound_stream *m_stream; attotime m_cur_time; uint32_t m_sound_clock; @@ -593,7 +610,7 @@ public: m_buffer.clear(); } - void sound_update_fill(std::size_t samples, stream_sample_t *target); + void sound_update_fill(write_stream_view &target); void set_sample_time(netlist::netlist_time t) { m_sample_time = t; } @@ -608,7 +625,7 @@ private: uint32_t m_channel; const char * m_out_name; - std::vector m_buffer; + std::vector m_buffer; double m_cur; netlist::netlist_time m_sample_time; diff --git a/src/devices/machine/s2636.cpp b/src/devices/machine/s2636.cpp index ddc46adf81c..bdf95dc69d0 100644 --- a/src/devices/machine/s2636.cpp +++ b/src/devices/machine/s2636.cpp @@ -203,7 +203,7 @@ void s2636_device::device_start() save_item(NAME(m_intreq)); save_item(NAME(m_intack)); - m_stream = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 1, machine().sample_rate()); save_item(NAME(m_sample_cnt)); save_item(NAME(m_sound_lvl)); @@ -447,10 +447,10 @@ void s2636_device::write_intack(int state) //------------------------------------------------- -// sound_stream_update - generate audio output +// sound_stream_update_legacy - generate audio output //------------------------------------------------- -void s2636_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void s2636_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; while (samples--) diff --git a/src/devices/machine/s2636.h b/src/devices/machine/s2636.h index bc82ed68903..b5e41b83499 100644 --- a/src/devices/machine/s2636.h +++ b/src/devices/machine/s2636.h @@ -58,7 +58,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: enum diff --git a/src/devices/machine/spg2xx_audio.cpp b/src/devices/machine/spg2xx_audio.cpp index f1ffd871f28..07d01e88be5 100644 --- a/src/devices/machine/spg2xx_audio.cpp +++ b/src/devices/machine/spg2xx_audio.cpp @@ -76,7 +76,7 @@ void spg2xx_audio_device::device_start() m_audio_beat = timer_alloc(TIMER_BEAT); m_audio_beat->adjust(attotime::never); - m_stream = stream_alloc(0, 2, 281250/4); + m_stream = stream_alloc_legacy(0, 2, 281250/4); m_channel_debug = -1; @@ -887,7 +887,7 @@ void spg2xx_audio_device::audio_w(offs_t offset, uint16_t data) } } -void spg2xx_audio_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void spg2xx_audio_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *out_l = outputs[0]; stream_sample_t *out_r = outputs[1]; diff --git a/src/devices/machine/spg2xx_audio.h b/src/devices/machine/spg2xx_audio.h index 30b001edfb2..59d7635198d 100644 --- a/src/devices/machine/spg2xx_audio.h +++ b/src/devices/machine/spg2xx_audio.h @@ -33,7 +33,7 @@ public: protected: // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; void audio_beat_tick(); void audio_rampdown_tick(const uint32_t channel); diff --git a/src/devices/sound/2203intf.cpp b/src/devices/sound/2203intf.cpp index 9b49479af97..6b579f486a3 100644 --- a/src/devices/sound/2203intf.cpp +++ b/src/devices/sound/2203intf.cpp @@ -54,11 +54,11 @@ void ym2203_device::timer_handler(int c, int count, int clock) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void ym2203_device::stream_generate(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ym2203_device::stream_generate(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { ym2203_update_one(m_chip, outputs[0], samples); } @@ -108,7 +108,7 @@ void ym2203_device::calculate_rates() if (m_stream != nullptr) m_stream->set_sample_rate(rate); else - m_stream = machine().sound().stream_alloc(*this,0,1,rate, stream_update_delegate(&ym2203_device::stream_generate,this)); + m_stream = machine().sound().stream_alloc_legacy(*this,0,1,rate, stream_update_legacy_delegate(&ym2203_device::stream_generate,this)); } //------------------------------------------------- diff --git a/src/devices/sound/2203intf.h b/src/devices/sound/2203intf.h index ff4af97c667..ccb5841cd82 100644 --- a/src/devices/sound/2203intf.h +++ b/src/devices/sound/2203intf.h @@ -39,7 +39,7 @@ protected: virtual void device_clock_changed() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; - void stream_generate(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); + void stream_generate(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples); private: enum diff --git a/src/devices/sound/2608intf.cpp b/src/devices/sound/2608intf.cpp index 1bc634d34c2..4ca366fa117 100644 --- a/src/devices/sound/2608intf.cpp +++ b/src/devices/sound/2608intf.cpp @@ -63,10 +63,10 @@ void ym2608_device::timer_handler(int c,int count,int clock) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void ym2608_device::stream_generate(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ym2608_device::stream_generate(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { ym2608_update_one(m_chip, outputs, samples); } @@ -93,7 +93,7 @@ void ym2608_device::device_start() m_timer[1] = timer_alloc(1); /* stream system initialize */ - m_stream = machine().sound().stream_alloc(*this,0,2,rate, stream_update_delegate(&ym2608_device::stream_generate,this)); + m_stream = machine().sound().stream_alloc_legacy(*this,0,2,rate, stream_update_legacy_delegate(&ym2608_device::stream_generate,this)); /* initialize YM2608 */ m_chip = ym2608_init(this,clock(),rate, diff --git a/src/devices/sound/2608intf.h b/src/devices/sound/2608intf.h index 97e488805c4..c6a3fec6fc9 100644 --- a/src/devices/sound/2608intf.h +++ b/src/devices/sound/2608intf.h @@ -39,7 +39,7 @@ protected: virtual void rom_bank_updated() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; - void stream_generate(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); + void stream_generate(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples); private: void irq_handler(int irq); diff --git a/src/devices/sound/2610intf.cpp b/src/devices/sound/2610intf.cpp index 03c3fc218a2..2f6e3e08620 100644 --- a/src/devices/sound/2610intf.cpp +++ b/src/devices/sound/2610intf.cpp @@ -62,18 +62,18 @@ void ym2610_device::timer_handler(int c,int count,int clock) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void ym2610_device::stream_generate(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ym2610_device::stream_generate(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { ym2610_update_one(m_chip, outputs, samples); } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void ym2610b_device::stream_generate(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ym2610b_device::stream_generate(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { ym2610b_update_one(m_chip, outputs, samples); } @@ -102,7 +102,7 @@ void ym2610_device::device_start() m_timer[1] = timer_alloc(1); /* stream system initialize */ - m_stream = machine().sound().stream_alloc(*this,0,2,rate, stream_update_delegate(&ym2610_device::stream_generate,this)); + m_stream = machine().sound().stream_alloc_legacy(*this,0,2,rate, stream_update_legacy_delegate(&ym2610_device::stream_generate,this)); if (!has_configured_map(0) && !has_configured_map(1)) { diff --git a/src/devices/sound/2610intf.h b/src/devices/sound/2610intf.h index 91de98a41a4..a305f9d352d 100644 --- a/src/devices/sound/2610intf.h +++ b/src/devices/sound/2610intf.h @@ -40,7 +40,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; - virtual void stream_generate(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); + virtual void stream_generate(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples); void * m_chip; @@ -75,7 +75,7 @@ public: ym2610b_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); protected: - virtual void stream_generate(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void stream_generate(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; }; diff --git a/src/devices/sound/2612intf.cpp b/src/devices/sound/2612intf.cpp index 4c09413339c..679333cdcf3 100644 --- a/src/devices/sound/2612intf.cpp +++ b/src/devices/sound/2612intf.cpp @@ -56,10 +56,10 @@ void ym2612_device::timer_handler(int c,int count,int clock) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void ym2612_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ym2612_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { ym2612_update_one(m_chip, outputs, samples, m_output_bits); } @@ -87,7 +87,7 @@ void ym2612_device::device_start() m_timer[1] = timer_alloc(1); /* stream system initialize */ - m_stream = machine().sound().stream_alloc(*this,0,2,rate); + m_stream = stream_alloc_legacy(0,2,rate); /**** initialize YM2612 ****/ m_chip = ym2612_init(this,clock(),rate,&ym2612_device::static_timer_handler,&ym2612_device::static_irq_handler); @@ -108,7 +108,7 @@ void ym2612_device::calculate_rates() if (m_stream != nullptr) m_stream->set_sample_rate(rate); else - m_stream = machine().sound().stream_alloc(*this,0,2,rate); + m_stream = stream_alloc_legacy(0,2,rate); } //------------------------------------------------- diff --git a/src/devices/sound/2612intf.h b/src/devices/sound/2612intf.h index 1bbf9ea3bf9..f9447081d9b 100644 --- a/src/devices/sound/2612intf.h +++ b/src/devices/sound/2612intf.h @@ -33,7 +33,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; u8 m_output_bits; private: diff --git a/src/devices/sound/262intf.cpp b/src/devices/sound/262intf.cpp index f2aee977b30..0a76cdf6d2b 100644 --- a/src/devices/sound/262intf.cpp +++ b/src/devices/sound/262intf.cpp @@ -50,10 +50,10 @@ void ymf262_device::timer_handler(int c, const attotime &period) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void ymf262_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ymf262_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { ymf262_update_one(m_chip, outputs, samples); } @@ -81,7 +81,7 @@ void ymf262_device::device_start() if (!m_chip) throw emu_fatalerror("ymf262_device(%s): Error creating YMF262 chip", tag()); - m_stream = machine().sound().stream_alloc(*this,0,4,rate); + m_stream = stream_alloc_legacy(0,4,rate); /* YMF262 setup */ ymf262_set_timer_handler (m_chip, &ymf262_device::static_timer_handler, this); diff --git a/src/devices/sound/262intf.h b/src/devices/sound/262intf.h index 816b2903831..09ae497748d 100644 --- a/src/devices/sound/262intf.h +++ b/src/devices/sound/262intf.h @@ -27,7 +27,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: void irq_handler(int irq); diff --git a/src/devices/sound/3526intf.cpp b/src/devices/sound/3526intf.cpp index dd81b0d7eb0..dce29c78440 100644 --- a/src/devices/sound/3526intf.cpp +++ b/src/devices/sound/3526intf.cpp @@ -60,10 +60,10 @@ void ym3526_device::timer_handler(int c,const attotime &period) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void ym3526_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ym3526_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { ym3526_update_one(m_chip, outputs[0], samples); } @@ -109,7 +109,7 @@ void ym3526_device::calculate_rates() if (m_stream != nullptr) m_stream->set_sample_rate(rate); else - m_stream = machine().sound().stream_alloc(*this,0,1,rate); + m_stream = stream_alloc_legacy(0,1,rate); } //------------------------------------------------- diff --git a/src/devices/sound/3526intf.h b/src/devices/sound/3526intf.h index 0e57a08e36d..5b425f41241 100644 --- a/src/devices/sound/3526intf.h +++ b/src/devices/sound/3526intf.h @@ -32,7 +32,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: void irq_handler(int irq); diff --git a/src/devices/sound/3812intf.cpp b/src/devices/sound/3812intf.cpp index c5f5aeabb05..b9287f21d9e 100644 --- a/src/devices/sound/3812intf.cpp +++ b/src/devices/sound/3812intf.cpp @@ -62,10 +62,10 @@ void ym3812_device::timer_handler(int c, const attotime &period) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void ym3812_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ym3812_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { ym3812_update_one(m_chip, outputs[0], samples); } @@ -110,7 +110,7 @@ void ym3812_device::calculate_rates() if (m_stream != nullptr) m_stream->set_sample_rate(rate); else - m_stream = machine().sound().stream_alloc(*this, 0, 1, rate); + m_stream = stream_alloc_legacy(0, 1, rate); } //------------------------------------------------- diff --git a/src/devices/sound/3812intf.h b/src/devices/sound/3812intf.h index 1bf4e536370..46266bbbca2 100644 --- a/src/devices/sound/3812intf.h +++ b/src/devices/sound/3812intf.h @@ -30,7 +30,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: enum diff --git a/src/devices/sound/8950intf.cpp b/src/devices/sound/8950intf.cpp index 3907daa4700..63056582a0e 100644 --- a/src/devices/sound/8950intf.cpp +++ b/src/devices/sound/8950intf.cpp @@ -56,10 +56,10 @@ void y8950_device::timer_handler(int c, const attotime &period) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void y8950_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void y8950_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { y8950_update_one(m_chip, outputs[0], samples); } @@ -87,7 +87,7 @@ void y8950_device::device_start() /* ADPCM ROM data */ y8950_set_delta_t_memory(m_chip, &y8950_device::static_read_byte, &y8950_device::static_write_byte); - m_stream = machine().sound().stream_alloc(*this,0,1,rate); + m_stream = stream_alloc_legacy(0,1,rate); /* port and keyboard handler */ y8950_set_port_handler(m_chip, &y8950_device::static_port_handler_w, &y8950_device::static_port_handler_r, this); y8950_set_keyboard_handler(m_chip, &y8950_device::static_keyboard_handler_w, &y8950_device::static_keyboard_handler_r, this); diff --git a/src/devices/sound/8950intf.h b/src/devices/sound/8950intf.h index 221c02bfb20..d1ba497c08d 100644 --- a/src/devices/sound/8950intf.h +++ b/src/devices/sound/8950intf.h @@ -41,7 +41,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: void irq_handler(int irq); diff --git a/src/devices/sound/aica.cpp b/src/devices/sound/aica.cpp index f3ce7c337e0..8d4ef4286cc 100644 --- a/src/devices/sound/aica.cpp +++ b/src/devices/sound/aica.cpp @@ -1231,7 +1231,7 @@ s32 aica_device::UpdateSlot(AICA_SLOT *slot) void aica_device::DoMasterSamples(int nsamples) { - stream_sample_t *exts[2]; + stream_sample_t const *exts[2]; int i; stream_sample_t *bufr = m_bufferr; @@ -1390,10 +1390,10 @@ int aica_device::IRQCB(void *param) #endif //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void aica_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void aica_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { m_bufferl = outputs[0]; m_bufferr = outputs[1]; @@ -1418,7 +1418,7 @@ void aica_device::device_start() m_irq_cb.resolve_safe(); m_main_irq_cb.resolve_safe(); - m_stream = machine().sound().stream_alloc(*this, 2, 2, (int)m_rate); + m_stream = stream_alloc_legacy(2, 2, (int)m_rate); // save state save_item(NAME(m_udata.data)); diff --git a/src/devices/sound/aica.h b/src/devices/sound/aica.h index 7c5597b5aa6..8b4aaee49d9 100644 --- a/src/devices/sound/aica.h +++ b/src/devices/sound/aica.h @@ -39,7 +39,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_memory_interface configuration virtual space_config_vector memory_space_config() const override; @@ -186,8 +186,8 @@ private: stream_sample_t *m_bufferl; stream_sample_t *m_bufferr; - stream_sample_t *m_exts0; - stream_sample_t *m_exts1; + stream_sample_t const *m_exts0; + stream_sample_t const *m_exts1; s32 m_EG_TABLE[0x400]; int m_PLFO_TRI[256],m_PLFO_SQR[256],m_PLFO_SAW[256],m_PLFO_NOI[256]; diff --git a/src/devices/sound/asc.cpp b/src/devices/sound/asc.cpp index f007f4131fb..ca794ca01e5 100644 --- a/src/devices/sound/asc.cpp +++ b/src/devices/sound/asc.cpp @@ -62,7 +62,7 @@ asc_device::asc_device(const machine_config &mconfig, const char *tag, device_t void asc_device::device_start() { // create the stream - m_stream = machine().sound().stream_alloc(*this, 0, 2, 22257); + m_stream = stream_alloc_legacy(0, 2, 22257); memset(m_regs, 0, sizeof(m_regs)); @@ -113,11 +113,11 @@ void asc_device::device_timer(emu_timer &timer, device_timer_id tid, int param, } //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void asc_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void asc_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *outL, *outR; int i, ch; diff --git a/src/devices/sound/asc.h b/src/devices/sound/asc.h index e720aab4efa..bb9904d6185 100644 --- a/src/devices/sound/asc.h +++ b/src/devices/sound/asc.h @@ -76,7 +76,7 @@ protected: virtual void device_reset() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; devcb_write_line write_irq; diff --git a/src/devices/sound/astrocde.cpp b/src/devices/sound/astrocde.cpp index 63f900b4806..c377f40440b 100644 --- a/src/devices/sound/astrocde.cpp +++ b/src/devices/sound/astrocde.cpp @@ -117,7 +117,7 @@ void astrocade_io_device::device_start() m_bitswap[i] = bitswap<8>(i, 0,1,2,3,4,5,6,7); /* allocate a stream for output */ - m_stream = stream_alloc(0, 1, clock()); + m_stream = stream_alloc_legacy(0, 1, clock()); /* reset state */ device_reset(); @@ -126,10 +126,10 @@ void astrocade_io_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void astrocade_io_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void astrocade_io_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *dest = outputs[0]; uint16_t noise_state; diff --git a/src/devices/sound/astrocde.h b/src/devices/sound/astrocde.h index 40bf8cc1448..c93788699e0 100644 --- a/src/devices/sound/astrocde.h +++ b/src/devices/sound/astrocde.h @@ -58,7 +58,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; public: void write(offs_t offset, uint8_t data); diff --git a/src/devices/sound/awacs.cpp b/src/devices/sound/awacs.cpp index c03c2d9eb11..1453fbd2305 100644 --- a/src/devices/sound/awacs.cpp +++ b/src/devices/sound/awacs.cpp @@ -42,7 +42,7 @@ awacs_device::awacs_device(const machine_config &mconfig, const char *tag, devic void awacs_device::device_start() { // create the stream - m_stream = machine().sound().stream_alloc(*this, 0, 2, 22050); + m_stream = stream_alloc_legacy(0, 2, 22050); memset(m_regs, 0, sizeof(m_regs)); @@ -82,11 +82,11 @@ void awacs_device::device_timer(emu_timer &timer, device_timer_id tid, int param } //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void awacs_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void awacs_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *outL, *outR; int offset = (m_buffer_num == 0) ? m_dma_offset_0 : m_dma_offset_1; diff --git a/src/devices/sound/awacs.h b/src/devices/sound/awacs.h index 4ef4a800a24..6c85317ddfa 100644 --- a/src/devices/sound/awacs.h +++ b/src/devices/sound/awacs.h @@ -36,7 +36,7 @@ protected: virtual void device_reset() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; sound_stream *m_stream; diff --git a/src/devices/sound/ay8910.cpp b/src/devices/sound/ay8910.cpp index 1b1026b9e57..26e99cf1bc7 100644 --- a/src/devices/sound/ay8910.cpp +++ b/src/devices/sound/ay8910.cpp @@ -593,7 +593,7 @@ YM2203 Japanese datasheet contents, translated: http://www.larwe.com/technical/c #define ENABLE_REGISTER_TEST (0) /* Enable preprogrammed registers */ #define LOG_IGNORED_WRITES (0) -static constexpr int MAX_OUTPUT = 0x7fff; +static constexpr stream_buffer::sample_t MAX_OUTPUT = 1.0; /************************************* * @@ -770,7 +770,7 @@ static const ay8910_device::mosfet_param ay8910_mosfet_param = * *************************************/ -static inline void build_3D_table(double rl, const ay8910_device::ay_ym_param *par, const ay8910_device::ay_ym_param *par_env, int normalize, double factor, int zero_is_off, s32 *tab) +static inline void build_3D_table(double rl, const ay8910_device::ay_ym_param *par, const ay8910_device::ay_ym_param *par_env, int normalize, double factor, int zero_is_off, stream_buffer::sample_t *tab) { double min = 10.0, max = 0.0; @@ -829,7 +829,7 @@ static inline void build_3D_table(double rl, const ay8910_device::ay_ym_param *p /* for (e = 0;e<16;e++) printf("%d %d\n",e << 10, tab[e << 10]); */ } -static inline void build_single_table(double rl, const ay8910_device::ay_ym_param *par, int normalize, s32 *tab, int zero_is_off) +static inline void build_single_table(double rl, const ay8910_device::ay_ym_param *par, int normalize, stream_buffer::sample_t *tab, int zero_is_off) { double rt; double rw; @@ -867,7 +867,7 @@ static inline void build_single_table(double rl, const ay8910_device::ay_ym_para } -static inline void build_mosfet_resistor_table(const ay8910_device::mosfet_param &par, const double rd, s32 *tab) +static inline void build_mosfet_resistor_table(const ay8910_device::mosfet_param &par, const double rd, stream_buffer::sample_t *tab) { for (int j = 0; j < par.m_count; j++) { @@ -878,18 +878,14 @@ static inline void build_mosfet_resistor_table(const ay8910_device::mosfet_param const double Vs = p2 - sqrt(p2 * p2 - Vg * Vg); const double res = rd * (Vd / Vs - 1.0); - /* That's the biggest value we can stream on to netlist. */ - if (res > (1 << 28)) - tab[j] = (1 << 28); - else - tab[j] = res; + tab[j] = res; //printf("%d %f %10d\n", j, rd / (res + rd) * 5.0, tab[j]); } } -u16 ay8910_device::mix_3D() +stream_buffer::sample_t ay8910_device::mix_3D() { int indx = 0; @@ -1085,27 +1081,18 @@ void ay8910_device::ay8910_write_reg(int r, int v) // sound_stream_update - handle a stream update //------------------------------------------------- -void ay8910_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ay8910_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - stream_sample_t *buf[NUM_CHANNELS]; tone_t *tone; envelope_t *envelope; - buf[0] = outputs[0]; - buf[1] = nullptr; - buf[2] = nullptr; - if (m_streams == NUM_CHANNELS) - { - buf[1] = outputs[1]; - buf[2] = outputs[2]; - } + int samples = outputs[0].samples(); /* hack to prevent us from hanging when starting filtered outputs */ if (!m_ready) { - for (int chan = 0; chan < NUM_CHANNELS; chan++) - if (buf[chan] != nullptr) - memset(buf[chan], 0, samples * sizeof(*buf[chan])); + for (int chan = 0; chan < m_streams; chan++) + outputs[chan].fill(0); } /* The 8910 has three outputs, each output is the mix of one of the three */ @@ -1116,7 +1103,7 @@ void ay8910_device::sound_stream_update(sound_stream &stream, stream_sample_t ** /* is 1, not 0, and can be modulated changing the volume. */ /* buffering loop */ - while (samples) + for (int sampindex = 0; sampindex < samples; sampindex++) { for (int chan = 0; chan < NUM_CHANNELS; chan++) { @@ -1212,40 +1199,39 @@ void ay8910_device::sound_stream_update(sound_stream &stream, stream_sample_t ** { env_volume >>= 1; if (m_feature & PSG_EXTENDED_ENVELOPE) // AY8914 Has a two bit tone_envelope field - *(buf[chan]++) = m_vol_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]; + outputs[chan].put(sampindex, m_vol_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); else - *(buf[chan]++) = m_vol_table[chan][m_vol_enabled[chan] ? env_volume : 0]; + outputs[chan].put(sampindex, m_vol_table[chan][m_vol_enabled[chan] ? env_volume : 0]); } else { if (m_feature & PSG_EXTENDED_ENVELOPE) // AY8914 Has a two bit tone_envelope field - *(buf[chan]++) = m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]; + outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); else - *(buf[chan]++) = m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]; + outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]); } } else { if (m_feature & PSG_EXTENDED_ENVELOPE) // AY8914 Has a two bit tone_envelope field - *(buf[chan]++) = m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]; + outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); else - *(buf[chan]++) = m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]; + outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]); } } else { if (is_expanded_mode()) - *(buf[chan]++) = m_env_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]; + outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]); else - *(buf[chan]++) = m_vol_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]; + outputs[chan].put(sampindex, m_vol_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]); } } } else { - *(buf[0]++) = mix_3D(); + outputs[0].put(sampindex, mix_3D()); } - samples--; } } @@ -1344,13 +1330,13 @@ void ay8910_device::device_start() m_streams = 1; } - m_vol3d_table = make_unique_clear(8*32*32*32); + m_vol3d_table = make_unique_clear(8*32*32*32); build_mixer_table(); /* The envelope is pacing twice as fast for the YM2149 as for the AY-3-8910, */ /* This handled by the step parameter. Consequently we use a multipler of 2 here. */ - m_channel = machine().sound().stream_alloc(*this, 0, m_streams, (m_feature & PSG_HAS_EXPANDED_MODE) ? master_clock * 2 : master_clock / 8); + m_channel = stream_alloc(0, m_streams, (m_feature & PSG_HAS_EXPANDED_MODE) ? master_clock * 2 : master_clock / 8); ay_set_clock(master_clock); ay8910_statesave(); @@ -1396,7 +1382,7 @@ void ay8910_device::set_volume(int channel,int volume) { for (int ch = 0; ch < m_streams; ch++) if (channel == ch || m_streams == 1 || channel == ALL_8910_CHANNELS) - m_channel->set_output_gain(ch, volume / 100.0); + set_output_gain(ch, volume / 100.0); } void ay8910_device::ay_set_clock(int clock) diff --git a/src/devices/sound/ay8910.h b/src/devices/sound/ay8910.h index d9af1b6b86f..373a850b662 100644 --- a/src/devices/sound/ay8910.h +++ b/src/devices/sound/ay8910.h @@ -135,7 +135,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; // trampolines for callbacks from fm.cpp static void psg_set_clock(device_t *device, int clock) { downcast(device)->ay_set_clock(clock); } @@ -276,7 +276,7 @@ private: // internal helpers void set_type(psg_type_t psg_type); - inline u16 mix_3D(); + inline stream_buffer::sample_t mix_3D(); void ay8910_write_reg(int r, int v); void build_mixer_table(); void ay8910_statesave(); @@ -308,9 +308,9 @@ private: u8 m_vol_enabled[NUM_CHANNELS]; const ay_ym_param *m_par; const ay_ym_param *m_par_env; - s32 m_vol_table[NUM_CHANNELS][16]; - s32 m_env_table[NUM_CHANNELS][32]; - std::unique_ptr m_vol3d_table; + stream_buffer::sample_t m_vol_table[NUM_CHANNELS][16]; + stream_buffer::sample_t m_env_table[NUM_CHANNELS][32]; + std::unique_ptr m_vol3d_table; int m_flags; /* Flags */ int m_feature; /* Chip specific features */ int m_res_load[3]; /* Load on channel in ohms */ diff --git a/src/devices/sound/beep.cpp b/src/devices/sound/beep.cpp index 8c5a404afd0..77e43fa2de8 100644 --- a/src/devices/sound/beep.cpp +++ b/src/devices/sound/beep.cpp @@ -47,7 +47,7 @@ beep_device::beep_device(const machine_config &mconfig, const char *tag, device_ void beep_device::device_start() { - m_stream = stream_alloc(0, 1, BEEP_RATE); + m_stream = stream_alloc_legacy(0, 1, BEEP_RATE); m_enable = 0; m_signal = 0x07fff; @@ -60,10 +60,10 @@ void beep_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void beep_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void beep_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; int16_t signal = m_signal; diff --git a/src/devices/sound/beep.h b/src/devices/sound/beep.h index 388d0fa6261..68b9b42bc2c 100644 --- a/src/devices/sound/beep.h +++ b/src/devices/sound/beep.h @@ -22,7 +22,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; public: DECLARE_WRITE_LINE_MEMBER(set_state); // enable/disable sound output diff --git a/src/devices/sound/bsmt2000.cpp b/src/devices/sound/bsmt2000.cpp index 05ea982bb8e..c815a1e0a08 100644 --- a/src/devices/sound/bsmt2000.cpp +++ b/src/devices/sound/bsmt2000.cpp @@ -116,7 +116,7 @@ void bsmt2000_device::device_start() // in theory we should generate a 24MHz stream, but that's certainly overkill // internally at 24MHz the max output sample rate is 32kHz // divided by 128 gives us 6x the max output rate which is plenty for oversampling - m_stream = stream_alloc(0, 2, clock() / 128); + m_stream = stream_alloc_legacy(0, 2, clock() / 128); // register for save states save_item(NAME(m_register_select)); @@ -171,11 +171,11 @@ void bsmt2000_device::device_timer(emu_timer &timer, device_timer_id id, int par //------------------------------------------------- -// sound_stream_update - handle update requests +// sound_stream_update_legacy - handle update requests // for our sound stream //------------------------------------------------- -void bsmt2000_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void bsmt2000_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // just fill with current left/right values for (int samp = 0; samp < samples; samp++) diff --git a/src/devices/sound/bsmt2000.h b/src/devices/sound/bsmt2000.h index ef3c13e045f..014d6bc6b2d 100644 --- a/src/devices/sound/bsmt2000.h +++ b/src/devices/sound/bsmt2000.h @@ -53,7 +53,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/c140.cpp b/src/devices/sound/c140.cpp index 7f3780c8ed3..3fe32fd13db 100644 --- a/src/devices/sound/c140.cpp +++ b/src/devices/sound/c140.cpp @@ -125,7 +125,7 @@ void c140_device::device_start() m_int1_callback.resolve_safe(); m_int1_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(c140_device::int1_on), this)); - m_stream = stream_alloc(0, 2, m_sample_rate); + m_stream = stream_alloc_legacy(0, 2, m_sample_rate); // make decompress pcm table (Verified from Wii Virtual Console Arcade Starblade) for (int i = 0; i < 256; i++) @@ -217,10 +217,10 @@ void c140_device::rom_bank_updated() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void c140_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void c140_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { s32 dt; @@ -337,7 +337,7 @@ void c140_device::sound_stream_update(sound_stream &stream, stream_sample_t **in } } -void c219_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void c219_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { s32 dt; diff --git a/src/devices/sound/c140.h b/src/devices/sound/c140.h index 6f645a06d9e..a6df491815b 100644 --- a/src/devices/sound/c140.h +++ b/src/devices/sound/c140.h @@ -44,7 +44,7 @@ protected: virtual void rom_bank_updated() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; virtual int find_sample(int adrs, int bank, int voice); @@ -116,7 +116,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; virtual int find_sample(int adrs, int bank, int voice) override; diff --git a/src/devices/sound/c352.cpp b/src/devices/sound/c352.cpp index 5038e0aaee2..ed27870c053 100644 --- a/src/devices/sound/c352.cpp +++ b/src/devices/sound/c352.cpp @@ -122,7 +122,7 @@ void c352_device::ramp_volume(c352_voice_t &v, int ch, u8 val) v.curr_vol[ch] += (vol_delta > 0) ? -1 : 1; } -void c352_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void c352_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer_fl = outputs[0]; stream_sample_t *buffer_fr = outputs[1]; @@ -358,14 +358,14 @@ void c352_device::device_clock_changed() if (m_stream != nullptr) m_stream->set_sample_rate(m_sample_rate_base); else - m_stream = machine().sound().stream_alloc(*this, 0, 4, m_sample_rate_base); + m_stream = stream_alloc_legacy(0, 4, m_sample_rate_base); } void c352_device::device_start() { m_sample_rate_base = clock() / m_divider; - m_stream = machine().sound().stream_alloc(*this, 0, 4, m_sample_rate_base); + m_stream = stream_alloc_legacy(0, 4, m_sample_rate_base); // generate mulaw table (Output similar to namco's VC emulator) int j = 0; diff --git a/src/devices/sound/c352.h b/src/devices/sound/c352.h index 2a8ea946c5b..cbb2f1fd2a6 100644 --- a/src/devices/sound/c352.h +++ b/src/devices/sound/c352.h @@ -39,7 +39,7 @@ protected: virtual void device_clock_changed() override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/c6280.cpp b/src/devices/sound/c6280.cpp index 0278620d943..f118b3725c5 100644 --- a/src/devices/sound/c6280.cpp +++ b/src/devices/sound/c6280.cpp @@ -42,7 +42,7 @@ #include -void c6280_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void c6280_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { const u8 lmal = (m_balance >> 4) & 0x0f; const u8 rmal = (m_balance >> 0) & 0x0f; @@ -319,7 +319,7 @@ void c6280_device::device_start() m_lfo_control = 0; memset(m_channel, 0, sizeof(channel) * 8); - m_stream = machine().sound().stream_alloc(*this, 0, 2, clock()); + m_stream = stream_alloc_legacy(0, 2, clock()); /* Make volume table */ /* PSG has 48dB volume range spread over 32 steps */ diff --git a/src/devices/sound/c6280.h b/src/devices/sound/c6280.h index 9a778c31a9d..406a2f8e2a9 100644 --- a/src/devices/sound/c6280.h +++ b/src/devices/sound/c6280.h @@ -22,7 +22,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: struct channel { diff --git a/src/devices/sound/cdda.cpp b/src/devices/sound/cdda.cpp index 1b2d766493e..47dab749d49 100644 --- a/src/devices/sound/cdda.cpp +++ b/src/devices/sound/cdda.cpp @@ -12,10 +12,10 @@ //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void cdda_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void cdda_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { get_audio_data(&outputs[0][0], &outputs[1][0], samples); m_audio_volume[0] = int16_t(outputs[0][0]); @@ -31,7 +31,7 @@ void cdda_device::device_start() /* allocate an audio cache */ m_audio_cache = std::make_unique(CD_MAX_SECTOR_DATA * MAX_SECTORS ); - m_stream = machine().sound().stream_alloc(*this, 0, 2, clock()); + m_stream = stream_alloc_legacy(0, 2, clock()); m_audio_playing = 0; m_audio_pause = 0; diff --git a/src/devices/sound/cdda.h b/src/devices/sound/cdda.h index 73a1e1a237d..6654a7949c1 100644 --- a/src/devices/sound/cdda.h +++ b/src/devices/sound/cdda.h @@ -30,7 +30,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: void get_audio_data(stream_sample_t *bufL, stream_sample_t *bufR, uint32_t samples_wanted); diff --git a/src/devices/sound/cdp1863.cpp b/src/devices/sound/cdp1863.cpp index 0f480f05bb6..f72490607ae 100644 --- a/src/devices/sound/cdp1863.cpp +++ b/src/devices/sound/cdp1863.cpp @@ -64,7 +64,7 @@ cdp1863_device::cdp1863_device(const machine_config &mconfig, const char *tag, d void cdp1863_device::device_start() { // create sound stream - m_stream = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 1, machine().sample_rate()); // register for state saving save_item(NAME(m_clock1)); @@ -77,11 +77,11 @@ void cdp1863_device::device_start() //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void cdp1863_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void cdp1863_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // reset the output stream memset(outputs[0], 0, samples * sizeof(*outputs[0])); diff --git a/src/devices/sound/cdp1863.h b/src/devices/sound/cdp1863.h index e44b65a6f9d..9441779a4f4 100644 --- a/src/devices/sound/cdp1863.h +++ b/src/devices/sound/cdp1863.h @@ -54,7 +54,7 @@ protected: virtual void device_start() override; // internal callbacks - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream *m_stream; diff --git a/src/devices/sound/cdp1864.cpp b/src/devices/sound/cdp1864.cpp index ba026792c49..12b138ac469 100644 --- a/src/devices/sound/cdp1864.cpp +++ b/src/devices/sound/cdp1864.cpp @@ -119,7 +119,7 @@ void cdp1864_device::device_start() initialize_palette(); // create sound stream - m_stream = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 1, machine().sample_rate()); // allocate timers m_int_timer = timer_alloc(TIMER_INT); @@ -253,11 +253,11 @@ void cdp1864_device::device_timer(emu_timer &timer, device_timer_id id, int para //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void cdp1864_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void cdp1864_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // reset the output stream memset(outputs[0], 0, samples * sizeof(*outputs[0])); diff --git a/src/devices/sound/cdp1864.h b/src/devices/sound/cdp1864.h index 54c8f3b8ab2..1b9a843954b 100644 --- a/src/devices/sound/cdp1864.h +++ b/src/devices/sound/cdp1864.h @@ -115,7 +115,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // internal callbacks - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: enum diff --git a/src/devices/sound/cdp1869.cpp b/src/devices/sound/cdp1869.cpp index 02977b6d860..8d89b42ba48 100644 --- a/src/devices/sound/cdp1869.cpp +++ b/src/devices/sound/cdp1869.cpp @@ -400,7 +400,7 @@ void cdp1869_device::device_start() m_bkg = 0; // create sound stream - m_stream = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 1, machine().sample_rate()); // initialize other m_tonediv = 0; @@ -506,11 +506,11 @@ void cdp1869_device::cdp1869_palette(palette_device &palette) const //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void cdp1869_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void cdp1869_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // reset the output stream memset(outputs[0], 0, samples * sizeof(*outputs[0])); diff --git a/src/devices/sound/cdp1869.h b/src/devices/sound/cdp1869.h index be366a8d029..50b32492233 100644 --- a/src/devices/sound/cdp1869.h +++ b/src/devices/sound/cdp1869.h @@ -216,7 +216,7 @@ protected: virtual space_config_vector memory_space_config() const override; // device_sound_interface callbacks - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; inline bool is_ntsc(); inline uint8_t read_page_ram_byte(offs_t address); diff --git a/src/devices/sound/cem3394.cpp b/src/devices/sound/cem3394.cpp index 60381d97723..778739c7a54 100644 --- a/src/devices/sound/cem3394.cpp +++ b/src/devices/sound/cem3394.cpp @@ -144,10 +144,10 @@ cem3394_device::cem3394_device(const machine_config &mconfig, const char *tag, d //------------------------------------------------- -// sound_stream_update - generate sound to the mix buffer in mono +// sound_stream_update_legacy - generate sound to the mix buffer in mono //------------------------------------------------- -void cem3394_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void cem3394_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int int_volume = (m_volume * m_mixer_internal) / 256; int ext_volume = (m_volume * m_mixer_external) / 256; @@ -333,7 +333,7 @@ void cem3394_device::device_start() m_inv_sample_rate = 1.0 / (double)m_sample_rate; /* allocate stream channels, 1 per chip */ - m_stream = stream_alloc(0, 1, m_sample_rate); + m_stream = stream_alloc_legacy(0, 1, m_sample_rate); m_ext_cb.resolve(); diff --git a/src/devices/sound/cem3394.h b/src/devices/sound/cem3394.h index 40a6a2d0204..9dfaa4d356c 100644 --- a/src/devices/sound/cem3394.h +++ b/src/devices/sound/cem3394.h @@ -39,7 +39,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; public: // Set the voltage going to a particular parameter diff --git a/src/devices/sound/dac.h b/src/devices/sound/dac.h index f1793b5f569..7a48ba80998 100644 --- a/src/devices/sound/dac.h +++ b/src/devices/sound/dac.h @@ -45,9 +45,10 @@ public: }; template -constexpr stream_sample_t dac_multiply(const double vref, const stream_sample_t code) +constexpr stream_buffer::sample_t dac_multiply(const double vref, const s32 code) { - return (bits > 1) ? ((vref * code) / (1 << (bits))) : (vref * code); + constexpr stream_buffer::sample_t scale = 1.0 / stream_buffer::sample_t((bits > 1) ? (1 << (bits)) : 1); + return vref * scale * stream_buffer::sample_t(code); } template @@ -62,12 +63,12 @@ protected: } sound_stream * m_stream; - stream_sample_t m_code; + s32 m_code; const double m_gain; - inline void setCode(stream_sample_t code) + inline void setCode(s32 code) { - code &= ~(~std::make_unsigned_t(0) << bits); + code &= ~(~u32(0) << bits); if (m_code != code) { m_stream->update(); @@ -75,7 +76,7 @@ protected: } } - virtual void sound_stream_update_tag(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) = 0; + virtual void sound_stream_update_tag(sound_stream &stream, std::vector const &inputs, std::vector &outputs) = 0; }; template @@ -84,14 +85,14 @@ class dac_code_binary : protected dac_code protected: using dac_code::dac_code; - virtual void sound_stream_update_tag(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override + virtual void sound_stream_update_tag(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override { - for (int samp = 0; samp < samples; samp++) + for (int samp = 0; samp < outputs[0].samples(); samp++) { - double const vref_pos = inputs[DAC_VREF_POS_INPUT][samp] * this->m_gain; - double const vref_neg = inputs[DAC_VREF_NEG_INPUT][samp] * this->m_gain; - stream_sample_t const vout = vref_neg + dac_multiply(vref_pos - vref_neg, this->m_code); - outputs[0][samp] = vout; + double const vref_pos = inputs[DAC_VREF_POS_INPUT].get(samp) * this->m_gain; + double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get(samp) * this->m_gain; + stream_buffer::sample_t const vout = vref_neg + dac_multiply(vref_pos - vref_neg, this->m_code); + outputs[0].put(samp, vout); } } }; @@ -102,24 +103,24 @@ class dac_code_ones_complement : protected dac_code protected: using dac_code::dac_code; - virtual void sound_stream_update_tag(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override + virtual void sound_stream_update_tag(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override { if (this->m_code & (1 << (bits - 1))) { - for (int samp = 0; samp < samples; samp++) + for (int samp = 0; samp < outputs[0].samples(); samp++) { - double const vref_neg = inputs[DAC_VREF_NEG_INPUT][samp] * this->m_gain; - stream_sample_t const vout = dac_multiply(vref_neg, this->m_code ^ ~(~0U << bits)); - outputs[0][samp] = vout; + double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get(samp) * this->m_gain; + stream_buffer::sample_t const vout = dac_multiply(vref_neg, this->m_code ^ ~(~0U << bits)); + outputs[0].put(samp, vout); } } else { - for (int samp = 0; samp < samples; samp++) + for (int samp = 0; samp < outputs[0].samples(); samp++) { - double const vref_pos = inputs[DAC_VREF_POS_INPUT][samp] * this->m_gain; - stream_sample_t const vout = dac_multiply(vref_pos, this->m_code); - outputs[0][samp] = vout; + double const vref_pos = inputs[DAC_VREF_POS_INPUT].get(samp) * this->m_gain; + stream_buffer::sample_t const vout = dac_multiply(vref_pos, this->m_code); + outputs[0].put(samp, vout); } } } @@ -131,14 +132,14 @@ class dac_code_twos_complement : protected dac_code protected: using dac_code::dac_code; - virtual void sound_stream_update_tag(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override + virtual void sound_stream_update_tag(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override { - for (int samp = 0; samp < samples; samp++) + for (int samp = 0; samp < outputs[0].samples(); samp++) { - double const vref_pos = inputs[DAC_VREF_POS_INPUT][samp] * this->m_gain; - double const vref_neg = inputs[DAC_VREF_NEG_INPUT][samp] * this->m_gain; - stream_sample_t const vout = vref_neg + dac_multiply(vref_pos - vref_neg, this->m_code ^ (1 << (bits - 1))); - outputs[0][samp] = vout; + double const vref_pos = inputs[DAC_VREF_POS_INPUT].get(samp) * this->m_gain; + double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get(samp) * this->m_gain; + stream_buffer::sample_t const vout = vref_neg + dac_multiply(vref_pos - vref_neg, this->m_code ^ (1 << (bits - 1))); + outputs[0].put(samp, vout); } } }; @@ -149,24 +150,24 @@ class dac_code_sign_magntitude : protected dac_code protected: using dac_code::dac_code; - virtual void sound_stream_update_tag(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override + virtual void sound_stream_update_tag(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override { if (this->m_code & (1 << (bits - 1))) { - for (int samp = 0; samp < samples; samp++) + for (int samp = 0; samp < outputs[0].samples(); samp++) { - double const vref_neg = inputs[DAC_VREF_NEG_INPUT][samp] * this->m_gain; - stream_sample_t const vout = dac_multiply(vref_neg, this->m_code ^ (1 << (bits - 1))); - outputs[0][samp] = vout; + double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get(samp) * this->m_gain; + stream_buffer::sample_t const vout = dac_multiply(vref_neg, this->m_code ^ (1 << (bits - 1))); + outputs[0].put(samp, vout); } } else { - for (int samp = 0; samp < samples; samp++) + for (int samp = 0; samp < outputs[0].samples(); samp++) { - double const vref_pos = inputs[DAC_VREF_POS_INPUT][samp] * this->m_gain; - stream_sample_t const vout = dac_multiply(vref_pos, this->m_code); - outputs[0][samp] = vout; + double const vref_pos = inputs[DAC_VREF_POS_INPUT].get(samp) * this->m_gain; + stream_buffer::sample_t const vout = dac_multiply(vref_pos, this->m_code); + outputs[0].put(samp, vout); } } } @@ -193,9 +194,9 @@ protected: save_item(NAME(this->m_code)); } - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override { - _dac_code::sound_stream_update_tag(stream, inputs, outputs, samples); + _dac_code::sound_stream_update_tag(stream, inputs, outputs); } }; diff --git a/src/devices/sound/dac76.cpp b/src/devices/sound/dac76.cpp index 846ae2306bd..9a8b57ead04 100644 --- a/src/devices/sound/dac76.cpp +++ b/src/devices/sound/dac76.cpp @@ -51,7 +51,7 @@ dac76_device::dac76_device(const machine_config &mconfig, const char *tag, devic void dac76_device::device_start() { // create sound stream - m_stream = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate() * 8); + m_stream = stream_alloc_legacy(0, 1, machine().sample_rate() * 8); // register for save states save_item(NAME(m_chord)); @@ -71,11 +71,11 @@ void dac76_device::device_reset() } //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void dac76_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void dac76_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // get current output level int step_size = (2 << m_chord); diff --git a/src/devices/sound/dac76.h b/src/devices/sound/dac76.h index f986b319917..521a432baf6 100644 --- a/src/devices/sound/dac76.h +++ b/src/devices/sound/dac76.h @@ -57,7 +57,7 @@ protected: virtual void device_start() override; virtual void device_reset() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: static constexpr int m_level[8] = { 0, 33, 99, 231, 495, 1023, 2079, 4191 }; diff --git a/src/devices/sound/dave.cpp b/src/devices/sound/dave.cpp index bac697ca619..f722afb97bc 100644 --- a/src/devices/sound/dave.cpp +++ b/src/devices/sound/dave.cpp @@ -122,7 +122,7 @@ void dave_device::device_start() the volumes are mixed internally and output as left and right volume */ /* 3 tone channels + 1 noise channel */ - m_sound_stream_var = machine().sound().stream_alloc(*this, 0, 2, machine().sample_rate()); + m_sound_stream_var = stream_alloc_legacy(0, 2, machine().sample_rate()); } @@ -187,10 +187,10 @@ device_memory_interface::space_config_vector dave_device::memory_space_config() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void dave_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void dave_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer1, *buffer2; /* 0 = channel 0 left volume, 1 = channel 0 right volume, diff --git a/src/devices/sound/dave.h b/src/devices/sound/dave.h index bd5cb6a8445..67df3cc1a5a 100644 --- a/src/devices/sound/dave.h +++ b/src/devices/sound/dave.h @@ -47,7 +47,7 @@ protected: virtual space_config_vector memory_space_config() const override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; uint8_t program_r(offs_t offset); void program_w(offs_t offset, uint8_t data); diff --git a/src/devices/sound/digitalk.cpp b/src/devices/sound/digitalk.cpp index 9992d6b160d..f498b0b7e39 100644 --- a/src/devices/sound/digitalk.cpp +++ b/src/devices/sound/digitalk.cpp @@ -541,10 +541,10 @@ void digitalker_device::digitalker_step() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void digitalker_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void digitalker_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *sout = outputs[0]; int cpos = 0; @@ -655,7 +655,7 @@ void digitalker_device::digitalker_register_for_save() void digitalker_device::device_start() { - m_stream = stream_alloc(0, 1, clock()/4); + m_stream = stream_alloc_legacy(0, 1, clock()/4); m_dac_index = 128; m_data = 0xff; m_cs = m_cms = m_wr = 1; diff --git a/src/devices/sound/digitalk.h b/src/devices/sound/digitalk.h index 44eff1e0343..89347d3c5fb 100644 --- a/src/devices/sound/digitalk.h +++ b/src/devices/sound/digitalk.h @@ -29,7 +29,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: void digitalker_write(uint8_t *adr, uint8_t vol, int8_t dac); diff --git a/src/devices/sound/disc_cls.h b/src/devices/sound/disc_cls.h index 1855fbc5444..07e95ad3b20 100644 --- a/src/devices/sound/disc_cls.h +++ b/src/devices/sound/disc_cls.h @@ -232,7 +232,7 @@ public: uint32_t m_stream_in_number; stream_sample_t *m_ptr; /* current in ptr for stream */ private: - void stream_generate(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); + void stream_generate(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples); double m_gain; /* node gain */ double m_offset; /* node offset */ diff --git a/src/devices/sound/disc_inp.hxx b/src/devices/sound/disc_inp.hxx index 2b39825f9f3..72a47909982 100644 --- a/src/devices/sound/disc_inp.hxx +++ b/src/devices/sound/disc_inp.hxx @@ -242,7 +242,7 @@ void DISCRETE_CLASS_FUNC(dss_input_pulse, input_write)(int sub_node, uint8_t dat #define DSS_INPUT_STREAM__GAIN DISCRETE_INPUT(1) #define DSS_INPUT_STREAM__OFFSET DISCRETE_INPUT(2) -void discrete_dss_input_stream_node::stream_generate(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void discrete_dss_input_stream_node::stream_generate(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *ptr = outputs[0]; int samplenum = samples; @@ -318,7 +318,7 @@ void DISCRETE_CLASS_NAME(dss_input_stream)::stream_start(void) discrete_sound_device *snd_device = downcast(m_device); //assert(DSS_INPUT_STREAM__STREAM < snd_device->m_input_stream_list.count()); - m_buffer_stream = m_device->machine().sound().stream_alloc(*snd_device, 0, 1, this->sample_rate(), stream_update_delegate(&discrete_dss_input_stream_node::stream_generate,this)); + m_buffer_stream = m_device->machine().sound().stream_alloc_legacy(*snd_device, 0, 1, this->sample_rate(), stream_update_legacy_delegate(&discrete_dss_input_stream_node::stream_generate,this)); snd_device->get_stream()->set_input(m_stream_in_number, m_buffer_stream); } diff --git a/src/devices/sound/discrete.cpp b/src/devices/sound/discrete.cpp index 2e90311ac46..b571126d11d 100644 --- a/src/devices/sound/discrete.cpp +++ b/src/devices/sound/discrete.cpp @@ -862,7 +862,7 @@ discrete_device::~discrete_device(void) void discrete_device::device_start() { // create the stream - //m_stream = machine().sound().stream_alloc(*this, 0, 2, 22257); + //m_stream = stream_alloc_legacy(0, 2, 22257); const discrete_block *intf_start = m_intf; @@ -988,7 +988,7 @@ void discrete_sound_device::device_start() fatalerror("init_nodes() - Couldn't find an output node\n"); /* initialize the stream(s) */ - m_stream = machine().sound().stream_alloc(*this,m_input_stream_list.count(), m_output_list.count(), m_sample_rate); + m_stream = stream_alloc_legacy(m_input_stream_list.count(), m_output_list.count(), m_sample_rate); /* Finalize stream_input_nodes */ for_each(discrete_dss_input_stream_node **, node, &m_input_stream_list) @@ -1060,11 +1060,11 @@ void discrete_device::process(int samples) } //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void discrete_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void discrete_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int outputnum = 0; diff --git a/src/devices/sound/discrete.h b/src/devices/sound/discrete.h index d06a18bf3a5..3375e756f3e 100644 --- a/src/devices/sound/discrete.h +++ b/src/devices/sound/discrete.h @@ -4387,7 +4387,7 @@ protected: virtual void device_reset() override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: /* the output stream */ diff --git a/src/devices/sound/dmadac.cpp b/src/devices/sound/dmadac.cpp index 59fe5b15546..3baba9b3c97 100644 --- a/src/devices/sound/dmadac.cpp +++ b/src/devices/sound/dmadac.cpp @@ -45,7 +45,7 @@ void dmadac_sound_device::device_start() m_volume = 0x100; /* allocate a stream channel */ - m_channel = machine().sound().stream_alloc(*this, 0, 1, DEFAULT_SAMPLE_RATE); + m_channel = stream_alloc_legacy(0, 1, DEFAULT_SAMPLE_RATE); /* register with the save state system */ save_item(NAME(m_bufin)); @@ -205,10 +205,10 @@ dmadac_sound_device::dmadac_sound_device(const machine_config &mconfig, const ch } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void dmadac_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void dmadac_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *output = outputs[0]; int16_t *source = m_buffer.get(); diff --git a/src/devices/sound/dmadac.h b/src/devices/sound/dmadac.h index 5bcffecc35f..b3f5c8e05c0 100644 --- a/src/devices/sound/dmadac.h +++ b/src/devices/sound/dmadac.h @@ -29,7 +29,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: // internal state diff --git a/src/devices/sound/dspv.cpp b/src/devices/sound/dspv.cpp index 4df5846d721..05c322db88e 100644 --- a/src/devices/sound/dspv.cpp +++ b/src/devices/sound/dspv.cpp @@ -93,7 +93,7 @@ void dspv_device::snd_w(offs_t offset, u16 data) logerror("w %02x, %04x %s\n", offset, data, machine().describe_context()); } -void dspv_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void dspv_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { } diff --git a/src/devices/sound/dspv.h b/src/devices/sound/dspv.h index ba39428005f..4e37e225904 100644 --- a/src/devices/sound/dspv.h +++ b/src/devices/sound/dspv.h @@ -29,7 +29,7 @@ protected: virtual void state_export(const device_state_entry &entry) override; virtual void state_string_export(const device_state_entry &entry, std::string &str) const override; virtual std::unique_ptr create_disassembler() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: address_space_config m_program_config, m_data_config; diff --git a/src/devices/sound/es1373.cpp b/src/devices/sound/es1373.cpp index 6ff92fcc90b..9475b410f0b 100644 --- a/src/devices/sound/es1373.cpp +++ b/src/devices/sound/es1373.cpp @@ -120,7 +120,7 @@ void es1373_device::device_start() add_map(0x40, M_IO, FUNC(es1373_device::map)); // create the stream - m_stream = machine().sound().stream_alloc(*this, 0, 2, 44100/2); + m_stream = stream_alloc_legacy(0, 2, 44100/2); m_timer = timer_alloc(0, nullptr); m_timer->adjust(attotime::zero, 0, attotime::from_hz(44100/2/16)); @@ -230,13 +230,13 @@ void es1373_device::device_timer(emu_timer &timer, device_timer_id tid, int para } //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void es1373_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void es1373_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { if (m_dac1.enable) { - logerror("%s: sound_stream_update DAC1 not implemented yet\n", tag()); + logerror("%s: sound_stream_update_legacy DAC1 not implemented yet\n", tag()); } if (m_dac2.enable) { @@ -245,7 +245,7 @@ void es1373_device::sound_stream_update(sound_stream &stream, stream_sample_t ** if (m_adc.enable) { if (m_adc.format!=SCTRL_16BIT_MONO) { - logerror("%s: sound_stream_update Only SCTRL_16BIT_MONO recorded supported\n", tag()); + logerror("%s: sound_stream_update_legacy Only SCTRL_16BIT_MONO recorded supported\n", tag()); } else { for (int i=0; iindex; } virtual inline u16 read_sample(es550x_voice *voice, offs_t addr) { return 0; } @@ -190,7 +190,7 @@ protected: virtual void update_envelopes(es550x_voice *voice) override; virtual void check_for_end_forward(es550x_voice *voice, u64 &accum) override; virtual void check_for_end_reverse(es550x_voice *voice, u64 &accum) override; - virtual void generate_samples(s32 **outputs, int offset, int samples) override; + virtual void generate_samples(s32 * const *outputs, int offset, int samples) override; virtual inline u16 read_sample(es550x_voice *voice, offs_t addr) override { update_index(voice); return m_cache[get_bank(voice->control)].read_word(addr); } @@ -244,7 +244,7 @@ protected: virtual void update_envelopes(es550x_voice *voice) override; virtual void check_for_end_forward(es550x_voice *voice, u64 &accum) override; virtual void check_for_end_reverse(es550x_voice *voice, u64 &accum) override; - virtual void generate_samples(s32 **outputs, int offset, int samples) override; + virtual void generate_samples(s32 * const *outputs, int offset, int samples) override; virtual inline u16 read_sample(es550x_voice *voice, offs_t addr) override { update_index(voice); return m_cache[get_bank(voice->control)].read_word(addr); } diff --git a/src/devices/sound/esqpump.cpp b/src/devices/sound/esqpump.cpp index 5ed977b9f81..7b37a2c9abd 100644 --- a/src/devices/sound/esqpump.cpp +++ b/src/devices/sound/esqpump.cpp @@ -32,7 +32,7 @@ void esq_5505_5510_pump_device::device_start() { logerror("Clock = %d\n", clock()); - m_stream = machine().sound().stream_alloc(*this, 8, 2, clock()); + m_stream = stream_alloc_legacy(8, 2, clock()); m_timer = timer_alloc(0); m_timer->enable(false); @@ -73,7 +73,7 @@ void esq_5505_5510_pump_device::device_clock_changed() m_timer->adjust(attotime::zero, 0, attotime::from_hz(clock())); } -void esq_5505_5510_pump_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void esq_5505_5510_pump_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { if (samples != 1) { logerror("Pump: request for %d samples\n", samples); diff --git a/src/devices/sound/esqpump.h b/src/devices/sound/esqpump.h index 8ebd12bccb0..a4fb62b60ff 100644 --- a/src/devices/sound/esqpump.h +++ b/src/devices/sound/esqpump.h @@ -75,7 +75,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // timer callback overrides virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; diff --git a/src/devices/sound/flt_rc.cpp b/src/devices/sound/flt_rc.cpp index 88fb3c7624f..8de64b37a40 100644 --- a/src/devices/sound/flt_rc.cpp +++ b/src/devices/sound/flt_rc.cpp @@ -37,7 +37,7 @@ filter_rc_device::filter_rc_device(const machine_config &mconfig, const char *ta void filter_rc_device::device_start() { - m_stream = stream_alloc(1, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(1, 1, machine().sample_rate()); recalc(); save_item(NAME(m_k)); @@ -51,12 +51,12 @@ void filter_rc_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void filter_rc_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void filter_rc_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { - stream_sample_t *src = inputs[0]; + stream_sample_t const *src = inputs[0]; stream_sample_t *dst = outputs[0]; int memory = m_memory; diff --git a/src/devices/sound/flt_rc.h b/src/devices/sound/flt_rc.h index cbf5772607e..9c1bc7f3381 100644 --- a/src/devices/sound/flt_rc.h +++ b/src/devices/sound/flt_rc.h @@ -109,7 +109,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: void recalc(); diff --git a/src/devices/sound/flt_vol.cpp b/src/devices/sound/flt_vol.cpp index eec55c413f8..8b8438f9b94 100644 --- a/src/devices/sound/flt_vol.cpp +++ b/src/devices/sound/flt_vol.cpp @@ -27,17 +27,17 @@ filter_volume_device::filter_volume_device(const machine_config &mconfig, const void filter_volume_device::device_start() { m_gain = 0x100; - m_stream = stream_alloc(1, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(1, 1, machine().sample_rate()); } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void filter_volume_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void filter_volume_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { - stream_sample_t *src = inputs[0]; + stream_sample_t const *src = inputs[0]; stream_sample_t *dst = outputs[0]; while (samples--) diff --git a/src/devices/sound/flt_vol.h b/src/devices/sound/flt_vol.h index bcd4a05d399..034c3a3cf79 100644 --- a/src/devices/sound/flt_vol.h +++ b/src/devices/sound/flt_vol.h @@ -24,7 +24,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream* m_stream; diff --git a/src/devices/sound/fm.cpp b/src/devices/sound/fm.cpp index 23ea6633674..5679860a2f2 100644 --- a/src/devices/sound/fm.cpp +++ b/src/devices/sound/fm.cpp @@ -2727,7 +2727,7 @@ static inline void YM2608IRQMaskWrite(FM_OPN *OPN, ym2608_state *F2608, int v) } /* Generate samples for one of the YM2608s */ -void ym2608_update_one(void *chip, FMSAMPLE **buffer, int length) +void ym2608_update_one(void *chip, FMSAMPLE * const *buffer, int length) { ym2608_state *F2608 = (ym2608_state *)chip; FM_OPN *OPN = &F2608->OPN; @@ -3275,7 +3275,7 @@ int ym2608_timer_over(void *chip,int c) /* YM2610(OPNB) */ /* Generate samples for one of the YM2610s */ -void ym2610_update_one(void *chip, FMSAMPLE **buffer, int length) +void ym2610_update_one(void *chip, FMSAMPLE * const *buffer, int length) { ym2610_state *F2610 = (ym2610_state *)chip; FM_OPN *OPN = &F2610->OPN; @@ -3411,7 +3411,7 @@ void ym2610_update_one(void *chip, FMSAMPLE **buffer, int length) #if BUILD_YM2610B /* Generate samples for one of the YM2610Bs */ -void ym2610b_update_one(void *chip, FMSAMPLE **buffer, int length) +void ym2610b_update_one(void *chip, FMSAMPLE * const *buffer, int length) { ym2610_state *F2610 = (ym2610_state *)chip; FM_OPN *OPN = &F2610->OPN; diff --git a/src/devices/sound/fm.h b/src/devices/sound/fm.h index d49c5a40e99..d5d8760a449 100644 --- a/src/devices/sound/fm.h +++ b/src/devices/sound/fm.h @@ -142,7 +142,7 @@ void * ym2608_init(device_t *device, int baseclock, int rate, void ym2608_clock_changed(void *chip, int clock, int rate); void ym2608_shutdown(void *chip); void ym2608_reset_chip(void *chip); -void ym2608_update_one(void *chip, FMSAMPLE **buffer, int length); +void ym2608_update_one(void *chip, FMSAMPLE * const *buffer, int length); int ym2608_write(void *chip, int a,unsigned char v); unsigned char ym2608_read(void *chip,int a); @@ -158,10 +158,10 @@ void * ym2610_init(device_t *device, int baseclock, int rate, void ym2610_clock_changed(void *chip, int clock, int rate); void ym2610_shutdown(void *chip); void ym2610_reset_chip(void *chip); -void ym2610_update_one(void *chip, FMSAMPLE **buffer, int length); +void ym2610_update_one(void *chip, FMSAMPLE * const *buffer, int length); #if BUILD_YM2610B -void ym2610b_update_one(void *chip, FMSAMPLE **buffer, int length); +void ym2610b_update_one(void *chip, FMSAMPLE * const *buffer, int length); #endif /* BUILD_YM2610B */ int ym2610_write(void *chip, int a,unsigned char v); @@ -176,7 +176,7 @@ void * ym2612_init(device_t *device, int baseclock, int rate, void ym2612_clock_changed(void *chip, int clock, int rate); void ym2612_shutdown(void *chip); void ym2612_reset_chip(void *chip); -void ym2612_update_one(void *chip, FMSAMPLE **buffer, int length, u8 output_bits); +void ym2612_update_one(void *chip, FMSAMPLE * const *buffer, int length, u8 output_bits); int ym2612_write(void *chip, int a,unsigned char v); unsigned char ym2612_read(void *chip,int a); diff --git a/src/devices/sound/fm2612.cpp b/src/devices/sound/fm2612.cpp index 6d5f71dac55..b3482d0ac72 100644 --- a/src/devices/sound/fm2612.cpp +++ b/src/devices/sound/fm2612.cpp @@ -2174,7 +2174,7 @@ static void init_tables(void) /*******************************************************************************/ /* Generate samples for one of the YM2612s */ -void ym2612_update_one(void *chip, FMSAMPLE **buffer, int length, u8 output_bits) +void ym2612_update_one(void *chip, FMSAMPLE * const *buffer, int length, u8 output_bits) { // TODO : 'ladder' effects for Mega Drive/Genesis const u8 output_shift = (output_bits > 14) ? 0 : (14 - output_bits); diff --git a/src/devices/sound/gaelco.cpp b/src/devices/sound/gaelco.cpp index 0c2495a4d64..41fbfc0a4c4 100644 --- a/src/devices/sound/gaelco.cpp +++ b/src/devices/sound/gaelco.cpp @@ -76,7 +76,7 @@ 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(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void gaelco_gae1_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { /* fill all data needed */ for (int j = 0; j < samples; j++) @@ -253,7 +253,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(0, 2, rate); + m_stream = stream_alloc_legacy(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 07af14a73ec..4f7eeaeb7a7 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(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) 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 e5fe37688cc..42944daf152 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 = machine().sound().stream_alloc(*this, 0, 2, machine().sample_rate()); + m_channel = stream_alloc_legacy(0, 2, machine().sample_rate()); 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)); @@ -1211,11 +1211,13 @@ void cgb04_apu_device::apu_power_off() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void gameboy_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { + stream_sample_t *outputl = outputs[0]; + stream_sample_t *outputr = outputs[1]; while (samples-- > 0) { stream_sample_t sample; @@ -1272,7 +1274,7 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp right <<= 6; /* Update the buffers */ - *(outputs[0]++) = left; - *(outputs[1]++) = right; + *outputl++ = left; + *outputr++ = right; } } diff --git a/src/devices/sound/gb.h b/src/devices/sound/gb.h index 989871fe08c..a0ea67ed0a8 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(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; protected: enum diff --git a/src/devices/sound/hc55516.cpp b/src/devices/sound/hc55516.cpp index 99cc782dc20..6397d2c927c 100644 --- a/src/devices/sound/hc55516.cpp +++ b/src/devices/sound/hc55516.cpp @@ -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 = machine().sound().stream_alloc(*this, 0, 1, SAMPLE_RATE); + m_channel = stream_alloc_legacy(0, 1, SAMPLE_RATE); save_item(NAME(m_last_clock_state)); save_item(NAME(m_digit)); @@ -241,10 +241,10 @@ int hc55516_device::clock_state_r() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void hc55516_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void hc55516_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; int i; @@ -301,12 +301,12 @@ void hc55516_device::sound_stream_update(sound_stream &stream, stream_sample_t * *buffer++ = sample; } -void mc3417_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void mc3417_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { - hc55516_device::sound_stream_update(stream, inputs, outputs, samples); + hc55516_device::sound_stream_update_legacy(stream, inputs, outputs, samples); } -void mc3418_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void mc3418_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { - hc55516_device::sound_stream_update(stream, inputs, outputs, samples); + hc55516_device::sound_stream_update_legacy(stream, inputs, outputs, samples); } diff --git a/src/devices/sound/hc55516.h b/src/devices/sound/hc55516.h index d375de7c413..96284167c52 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(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; void start_common(uint8_t _shiftreg_mask, int _active_clock_hi); @@ -70,7 +70,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; }; @@ -84,7 +84,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; }; diff --git a/src/devices/sound/huc6230.cpp b/src/devices/sound/huc6230.cpp index 88206877a36..fd2ef5b9689 100644 --- a/src/devices/sound/huc6230.cpp +++ b/src/devices/sound/huc6230.cpp @@ -21,7 +21,7 @@ constexpr int clamp(int val, int min, int max) { return std::min(max, std::max(min, val)); } -void huc6230_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void huc6230_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { for (int i = 0; i < samples; i++) { @@ -172,7 +172,7 @@ void huc6230_device::device_start() m_vca_cb.resolve_safe(); - m_stream = machine().sound().stream_alloc(*this, 2, 2, clock() / 6); + m_stream = stream_alloc_legacy(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 0337d3165e5..27e67ce41a3 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(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: struct adpcm_channel { diff --git a/src/devices/sound/i5000.cpp b/src/devices/sound/i5000.cpp index c317d976d9f..747d5e96e19 100644 --- a/src/devices/sound/i5000.cpp +++ b/src/devices/sound/i5000.cpp @@ -44,7 +44,7 @@ void i5000snd_device::device_start() m_lut_volume[0xff] = 0; // create the stream - m_stream = machine().sound().stream_alloc(*this, 0, 2, clock() / 0x400); + m_stream = stream_alloc_legacy(0, 2, clock() / 0x400); m_rom_base = (uint16_t *)device().machine().root_device().memregion(":i5000snd")->base(); m_rom_mask = device().machine().root_device().memregion(":i5000snd")->bytes() / 2 - 1; @@ -114,7 +114,7 @@ bool i5000snd_device::read_sample(int ch) } -void i5000snd_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void i5000snd_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { for (int i = 0; i < samples; i++) { diff --git a/src/devices/sound/i5000.h b/src/devices/sound/i5000.h index 9a9a8efb3af..0bb994ebdb6 100644 --- a/src/devices/sound/i5000.h +++ b/src/devices/sound/i5000.h @@ -33,7 +33,7 @@ protected: virtual void device_start() override; virtual void device_reset() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; sound_stream *m_stream; diff --git a/src/devices/sound/ics2115.cpp b/src/devices/sound/ics2115.cpp index c61ddd819b2..fa570814019 100644 --- a/src/devices/sound/ics2115.cpp +++ b/src/devices/sound/ics2115.cpp @@ -63,7 +63,7 @@ void ics2115_device::device_start() m_timer[0].timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ics2115_device::timer_cb_0),this), this); m_timer[1].timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ics2115_device::timer_cb_1),this), this); - m_stream = machine().sound().stream_alloc(*this, 0, 2, clock() / (32 * 32)); + m_stream = stream_alloc_legacy(0, 2, clock() / (32 * 32)); m_irq_cb.resolve_safe(); @@ -385,7 +385,7 @@ void ics2115_device::ics2115_voice::update_ramp() } } -int ics2115_device::fill_output(ics2115_voice& voice, stream_sample_t *outputs[2], int samples) +int ics2115_device::fill_output(ics2115_voice& voice, stream_sample_t * const outputs[2], int samples) { bool irq_invalid = false; const u16 fine = 1 << (3*(voice.vol.incr >> 6)); @@ -426,7 +426,7 @@ int ics2115_device::fill_output(ics2115_voice& voice, stream_sample_t *outputs[2 return irq_invalid; } -void ics2115_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ics2115_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { memset(outputs[0], 0, samples * sizeof(stream_sample_t)); memset(outputs[1], 0, samples * sizeof(stream_sample_t)); diff --git a/src/devices/sound/ics2115.h b/src/devices/sound/ics2115.h index ea26826da4a..777ee8eabf4 100644 --- a/src/devices/sound/ics2115.h +++ b/src/devices/sound/ics2115.h @@ -39,7 +39,7 @@ protected: virtual void device_clock_changed() override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_memory_interface configuration virtual space_config_vector memory_space_config() const override; @@ -119,7 +119,7 @@ private: void recalc_irq(); // stream helper functions - int fill_output(ics2115_voice& voice, stream_sample_t *outputs[2], int samples); + int fill_output(ics2115_voice& voice, stream_sample_t * const outputs[2], int samples); stream_sample_t get_sample(ics2115_voice& voice); u8 read_sample(ics2115_voice& voice, u32 addr) { return m_cache.read_byte((voice.osc.saddr << 20) | (addr & 0xfffff)); } diff --git a/src/devices/sound/iopspu.cpp b/src/devices/sound/iopspu.cpp index 1d4e78f879c..73399b1ef2c 100644 --- a/src/devices/sound/iopspu.cpp +++ b/src/devices/sound/iopspu.cpp @@ -89,7 +89,7 @@ void iop_spu_device::dma_done(int bank) core.m_status &= ~STATUS_DMA_ACTIVE; } -void iop_spu_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void iop_spu_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // TODO } diff --git a/src/devices/sound/iopspu.h b/src/devices/sound/iopspu.h index 6a9e6235409..4348e471051 100644 --- a/src/devices/sound/iopspu.h +++ b/src/devices/sound/iopspu.h @@ -48,7 +48,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // HACK: This timer is currently used to trigger an interrupt after the auto-DMA-transferred buffer would have been // mixed and played back, as the PS2 BIOS pulls a null return address and crashes if we trigger the auto-DMA-complete diff --git a/src/devices/sound/iremga20.cpp b/src/devices/sound/iremga20.cpp index 041ec44241e..ba49eaa75c4 100644 --- a/src/devices/sound/iremga20.cpp +++ b/src/devices/sound/iremga20.cpp @@ -73,7 +73,7 @@ iremga20_device::iremga20_device(const machine_config &mconfig, const char *tag, void iremga20_device::device_start() { - m_stream = stream_alloc(0, 2, clock()/4); + m_stream = stream_alloc_legacy(0, 2, clock()/4); save_item(NAME(m_regs)); for (int i = 0; i < 4; i++) @@ -126,10 +126,10 @@ void iremga20_device::rom_bank_updated() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void iremga20_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void iremga20_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *outL, *outR; diff --git a/src/devices/sound/iremga20.h b/src/devices/sound/iremga20.h index dfe5040f65e..df9942c9ccb 100644 --- a/src/devices/sound/iremga20.h +++ b/src/devices/sound/iremga20.h @@ -36,7 +36,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/k005289.cpp b/src/devices/sound/k005289.cpp index 26d14258406..bf07743f7d3 100644 --- a/src/devices/sound/k005289.cpp +++ b/src/devices/sound/k005289.cpp @@ -74,7 +74,7 @@ void k005289_device::device_start() { /* get stream channels */ m_rate = clock() / CLOCK_DIVIDER; - m_stream = stream_alloc(0, 1, m_rate); + m_stream = stream_alloc_legacy(0, 1, m_rate); /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */ m_mixer_buffer = std::make_unique(2 * m_rate); @@ -101,10 +101,10 @@ void k005289_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void k005289_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void k005289_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; short *mix; diff --git a/src/devices/sound/k005289.h b/src/devices/sound/k005289.h index 39cac2cc300..a8dc7b1d0b0 100644 --- a/src/devices/sound/k005289.h +++ b/src/devices/sound/k005289.h @@ -26,7 +26,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: void make_mixer_table(int voices); diff --git a/src/devices/sound/k007232.cpp b/src/devices/sound/k007232.cpp index 2795053520d..3b35eeb9d5c 100644 --- a/src/devices/sound/k007232.cpp +++ b/src/devices/sound/k007232.cpp @@ -86,7 +86,7 @@ void k007232_device::device_start() for (auto & elem : m_wreg) elem = 0; - m_stream = machine().sound().stream_alloc(*this, 0, 2, clock()/128); + m_stream = stream_alloc_legacy(0, 2, clock()/128); save_item(STRUCT_MEMBER(m_channel, vol)); save_item(STRUCT_MEMBER(m_channel, addr)); @@ -206,10 +206,10 @@ void k007232_device::set_bank(int chan_a_bank, int chan_b_bank) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void k007232_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void k007232_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { memset(outputs[0], 0, samples * sizeof(stream_sample_t)); memset(outputs[1], 0, samples * sizeof(stream_sample_t)); diff --git a/src/devices/sound/k007232.h b/src/devices/sound/k007232.h index 72d5e701dc9..e9a4ba255da 100644 --- a/src/devices/sound/k007232.h +++ b/src/devices/sound/k007232.h @@ -37,7 +37,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_memory_interface configuration virtual space_config_vector memory_space_config() const override; diff --git a/src/devices/sound/k051649.cpp b/src/devices/sound/k051649.cpp index 07df808d42f..0e39a94230a 100644 --- a/src/devices/sound/k051649.cpp +++ b/src/devices/sound/k051649.cpp @@ -71,7 +71,7 @@ void k051649_device::device_start() { // get stream channels m_rate = clock()/16; - m_stream = stream_alloc(0, 1, m_rate); + m_stream = stream_alloc_legacy(0, 1, m_rate); // allocate a buffer to mix into - 1 second's worth should be more than enough m_mixer_buffer.resize(2 * m_rate); @@ -140,10 +140,10 @@ void k051649_device::device_clock_changed() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void k051649_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void k051649_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // zap the contents of the mixer buffer std::fill(m_mixer_buffer.begin(), m_mixer_buffer.end(), 0); diff --git a/src/devices/sound/k051649.h b/src/devices/sound/k051649.h index f69ae00b707..2fda5936685 100644 --- a/src/devices/sound/k051649.h +++ b/src/devices/sound/k051649.h @@ -38,7 +38,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: // Parameters for a channel diff --git a/src/devices/sound/k053260.cpp b/src/devices/sound/k053260.cpp index 181c992f360..ff2356ac600 100644 --- a/src/devices/sound/k053260.cpp +++ b/src/devices/sound/k053260.cpp @@ -115,7 +115,7 @@ void k053260_device::device_start() m_sh1_cb.resolve_safe(); m_sh2_cb.resolve_safe(); - m_stream = stream_alloc( 0, 2, clock() / CLOCKS_PER_SAMPLE ); + m_stream = stream_alloc_legacy( 0, 2, clock() / CLOCKS_PER_SAMPLE ); /* register with the save state system */ save_item(NAME(m_portdata)); @@ -310,10 +310,10 @@ static constexpr s32 MAXOUT = 0x7fff; static constexpr s32 MINOUT = -0x8000; //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void k053260_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void k053260_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { if (m_mode & 2) { @@ -429,7 +429,7 @@ void k053260_device::KDSC_Voice::update_pan_volume() void k053260_device::KDSC_Voice::key_on() { m_position = m_kadpcm ? 1 : 0; // for kadpcm low bit is nybble offset, so must start at 1 due to preincrement - m_counter = 0x1000 - CLOCKS_PER_SAMPLE; // force update on next sound_stream_update + m_counter = 0x1000 - CLOCKS_PER_SAMPLE; // force update on next sound_stream_update_legacy m_output = 0; m_playing = true; if (LOG) m_device.logerror("K053260: start = %06x, length = %06x, pitch = %04x, vol = %02x:%x, loop = %s, %s\n", diff --git a/src/devices/sound/k053260.h b/src/devices/sound/k053260.h index 648fa00cb58..4288b603d5a 100644 --- a/src/devices/sound/k053260.h +++ b/src/devices/sound/k053260.h @@ -42,7 +42,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/k054539.cpp b/src/devices/sound/k054539.cpp index 5fbeaa14b3d..2ed7dc134a2 100644 --- a/src/devices/sound/k054539.cpp +++ b/src/devices/sound/k054539.cpp @@ -105,7 +105,7 @@ void k054539_device::keyoff(int channel) regs[0x22c] &= ~(1 << channel); } -void k054539_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void k054539_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { #define VOL_CAP 1.80 @@ -118,9 +118,14 @@ void k054539_device::sound_stream_update(sound_stream &stream, stream_sample_t * int16_t *rbase = (int16_t *)ram.get(); if(!(regs[0x22f] & 1)) + { + outputs[0].fill(0); + outputs[1].fill(0); return; + } - for(int sample = 0; sample != samples; sample++) { + 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)) lval = rval = rbase[reverb_pos]; @@ -298,8 +303,8 @@ void k054539_device::sound_stream_update(sound_stream &stream, stream_sample_t * } } reverb_pos = (reverb_pos + 1) & 0x1fff; - outputs[0][sample] = int16_t(lval); - outputs[1][sample] = int16_t(rval); + outputs[0].put(sample, stream_buffer::sample_t(lval) * sample_scale); + outputs[1].put(sample, stream_buffer::sample_t(rval) * sample_scale); } } diff --git a/src/devices/sound/k054539.h b/src/devices/sound/k054539.h index ba1c96ffc64..6e4b6c10c8c 100644 --- a/src/devices/sound/k054539.h +++ b/src/devices/sound/k054539.h @@ -67,7 +67,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/ks0164.cpp b/src/devices/sound/ks0164.cpp index 8974ddeaa74..5280af611f6 100644 --- a/src/devices/sound/ks0164.cpp +++ b/src/devices/sound/ks0164.cpp @@ -50,7 +50,7 @@ void ks0164_device::device_start() space().install_rom(0, rend, ((1 << 23) - 1) ^ rmask, m_mem_region->base()); } - m_stream = stream_alloc(0, 2, clock()/3/2/2/32); + m_stream = stream_alloc_legacy(0, 2, clock()/3/2/2/32); space().cache(m_mem_cache); m_timer = timer_alloc(0); @@ -368,7 +368,7 @@ u16 ks0164_device::uncomp_8_16(u8 value) return o; } -void ks0164_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ks0164_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { for(int sample = 0; sample != samples; sample++) { s32 suml = 0, sumr = 0; diff --git a/src/devices/sound/ks0164.h b/src/devices/sound/ks0164.h index bb654c83cc4..a668753f250 100644 --- a/src/devices/sound/ks0164.h +++ b/src/devices/sound/ks0164.h @@ -23,7 +23,7 @@ public: protected: virtual void device_start() override; virtual void device_reset() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + 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 device_add_mconfig(machine_config &config) override; virtual space_config_vector memory_space_config() const override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; diff --git a/src/devices/sound/l7a1045_l6028_dsp_a.cpp b/src/devices/sound/l7a1045_l6028_dsp_a.cpp index 1c7cf2631c1..280d12a20d9 100644 --- a/src/devices/sound/l7a1045_l6028_dsp_a.cpp +++ b/src/devices/sound/l7a1045_l6028_dsp_a.cpp @@ -117,7 +117,7 @@ l7a1045_sound_device::l7a1045_sound_device(const machine_config &mconfig, const void l7a1045_sound_device::device_start() { /* Allocate the stream */ - m_stream = stream_alloc(0, 2, 66150); //clock() / 384); + m_stream = stream_alloc_legacy(0, 2, 66150); //clock() / 384); for (int voice = 0; voice < 32; voice++) { @@ -143,10 +143,10 @@ void l7a1045_sound_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void l7a1045_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void l7a1045_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { /* Clear the buffers */ memset(outputs[0], 0, samples*sizeof(*outputs[0])); diff --git a/src/devices/sound/l7a1045_l6028_dsp_a.h b/src/devices/sound/l7a1045_l6028_dsp_a.h index 06cdd5b7509..bc9c3b5d500 100644 --- a/src/devices/sound/l7a1045_l6028_dsp_a.h +++ b/src/devices/sound/l7a1045_l6028_dsp_a.h @@ -33,7 +33,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: struct l7a1045_voice diff --git a/src/devices/sound/lmc1992.cpp b/src/devices/sound/lmc1992.cpp index 84eb7f7c9d7..ad412395d9d 100644 --- a/src/devices/sound/lmc1992.cpp +++ b/src/devices/sound/lmc1992.cpp @@ -171,11 +171,11 @@ void lmc1992_device::device_start() //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void lmc1992_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void lmc1992_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { } diff --git a/src/devices/sound/lmc1992.h b/src/devices/sound/lmc1992.h index 88763628999..cfaffc1f13f 100644 --- a/src/devices/sound/lmc1992.h +++ b/src/devices/sound/lmc1992.h @@ -71,7 +71,7 @@ protected: virtual void device_start() override; // internal callbacks - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: inline void execute_command(int addr, int data); diff --git a/src/devices/sound/mas3507d.cpp b/src/devices/sound/mas3507d.cpp index 9fa4eeadbc9..641ec52a06e 100644 --- a/src/devices/sound/mas3507d.cpp +++ b/src/devices/sound/mas3507d.cpp @@ -29,7 +29,7 @@ mas3507d_device::mas3507d_device(const machine_config &mconfig, const char *tag, void mas3507d_device::device_start() { current_rate = 44100; - stream = stream_alloc(0, 2, current_rate); + stream = stream_alloc_legacy(0, 2, current_rate); cb_sample.resolve(); } @@ -290,7 +290,7 @@ void mas3507d_device::mem_write(int bank, uint32_t adr, uint32_t val) case 0x0032f: logerror("MAS3507D: OutputConfig = %05x\n", val); break; case 0x107f8: logerror("MAS3507D: left->left gain = %05x (%d dB, %f%%)\n", val, gain_to_db(val), gain_to_percentage(val)); - stream->set_output_gain(0, gain_to_percentage(val)); + set_output_gain(0, gain_to_percentage(val)); break; case 0x107f9: logerror("MAS3507D: left->right gain = %05x (%d dB, %f%%)\n", val, gain_to_db(val), gain_to_percentage(val)); @@ -300,7 +300,7 @@ void mas3507d_device::mem_write(int bank, uint32_t adr, uint32_t val) break; case 0x107fb: logerror("MAS3507D: right->right gain = %05x (%d dB, %f%%)\n", val, gain_to_db(val), gain_to_percentage(val)); - stream->set_output_gain(1, gain_to_percentage(val)); + set_output_gain(1, gain_to_percentage(val)); break; default: logerror("MAS3507D: %d:%04x = %05x\n", bank, adr, val); break; } @@ -359,7 +359,7 @@ void mas3507d_device::fill_buffer() } } -void mas3507d_device::append_buffer(stream_sample_t **outputs, int &pos, int scount) +void mas3507d_device::append_buffer(stream_sample_t * const *outputs, int &pos, int scount) { if(!sample_count) return; @@ -400,7 +400,7 @@ void mas3507d_device::append_buffer(stream_sample_t **outputs, int &pos, int sco total_frame_count += s1; } -void mas3507d_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int csamples) +void mas3507d_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int csamples) { int pos = 0; diff --git a/src/devices/sound/mas3507d.h b/src/devices/sound/mas3507d.h index 64876cb321b..31410fa576e 100644 --- a/src/devices/sound/mas3507d.h +++ b/src/devices/sound/mas3507d.h @@ -27,7 +27,7 @@ public: protected: virtual void device_start() override; virtual void device_reset() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: devcb_read16 cb_sample; @@ -63,7 +63,7 @@ private: void reg_write(uint32_t adr, uint32_t val); void fill_buffer(); - void append_buffer(stream_sample_t **outputs, int &pos, int samples); + void append_buffer(stream_sample_t * const *outputs, int &pos, int samples); }; diff --git a/src/devices/sound/mea8000.cpp b/src/devices/sound/mea8000.cpp index ef528309897..4f7fbc453ac 100644 --- a/src/devices/sound/mea8000.cpp +++ b/src/devices/sound/mea8000.cpp @@ -134,7 +134,7 @@ void mea8000_device::device_start() init_tables(); - m_stream = stream_alloc(0, 1, clock() / 60); + m_stream = stream_alloc_legacy(0, 1, clock() / 60); save_item(NAME(m_output)); m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mea8000_device::timer_expire),this)); @@ -422,7 +422,7 @@ void mea8000_device::stop_frame() -void mea8000_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void mea8000_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { for (int samp = 0; samp < samples; samp++) { diff --git a/src/devices/sound/mea8000.h b/src/devices/sound/mea8000.h index 77c61669721..14cb0384d09 100644 --- a/src/devices/sound/mea8000.h +++ b/src/devices/sound/mea8000.h @@ -29,7 +29,7 @@ public: protected: // device-level overrides virtual void device_start() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: /* filter coefficients from frequencies */ diff --git a/src/devices/sound/mos6560.cpp b/src/devices/sound/mos6560.cpp index a0121a79e08..05ab0bcd08e 100644 --- a/src/devices/sound/mos6560.cpp +++ b/src/devices/sound/mos6560.cpp @@ -622,7 +622,7 @@ void mos6560_device::sound_start() { int i; - m_channel = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_channel = stream_alloc_legacy(0, 1, machine().sample_rate()); /* buffer for fastest played sample for 5 second so we have enough data for min 5 second */ m_noisesize = NOISE_FREQUENCY_MAX * NOISE_BUFFER_SIZE_SEC; @@ -888,10 +888,10 @@ void mos6560_device::device_timer(emu_timer &timer, device_timer_id id, int para } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void mos6560_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void mos6560_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int i, v; stream_sample_t *buffer = outputs[0]; diff --git a/src/devices/sound/mos6560.h b/src/devices/sound/mos6560.h index ecee2ec3f82..cf657255198 100644 --- a/src/devices/sound/mos6560.h +++ b/src/devices/sound/mos6560.h @@ -124,7 +124,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; inline uint8_t read_videoram(offs_t offset); inline uint8_t read_colorram(offs_t offset); diff --git a/src/devices/sound/mos6581.cpp b/src/devices/sound/mos6581.cpp index 99b3620c228..2fe073a1347 100644 --- a/src/devices/sound/mos6581.cpp +++ b/src/devices/sound/mos6581.cpp @@ -199,7 +199,7 @@ void mos6581_device::device_start() m_read_poty.resolve_safe(0xff); // create sound stream - m_stream = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 1, machine().sample_rate()); // initialize SID engine m_token->device = this; @@ -235,11 +235,11 @@ void mos6581_device::device_post_load() //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void mos6581_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void mos6581_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { m_token->fill_buffer(outputs[0], samples); } diff --git a/src/devices/sound/mos6581.h b/src/devices/sound/mos6581.h index e6d694ae90d..47e5959ef41 100644 --- a/src/devices/sound/mos6581.h +++ b/src/devices/sound/mos6581.h @@ -65,7 +65,7 @@ protected: virtual void device_post_load() override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; void save_state(SID6581_t *token); private: diff --git a/src/devices/sound/mos7360.cpp b/src/devices/sound/mos7360.cpp index 09f0a310b45..9105fd656e3 100644 --- a/src/devices/sound/mos7360.cpp +++ b/src/devices/sound/mos7360.cpp @@ -297,7 +297,7 @@ void mos7360_device::device_start() screen().register_screen_bitmap(m_bitmap); // create sound stream - m_stream = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 1, machine().sample_rate()); // buffer for fastest played sample for 5 second so we have enough data for min 5 second m_noisesize = NOISE_FREQUENCY_MAX * NOISE_BUFFER_SIZE_SEC; @@ -454,11 +454,11 @@ void mos7360_device::device_timer(emu_timer &timer, device_timer_id id, int para //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void mos7360_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void mos7360_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int i, v, a; stream_sample_t *buffer = outputs[0]; diff --git a/src/devices/sound/mos7360.h b/src/devices/sound/mos7360.h index 93ec30b2277..7e41bddb7c6 100644 --- a/src/devices/sound/mos7360.h +++ b/src/devices/sound/mos7360.h @@ -110,7 +110,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // device_sound_interface callbacks - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; inline void set_interrupt(int mask); inline void clear_interrupt(int mask); diff --git a/src/devices/sound/msm5205.cpp b/src/devices/sound/msm5205.cpp index 718f82530e7..9e889503ed9 100644 --- a/src/devices/sound/msm5205.cpp +++ b/src/devices/sound/msm5205.cpp @@ -98,7 +98,7 @@ void msm5205_device::device_start() compute_tables(); /* stream system initialize */ - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock()); + m_stream = stream_alloc(0, 1, clock()); m_vck_timer = timer_alloc(TIMER_VCK); m_capture_timer = timer_alloc(TIMER_ADPCM_CAPTURE); @@ -360,23 +360,20 @@ void msm5205_device::device_clock_changed() // sound_stream_update - handle a stream update //------------------------------------------------- -void msm5205_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void msm5205_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - stream_sample_t *buffer = outputs[0]; + auto &output = outputs[0]; /* if this voice is active */ - if(m_signal) + if (m_signal) { + constexpr stream_buffer::sample_t sample_scale = 1.0 / double(1 << 12); const int dac_mask = (m_dac_bits >= 12) ? 0 : (1 << (12 - m_dac_bits)) - 1; - short val = (m_signal & ~dac_mask) * 16; // 10 bit DAC - while (samples) - { - *buffer++ = val; - samples--; - } + stream_buffer::sample_t val = stream_buffer::sample_t(m_signal & ~dac_mask) * sample_scale; + output.fill(val); } else - memset(buffer, 0, samples * sizeof(*buffer)); + output.fill(0); } @@ -407,8 +404,8 @@ void msm6585_device::device_timer(emu_timer &timer, device_timer_id id, int para // sound_stream_update - handle a stream update //------------------------------------------------- -void msm6585_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void msm6585_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { // should this be different? - msm5205_device::sound_stream_update(stream, inputs, outputs,samples); + msm5205_device::sound_stream_update(stream, inputs, outputs); } diff --git a/src/devices/sound/msm5205.h b/src/devices/sound/msm5205.h index 87df5e870f8..02b8bc3746c 100644 --- a/src/devices/sound/msm5205.h +++ b/src/devices/sound/msm5205.h @@ -65,7 +65,7 @@ protected: void update_adpcm(); // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; void compute_tables(); virtual int get_prescaler() const; @@ -108,7 +108,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; }; diff --git a/src/devices/sound/msm5232.cpp b/src/devices/sound/msm5232.cpp index 9a4317491e3..da8fc499dc7 100644 --- a/src/devices/sound/msm5232.cpp +++ b/src/devices/sound/msm5232.cpp @@ -34,7 +34,7 @@ void msm5232_device::device_start() init(clock(), rate); - m_stream = machine().sound().stream_alloc(*this, 0, 11, rate); + m_stream = stream_alloc_legacy(0, 11, rate); /* register with the save state system */ save_item(NAME(m_EN_out16)); @@ -725,10 +725,10 @@ void msm5232_device::set_clock(int clock) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void msm5232_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void msm5232_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buf1 = outputs[0]; stream_sample_t *buf2 = outputs[1]; diff --git a/src/devices/sound/msm5232.h b/src/devices/sound/msm5232.h index 2dd3997a346..364f944353b 100644 --- a/src/devices/sound/msm5232.h +++ b/src/devices/sound/msm5232.h @@ -26,7 +26,7 @@ protected: virtual void device_post_load() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: struct VOICE { diff --git a/src/devices/sound/multipcm.cpp b/src/devices/sound/multipcm.cpp index 6698792fbe1..d594cc05e54 100644 --- a/src/devices/sound/multipcm.cpp +++ b/src/devices/sound/multipcm.cpp @@ -479,7 +479,7 @@ void multipcm_device::device_start() const float clock_divider = 180.0f; m_rate = (float)clock() / clock_divider; - m_stream = machine().sound().stream_alloc(*this, 0, 2, m_rate); + m_stream = stream_alloc_legacy(0, 2, m_rate); // Volume + pan table m_left_pan_table = make_unique_clear(0x800); @@ -677,10 +677,10 @@ void multipcm_device::dump_sample(slot_t &slot) #endif //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void multipcm_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int32_t samples) +void multipcm_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int32_t samples) { stream_sample_t *datap[2]; diff --git a/src/devices/sound/multipcm.h b/src/devices/sound/multipcm.h index 7a4bc55fc2c..4308703b9dc 100644 --- a/src/devices/sound/multipcm.h +++ b/src/devices/sound/multipcm.h @@ -29,7 +29,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/n63701x.cpp b/src/devices/sound/n63701x.cpp index 7ba7eb2af7f..f9dea8e4509 100644 --- a/src/devices/sound/n63701x.cpp +++ b/src/devices/sound/n63701x.cpp @@ -46,7 +46,7 @@ namco_63701x_device::namco_63701x_device(const machine_config &mconfig, const ch void namco_63701x_device::device_start() { - m_stream = stream_alloc(0, 2, clock()/1000); + m_stream = stream_alloc_legacy(0, 2, clock()/1000); for (int i = 0; i < 2; i++) { @@ -61,10 +61,10 @@ void namco_63701x_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void namco_63701x_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void namco_63701x_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int ch; diff --git a/src/devices/sound/n63701x.h b/src/devices/sound/n63701x.h index 0bb48b5afc8..4992065d7bf 100644 --- a/src/devices/sound/n63701x.h +++ b/src/devices/sound/n63701x.h @@ -25,7 +25,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: struct voice_63701x diff --git a/src/devices/sound/namco.cpp b/src/devices/sound/namco.cpp index 3eeb77617bc..830f3713b45 100644 --- a/src/devices/sound/namco.cpp +++ b/src/devices/sound/namco.cpp @@ -43,6 +43,8 @@ /* 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") @@ -99,9 +101,9 @@ void namco_audio_device::device_start() /* get stream channels */ if (m_stereo) - m_stream = machine().sound().stream_alloc(*this, 0, 2, 192000); + m_stream = stream_alloc(0, 2, 192000); else - m_stream = machine().sound().stream_alloc(*this, 0, 1, 192000); + m_stream = stream_alloc(0, 1, 192000); /* start with sound enabled, many games don't have a sound enable register */ m_sound_enable = true; @@ -233,11 +235,11 @@ void namco_audio_device::build_decoded_waveform(uint8_t *rgnbase) /* generate sound by oversampling */ -uint32_t namco_audio_device::namco_update_one(stream_sample_t *buffer, int length, const int16_t *wave, uint32_t counter, uint32_t freq) +uint32_t namco_audio_device::namco_update_one(write_stream_view &buffer, const int16_t *wave, uint32_t counter, uint32_t freq) { - while (length-- > 0) + for (int sampindex = 0; sampindex < buffer.samples(); sampindex++) { - *buffer++ += wave[WAVEFORM_POSITION(counter)]; + buffer.add(sampindex, stream_buffer::sample_t(wave[WAVEFORM_POSITION(counter)]) * sample_scale); counter += freq; } @@ -655,25 +657,23 @@ void namco_15xx_device::sharedram_w(offs_t offset, uint8_t data) // sound_stream_update - handle a stream update //------------------------------------------------- -void namco_audio_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void namco_audio_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { if (m_stereo) { - sound_channel *voice; - /* zap the contents of the buffers */ - memset(outputs[0], 0, samples * sizeof(*outputs[0])); - memset(outputs[1], 0, samples * sizeof(*outputs[1])); + outputs[0].fill(0); + outputs[1].fill(0); /* if no sound, we're done */ if (!m_sound_enable) return; /* loop over each voice and add its contribution */ - for (voice = m_channel_list; voice < m_last_channel; voice++) + for (sound_channel *voice = m_channel_list; voice < m_last_channel; voice++) { - stream_sample_t *lmix = outputs[0]; - stream_sample_t *rmix = outputs[1]; + auto &lmix = outputs[0]; + auto &rmix = outputs[1]; int lv = voice->volume[0]; int rv = voice->volume[1]; @@ -693,19 +693,19 @@ void namco_audio_device::sound_stream_update(sound_stream &stream, stream_sample int i; /* add our contribution */ - for (i = 0; i < samples; i++) + for (i = 0; i < lmix.samples(); i++) { int cnt; if (voice->noise_state) { - *lmix++ += l_noise_data; - *rmix++ += r_noise_data; + lmix.add(i, stream_buffer::sample_t(l_noise_data) * sample_scale); + rmix.add(i, stream_buffer::sample_t(r_noise_data) * sample_scale); } else { - *lmix++ -= l_noise_data; - *rmix++ -= r_noise_data; + lmix.add(i, stream_buffer::sample_t(-l_noise_data) * sample_scale); + rmix.add(i, stream_buffer::sample_t(-r_noise_data) * sample_scale); } if (hold) @@ -746,7 +746,7 @@ void namco_audio_device::sound_stream_update(sound_stream &stream, stream_sample const int16_t *lw = &m_waveform[lv][voice->waveform_select * 32]; /* generate sound into the buffer */ - c = namco_update_one(lmix, samples, lw, voice->counter, voice->frequency); + c = namco_update_one(lmix, lw, voice->counter, voice->frequency); } /* only update if we have non-zero right volume */ @@ -755,7 +755,7 @@ void namco_audio_device::sound_stream_update(sound_stream &stream, stream_sample const int16_t *rw = &m_waveform[rv][voice->waveform_select * 32]; /* generate sound into the buffer */ - c = namco_update_one(rmix, samples, rw, voice->counter, voice->frequency); + c = namco_update_one(rmix, rw, voice->counter, voice->frequency); } /* update the counter for this voice */ @@ -768,9 +768,9 @@ void namco_audio_device::sound_stream_update(sound_stream &stream, stream_sample { sound_channel *voice; - stream_sample_t *buffer = outputs[0]; + auto &buffer = outputs[0]; /* zap the contents of the buffer */ - memset(buffer, 0, samples * sizeof(*buffer)); + buffer.fill(0); /* if no sound, we're done */ if (!m_sound_enable) @@ -779,81 +779,80 @@ void namco_audio_device::sound_stream_update(sound_stream &stream, stream_sample /* loop over each voice and add its contribution */ for (voice = m_channel_list; voice < m_last_channel; voice++) { - stream_sample_t *mix = buffer; int v = voice->volume[0]; - if (voice->noise_sw) - { + if (voice->noise_sw) + { int f = voice->frequency & 0xff; /* only update if we have non-zero volume and frequency */ if (v && f) { - int hold_time = 1 << (m_f_fracbits - 16); - int hold = voice->noise_hold; - uint32_t delta = f << 4; - uint32_t c = voice->noise_counter; - int16_t noise_data = OUTPUT_LEVEL(0x07 * (v >> 1)); - int i; - - /* add our contribution */ - for (i = 0; i < samples; i++) + int hold_time = 1 << (m_f_fracbits - 16); + int hold = voice->noise_hold; + uint32_t delta = f << 4; + uint32_t c = voice->noise_counter; + int16_t noise_data = OUTPUT_LEVEL(0x07 * (v >> 1)); + int i; + + /* add our contribution */ + for (i = 0; i < buffer.samples(); i++) + { + int cnt; + + if (voice->noise_state) + buffer.add(i, stream_buffer::sample_t(noise_data) * sample_scale); + else + buffer.add(i, stream_buffer::sample_t(-noise_data) * sample_scale); + + if (hold) { - int cnt; - - if (voice->noise_state) - *mix++ += noise_data; - else - *mix++ -= noise_data; - - if (hold) - { - hold--; - continue; - } - - hold = hold_time; - - c += delta; - cnt = (c >> 12); - c &= (1 << 12) - 1; - for( ;cnt > 0; cnt--) - { - if ((voice->noise_seed + 1) & 2) voice->noise_state ^= 1; - if (voice->noise_seed & 1) voice->noise_seed ^= 0x28000; - voice->noise_seed >>= 1; - } + hold--; + continue; } - /* update the counter and hold time for this voice */ - voice->noise_counter = c; - voice->noise_hold = hold; + hold = hold_time; + + c += delta; + cnt = (c >> 12); + c &= (1 << 12) - 1; + for( ;cnt > 0; cnt--) + { + if ((voice->noise_seed + 1) & 2) voice->noise_state ^= 1; + if (voice->noise_seed & 1) voice->noise_seed ^= 0x28000; + voice->noise_seed >>= 1; + } } + + /* update the counter and hold time for this voice */ + voice->noise_counter = c; + voice->noise_hold = hold; } - else - { + } + else + { /* only update if we have non-zero volume and frequency */ if (v && voice->frequency) { const int16_t *w = &m_waveform[v][voice->waveform_select * 32]; /* generate sound into buffer and update the counter for this voice */ - voice->counter = namco_update_one(mix, samples, w, voice->counter, voice->frequency); + voice->counter = namco_update_one(buffer, w, voice->counter, voice->frequency); } } } } } -void namco_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void namco_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - namco_audio_device::sound_stream_update(stream, inputs, outputs, samples); + namco_audio_device::sound_stream_update(stream, inputs, outputs); } -void namco_15xx_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void namco_15xx_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - namco_audio_device::sound_stream_update(stream, inputs, outputs, samples); + namco_audio_device::sound_stream_update(stream, inputs, outputs); } -void namco_cus30_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void namco_cus30_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - namco_audio_device::sound_stream_update(stream, inputs, outputs, samples); + namco_audio_device::sound_stream_update(stream, inputs, outputs); } diff --git a/src/devices/sound/namco.h b/src/devices/sound/namco.h index 770e0e287c8..6b3cee6a1f5 100644 --- a/src/devices/sound/namco.h +++ b/src/devices/sound/namco.h @@ -44,7 +44,7 @@ protected: void build_decoded_waveform( uint8_t *rgnbase ); void update_namco_waveform(int offset, uint8_t data); - uint32_t namco_update_one(stream_sample_t *buffer, int length, const int16_t *wave, uint32_t counter, uint32_t freq); + uint32_t namco_update_one(write_stream_view &buffer, const int16_t *wave, uint32_t counter, uint32_t freq); /* waveform region */ optional_region_ptr m_wave_ptr; @@ -69,7 +69,7 @@ protected: /* decoded waveform table */ int16_t *m_waveform[MAX_VOLUME]; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; }; class namco_device : public namco_audio_device @@ -85,7 +85,7 @@ public: void polepos_sound_w(offs_t offset, uint8_t data); protected: - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; }; @@ -99,7 +99,7 @@ public: void sharedram_w(offs_t offset, uint8_t data); protected: - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; }; @@ -115,7 +115,7 @@ public: void pacman_sound_w(offs_t offset, uint8_t data); protected: - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; }; diff --git a/src/devices/sound/namco_163.cpp b/src/devices/sound/namco_163.cpp index 11ff6ed1eb5..153b0bfe042 100644 --- a/src/devices/sound/namco_163.cpp +++ b/src/devices/sound/namco_163.cpp @@ -34,7 +34,7 @@ namco_163_sound_device::namco_163_sound_device(const machine_config &mconfig, co void namco_163_sound_device::device_start() { m_ram = make_unique_clear(0x80); - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock() / 15); + m_stream = stream_alloc_legacy(0, 1, clock() / 15); save_pointer(NAME(m_ram), 0x80); save_item(NAME(m_reg_addr)); @@ -143,7 +143,7 @@ u8 namco_163_sound_device::data_r() } -void namco_163_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void namco_163_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { std::fill_n(&outputs[0][0], samples, 0); diff --git a/src/devices/sound/namco_163.h b/src/devices/sound/namco_163.h index 1256884242b..74d2ceacb68 100644 --- a/src/devices/sound/namco_163.h +++ b/src/devices/sound/namco_163.h @@ -34,7 +34,7 @@ protected: // internals inline s8 get_sample(u16 addr); - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; }; DECLARE_DEVICE_TYPE(NAMCO_163, namco_163_sound_device) diff --git a/src/devices/sound/nes_apu.cpp b/src/devices/sound/nes_apu.cpp index 3f5c7787a93..1e79304fb3a 100644 --- a/src/devices/sound/nes_apu.cpp +++ b/src/devices/sound/nes_apu.cpp @@ -134,7 +134,7 @@ void nesapu_device::calculate_rates() if (m_stream != nullptr) m_stream->set_sample_rate(rate); else - m_stream = machine().sound().stream_alloc(*this, 0, 1, rate); + m_stream = stream_alloc_legacy(0, 1, rate); } //------------------------------------------------- @@ -725,13 +725,14 @@ void nesapu_device::write(offs_t address, u8 value) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void nesapu_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void nesapu_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int accum; - memset( outputs[0], 0, samples*sizeof(*outputs[0]) ); + stream_sample_t *output = outputs[0]; + memset( output, 0, samples*sizeof(*output) ); while (samples--) { @@ -747,6 +748,6 @@ void nesapu_device::sound_stream_update(sound_stream &stream, stream_sample_t ** else if (accum < -128) accum = -128; - *(outputs[0]++)=accum<<8; + *output++=accum<<8; } } diff --git a/src/devices/sound/nes_apu.h b/src/devices/sound/nes_apu.h index 731bf565940..c0e2e02244b 100644 --- a/src/devices/sound/nes_apu.h +++ b/src/devices/sound/nes_apu.h @@ -60,7 +60,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: /* GLOBAL CONSTANTS */ diff --git a/src/devices/sound/nile.cpp b/src/devices/sound/nile.cpp index 80023870593..aeaeeaca59c 100644 --- a/src/devices/sound/nile.cpp +++ b/src/devices/sound/nile.cpp @@ -68,7 +68,7 @@ nile_device::nile_device(const machine_config &mconfig, const char *tag, device_ void nile_device::device_start() { - m_stream = stream_alloc(0, 2, 44100); + m_stream = stream_alloc_legacy(0, 2, 44100); save_item(NAME(m_sound_regs)); save_item(NAME(m_vpos)); save_item(NAME(m_frac)); @@ -78,11 +78,11 @@ void nile_device::device_start() //------------------------------------------------- -// sound_stream_update - handle update requests +// sound_stream_update_legacy - handle update requests // for our sound stream //------------------------------------------------- -void nile_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void nile_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { uint8_t *sound_ram = &m_sound_ram[0]; int v, i, snum; diff --git a/src/devices/sound/nile.h b/src/devices/sound/nile.h index 169c90c9e4d..a87fb875c11 100644 --- a/src/devices/sound/nile.h +++ b/src/devices/sound/nile.h @@ -23,7 +23,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; public: void nile_snd_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); diff --git a/src/devices/sound/okim6258.cpp b/src/devices/sound/okim6258.cpp index 639c6fde50d..5f063f4cd87 100644 --- a/src/devices/sound/okim6258.cpp +++ b/src/devices/sound/okim6258.cpp @@ -114,7 +114,7 @@ void okim6258_device::device_start() m_divider = dividers[m_start_divider]; - m_stream = stream_alloc(0, 1, clock()/m_divider); + m_stream = stream_alloc_legacy(0, 1, clock()/m_divider); m_signal = -2; m_step = 0; @@ -138,10 +138,10 @@ void okim6258_device::device_reset() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void okim6258_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void okim6258_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; diff --git a/src/devices/sound/okim6258.h b/src/devices/sound/okim6258.h index 57f764d4eb7..c8397b998bf 100644 --- a/src/devices/sound/okim6258.h +++ b/src/devices/sound/okim6258.h @@ -47,7 +47,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: void state_save_register(); diff --git a/src/devices/sound/okim6295.cpp b/src/devices/sound/okim6295.cpp index 63a039a0b32..c3aee26e52e 100644 --- a/src/devices/sound/okim6295.cpp +++ b/src/devices/sound/okim6295.cpp @@ -56,24 +56,24 @@ DEFINE_DEVICE_TYPE(OKIM6295, okim6295_device, "okim6295", "OKI MSM6295 ADPCM") // volume lookup table. The manual lists only 9 steps, ~3dB per step. Given the dB values, // that seems to map to a 5-bit volume control. Any volume parameter beyond the 9th index // results in silent playback. -const uint8_t okim6295_device::s_volume_table[16] = +const stream_buffer::sample_t okim6295_device::s_volume_table[16] = { - 0x20, // 0 dB - 0x16, // -3.2 dB - 0x10, // -6.0 dB - 0x0b, // -9.2 dB - 0x08, // -12.0 dB - 0x06, // -14.5 dB - 0x04, // -18.0 dB - 0x03, // -20.5 dB - 0x02, // -24.0 dB - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, + stream_buffer::sample_t(0x20) / stream_buffer::sample_t(0x20), // 0 dB + stream_buffer::sample_t(0x16) / stream_buffer::sample_t(0x20), // -3.2 dB + stream_buffer::sample_t(0x10) / stream_buffer::sample_t(0x20), // -6.0 dB + stream_buffer::sample_t(0x0b) / stream_buffer::sample_t(0x20), // -9.2 dB + stream_buffer::sample_t(0x08) / stream_buffer::sample_t(0x20), // -12.0 dB + stream_buffer::sample_t(0x06) / stream_buffer::sample_t(0x20), // -14.5 dB + stream_buffer::sample_t(0x04) / stream_buffer::sample_t(0x20), // -18.0 dB + stream_buffer::sample_t(0x03) / stream_buffer::sample_t(0x20), // -20.5 dB + stream_buffer::sample_t(0x02) / stream_buffer::sample_t(0x20), // -24.0 dB + stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20), + stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20), + stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20), + stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20), + stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20), + stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20), + stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20), }; @@ -118,7 +118,7 @@ void okim6295_device::device_start() // create the stream int divisor = m_pin7_state ? 132 : 165; - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock() / divisor); + m_stream = stream_alloc(0, 1, clock() / divisor); save_item(NAME(m_command)); save_item(NAME(m_pin7_state)); @@ -171,18 +171,18 @@ void okim6295_device::device_clock_changed() //------------------------------------------------- -// stream_generate - handle update requests for +// sound_stream_update - handle update requests for // our sound stream //------------------------------------------------- -void okim6295_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void okim6295_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { // reset the output stream - memset(outputs[0], 0, samples * sizeof(*outputs[0])); + outputs[0].fill(0); // iterate over voices and accumulate sample data for (auto & elem : m_voice) - elem.generate_adpcm(*this, outputs[0], samples); + elem.generate_adpcm(*this, outputs[0]); } @@ -337,21 +337,22 @@ okim6295_device::okim_voice::okim_voice() // add them to an output stream //------------------------------------------------- -void okim6295_device::okim_voice::generate_adpcm(device_rom_interface &rom, stream_sample_t *buffer, int samples) +void okim6295_device::okim_voice::generate_adpcm(device_rom_interface &rom, write_stream_view &buffer) { // skip if not active if (!m_playing) return; // loop while we still have samples to generate - while (samples-- != 0) + constexpr stream_buffer::sample_t sample_scale = 1.0 / 2048.0; + for (int sampindex = 0; sampindex < buffer.samples(); sampindex++) { // fetch the next sample byte int nibble = rom.read_byte(m_base_offset + m_sample / 2) >> (((m_sample & 1) << 2) ^ 4); // output to the buffer, scaling by the volume - // signal in range -2048..2047, volume in range 2..32 => signal * volume / 2 in range -32768..32767 - *buffer++ += m_adpcm.clock(nibble) * m_volume / 2; + // signal in range -2048..2047 + buffer.add(sampindex, m_adpcm.clock(nibble) * sample_scale * m_volume); // next! if (++m_sample >= m_count) diff --git a/src/devices/sound/okim6295.h b/src/devices/sound/okim6295.h index ee7c38f03c1..29f0a17f1a1 100644 --- a/src/devices/sound/okim6295.h +++ b/src/devices/sound/okim6295.h @@ -60,7 +60,7 @@ protected: virtual void device_clock_changed() override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; // device_rom_interface overrides virtual void rom_bank_updated() override; @@ -70,14 +70,14 @@ protected: { public: okim_voice(); - void generate_adpcm(device_rom_interface &rom, stream_sample_t *buffer, int samples); + void generate_adpcm(device_rom_interface &rom, write_stream_view &buffer); - oki_adpcm_state m_adpcm; // current ADPCM state + oki_adpcm_state m_adpcm; // current ADPCM state bool m_playing; - offs_t m_base_offset; // pointer to the base memory location - uint32_t m_sample; // current sample number - uint32_t m_count; // total samples to play - int8_t m_volume; // output volume + offs_t m_base_offset; // pointer to the base memory location + uint32_t m_sample; // current sample number + uint32_t m_count; // total samples to play + stream_buffer::sample_t m_volume; // output volume }; // configuration state @@ -86,12 +86,12 @@ protected: // internal state static constexpr int OKIM6295_VOICES = 4; - okim_voice m_voice[OKIM6295_VOICES]; + okim_voice m_voice[OKIM6295_VOICES]; int32_t m_command; - sound_stream * m_stream; + sound_stream * m_stream; uint8_t m_pin7_state; - static const uint8_t s_volume_table[16]; + static const stream_buffer::sample_t s_volume_table[16]; }; diff --git a/src/devices/sound/okim6376.cpp b/src/devices/sound/okim6376.cpp index 76ee6a5f0a7..3cb3e6fc17b 100644 --- a/src/devices/sound/okim6376.cpp +++ b/src/devices/sound/okim6376.cpp @@ -169,7 +169,7 @@ void okim6376_device::device_start() m_ch2_update = 0; m_st_pulses = 0; /* generate the name and create the stream */ - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock() / m_divisor); + m_stream = stream_alloc_legacy(0, 1, get_sample_rate()); /* initialize the voices */ for (voice = 0; voice < OKIM6376_VOICES; voice++) @@ -252,6 +252,18 @@ offs_t okim6650_device::get_start_position(int channel) } +u32 okim6376_device::get_sample_rate() +{ + return clock() / m_divisor; +} + +u32 okim6650_device::get_sample_rate() +{ + return clock() / 64 / m_divisor; +} + + + void okim6376_device::oki_process(int channel, int command) { /* if a command is pending, process the second half */ @@ -433,12 +445,7 @@ void okim6376_device::okim6376_state_save_register() void okim6376_device::device_clock_changed() { - m_stream->set_sample_rate(clock() / m_divisor); -} - -void okim6650_device::device_clock_changed() -{ - m_stream->set_sample_rate(clock() / 64 / m_divisor); + m_stream->set_sample_rate(get_sample_rate()); } @@ -571,10 +578,10 @@ void okim6376_device::write(uint8_t data) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void okim6376_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void okim6376_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int i; diff --git a/src/devices/sound/okim6376.h b/src/devices/sound/okim6376.h index 5a73bae88e3..83be973fadf 100644 --- a/src/devices/sound/okim6376.h +++ b/src/devices/sound/okim6376.h @@ -32,12 +32,13 @@ protected: virtual void device_post_load() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; virtual offs_t get_start_position(int channel); + virtual u32 get_sample_rate(); /* struct describing a single playing ADPCM voice */ struct ADPCMVoice @@ -88,10 +89,8 @@ public: DECLARE_WRITE_LINE_MEMBER( cmd_w ); protected: - // device-level overrides - virtual void device_clock_changed() override; - virtual offs_t get_start_position(int channel) override; + virtual u32 get_sample_rate() override; }; DECLARE_DEVICE_TYPE(OKIM6376, okim6376_device) diff --git a/src/devices/sound/okim9810.cpp b/src/devices/sound/okim9810.cpp index 78717fd9ae9..a28cfb1af79 100644 --- a/src/devices/sound/okim9810.cpp +++ b/src/devices/sound/okim9810.cpp @@ -112,7 +112,7 @@ okim9810_device::okim9810_device(const machine_config &mconfig, const char *tag, void okim9810_device::device_start() { // create the stream - m_stream = machine().sound().stream_alloc(*this, 0, 2, clock()); + m_stream = stream_alloc_legacy(0, 2, clock()); // save state stuff save_item(NAME(m_TMP_register)); @@ -214,7 +214,7 @@ void okim9810_device::rom_bank_updated() // our sound stream //------------------------------------------------- -void okim9810_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void okim9810_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // reset the output streams memset(outputs[0], 0, samples * sizeof(*outputs[0])); @@ -613,7 +613,7 @@ okim9810_device::okim_voice::okim_voice() //------------------------------------------------- void okim9810_device::okim_voice::generate_audio(device_rom_interface &rom, - stream_sample_t **buffers, + stream_sample_t * const *buffers, int samples, const uint8_t global_volume, const uint8_t filter_type) diff --git a/src/devices/sound/okim9810.h b/src/devices/sound/okim9810.h index b5c8d566de0..dfb4cd047aa 100644 --- a/src/devices/sound/okim9810.h +++ b/src/devices/sound/okim9810.h @@ -87,7 +87,7 @@ protected: virtual void device_clock_changed() override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; @@ -98,7 +98,7 @@ protected: public: okim_voice(); void generate_audio(device_rom_interface &rom, - stream_sample_t **buffers, + stream_sample_t * const *buffers, int samples, const uint8_t global_volume, const uint8_t filter_type); diff --git a/src/devices/sound/pcd3311.cpp b/src/devices/sound/pcd3311.cpp index d332caa3400..deae4f61062 100644 --- a/src/devices/sound/pcd3311.cpp +++ b/src/devices/sound/pcd3311.cpp @@ -48,10 +48,10 @@ void pcd3311_device::device_start() //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void pcd3311_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void pcd3311_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { } diff --git a/src/devices/sound/pcd3311.h b/src/devices/sound/pcd3311.h index 25c5c630fc6..f56d63633ba 100644 --- a/src/devices/sound/pcd3311.h +++ b/src/devices/sound/pcd3311.h @@ -48,7 +48,7 @@ protected: virtual void device_start() override; // internal callbacks - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: int m_a0; diff --git a/src/devices/sound/pokey.cpp b/src/devices/sound/pokey.cpp index 3b174c22766..f749afad2ae 100644 --- a/src/devices/sound/pokey.cpp +++ b/src/devices/sound/pokey.cpp @@ -677,14 +677,13 @@ void pokey_device::step_one_clock(void) } //------------------------------------------------- -// stream_generate - handle update requests for +// sound_stream_update - handle update requests for // our sound stream //------------------------------------------------- - -void pokey_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void pokey_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - stream_sample_t *buffer = outputs[0]; + auto &buffer = outputs[0]; if (m_output_type == LEGACY_LINEAR) { @@ -693,26 +692,21 @@ void pokey_device::sound_stream_update(sound_stream &stream, stream_sample_t **i out += ((m_out_raw >> (4*i)) & 0x0f); out *= POKEY_DEFAULT_GAIN; out = (out > 0x7fff) ? 0x7fff : out; - while( samples > 0 ) - { - *buffer++ = out; - samples--; - } + stream_buffer::sample_t outsamp = out * stream_buffer::sample_t(1.0 / 32768.0); + buffer.fill(outsamp); } else if (m_output_type == RC_LOWPASS) { double rTot = m_voltab[m_out_raw]; - double V0 = rTot / (rTot+m_r_pullup) * m_v_ref / 5.0 * 32767.0; + double V0 = rTot / (rTot+m_r_pullup) * m_v_ref / 5.0; double mult = (m_cap == 0.0) ? 1.0 : 1.0 - exp(-(rTot + m_r_pullup) / (m_cap * m_r_pullup * rTot) * m_clock_period.as_double()); - while( samples > 0 ) + for (int sampindex = 0; sampindex < buffer.samples(); sampindex++) { /* store sum of output signals into the buffer */ m_out_filter += (V0 - m_out_filter) * mult; - *buffer++ = m_out_filter; - samples--; - + buffer.put(sampindex, m_out_filter); } } else if (m_output_type == OPAMP_C_TO_GROUND) @@ -727,15 +721,8 @@ void pokey_device::sound_stream_update(sound_stream &stream, stream_sample_t **i * It is approximated by eliminating m_v_ref ( -1.0 term) */ - double V0 = ((rTot+m_r_pullup) / rTot - 1.0) * m_v_ref / 5.0 * 32767.0; - - while( samples > 0 ) - { - /* store sum of output signals into the buffer */ - *buffer++ = V0; - samples--; - - } + double V0 = ((rTot+m_r_pullup) / rTot - 1.0) * m_v_ref / 5.0; + buffer.fill(V0); } else if (m_output_type == OPAMP_LOW_PASS) { @@ -744,25 +731,19 @@ void pokey_device::sound_stream_update(sound_stream &stream, stream_sample_t **i * It is approximated by not adding in VRef below. */ - double V0 = (m_r_pullup / rTot) * m_v_ref / 5.0 * 32767.0; + double V0 = (m_r_pullup / rTot) * m_v_ref / 5.0; double mult = (m_cap == 0.0) ? 1.0 : 1.0 - exp(-1.0 / (m_cap * m_r_pullup) * m_clock_period.as_double()); - while( samples > 0 ) + for (int sampindex = 0; sampindex < buffer.samples(); sampindex++) { /* store sum of output signals into the buffer */ m_out_filter += (V0 - m_out_filter) * mult; - *buffer++ = m_out_filter /* + m_v_ref */; // see above - samples--; + buffer.put(sampindex, m_out_filter); } } else if (m_output_type == DISCRETE_VAR_R) { - int32_t out = m_voltab[m_out_raw]; - while( samples > 0 ) - { - *buffer++ = out; - samples--; - } + buffer.fill(m_voltab[m_out_raw]); } } diff --git a/src/devices/sound/pokey.h b/src/devices/sound/pokey.h index 47ad6519ab8..0717429aff3 100644 --- a/src/devices/sound/pokey.h +++ b/src/devices/sound/pokey.h @@ -193,7 +193,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; virtual void execute_run() override; @@ -306,7 +306,7 @@ private: uint32_t m_poly5[0x1f]; uint32_t m_poly9[0x1ff]; uint32_t m_poly17[0x1ffff]; - uint32_t m_voltab[0x10000]; + stream_buffer::sample_t m_voltab[0x10000]; output_type m_output_type; double m_r_pullup; diff --git a/src/devices/sound/qs1000.cpp b/src/devices/sound/qs1000.cpp index 0fd23945a2e..5674ab6db18 100644 --- a/src/devices/sound/qs1000.cpp +++ b/src/devices/sound/qs1000.cpp @@ -229,7 +229,7 @@ void qs1000_device::device_start() // The QS1000 operates at 24MHz. Creating a stream at that rate // would be overkill so we opt for a fraction of that rate which // gives reasonable results - m_stream = stream_alloc(0, 2, clock() / 32); + m_stream = stream_alloc_legacy(0, 2, clock() / 32); // Resolve CPU port callbacks m_in_p1_cb.resolve_safe(0); @@ -466,9 +466,9 @@ void qs1000_device::wave_w(offs_t offset, uint8_t data) //------------------------------------------------- -// sound_stream_update - +// sound_stream_update_legacy - //------------------------------------------------- -void qs1000_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void qs1000_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // Rset the output stream memset(outputs[0], 0x0, samples * sizeof(*outputs[0])); diff --git a/src/devices/sound/qs1000.h b/src/devices/sound/qs1000.h index d8e5fa8c545..0c16e69b193 100644 --- a/src/devices/sound/qs1000.h +++ b/src/devices/sound/qs1000.h @@ -73,7 +73,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/qsound.cpp b/src/devices/sound/qsound.cpp index 05410b73c6c..232e367f1d2 100644 --- a/src/devices/sound/qsound.cpp +++ b/src/devices/sound/qsound.cpp @@ -207,7 +207,7 @@ void qsound_device::device_add_mconfig(machine_config &config) void qsound_device::device_start() { // hope we get good synchronisation between the DSP and the sound system - m_stream = stream_alloc(0, 2, clock() / 2 / 1248); + m_stream = stream_alloc_legacy(0, 2, clock() / 2 / 1248); // save DSP communication state save_item(NAME(m_rom_bank)); @@ -251,10 +251,10 @@ void qsound_device::device_reset() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void qsound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void qsound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { std::fill_n(outputs[0], samples, m_samples[0]); std::fill_n(outputs[1], samples, m_samples[1]); diff --git a/src/devices/sound/qsound.h b/src/devices/sound/qsound.h index 401991c6a59..ac0a1053ffe 100644 --- a/src/devices/sound/qsound.h +++ b/src/devices/sound/qsound.h @@ -32,7 +32,7 @@ protected: virtual void device_reset() override; // device_sound_interface implementation - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface implementation virtual void rom_bank_updated() override; diff --git a/src/devices/sound/qsoundhle.cpp b/src/devices/sound/qsoundhle.cpp index ef99f0ee837..9ff99ee8cab 100644 --- a/src/devices/sound/qsoundhle.cpp +++ b/src/devices/sound/qsoundhle.cpp @@ -64,7 +64,7 @@ void qsound_hle_device::rom_bank_updated() void qsound_hle_device::device_start() { - m_stream = stream_alloc(0, 2, clock() / 2 / 1248); // DSP program uses 1248 machine cycles per iteration + m_stream = stream_alloc_legacy(0, 2, clock() / 2 / 1248); // DSP program uses 1248 machine cycles per iteration init_register_map(); @@ -158,10 +158,10 @@ void qsound_hle_device::device_reset() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void qsound_hle_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void qsound_hle_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // Clear the buffers std::fill_n(outputs[0], samples, 0); diff --git a/src/devices/sound/qsoundhle.h b/src/devices/sound/qsoundhle.h index 6c9872fcc9d..23b92738b9b 100644 --- a/src/devices/sound/qsoundhle.h +++ b/src/devices/sound/qsoundhle.h @@ -30,7 +30,7 @@ protected: virtual void device_reset() override; // device_sound_interface implementation - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface implementation virtual void rom_bank_updated() override; diff --git a/src/devices/sound/rf5c400.cpp b/src/devices/sound/rf5c400.cpp index d61ccb65337..b8de150f7f6 100644 --- a/src/devices/sound/rf5c400.cpp +++ b/src/devices/sound/rf5c400.cpp @@ -180,7 +180,7 @@ void rf5c400_device::device_start() save_item(STRUCT_MEMBER(m_channels, env_step)); save_item(STRUCT_MEMBER(m_channels, env_scale)); - m_stream = stream_alloc(0, 2, clock() / 384); + m_stream = stream_alloc_legacy(0, 2, clock() / 384); } //------------------------------------------------- @@ -195,10 +195,10 @@ void rf5c400_device::device_clock_changed() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void rf5c400_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void rf5c400_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int i, ch; uint64_t end, loop; diff --git a/src/devices/sound/rf5c400.h b/src/devices/sound/rf5c400.h index faccf327bf2..fdd82910b76 100644 --- a/src/devices/sound/rf5c400.h +++ b/src/devices/sound/rf5c400.h @@ -34,7 +34,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/rf5c68.cpp b/src/devices/sound/rf5c68.cpp index adb544afc64..1c00941000b 100644 --- a/src/devices/sound/rf5c68.cpp +++ b/src/devices/sound/rf5c68.cpp @@ -81,7 +81,7 @@ void rf5c68_device::device_start() m_sample_end_cb.resolve(); /* allocate the stream */ - m_stream = stream_alloc(0, 2, clock() / 384); + m_stream = stream_alloc_legacy(0, 2, clock() / 384); save_item(STRUCT_MEMBER(m_chan, enable)); save_item(STRUCT_MEMBER(m_chan, env)); @@ -116,10 +116,10 @@ device_memory_interface::space_config_vector rf5c68_device::memory_space_config( } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void rf5c68_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void rf5c68_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *left = outputs[0]; stream_sample_t *right = outputs[1]; diff --git a/src/devices/sound/rf5c68.h b/src/devices/sound/rf5c68.h index f5585506828..4a1d465e291 100644 --- a/src/devices/sound/rf5c68.h +++ b/src/devices/sound/rf5c68.h @@ -45,7 +45,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_memory_interface configuration virtual space_config_vector memory_space_config() const override; diff --git a/src/devices/sound/rolandpcm.cpp b/src/devices/sound/rolandpcm.cpp index 08e8158afbe..4916605dd7e 100644 --- a/src/devices/sound/rolandpcm.cpp +++ b/src/devices/sound/rolandpcm.cpp @@ -61,7 +61,7 @@ void mb87419_mb87420_device::device_start() m_clock = clock() / 2; m_rate = m_clock / 512; // usually 32 KHz - m_stream = machine().sound().stream_alloc(*this, 0, 2, m_rate); + m_stream = stream_alloc_legacy(0, 2, m_rate); logerror("Roland PCM: Clock %u, Rate %u\n", m_clock, m_rate); } @@ -266,10 +266,10 @@ void mb87419_mb87420_device::write(offs_t offset, u8 data) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void mb87419_mb87420_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void mb87419_mb87420_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { memset(outputs[0], 0, samples * sizeof(stream_sample_t)); memset(outputs[1], 0, samples * sizeof(stream_sample_t)); diff --git a/src/devices/sound/rolandpcm.h b/src/devices/sound/rolandpcm.h index 42dfa91efba..5d1e814d517 100644 --- a/src/devices/sound/rolandpcm.h +++ b/src/devices/sound/rolandpcm.h @@ -24,7 +24,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/rp2c33_snd.cpp b/src/devices/sound/rp2c33_snd.cpp index 15446374ac1..57e60cf9fb5 100644 --- a/src/devices/sound/rp2c33_snd.cpp +++ b/src/devices/sound/rp2c33_snd.cpp @@ -56,7 +56,7 @@ void rp2c33_sound_device::device_start() for (int i = 0; i < 4; i++) m_mvol_table[i] = int((65536.0 / (32.0 * 64.0)) * 2.0 / double(i + 2)); - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock()); + m_stream = stream_alloc_legacy(0, 1, clock()); // save states save_item(NAME(m_regs)); @@ -218,10 +218,10 @@ void rp2c33_sound_device::write(offs_t offset, u8 data) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void rp2c33_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void rp2c33_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { for (int i = 0; i < samples; i++) { diff --git a/src/devices/sound/rp2c33_snd.h b/src/devices/sound/rp2c33_snd.h index cf3c5c23b55..73b737409c2 100644 --- a/src/devices/sound/rp2c33_snd.h +++ b/src/devices/sound/rp2c33_snd.h @@ -43,7 +43,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream *m_stream = nullptr; diff --git a/src/devices/sound/s14001a.cpp b/src/devices/sound/s14001a.cpp index c7ceacb59a5..5230a66b534 100644 --- a/src/devices/sound/s14001a.cpp +++ b/src/devices/sound/s14001a.cpp @@ -226,7 +226,7 @@ ALLOW_SAVE_TYPE(s14001a_device::states); // allow save_item on a non-fundamental void s14001a_device::device_start() { - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock() ? clock() : machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 1, clock() ? clock() : machine().sample_rate()); // resolve callbacks m_ext_read_handler.resolve(); @@ -311,10 +311,10 @@ void s14001a_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void s14001a_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void s14001a_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { for (int i = 0; i < samples; i++) { diff --git a/src/devices/sound/s14001a.h b/src/devices/sound/s14001a.h index 819cfba1920..09f985a51dc 100644 --- a/src/devices/sound/s14001a.h +++ b/src/devices/sound/s14001a.h @@ -31,7 +31,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: uint8_t readmem(uint16_t offset, bool phase); diff --git a/src/devices/sound/s_dsp.cpp b/src/devices/sound/s_dsp.cpp index 487b77bff2f..9385273ba66 100644 --- a/src/devices/sound/s_dsp.cpp +++ b/src/devices/sound/s_dsp.cpp @@ -160,7 +160,7 @@ void s_dsp_device::device_start() space().cache(m_cache); space().specific(m_data); - m_channel = machine().sound().stream_alloc(*this, 0, 2, clock() / 64); + m_channel = stream_alloc_legacy(0, 2, clock() / 64); state_register(); } @@ -965,8 +965,8 @@ int s_dsp_device::advance_envelope( int v ) void s_dsp_device::set_volume(int volume) { - m_channel->set_output_gain(0, volume / 100.0); - m_channel->set_output_gain(1, volume / 100.0); + set_output_gain(0, volume / 100.0); + set_output_gain(1, volume / 100.0); } @@ -1061,10 +1061,10 @@ void s_dsp_device::state_register() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void s_dsp_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void s_dsp_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { s16 mix[2]; diff --git a/src/devices/sound/s_dsp.h b/src/devices/sound/s_dsp.h index 953991dcd2c..4ab841d0ebd 100644 --- a/src/devices/sound/s_dsp.h +++ b/src/devices/sound/s_dsp.h @@ -30,7 +30,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_memory_interface configuration virtual space_config_vector memory_space_config() const override; diff --git a/src/devices/sound/saa1099.cpp b/src/devices/sound/saa1099.cpp index 9edec91113a..cad84d184bb 100644 --- a/src/devices/sound/saa1099.cpp +++ b/src/devices/sound/saa1099.cpp @@ -161,7 +161,7 @@ saa1099_device::saa1099_device(const machine_config &mconfig, const char *tag, d void saa1099_device::device_start() { /* for each chip allocate one stream */ - m_stream = stream_alloc(0, 2, clock()/clock_divider); + m_stream = stream_alloc_legacy(0, 2, clock()/clock_divider); save_item(NAME(m_noise_params)); save_item(NAME(m_env_enable)); @@ -200,10 +200,10 @@ void saa1099_device::device_clock_changed() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void saa1099_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int j, ch; /* if the channels are disabled we're done */ diff --git a/src/devices/sound/saa1099.h b/src/devices/sound/saa1099.h index 2831b4b1f73..2f9361d5ce8 100644 --- a/src/devices/sound/saa1099.h +++ b/src/devices/sound/saa1099.h @@ -32,7 +32,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: struct saa1099_channel diff --git a/src/devices/sound/samples.cpp b/src/devices/sound/samples.cpp index 82ce481e72e..5c8d129b799 100644 --- a/src/devices/sound/samples.cpp +++ b/src/devices/sound/samples.cpp @@ -86,12 +86,11 @@ void samples_device::start(uint8_t channel, uint32_t samplenum, bool loop) // update the parameters sample_t &sample = m_sample[samplenum]; chan.source = (sample.data.size() > 0) ? &sample.data[0] : nullptr; - chan.source_length = sample.data.size(); - chan.source_num = (chan.source_length > 0) ? samplenum : -1; + chan.source_num = (chan.source_len > 0) ? samplenum : -1; + chan.source_len = sample.data.size(); chan.pos = 0; - chan.frac = 0; chan.basefreq = sample.frequency; - chan.step = (int64_t(chan.basefreq) << FRAC_BITS) / machine().sample_rate(); + chan.curfreq = sample.frequency; chan.loop = loop; } @@ -111,12 +110,11 @@ void samples_device::start_raw(uint8_t channel, const int16_t *sampledata, uint3 // update the parameters chan.source = sampledata; - chan.source_length = samples; chan.source_num = -1; + chan.source_len = samples; chan.pos = 0; - chan.frac = 0; chan.basefreq = frequency; - chan.step = (int64_t(chan.basefreq) << FRAC_BITS) / machine().sample_rate(); + chan.curfreq = frequency; chan.loop = loop; } @@ -133,7 +131,7 @@ void samples_device::set_frequency(uint8_t channel, uint32_t freq) // force an update before we start channel_t &chan = m_channel[channel]; chan.stream->update(); - chan.step = (int64_t(freq) << FRAC_BITS) / machine().sample_rate(); + chan.curfreq = freq; } @@ -147,8 +145,7 @@ void samples_device::set_volume(uint8_t channel, float volume) assert(channel < m_channels); // force an update before we start - channel_t &chan = m_channel[channel]; - chan.stream->set_output_gain(0, volume); + set_output_gain(channel, volume); } @@ -201,11 +198,7 @@ void samples_device::stop_all() uint32_t samples_device::base_frequency(uint8_t channel) const { assert(channel < m_channels); - - // force an update before we start - const channel_t &chan = m_channel[channel]; - chan.stream->update(); - return chan.basefreq; + return m_channel[channel].basefreq; } @@ -245,19 +238,17 @@ void samples_device::device_start() { // initialize channel channel_t &chan = m_channel[channel]; - chan.stream = stream_alloc(0, 1, machine().sample_rate()); + chan.stream = stream_alloc(0, 1, SAMPLE_RATE_OUTPUT_ADAPTIVE); chan.source = nullptr; chan.source_num = -1; - chan.step = 0; + chan.pos = 0; chan.loop = 0; chan.paused = 0; // register with the save state system - save_item(NAME(chan.source_length), channel); save_item(NAME(chan.source_num), channel); + save_item(NAME(chan.source_len), channel); save_item(NAME(chan.pos), channel); - save_item(NAME(chan.frac), channel); - save_item(NAME(chan.step), channel); save_item(NAME(chan.loop), channel); save_item(NAME(chan.paused), channel); } @@ -296,16 +287,21 @@ void samples_device::device_post_load() { sample_t &sample = m_sample[chan.source_num]; chan.source = &sample.data[0]; - chan.source_length = sample.data.size(); + chan.source_len = sample.data.size(); if (sample.data.empty()) chan.source_num = -1; } // validate the position against the length in case the sample is smaller - if (chan.source != nullptr && chan.pos >= chan.source_length) + double endpos = chan.source_len; + if (chan.source != nullptr && chan.pos >= endpos) { if (chan.loop) - chan.pos %= chan.source_length; + { + double posfloor = floor(chan.pos); + chan.pos -= posfloor; + chan.pos += double(int32_t(posfloor) % chan.source_len); + } else { chan.source = nullptr; @@ -320,60 +316,55 @@ void samples_device::device_post_load() // sound_stream_update - update a sound stream //------------------------------------------------- -void samples_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void samples_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { // find the channel with this stream + constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; for (int channel = 0; channel < m_channels; channel++) if (&stream == m_channel[channel].stream) { channel_t &chan = m_channel[channel]; - stream_sample_t *buffer = outputs[0]; + auto &buffer = outputs[0]; // process if we still have a source and we're not paused if (chan.source != nullptr && !chan.paused) { // load some info locally - uint32_t pos = chan.pos; - uint32_t frac = chan.frac; - uint32_t step = chan.step; + double step = double(chan.curfreq) / double(buffer.sample_rate()); + double endpos = chan.source_len; const int16_t *sample = chan.source; - uint32_t sample_length = chan.source_length; - while (samples--) + for (int sampindex = 0; sampindex < buffer.samples(); sampindex++) { // do a linear interp on the sample - int32_t sample1 = sample[pos]; - int32_t sample2 = sample[(pos + 1) % sample_length]; - int32_t fracmult = frac >> (FRAC_BITS - 14); - *buffer++ = ((0x4000 - fracmult) * sample1 + fracmult * sample2) >> 14; + double pos_floor = floor(chan.pos); + double frac = chan.pos - pos_floor; + int32_t ipos = int32_t(pos_floor); + + stream_buffer::sample_t sample1 = stream_buffer::sample_t(sample[ipos++]); + stream_buffer::sample_t sample2 = stream_buffer::sample_t(sample[(ipos + 1) % chan.source_len]); + buffer.put(sampindex, sample_scale * ((1.0 - frac) * sample1 + frac * sample2)); // advance - frac += step; - pos += frac >> FRAC_BITS; - frac = frac & ((1 << FRAC_BITS) - 1); + chan.pos += step; // handle looping/ending - if (pos >= sample_length) + if (chan.pos >= endpos) { if (chan.loop) - pos %= sample_length; + chan.pos -= endpos; else { chan.source = nullptr; chan.source_num = -1; - if (samples > 0) - memset(buffer, 0, samples * sizeof(*buffer)); + buffer.fill(0, sampindex); break; } } } - - // push position back out - chan.pos = pos; - chan.frac = frac; } else - memset(buffer, 0, samples * sizeof(*buffer)); + buffer.fill(0); break; } } diff --git a/src/devices/sound/samples.h b/src/devices/sound/samples.h index aae6aa2cef1..394af9d0fdf 100644 --- a/src/devices/sound/samples.h +++ b/src/devices/sound/samples.h @@ -85,19 +85,18 @@ protected: virtual void device_post_load() override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; // internal classes struct channel_t { sound_stream * stream; - const int16_t * source; - int32_t source_length; - int32_t source_num; - uint32_t pos; - uint32_t frac; - uint32_t step; - uint32_t basefreq; + const int16_t * source; + int32_t source_num; + uint32_t source_len; + double pos; + uint32_t basefreq; + uint32_t curfreq; bool loop; bool paused; }; diff --git a/src/devices/sound/scsp.cpp b/src/devices/sound/scsp.cpp index 97256bfe01a..143be37ca40 100644 --- a/src/devices/sound/scsp.cpp +++ b/src/devices/sound/scsp.cpp @@ -212,7 +212,7 @@ void scsp_device::device_start() m_main_irq_cb.resolve_safe(); // Stereo output with EXTS0,1 Input (External digital audio output) - m_stream = machine().sound().stream_alloc(*this, 2, 2, clock() / 512); + m_stream = stream_alloc_legacy(2, 2, clock() / 512); for (int slot = 0; slot < 32; slot++) { @@ -297,8 +297,8 @@ void scsp_device::device_post_load() for (int slot = 0; slot < 32; slot++) Compute_LFO(&m_Slots[slot]); - m_stream->set_output_gain(0, MVOL() / 15.0); - m_stream->set_output_gain(1, MVOL() / 15.0); + set_output_gain(0, MVOL() / 15.0); + set_output_gain(1, MVOL() / 15.0); } //------------------------------------------------- @@ -317,10 +317,10 @@ void scsp_device::rom_bank_updated() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void scsp_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void scsp_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { m_exts0 = inputs[0]; m_exts1 = inputs[1]; @@ -738,8 +738,8 @@ void scsp_device::UpdateReg(int reg) switch (reg & 0x3f) { case 0x0: - m_stream->set_output_gain(0, MVOL() / 15.0); - m_stream->set_output_gain(1, MVOL() / 15.0); + set_output_gain(0, MVOL() / 15.0); + set_output_gain(1, MVOL() / 15.0); break; case 0x2: case 0x3: @@ -1279,7 +1279,7 @@ inline s32 scsp_device::UpdateSlot(SCSP_SLOT *slot) void scsp_device::DoMasterSamples(int nsamples) { stream_sample_t *bufr,*bufl; - stream_sample_t *exts[2]; + stream_sample_t const *exts[2]; bufr = m_bufferr; bufl = m_bufferl; diff --git a/src/devices/sound/scsp.h b/src/devices/sound/scsp.h index 3a4e94074a6..4fe8c5e2a91 100644 --- a/src/devices/sound/scsp.h +++ b/src/devices/sound/scsp.h @@ -45,7 +45,7 @@ protected: virtual void rom_bank_updated() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: enum SCSP_STATE { SCSP_ATTACK, SCSP_DECAY1, SCSP_DECAY2, SCSP_RELEASE }; @@ -150,8 +150,8 @@ private: stream_sample_t *m_bufferl; stream_sample_t *m_bufferr; - stream_sample_t *m_exts0; - stream_sample_t *m_exts1; + stream_sample_t const *m_exts0; + stream_sample_t const *m_exts1; int m_length; diff --git a/src/devices/sound/segapcm.cpp b/src/devices/sound/segapcm.cpp index 576bc3d2cd0..e93bbaec7ee 100644 --- a/src/devices/sound/segapcm.cpp +++ b/src/devices/sound/segapcm.cpp @@ -39,7 +39,7 @@ void segapcm_device::device_start() std::fill(&m_ram[0], &m_ram[0x800], 0xff); - m_stream = stream_alloc(0, 2, clock() / 128); + m_stream = stream_alloc_legacy(0, 2, clock() / 128); save_item(NAME(m_low)); save_pointer(NAME(m_ram), 0x800); @@ -68,10 +68,10 @@ void segapcm_device::rom_bank_updated() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void segapcm_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void segapcm_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { /* clear the buffers */ memset(outputs[0], 0, samples*sizeof(*outputs[0])); diff --git a/src/devices/sound/segapcm.h b/src/devices/sound/segapcm.h index 666a0efed2c..8b9942a5727 100644 --- a/src/devices/sound/segapcm.h +++ b/src/devices/sound/segapcm.h @@ -41,7 +41,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/sn76477.cpp b/src/devices/sound/sn76477.cpp index 3a487d29edf..2903af1904b 100644 --- a/src/devices/sound/sn76477.cpp +++ b/src/devices/sound/sn76477.cpp @@ -203,7 +203,7 @@ sn76477_device::sn76477_device(const machine_config &mconfig, const char *tag, d void sn76477_device::device_start() { - m_channel = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_channel = stream_alloc_legacy(0, 1, machine().sample_rate()); if (clock() > 0) { @@ -1698,10 +1698,10 @@ void sn76477_device::state_save_register() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void sn76477_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void sn76477_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { double one_shot_cap_charging_step; double one_shot_cap_discharging_step; diff --git a/src/devices/sound/sn76477.h b/src/devices/sound/sn76477.h index 5e58407cb50..42fa82e5efc 100644 --- a/src/devices/sound/sn76477.h +++ b/src/devices/sound/sn76477.h @@ -147,7 +147,7 @@ protected: virtual void device_stop() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: /* chip's external interface */ diff --git a/src/devices/sound/sn76496.cpp b/src/devices/sound/sn76496.cpp index 83f2d0c5e50..9bc686dedb2 100644 --- a/src/devices/sound/sn76496.cpp +++ b/src/devices/sound/sn76496.cpp @@ -233,7 +233,7 @@ void sn76496_base_device::device_start() m_ready_handler.resolve_safe(); - m_sound = machine().sound().stream_alloc(*this, 0, (m_stereo? 2:1), sample_rate); + m_sound = stream_alloc(0, (m_stereo? 2:1), sample_rate); for (i = 0; i < 4; i++) m_volume[i] = 0; @@ -369,16 +369,17 @@ inline bool sn76496_base_device::in_noise_mode() return ((m_register[6] & 4)!=0); } -void sn76496_base_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void sn76496_base_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { int i; - stream_sample_t *lbuffer = outputs[0]; - stream_sample_t *rbuffer = (m_stereo)? outputs[1] : nullptr; + auto *lbuffer = &outputs[0]; + auto *rbuffer = m_stereo ? &outputs[1] : nullptr; int16_t out; int16_t out2 = 0; - while (samples > 0) + constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; + for (int sampindex = 0; sampindex < lbuffer->samples(); sampindex++) { // clock chip once if (m_current_clock > 0) // not ready for new divided clock @@ -444,9 +445,9 @@ void sn76496_base_device::sound_stream_update(sound_stream &stream, stream_sampl if (m_negate) { out = -out; out2 = -out2; } - *(lbuffer++) = out; - if (m_stereo) *(rbuffer++) = out2; - samples--; + lbuffer->put(sampindex, stream_buffer::sample_t(out) * sample_scale); + if (m_stereo) + rbuffer->put(sampindex, stream_buffer::sample_t(out2) * sample_scale); } } diff --git a/src/devices/sound/sn76496.h b/src/devices/sound/sn76496.h index f58e259b439..da6ec178f3e 100644 --- a/src/devices/sound/sn76496.h +++ b/src/devices/sound/sn76496.h @@ -44,7 +44,7 @@ protected: virtual void device_start() override; virtual void device_clock_changed() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; private: inline bool in_noise_mode(); diff --git a/src/devices/sound/snkwave.cpp b/src/devices/sound/snkwave.cpp index 2c9e9b75f9f..718dde017fb 100644 --- a/src/devices/sound/snkwave.cpp +++ b/src/devices/sound/snkwave.cpp @@ -44,7 +44,7 @@ void snkwave_device::device_start() m_sample_rate = m_external_clock >> CLOCK_SHIFT; /* get stream channels */ - m_stream = stream_alloc(0, 1, m_sample_rate); + m_stream = stream_alloc_legacy(0, 1, m_sample_rate); /* reset all the voices */ m_frequency = 0; @@ -60,11 +60,11 @@ void snkwave_device::device_start() //------------------------------------------------- -// sound_stream_update - handle update requests +// sound_stream_update_legacy - handle update requests // for our sound stream //------------------------------------------------- -void snkwave_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void snkwave_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; diff --git a/src/devices/sound/snkwave.h b/src/devices/sound/snkwave.h index 6777118c7ca..2ecb5f7715d 100644 --- a/src/devices/sound/snkwave.h +++ b/src/devices/sound/snkwave.h @@ -26,7 +26,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: static constexpr unsigned WAVEFORM_LENGTH = 16; diff --git a/src/devices/sound/sp0250.cpp b/src/devices/sound/sp0250.cpp index 1ced1f3ff87..e18143a29b0 100644 --- a/src/devices/sound/sp0250.cpp +++ b/src/devices/sound/sp0250.cpp @@ -63,10 +63,7 @@ void sp0250_device::device_start() // output PWM data at the ROMCLOCK frequency int sample_rate = clock() / 2; int frame_rate = sample_rate / (4 * PWM_CLOCKS); - if (!m_pwm_mode) - m_stream = machine().sound().stream_alloc(*this, 0, 1, frame_rate); - else - m_stream = machine().sound().stream_alloc(*this, 0, 1, sample_rate); + m_stream = stream_alloc(0, 1, m_pwm_mode ? sample_rate : frame_rate); // if a DRQ callback is offered, run a timer at the frame rate // to ensure the DRQ gets picked up in a timely manner @@ -255,17 +252,19 @@ int8_t sp0250_device::next() // sound_stream_update - handle a stream update //------------------------------------------------- -void sp0250_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void sp0250_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - stream_sample_t *output = outputs[0]; + auto &output = outputs[0]; + if (!m_pwm_mode) { - while (samples-- != 0) - *output++ = next() << 8; + 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); } else { - while (samples != 0) + for (int sampindex = 0; sampindex < output.samples(); ) { // see where we're at in the current PWM cycle if (m_pwm_index >= PWM_CLOCKS) @@ -279,28 +278,27 @@ void sp0250_device::sound_stream_update(sound_stream &stream, stream_sample_t ** // determine the value to fill and the number of samples remaining // until it changes - stream_sample_t value; + stream_buffer::sample_t value; int remaining; if (m_pwm_index < m_pwm_count) { - value = 32767; + value = 1.0; remaining = m_pwm_count - m_pwm_index; } else { - value = 0; + value = 0.0; remaining = PWM_CLOCKS - m_pwm_index; } // clamp to the number of samples requested and advance the counters - if (remaining > samples) - remaining = samples; + if (remaining > output.samples() - sampindex) + remaining = output.samples() - sampindex; m_pwm_index += remaining; - samples -= remaining; // fill the output while (remaining-- != 0) - *output++ = value; + outputs[0].put(sampindex++, value); } } } diff --git a/src/devices/sound/sp0250.h b/src/devices/sound/sp0250.h index 48f77a69d01..d51ab2286bd 100644 --- a/src/devices/sound/sp0250.h +++ b/src/devices/sound/sp0250.h @@ -22,7 +22,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; private: // internal helpers diff --git a/src/devices/sound/sp0256.cpp b/src/devices/sound/sp0256.cpp index 54c17fcaf21..b4d18e6d6d3 100644 --- a/src/devices/sound/sp0256.cpp +++ b/src/devices/sound/sp0256.cpp @@ -74,7 +74,7 @@ void sp0256_device::device_start() m_drq_cb(1); m_sby_cb(1); - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock() / CLOCK_DIVIDER); + m_stream = stream_alloc_legacy(0, 1, clock() / CLOCK_DIVIDER); /* -------------------------------------------------------------------- */ /* Configure our internal variables. */ @@ -1260,10 +1260,10 @@ TIMER_CALLBACK_MEMBER(sp0256_device::set_lrq_timer_proc) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void sp0256_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void sp0256_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *output = outputs[0]; int output_index = 0; diff --git a/src/devices/sound/sp0256.h b/src/devices/sound/sp0256.h index 83a3aa75c5d..3720b3429ed 100644 --- a/src/devices/sound/sp0256.h +++ b/src/devices/sound/sp0256.h @@ -61,7 +61,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: struct lpc12_t diff --git a/src/devices/sound/spkrdev.cpp b/src/devices/sound/spkrdev.cpp index c44e00f5708..3fc3467771e 100644 --- a/src/devices/sound/spkrdev.cpp +++ b/src/devices/sound/spkrdev.cpp @@ -102,7 +102,7 @@ void speaker_sound_device::device_start() int i; double x; - m_channel = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_channel = stream_alloc_legacy(0, 1, machine().sample_rate()); m_level = 0; for (i = 0; i < FILTER_LENGTH; i++) @@ -198,11 +198,11 @@ void speaker_sound_device::device_post_load() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- // This can be triggered by the core (based on emulated time) or via level_w(). -void speaker_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void speaker_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; int volume = m_levels[m_level]; diff --git a/src/devices/sound/spkrdev.h b/src/devices/sound/spkrdev.h index 49e953b5d40..7411e47170d 100644 --- a/src/devices/sound/spkrdev.h +++ b/src/devices/sound/spkrdev.h @@ -32,7 +32,7 @@ protected: virtual void device_post_load() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: // Length of anti-aliasing filter kernel, measured in number of intermediate samples diff --git a/src/devices/sound/spu.cpp b/src/devices/sound/spu.cpp index c4550e928c7..82f5d3973ac 100644 --- a/src/devices/sound/spu.cpp +++ b/src/devices/sound/spu.cpp @@ -444,7 +444,7 @@ struct spu_device::voiceinfo // // -class stream_buffer +class spu_stream_buffer { public: struct stream_marker @@ -466,7 +466,7 @@ public: stream_marker *marker_head, *marker_tail; - stream_buffer(const unsigned int _sector_size, + spu_stream_buffer(const unsigned int _sector_size, const unsigned int _num_sectors) : head(0), tail(0), @@ -481,7 +481,7 @@ public: memset(&buffer[0], 0, buffer_size); } - ~stream_buffer() + ~spu_stream_buffer() { flush_all(); } @@ -969,8 +969,8 @@ void spu_device::device_start() voice=new voiceinfo [24]; spu_ram=new unsigned char [spu_ram_size]; - xa_buffer=new stream_buffer(xa_sector_size,xa_buffer_sectors); - cdda_buffer=new stream_buffer(cdda_sector_size,cdda_buffer_sectors); + xa_buffer=new spu_stream_buffer(xa_sector_size,xa_buffer_sectors); + cdda_buffer=new spu_stream_buffer(cdda_sector_size,cdda_buffer_sectors); init_stream(); @@ -1093,7 +1093,7 @@ void spu_device::init_stream() { const unsigned int hz=44100; - m_stream = machine().sound().stream_alloc(*this, 0, 2, hz); + m_stream = stream_alloc_legacy(0, 2, hz); rev=new reverb(hz); @@ -2761,7 +2761,7 @@ void spu_device::update_timing() // // -void spu_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void spu_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *outL, *outR; int16_t temp[44100], *src; @@ -3034,7 +3034,7 @@ bool spu_device::play_cdda(const unsigned int sector, const unsigned char *cdda) flip[i] = flip[i+1]; flip[i+1] = temp; } - // this should be done in generate but sound_stream_update may not be called frequently enough + // this should be done in generate but sound_stream_update_legacy may not be called frequently enough if(((spureg.irq_addr << 3) < 0x800) && (spureg.ctrl & spuctrl_irq_enable)) m_irq_handler(1); diff --git a/src/devices/sound/spu.h b/src/devices/sound/spu.h index b4e73c04726..7913670c667 100644 --- a/src/devices/sound/spu.h +++ b/src/devices/sound/spu.h @@ -7,7 +7,7 @@ // ======================> spu_device -class stream_buffer; +class spu_stream_buffer; class psxcpu_device; class spu_device : public device_t, public device_sound_interface @@ -35,7 +35,7 @@ protected: virtual void device_post_load() override; virtual void device_stop() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; static constexpr float ms_to_rate(float ms) { return 1.0f / (ms * (float(spu_base_frequency_hz) / 1000.0f)); } static constexpr float s_to_rate(float s) { return ms_to_rate(s * 1000.0f); } @@ -54,8 +54,8 @@ protected: unsigned int taddr; unsigned int sample_t; - stream_buffer *xa_buffer; - stream_buffer *cdda_buffer; + spu_stream_buffer *xa_buffer; + spu_stream_buffer *cdda_buffer; unsigned int xa_cnt; unsigned int cdda_cnt; unsigned int xa_freq; diff --git a/src/devices/sound/st0016.cpp b/src/devices/sound/st0016.cpp index 6ba2a8ec015..e0318eca466 100644 --- a/src/devices/sound/st0016.cpp +++ b/src/devices/sound/st0016.cpp @@ -43,7 +43,7 @@ st0016_device::st0016_device(const machine_config &mconfig, const char *tag, dev void st0016_device::device_start() { - m_stream = stream_alloc(0, 2, 44100); + m_stream = stream_alloc_legacy(0, 2, 44100); m_ram_read_cb.resolve_safe(0); save_item(NAME(m_vpos)); @@ -54,10 +54,10 @@ void st0016_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void st0016_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void st0016_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int v, i, snum; unsigned char *slot; diff --git a/src/devices/sound/st0016.h b/src/devices/sound/st0016.h index 4dde038cfe8..21dd14e07c7 100644 --- a/src/devices/sound/st0016.h +++ b/src/devices/sound/st0016.h @@ -27,7 +27,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream *m_stream; diff --git a/src/devices/sound/swp00.cpp b/src/devices/sound/swp00.cpp index 0fa494658b1..d4d323af0a5 100644 --- a/src/devices/sound/swp00.cpp +++ b/src/devices/sound/swp00.cpp @@ -21,7 +21,7 @@ void swp00_device::device_add_mconfig(machine_config &config) void swp00_device::device_start() { - m_stream = stream_alloc(0, 2, 44100); + m_stream = stream_alloc_legacy(0, 2, 44100); } void swp00_device::device_reset() @@ -97,6 +97,6 @@ void swp00_device::snd_w(offs_t offset, u8 data) // Synthesis -void swp00_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void swp00_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { } diff --git a/src/devices/sound/swp00.h b/src/devices/sound/swp00.h index 9ada0cdaadb..0bf2d8b43d3 100644 --- a/src/devices/sound/swp00.h +++ b/src/devices/sound/swp00.h @@ -21,7 +21,7 @@ public: protected: virtual void device_start() override; virtual void device_reset() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + 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 rom_bank_updated() override; virtual void device_add_mconfig(machine_config &config) override; diff --git a/src/devices/sound/swp20.cpp b/src/devices/sound/swp20.cpp index c5127168f11..c1c92c8cb27 100644 --- a/src/devices/sound/swp20.cpp +++ b/src/devices/sound/swp20.cpp @@ -69,7 +69,7 @@ void swp20_device::snd_w(offs_t offset, u8 data) logerror("w %02x, %02x %s\n", offset, data, machine().describe_context()); } -void swp20_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void swp20_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { } diff --git a/src/devices/sound/swp20.h b/src/devices/sound/swp20.h index b2aca4c8a71..a65bae793a3 100644 --- a/src/devices/sound/swp20.h +++ b/src/devices/sound/swp20.h @@ -20,7 +20,7 @@ public: protected: virtual void device_start() override; virtual void device_reset() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + 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 rom_bank_updated() override; private: diff --git a/src/devices/sound/swp30.cpp b/src/devices/sound/swp30.cpp index 18b4f498c1b..849af9f9946 100644 --- a/src/devices/sound/swp30.cpp +++ b/src/devices/sound/swp30.cpp @@ -163,7 +163,7 @@ void swp30_device::device_add_mconfig(machine_config &config) void swp30_device::device_start() { - m_stream = stream_alloc(0, 2, 44100); + m_stream = stream_alloc_legacy(0, 2, 44100); // Attenuantion for panning is 4.4 floating point. That means 0 // to -96.3dB. Since it's a nice range, we assume it's the same @@ -761,7 +761,7 @@ void swp30_device::snd_w(offs_t offset, u16 data) // Synthesis -void swp30_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void swp30_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // Loop first on the samples and not on the channels otherwise // effects will be annoying to implement. diff --git a/src/devices/sound/swp30.h b/src/devices/sound/swp30.h index 35a90341bf3..fc8424b66d2 100644 --- a/src/devices/sound/swp30.h +++ b/src/devices/sound/swp30.h @@ -21,7 +21,7 @@ public: protected: virtual void device_start() override; virtual void device_reset() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + 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 rom_bank_updated() override; virtual void device_add_mconfig(machine_config &config) override; diff --git a/src/devices/sound/t6721a.cpp b/src/devices/sound/t6721a.cpp index 423cd3edc19..7c0c07544e0 100644 --- a/src/devices/sound/t6721a.cpp +++ b/src/devices/sound/t6721a.cpp @@ -56,16 +56,16 @@ void t6721a_device::device_start() m_write_apd.resolve_safe(); // create sound stream - m_stream = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 1, machine().sample_rate()); } //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void t6721a_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void t6721a_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { } diff --git a/src/devices/sound/t6721a.h b/src/devices/sound/t6721a.h index ebc7ea6924e..208cd7e8896 100644 --- a/src/devices/sound/t6721a.h +++ b/src/devices/sound/t6721a.h @@ -65,7 +65,7 @@ protected: virtual void device_start() override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: enum diff --git a/src/devices/sound/t6w28.cpp b/src/devices/sound/t6w28.cpp index cc7324d41f1..6c024c37757 100644 --- a/src/devices/sound/t6w28.cpp +++ b/src/devices/sound/t6w28.cpp @@ -101,10 +101,10 @@ void t6w28_device::write(offs_t offset, uint8_t data) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void t6w28_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void t6w28_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int i; stream_sample_t *buffer0 = outputs[0]; @@ -296,7 +296,7 @@ void t6w28_device::device_start() int i; m_sample_rate = clock() / 16; - m_channel = machine().sound().stream_alloc(*this, 0, 2, m_sample_rate); + m_channel = stream_alloc_legacy(0, 2, m_sample_rate); for (i = 0;i < 8;i++) m_volume[i] = 0; diff --git a/src/devices/sound/t6w28.h b/src/devices/sound/t6w28.h index e6cc2d9319d..f1112f58839 100644 --- a/src/devices/sound/t6w28.h +++ b/src/devices/sound/t6w28.h @@ -18,7 +18,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; void set_gain(int gain); diff --git a/src/devices/sound/tc8830f.cpp b/src/devices/sound/tc8830f.cpp index 37a6fecdbe3..e387cc746f7 100644 --- a/src/devices/sound/tc8830f.cpp +++ b/src/devices/sound/tc8830f.cpp @@ -46,7 +46,7 @@ tc8830f_device::tc8830f_device(const machine_config &mconfig, const char *tag, d void tc8830f_device::device_start() { // create the stream - m_stream = stream_alloc(0, 1, clock() / 0x10); + m_stream = stream_alloc_legacy(0, 1, clock() / 0x10); // register for savestates save_item(NAME(m_playing)); @@ -79,7 +79,7 @@ void tc8830f_device::device_clock_changed() -void tc8830f_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void tc8830f_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int32_t mix = 0; diff --git a/src/devices/sound/tc8830f.h b/src/devices/sound/tc8830f.h index f108eb72f69..e0e715ccbef 100644 --- a/src/devices/sound/tc8830f.h +++ b/src/devices/sound/tc8830f.h @@ -32,7 +32,7 @@ protected: virtual void device_post_load() override; virtual void device_clock_changed() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream *m_stream; diff --git a/src/devices/sound/tiaintf.cpp b/src/devices/sound/tiaintf.cpp index d382707612a..5c85db19b91 100644 --- a/src/devices/sound/tiaintf.cpp +++ b/src/devices/sound/tiaintf.cpp @@ -31,7 +31,7 @@ tia_device::tia_device(const machine_config &mconfig, const char *tag, device_t void tia_device::device_start() { - m_channel = stream_alloc(0, 1, clock()); + m_channel = stream_alloc_legacy(0, 1, clock()); m_chip = tia_sound_init(this, clock(), clock(), 16); if (!m_chip) throw emu_fatalerror("tia_device(%s): Error creating TIA chip", tag()); @@ -49,10 +49,10 @@ void tia_device::device_stop() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void tia_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void tia_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { tia_process(m_chip, outputs[0], samples); } diff --git a/src/devices/sound/tiaintf.h b/src/devices/sound/tiaintf.h index 140c4f3de65..c86be7173a9 100644 --- a/src/devices/sound/tiaintf.h +++ b/src/devices/sound/tiaintf.h @@ -24,7 +24,7 @@ protected: virtual void device_stop() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream *m_channel; diff --git a/src/devices/sound/tms3615.cpp b/src/devices/sound/tms3615.cpp index 85f1ec5ece0..e59c64eab04 100644 --- a/src/devices/sound/tms3615.cpp +++ b/src/devices/sound/tms3615.cpp @@ -3,9 +3,6 @@ #include "emu.h" #include "tms3615.h" -#define VMIN 0x0000 -#define VMAX 0x7fff - const int tms3615_device::divisor[TMS3615_TONES] = { 478, 451, 426, 402, 379, 358, 338, 319, 301, 284, 268, 253, 239 }; @@ -49,20 +46,22 @@ void tms3615_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void tms3615_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void tms3615_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - int samplerate = m_samplerate; - stream_sample_t *buffer8 = outputs[FOOTAGE_8]; - stream_sample_t *buffer16 = outputs[FOOTAGE_16]; + auto &buffer8 = outputs[FOOTAGE_8]; + auto &buffer16 = outputs[FOOTAGE_16]; + + int samplerate = buffer8.sample_rate(); - while( samples-- > 0 ) + constexpr stream_buffer::sample_t VMAX = 1.0f / stream_buffer::sample_t(TMS3615_TONES); + for (int sampindex = 0; sampindex < buffer8.samples(); sampindex++) { - int sum8 = 0, sum16 = 0, tone = 0; + stream_buffer::sample_t sum8 = 0, sum16 = 0; - for (tone = 0; tone < TMS3615_TONES; tone++) + for (int tone = 0; tone < TMS3615_TONES; tone++) { // 8' @@ -95,11 +94,9 @@ void tms3615_device::sound_stream_update(sound_stream &stream, stream_sample_t * } } - *buffer8++ = sum8 / TMS3615_TONES; - *buffer16++ = sum16 / TMS3615_TONES; + buffer8.put(sampindex, sum8); + buffer16.put(sampindex, sum16); } - - m_enable = 0; } diff --git a/src/devices/sound/tms3615.h b/src/devices/sound/tms3615.h index b3325ebc354..a1eeaab5318 100644 --- a/src/devices/sound/tms3615.h +++ b/src/devices/sound/tms3615.h @@ -28,7 +28,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; private: static constexpr unsigned TMS3615_TONES = 13; diff --git a/src/devices/sound/tms36xx.cpp b/src/devices/sound/tms36xx.cpp index 89211700a7d..73ec59b4121 100644 --- a/src/devices/sound/tms36xx.cpp +++ b/src/devices/sound/tms36xx.cpp @@ -355,7 +355,7 @@ void tms36xx_device::device_start() { int enable = 0; - m_channel = stream_alloc(0, 1, clock() * 64); + m_channel = stream_alloc_legacy(0, 1, clock() * 64); m_samplerate = clock() * 64; m_basefreq = clock(); @@ -394,10 +394,10 @@ void tms36xx_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void tms36xx_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void tms36xx_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int samplerate = m_samplerate; stream_sample_t *buffer = outputs[0]; diff --git a/src/devices/sound/tms36xx.h b/src/devices/sound/tms36xx.h index 3e517a09f77..03dd5dc2412 100644 --- a/src/devices/sound/tms36xx.h +++ b/src/devices/sound/tms36xx.h @@ -63,7 +63,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; public: // MM6221AA interface functions diff --git a/src/devices/sound/tms5110.cpp b/src/devices/sound/tms5110.cpp index d9d8427688a..73f5244738e 100644 --- a/src/devices/sound/tms5110.cpp +++ b/src/devices/sound/tms5110.cpp @@ -1048,7 +1048,7 @@ void tms5110_device::device_start() m_data_cb.resolve(); /* initialize a stream */ - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock() / 80); + m_stream = stream_alloc_legacy(0, 1, clock() / 80); m_state = CTL_STATE_INPUT; /* most probably not defined */ m_romclk_hack_timer = timer_alloc(0); @@ -1220,10 +1220,10 @@ int tms5110_device::romclk_hack_r() ******************************************************************************/ //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void tms5110_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void tms5110_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int16_t sample_data[MAX_SAMPLE_CHUNK]; stream_sample_t *buffer = outputs[0]; diff --git a/src/devices/sound/tms5110.h b/src/devices/sound/tms5110.h index d873da55db4..84c7f68fc73 100644 --- a/src/devices/sound/tms5110.h +++ b/src/devices/sound/tms5110.h @@ -60,7 +60,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; uint8_t TALK_STATUS() const { return m_SPEN | m_TALKD; } diff --git a/src/devices/sound/tms5220.cpp b/src/devices/sound/tms5220.cpp index 4889cd85c60..9c4974c34e2 100644 --- a/src/devices/sound/tms5220.cpp +++ b/src/devices/sound/tms5220.cpp @@ -1649,7 +1649,7 @@ void tms5220_device::device_start() m_data_cb.resolve(); /* initialize a stream */ - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock() / 80); + m_stream = stream_alloc(0, 1, clock() / 80); m_timer_io_ready = timer_alloc(0); @@ -2055,24 +2055,21 @@ READ_LINE_MEMBER( tms5220_device::intq_r ) // sound_stream_update - handle a stream update //------------------------------------------------- -void tms5220_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void tms5220_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { int16_t sample_data[MAX_SAMPLE_CHUNK]; - stream_sample_t *buffer = outputs[0]; + auto &output = outputs[0]; /* loop while we still have samples to generate */ - while (samples) + constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; + for (int sampindex = 0; sampindex < output.samples(); ) { - int length = (samples > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : samples; - int index; + int length = (output.samples() > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : output.samples(); /* generate the samples and copy to the target buffer */ process(sample_data, length); - for (index = 0; index < length; index++) - *buffer++ = sample_data[index]; - - /* account for the samples */ - samples -= length; + for (int index = 0; index < length; index++) + output.put(sampindex++, sample_data[index] * sample_scale); } } diff --git a/src/devices/sound/tms5220.h b/src/devices/sound/tms5220.h index bc844b04e7b..5c45a685e21 100644 --- a/src/devices/sound/tms5220.h +++ b/src/devices/sound/tms5220.h @@ -75,7 +75,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; private: static constexpr unsigned FIFO_SIZE = 16; diff --git a/src/devices/sound/upd1771.cpp b/src/devices/sound/upd1771.cpp index c646f9954a6..bb8e61f2d00 100644 --- a/src/devices/sound/upd1771.cpp +++ b/src/devices/sound/upd1771.cpp @@ -255,7 +255,7 @@ void upd1771c_device::device_start() m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(upd1771c_device::ack_callback),this)); - m_channel = machine().sound().stream_alloc(*this, 0, 1, clock() / 4); + m_channel = stream_alloc_legacy(0, 1, clock() / 4); save_item(NAME(m_packet)); save_item(NAME(m_index)); @@ -476,10 +476,10 @@ TIMER_CALLBACK_MEMBER( upd1771c_device::ack_callback ) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void upd1771c_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void upd1771c_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; diff --git a/src/devices/sound/upd1771.h b/src/devices/sound/upd1771.h index 7dfc7ae32e5..9fe86b58c1d 100644 --- a/src/devices/sound/upd1771.h +++ b/src/devices/sound/upd1771.h @@ -32,7 +32,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: static constexpr unsigned MAX_PACKET_SIZE = 0x8000; diff --git a/src/devices/sound/upd7752.cpp b/src/devices/sound/upd7752.cpp index c1253da1a2b..19977dcafdc 100644 --- a/src/devices/sound/upd7752.cpp +++ b/src/devices/sound/upd7752.cpp @@ -72,7 +72,7 @@ device_memory_interface::space_config_vector upd7752_device::memory_space_config void upd7752_device::device_start() { /* TODO: clock */ - m_stream = stream_alloc(0, 1, clock() / 64); + m_stream = stream_alloc_legacy(0, 1, clock() / 64); m_status = 0; } @@ -96,10 +96,10 @@ void upd7752_device::device_stop() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void upd7752_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void upd7752_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { } diff --git a/src/devices/sound/upd7752.h b/src/devices/sound/upd7752.h index 85c3cd82d3c..b65048624f1 100644 --- a/src/devices/sound/upd7752.h +++ b/src/devices/sound/upd7752.h @@ -30,7 +30,7 @@ protected: virtual void device_stop() override; virtual void device_reset() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; virtual space_config_vector memory_space_config() const override; private: diff --git a/src/devices/sound/upd7759.cpp b/src/devices/sound/upd7759.cpp index 35a66d0b736..fc07c0f95ab 100644 --- a/src/devices/sound/upd7759.cpp +++ b/src/devices/sound/upd7759.cpp @@ -210,7 +210,7 @@ upd7756_device::upd7756_device(const machine_config &mconfig, device_type type, void upd775x_device::device_start() { // allocate a stream channel - m_channel = machine().sound().stream_alloc(*this, 0, 1, clock()/4); + m_channel = stream_alloc(0, 1, clock()/4); // compute the stepping rate based on the chip's clock speed m_step = 4 * FRAC_ONE; @@ -264,7 +264,7 @@ void upd7759_device::device_start() // chip configuration m_sample_offset_shift = 1; - m_timer = timer_alloc(TIMER_SLAVE_UPDATE); + m_timer = timer_alloc(TID_SLAVE_UPDATE); m_drqcallback.resolve_safe(); @@ -599,24 +599,35 @@ void upd7759_device::device_timer(emu_timer &timer, device_timer_id id, int para switch (id) { - case TIMER_SLAVE_UPDATE: + case TID_PORT_WRITE: + m_fifo_in = param; + break; + + case TID_RESET_WRITE: + internal_reset_w(param); + break; + + case TID_START_WRITE: + internal_start_w(param); + break; - /* update the stream */ - m_channel->update(); + case TID_SLAVE_UPDATE: + /* update the stream */ + m_channel->update(); - /* advance the state */ - advance_state(); + /* advance the state */ + advance_state(); - /* if the DRQ changed, update it */ - if (DEBUG_STATES) - logerror("upd7759_slave_update: DRQ %d->%d\n", olddrq, m_drq); - if (olddrq != m_drq) - m_drqcallback(m_drq); + /* if the DRQ changed, update it */ + if (DEBUG_STATES) + logerror("upd7759_slave_update: DRQ %d->%d\n", olddrq, m_drq); + if (olddrq != m_drq) + m_drqcallback(m_drq); - /* set a timer to go off when that is done */ - if (m_state != STATE_IDLE) - m_timer->adjust(m_clock_period * m_clocks_left); - break; + /* set a timer to go off when that is done */ + if (m_state != STATE_IDLE) + m_timer->adjust(m_clock_period * m_clocks_left); + break; default: throw emu_fatalerror("Unknown id in upd7759_device::device_timer"); @@ -630,6 +641,11 @@ void upd7759_device::device_timer(emu_timer &timer, device_timer_id id, int para *************************************************************/ WRITE_LINE_MEMBER( upd775x_device::reset_w ) +{ + synchronize(TID_RESET_WRITE, state); +} + +void upd775x_device::internal_reset_w(int state) { /* update the reset value */ uint8_t oldreset = m_reset; @@ -643,12 +659,12 @@ WRITE_LINE_MEMBER( upd775x_device::reset_w ) device_reset(); } -WRITE_LINE_MEMBER(upd7759_device::md_w) +WRITE_LINE_MEMBER( upd775x_device::start_w ) { - m_md = state; + synchronize(TID_START_WRITE, state); } -WRITE_LINE_MEMBER( upd7759_device::start_w ) +void upd7759_device::internal_start_w(int state) { /* update the start value */ uint8_t oldstart = m_start; @@ -671,8 +687,9 @@ WRITE_LINE_MEMBER( upd7759_device::start_w ) } } -WRITE_LINE_MEMBER( upd7756_device::start_w ) +void upd7756_device::internal_start_w(int state) { + /* update the start value */ uint8_t oldstart = m_start; m_start = (state != 0); @@ -694,7 +711,7 @@ WRITE_LINE_MEMBER( upd7756_device::start_w ) void upd775x_device::port_w(u8 data) { /* update the FIFO value */ - m_fifo_in = data; + synchronize(TID_PORT_WRITE, data); } @@ -712,21 +729,21 @@ READ_LINE_MEMBER( upd775x_device::busy_r ) // sound_stream_update - handle a stream update //------------------------------------------------- -void upd775x_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void upd775x_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { + constexpr stream_buffer::sample_t sample_scale = 128.0 / 32768.0; + stream_buffer::sample_t sample = stream_buffer::sample_t(m_sample) * sample_scale; int32_t clocks_left = m_clocks_left; - int16_t sample = m_sample; uint32_t step = m_step; uint32_t pos = m_pos; - stream_sample_t *buffer = outputs[0]; /* loop until done */ + u32 index = 0; if (m_state != STATE_IDLE) - while (samples != 0) + for ( ; index < outputs[0].samples(); index++) { /* store the current sample */ - *buffer++ = sample << 7; - samples--; + outputs[0].put(index, sample); /* advance by the number of clocks/output sample */ pos += step; @@ -752,14 +769,14 @@ void upd775x_device::sound_stream_update(sound_stream &stream, stream_sample_t * /* reimport the variables that we cached */ clocks_left = m_clocks_left; - sample = m_sample; + sample = stream_buffer::sample_t(m_sample) * sample_scale; } } } /* if we got out early, just zap the rest of the buffer */ - if (samples != 0) - memset(buffer, 0, samples * sizeof(*buffer)); + for (; index < outputs[0].samples(); index++) + outputs[0].put(index, 0); /* flush the state back */ m_clocks_left = clocks_left; diff --git a/src/devices/sound/upd7759.h b/src/devices/sound/upd7759.h index 813f5270d89..ab1ff98e3a2 100644 --- a/src/devices/sound/upd7759.h +++ b/src/devices/sound/upd7759.h @@ -23,11 +23,23 @@ public: enum : u32 { STANDARD_CLOCK = 640'000 }; DECLARE_WRITE_LINE_MEMBER( reset_w ); + DECLARE_WRITE_LINE_MEMBER( start_w ); DECLARE_READ_LINE_MEMBER( busy_r ); virtual void port_w(u8 data); void set_start_delay(uint32_t data) { m_start_delay = data; }; protected: + virtual void internal_start_w(int state) = 0; + virtual void internal_reset_w(int state); + + enum + { + TID_PORT_WRITE, + TID_START_WRITE, + TID_RESET_WRITE, + TID_SLAVE_UPDATE + }; + // chip states enum { @@ -56,7 +68,7 @@ protected: virtual void rom_bank_updated() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; void update_adpcm(int data); virtual void advance_state(); @@ -110,14 +122,10 @@ public: upd7759_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = STANDARD_CLOCK); - DECLARE_WRITE_LINE_MEMBER( md_w ); - DECLARE_WRITE_LINE_MEMBER( start_w ); + DECLARE_WRITE_LINE_MEMBER( md_w ) { m_md = state; } protected: - enum - { - TIMER_SLAVE_UPDATE - }; + virtual void internal_start_w(int state) override; upd7759_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); @@ -136,9 +144,9 @@ public: virtual void device_reset() override; - DECLARE_WRITE_LINE_MEMBER( start_w ); - protected: + virtual void internal_start_w(int state) override; + upd7756_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); virtual void device_start() override; diff --git a/src/devices/sound/upd934g.cpp b/src/devices/sound/upd934g.cpp index 75ba3fb4186..fecb6fc8a18 100644 --- a/src/devices/sound/upd934g.cpp +++ b/src/devices/sound/upd934g.cpp @@ -49,7 +49,7 @@ upd934g_device::upd934g_device(const machine_config &mconfig, const char *tag, d void upd934g_device::device_start() { // create sound stream - m_stream = machine().sound().stream_alloc(*this, 0, 4, 20000); + m_stream = stream_alloc_legacy(0, 4, 20000); // resolve callbacks m_data_cb.resolve_safe(0); @@ -81,11 +81,11 @@ void upd934g_device::device_reset() } //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void upd934g_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void upd934g_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { for (unsigned ch = 0; ch < 4; ch++) { diff --git a/src/devices/sound/upd934g.h b/src/devices/sound/upd934g.h index 9d872104617..ed145671c38 100644 --- a/src/devices/sound/upd934g.h +++ b/src/devices/sound/upd934g.h @@ -36,7 +36,7 @@ protected: virtual void device_start() override; virtual void device_reset() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: devcb_read8 m_data_cb; diff --git a/src/devices/sound/vgm_visualizer.cpp b/src/devices/sound/vgm_visualizer.cpp index 129f84c0a5a..c1f438f2b2c 100644 --- a/src/devices/sound/vgm_visualizer.cpp +++ b/src/devices/sound/vgm_visualizer.cpp @@ -283,35 +283,25 @@ void vgmviz_device::cycle_viz_mode() // audio stream and process as necessary //------------------------------------------------- -void vgmviz_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void vgmviz_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - // clear output buffers - for (int output = 0; output < m_outputs; output++) - std::fill_n(outputs[output], samples, 0); + // call the normal interface to actually mix + device_mixer_interface::sound_stream_update(stream, inputs, outputs); - m_current_rate = stream.sample_rate(); - - // loop over samples - const u8 *outmap = &m_outputmap[0]; - - // for each input, add it to the appropriate output - for (int pos = 0; pos < samples; pos++) + // now consume the outputs + for (int pos = 0; pos < outputs[0].samples(); pos++) { - for (int inp = 0; inp < m_auto_allocated_inputs; inp++) - { - outputs[outmap[inp]][pos] += inputs[inp][pos]; - } - - for (int i = 0; i < m_outputs; i++) + for (int i = 0; i < outputs.size(); i++) { - const float sample = (float)(int16_t)outputs[i][pos] / 65336.0f; + // Original code took 16-bit sample / 65536.0 instead of 32768.0, so multiply by 0.5 here but is it necessary? + const float sample = outputs[i].get(pos) * 0.5f; m_audio_buf[m_audio_fill_index][i][m_audio_count[m_audio_fill_index]] = sample + 0.5f; } switch (m_viz_mode) { default: - update_waveform(outputs); + update_waveform(); break; case VIZ_WATERFALL: case VIZ_RAW_SPEC: @@ -325,7 +315,7 @@ void vgmviz_device::sound_stream_update(sound_stream &stream, stream_sample_t ** case VIZ_TOP_SPEC4: case VIZ_TOP_SPEC8: case VIZ_TOP_SPEC16: - update_fft(outputs); + update_fft(); break; } } @@ -336,7 +326,7 @@ void vgmviz_device::sound_stream_update(sound_stream &stream, stream_sample_t ** // update_waveform - perform a wave-style update //------------------------------------------------- -void vgmviz_device::update_waveform(stream_sample_t **outputs) +void vgmviz_device::update_waveform() { m_history_length++; m_audio_count[m_audio_fill_index]++; @@ -355,7 +345,7 @@ void vgmviz_device::update_waveform(stream_sample_t **outputs) // update_fft - keep the FFT up-to-date //------------------------------------------------- -void vgmviz_device::update_fft(stream_sample_t **outputs) +void vgmviz_device::update_fft() { m_audio_count[m_audio_fill_index]++; if (m_audio_count[m_audio_fill_index] >= FFT_LENGTH) diff --git a/src/devices/sound/vgm_visualizer.h b/src/devices/sound/vgm_visualizer.h index 8455b3d2bc0..516e4e4bfad 100644 --- a/src/devices/sound/vgm_visualizer.h +++ b/src/devices/sound/vgm_visualizer.h @@ -91,10 +91,10 @@ protected: virtual void device_reset() override; // device_sound_interface-level overrides - void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; - void update_waveform(stream_sample_t **outputs); - void update_fft(stream_sample_t **outputs); + void update_waveform(); + void update_fft(); void init_palette(palette_device &palette) const; diff --git a/src/devices/sound/vlm5030.cpp b/src/devices/sound/vlm5030.cpp index 0d71f7e60b9..3d3cc7863fd 100644 --- a/src/devices/sound/vlm5030.cpp +++ b/src/devices/sound/vlm5030.cpp @@ -214,7 +214,7 @@ void vlm5030_device::device_start() device_reset(); m_phase = PH_IDLE; - m_channel = machine().sound().stream_alloc(*this, 0, 1, clock() / 440); + m_channel = stream_alloc_legacy(0, 1, clock() / 440); save_item(NAME(m_address)); save_item(NAME(m_pin_BSY)); @@ -491,10 +491,10 @@ if( m_interp_step != 1) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void vlm5030_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void vlm5030_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int buf_count=0; int interp_effect; diff --git a/src/devices/sound/vlm5030.h b/src/devices/sound/vlm5030.h index 891fb7ca595..7520bf76007 100644 --- a/src/devices/sound/vlm5030.h +++ b/src/devices/sound/vlm5030.h @@ -34,7 +34,7 @@ protected: virtual void device_post_load() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/volt_reg.cpp b/src/devices/sound/volt_reg.cpp index dbd922a808f..48693204e46 100644 --- a/src/devices/sound/volt_reg.cpp +++ b/src/devices/sound/volt_reg.cpp @@ -21,19 +21,16 @@ voltage_regulator_device::voltage_regulator_device(const machine_config &mconfig device_t(mconfig, VOLTAGE_REGULATOR, tag, owner, clock), device_sound_interface(mconfig, *this), m_stream(nullptr), - m_output(0x7fff) + m_output(1.0) { } void voltage_regulator_device::device_start() { - m_stream = stream_alloc(0, 1, 48000 * 4); + m_stream = stream_alloc(0, 1, SAMPLE_RATE_OUTPUT_ADAPTIVE); } -void voltage_regulator_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void voltage_regulator_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - for (int samp = 0; samp < samples; samp++) - { - outputs[0][samp] = m_output; - } + outputs[0].fill(m_output); } diff --git a/src/devices/sound/volt_reg.h b/src/devices/sound/volt_reg.h index 516039aac17..c672878fd4b 100644 --- a/src/devices/sound/volt_reg.h +++ b/src/devices/sound/volt_reg.h @@ -17,7 +17,7 @@ class voltage_regulator_device : public device_t, public device_sound_interface { public: - voltage_regulator_device &set_output(double analogue_dc) { m_output = (analogue_dc * 0x7fff) / 5.0f; return *this; } + voltage_regulator_device &set_output(double analogue_dc) { m_output = analogue_dc / 5.0f; return *this; } voltage_regulator_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0); @@ -28,11 +28,11 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; private: sound_stream* m_stream; - stream_sample_t m_output; + stream_buffer::sample_t m_output; }; DECLARE_DEVICE_TYPE(VOLTAGE_REGULATOR, voltage_regulator_device) diff --git a/src/devices/sound/votrax.cpp b/src/devices/sound/votrax.cpp index 8b416da6188..2b1f91ced1d 100644 --- a/src/devices/sound/votrax.cpp +++ b/src/devices/sound/votrax.cpp @@ -127,11 +127,11 @@ void votrax_sc01_device::inflection_w(uint8_t data) //------------------------------------------------- -// sound_stream_update - handle update requests +// sound_stream_update_legacy - handle update requests // for our sound stream //------------------------------------------------- -void votrax_sc01_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void votrax_sc01_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { for(int i=0; i 1) - machine().sound().stream_alloc(*this, 0, 2, machine().sample_rate()); + stream_alloc_legacy(0, 2, machine().sample_rate()); else - machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + stream_alloc_legacy(0, 1, machine().sample_rate()); } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void wave_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void wave_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *left_buffer = outputs[0]; stream_sample_t *right_buffer = nullptr; diff --git a/src/devices/sound/wave.h b/src/devices/sound/wave.h index fe5cf6b51a2..9f2a834d6c1 100644 --- a/src/devices/sound/wave.h +++ b/src/devices/sound/wave.h @@ -30,7 +30,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: required_device m_cass; diff --git a/src/devices/sound/x1_010.cpp b/src/devices/sound/x1_010.cpp index fdb824c0df7..8334db4a299 100644 --- a/src/devices/sound/x1_010.cpp +++ b/src/devices/sound/x1_010.cpp @@ -119,7 +119,7 @@ void x1_010_device::device_start() LOG_SOUND("masterclock = %d rate = %d\n", clock(), m_rate); /* get stream channels */ - m_stream = machine().sound().stream_alloc(*this, 0, 2, m_rate); + m_stream = stream_alloc_legacy(0, 2, m_rate); m_reg = make_unique_clear(0x2000); m_HI_WORD_BUF = make_unique_clear(0x2000); @@ -204,10 +204,10 @@ void x1_010_device::word_w(offs_t offset, u16 data) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void x1_010_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void x1_010_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // mixer buffer zero clear memset(outputs[0], 0, samples*sizeof(*outputs[0])); diff --git a/src/devices/sound/x1_010.h b/src/devices/sound/x1_010.h index 1664e2abd4c..3c8f1e60dc6 100644 --- a/src/devices/sound/x1_010.h +++ b/src/devices/sound/x1_010.h @@ -26,7 +26,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/ym2151.cpp b/src/devices/sound/ym2151.cpp index 744fec923ad..b519d9a1224 100644 --- a/src/devices/sound/ym2151.cpp +++ b/src/devices/sound/ym2151.cpp @@ -1836,16 +1836,17 @@ WRITE_LINE_MEMBER(ym2151_device::reset_w) // sound_stream_update - handle a stream update //------------------------------------------------- -void ym2151_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ym2151_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { if (m_reset_active) { - std::fill(&outputs[0][0], &outputs[0][samples], 0); - std::fill(&outputs[1][0], &outputs[1][samples], 0); + outputs[0].fill(0); + outputs[1].fill(0); return; } - for (int i=0; i const &inputs, std::vector &outputs) override; virtual void calculate_timers(); virtual void write_reg(int r, int v); diff --git a/src/devices/sound/ym2413.cpp b/src/devices/sound/ym2413.cpp index 0f78fad1daa..ca4a9acb874 100644 --- a/src/devices/sound/ym2413.cpp +++ b/src/devices/sound/ym2413.cpp @@ -1470,10 +1470,10 @@ void ym2413_device::write_reg(int r, int v) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void ym2413_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ym2413_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { for(int i=0; i < samples ; i++ ) { @@ -1511,7 +1511,7 @@ void ym2413_device::device_start() { int rate = clock()/72; - m_stream = machine().sound().stream_alloc(*this,0,2,rate); + m_stream = stream_alloc_legacy(0,2,rate); for (int x=0; x(m_mem_blocks); @@ -280,10 +280,10 @@ void zsg2_device::filter_samples(zchan *ch) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void zsg2_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void zsg2_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { for (int i = 0; i < samples; i++) { diff --git a/src/devices/sound/zsg2.h b/src/devices/sound/zsg2.h index b0506927440..592cbf83787 100644 --- a/src/devices/sound/zsg2.h +++ b/src/devices/sound/zsg2.h @@ -29,7 +29,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: const uint16_t STATUS_ACTIVE = 0x8000; diff --git a/src/devices/video/i8244.cpp b/src/devices/video/i8244.cpp index 5e7893aa6ae..5a4a1551cc0 100644 --- a/src/devices/video/i8244.cpp +++ b/src/devices/video/i8244.cpp @@ -129,7 +129,7 @@ void i8244_device::device_start() m_hblank_timer->adjust(screen().time_until_pos(0, m_hblank_start), 0, screen().scan_period()); // allocate a stream - m_stream = stream_alloc(0, 1, clock()); + m_stream = stream_alloc_legacy(0, 1, clock()); // register our state memset(m_vdc.reg, 0, 0x100); @@ -740,7 +740,7 @@ uint32_t i8244_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap } -void i8244_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void i8244_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { u8 volume = m_vdc.s.sound & 0xf; int sample_on = (m_sh_output & m_vdc.s.sound >> 7) * 0x4000; diff --git a/src/devices/video/i8244.h b/src/devices/video/i8244.h index c46034dd2b4..ebcbebbdea3 100644 --- a/src/devices/video/i8244.h +++ b/src/devices/video/i8244.h @@ -97,7 +97,7 @@ protected: virtual const tiny_rom_entry *device_rom_region() const override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + 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 set_default_params(); diff --git a/src/emu/disound.cpp b/src/emu/disound.cpp index 4d7d60265b6..29d8b4e13b5 100644 --- a/src/emu/disound.cpp +++ b/src/emu/disound.cpp @@ -66,13 +66,23 @@ device_sound_interface &device_sound_interface::add_route(u32 output, device_t & //------------------------------------------------- -// stream_alloc - allocate a stream implicitly +// stream_alloc_legacy - allocate a stream implicitly // associated with this device //------------------------------------------------- +sound_stream *device_sound_interface::stream_alloc_legacy(int inputs, int outputs, int sample_rate) +{ + return device().machine().sound().stream_alloc_legacy(*this, inputs, outputs, sample_rate, stream_update_legacy_delegate(&device_sound_interface::sound_stream_update_legacy, this)); +} + sound_stream *device_sound_interface::stream_alloc(int inputs, int outputs, int sample_rate) { - return device().machine().sound().stream_alloc(*this, inputs, outputs, sample_rate); + return device().machine().sound().stream_alloc(*this, inputs, outputs, sample_rate, stream_update_delegate(&device_sound_interface::sound_stream_update, this), STREAM_DEFAULT_FLAGS); +} + +sound_stream *device_sound_interface::stream_alloc(int inputs, int outputs, int sample_rate, sound_stream_flags flags) +{ + return device().machine().sound().stream_alloc(*this, inputs, outputs, sample_rate, stream_update_delegate(&device_sound_interface::sound_stream_update, this), flags); } @@ -171,7 +181,7 @@ float device_sound_interface::input_gain(int inputnum) const { int stream_inputnum; sound_stream *stream = input_to_stream_input(inputnum, stream_inputnum); - return (stream != nullptr) ? stream->input_gain(stream_inputnum) : 0.0f; + return (stream != nullptr) ? stream->input(stream_inputnum).gain() : 0.0f; } @@ -184,7 +194,7 @@ float device_sound_interface::output_gain(int outputnum) const { int stream_outputnum; sound_stream *stream = output_to_stream_output(outputnum, stream_outputnum); - return (stream != nullptr) ? stream->output_gain(stream_outputnum) : 0.0f; + return (stream != nullptr) ? stream->output(stream_outputnum).gain() : 0.0f; } @@ -198,7 +208,7 @@ void device_sound_interface::set_input_gain(int inputnum, float gain) int stream_inputnum; sound_stream *stream = input_to_stream_input(inputnum, stream_inputnum); if (stream != nullptr) - stream->set_input_gain(stream_inputnum, gain); + stream->input(stream_inputnum).set_gain(gain); } @@ -215,7 +225,7 @@ void device_sound_interface::set_output_gain(int outputnum, float gain) for (auto &stream : device().machine().sound().streams()) if (&stream->device() == &device()) for (int num = 0; num < stream->output_count(); num++) - stream->set_output_gain(num, gain); + stream->output(num).set_gain(gain); } // look up the stream and stream output index @@ -224,7 +234,7 @@ void device_sound_interface::set_output_gain(int outputnum, float gain) int stream_outputnum; sound_stream *stream = output_to_stream_output(outputnum, stream_outputnum); if (stream != nullptr) - stream->set_output_gain(stream_outputnum, gain); + stream->output(stream_outputnum).set_gain(gain); } } @@ -240,8 +250,11 @@ int device_sound_interface::inputnum_from_device(device_t &source_device, int ou for (auto &stream : device().machine().sound().streams()) if (&stream->device() == &device()) for (int inputnum = 0; inputnum < stream->input_count(); inputnum++, overall++) - if (stream->input_source_device(inputnum) == &source_device && stream->input_source_outputnum(inputnum) == outputnum) + { + auto &input = stream->input(inputnum); + if (input.valid() && &input.source().stream().device() == &source_device && input.source().index() == outputnum) return overall; + } return -1; } @@ -368,6 +381,28 @@ void device_sound_interface::interface_pre_reset() } +//------------------------------------------------- +// sound_stream_update_legacy - implementation +// that should be overridden by legacy devices +//------------------------------------------------- + +void device_sound_interface::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +{ + throw emu_fatalerror("sound_stream_update_legacy called but not overridden by owning class"); +} + + +//------------------------------------------------- +// sound_stream_update - default implementation +// that should be overridden +//------------------------------------------------- + +void device_sound_interface::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) +{ + throw emu_fatalerror("sound_stream_update called but not overridden by owning class"); +} + + //************************************************************************** // SIMPLE DERIVED MIXER INTERFACE @@ -430,8 +465,11 @@ void device_mixer_interface::interface_pre_start() } } + // keep a small buffer handy for tracking cleared buffers + m_output_clear.resize(m_outputs); + // allocate the mixer stream - m_mixer_stream = stream_alloc(m_auto_allocated_inputs, m_outputs, device().machine().sample_rate()); + m_mixer_stream = stream_alloc(m_auto_allocated_inputs, m_outputs, device().machine().sample_rate(), STREAM_DEFAULT_FLAGS); } @@ -443,9 +481,8 @@ void device_mixer_interface::interface_pre_start() void device_mixer_interface::interface_post_load() { - // Beware that there's not going to be a mixer stream if there was - // no inputs - if (m_mixer_stream) + // mixer stream could be null if no inputs were specified + if (m_mixer_stream != nullptr) m_mixer_stream->set_sample_rate(device().machine().sample_rate()); // call our parent @@ -454,21 +491,36 @@ void device_mixer_interface::interface_post_load() //------------------------------------------------- -// mixer_update - mix all inputs to one output +// sound_stream_update - mix all inputs to one +// output //------------------------------------------------- -void device_mixer_interface::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void device_mixer_interface::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - // clear output buffers - for (int output = 0; output < m_outputs; output++) - std::fill_n(outputs[output], samples, 0); + // reset the clear flags + std::fill(std::begin(m_output_clear), std::end(m_output_clear), false); - // loop over samples - const u8 *outmap = &m_outputmap[0]; - for (int pos = 0; pos < samples; pos++) + // loop over inputs + for (int inputnum = 0; inputnum < m_auto_allocated_inputs; inputnum++) { - // for each input, add it to the appropriate output - for (int inp = 0; inp < m_auto_allocated_inputs; inp++) - outputs[outmap[inp]][pos] += inputs[inp][pos]; + // skip if the gain is 0 + auto &input = inputs[inputnum]; + if (input.gain() == 0) + continue; + + // either store or accumulate + int outputnum = m_outputmap[inputnum]; + auto &output = outputs[outputnum]; + if (!m_output_clear[outputnum]) + output.copy(input); + else + output.add(input); + + m_output_clear[outputnum] = true; } + + // clear anything unused + for (int outputnum = 0; outputnum < m_outputs; outputnum++) + if (!m_output_clear[outputnum]) + outputs[outputnum].fill(0); } diff --git a/src/emu/disound.h b/src/emu/disound.h index 37a7df462be..d6135123ddb 100644 --- a/src/emu/disound.h +++ b/src/emu/disound.h @@ -34,6 +34,10 @@ constexpr int AUTO_ALLOC_INPUT = 65535; // TYPE DEFINITIONS //************************************************************************** +class read_stream_view; +class write_stream_view; +enum sound_stream_flags : u32; + // ======================> device_sound_interface @@ -73,10 +77,13 @@ public: device_sound_interface &reset_routes() { m_route_list.clear(); return *this; } // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) = 0; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples); + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs); // stream creation + sound_stream *stream_alloc_legacy(int inputs, int outputs, int sample_rate); sound_stream *stream_alloc(int inputs, int outputs, int sample_rate); + sound_stream *stream_alloc(int inputs, int outputs, int sample_rate, sound_stream_flags flags); // helpers int inputs() const; @@ -126,12 +133,13 @@ protected: virtual void interface_post_load() override; // sound interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; // internal state - u8 m_outputs; // number of outputs - std::vector m_outputmap; // map of inputs to outputs - sound_stream * m_mixer_stream; // mixing stream + u8 m_outputs; // number of outputs + std::vector m_outputmap; // map of inputs to outputs + std::vector m_output_clear; // flag for tracking cleared buffers + sound_stream *m_mixer_stream; // mixing stream }; // iterator diff --git a/src/emu/sound.cpp b/src/emu/sound.cpp index b59b2304edd..2dd2643b7b7 100644 --- a/src/emu/sound.cpp +++ b/src/emu/sound.cpp @@ -25,6 +25,8 @@ #define VPRINTF(x) do { if (VERBOSE) osd_printf_debug x; } while (0) +#define LOG_OUTPUT_WAV (0) + //************************************************************************** @@ -42,288 +44,596 @@ const attotime sound_manager::STREAMS_UPDATE_ATTOTIME = attotime::from_hz(STREAM //************************************************************************** -// INITIALIZATION +// STREAM BUFFER //************************************************************************** //------------------------------------------------- -// sound_stream - constructor -//------------------------------------------------- - -sound_stream::sound_stream(device_t &device, int inputs, int outputs, int sample_rate, stream_update_delegate callback) - : m_device(device), - m_next(nullptr), - m_sample_rate(sample_rate), - m_new_sample_rate(0xffffffff), - m_attoseconds_per_sample(0), - m_max_samples_per_update(0), - m_input(inputs), - m_input_array(inputs), - m_resample_bufalloc(0), - m_output(outputs), - m_output_array(outputs), - m_output_bufalloc(0), - m_output_sampindex(0), - m_output_update_sampindex(0), - m_output_base_sampindex(0), - m_callback(std::move(callback)) +// stream_buffer - constructor +//------------------------------------------------- + +stream_buffer::stream_buffer(u32 sample_rate) : + m_end_second(0), + m_end_sample(0), + m_sample_rate(sample_rate), + m_sample_attos((sample_rate == 0) ? ATTOSECONDS_PER_SECOND : ((ATTOSECONDS_PER_SECOND + sample_rate - 1) / sample_rate)), + m_buffer(sample_rate) { - // get the device's sound interface - device_sound_interface *sound; - if (!device.interface(sound)) - throw emu_fatalerror("Attempted to create a sound_stream with a non-sound device"); +} - if(m_callback.isnull()) - m_callback = stream_update_delegate(&device_sound_interface::sound_stream_update,(device_sound_interface *)sound); - // create a unique tag for saving - std::string state_tag = string_format("%d", m_device.machine().sound().m_stream_list.size()); - m_device.machine().save().save_item(&m_device, "stream", state_tag.c_str(), 0, NAME(m_sample_rate)); - m_device.machine().save().register_postload(save_prepost_delegate(FUNC(sound_stream::postload), this)); +//------------------------------------------------- +// stream_buffer - destructor +//------------------------------------------------- - // save the gain of each input and output - for (unsigned int inputnum = 0; inputnum < m_input.size(); inputnum++) +stream_buffer::~stream_buffer() +{ +#if (SOUND_DEBUG) + if (m_wav_file != nullptr) { - m_device.machine().save().save_item(&m_device, "stream", state_tag.c_str(), inputnum, NAME(m_input[inputnum].m_gain)); - m_device.machine().save().save_item(&m_device, "stream", state_tag.c_str(), inputnum, NAME(m_input[inputnum].m_user_gain)); + flush_wav(); + close_wav(); } - for (unsigned int outputnum = 0; outputnum < m_output.size(); outputnum++) +#endif +} + + +//------------------------------------------------- +// set_sample_rate - set a new sample rate for +// this buffer +//------------------------------------------------- + +void stream_buffer::set_sample_rate(u32 rate, bool resample) +{ + // skip if nothing is actually changing + if (rate == m_sample_rate) + return; + + // force resampling off if coming to or from an invalid rate + sound_assert(rate >= SAMPLE_RATE_MINIMUM - 1); + if (rate < SAMPLE_RATE_MINIMUM || m_sample_rate < SAMPLE_RATE_MINIMUM) + resample = false; + + // note the time and period of the current buffer (end_time is AFTER the final sample) + attotime prevperiod = sample_period(); + attotime prevend = end_time(); + + // compute the time and period of the new buffer + attotime newperiod = attotime(0, (ATTOSECONDS_PER_SECOND + rate - 1) / rate); + attotime newend = attotime(prevend.seconds(), (prevend.attoseconds() / newperiod.attoseconds()) * newperiod.attoseconds()); + + // buffer a short runway of previous samples; in order to support smooth + // sample rate changes (needed by, e.g., Q*Bert's Votrax), we buffer a few + // samples at the previous rate, and then reconstitute them resampled + // (via simple point sampling) at the new rate. The litmus test is the + // voice when jumping off the edge in Q*Bert; without this extra effort + // it is crackly and/or glitchy at times + sample_t buffer[64]; + int buffered_samples = std::min(m_sample_rate, std::min(rate, u32(ARRAY_LENGTH(buffer)))); + + // if the new rate is lower, downsample into our holding buffer; + // otherwise just copy into our holding buffer for later upsampling + bool new_rate_higher = (rate > m_sample_rate); + if (resample) { - m_output[outputnum].m_stream = this; - m_device.machine().save().save_item(&m_device, "stream", state_tag.c_str(), outputnum, NAME(m_output[outputnum].m_gain)); + if (!new_rate_higher) + backfill_downsample(&buffer[0], buffered_samples, newend, newperiod); + else + { + u32 end = m_end_sample; + for (int index = 0; index < buffered_samples; index++) + { + end = prev_index(end); + buffer[index] = get(end); + } + } } - // Mark synchronous streams as such - m_synchronous = m_sample_rate == STREAM_SYNC; - if (m_synchronous) + // ensure our buffer is large enough to hold a full second at the new rate + if (m_buffer.size() < rate) + m_buffer.resize(rate); + + // set the new rate + m_sample_rate = rate; + m_sample_attos = newperiod.attoseconds(); + + // compute the new end sample index based on the buffer time + m_end_sample = time_to_buffer_index(prevend, false, true); + + // if the new rate is higher, upsample from our temporary buffer; + // otherwise just copy our previously-downsampled data + if (resample) { - m_sample_rate = 0; - m_sync_timer = m_device.machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sound_stream::sync_update), this)); +#if (SOUND_DEBUG) + // for aggressive debugging, fill the buffer with NANs to catch anyone + // reading beyond what we resample below + fill(NAN); +#endif + + if (new_rate_higher) + backfill_upsample(&buffer[0], buffered_samples, prevend, prevperiod); + else + { + u32 end = m_end_sample; + for (int index = 0; index < buffered_samples; index++) + { + end = prev_index(end); + put(end, buffer[index]); + } + } } + + // if not resampling, clear the buffer else - m_sync_timer = nullptr; + fill(0); +} + + +//------------------------------------------------- +// open_wav - open a WAV file for logging purposes +//------------------------------------------------- + +#if (SOUND_DEBUG) +void stream_buffer::open_wav(char const *filename) +{ + // always open at 48k so that sound programs can handle it + // re-sample as needed + m_wav_file = wav_open(filename, 48000, 1); +} +#endif - // force an update to the sample rates; this will cause everything to be recomputed - // and will generate the initial resample buffers for our inputs - recompute_sample_rate_data(); - // set up the initial output buffer positions now that we have data - m_output_base_sampindex = -m_max_samples_per_update; +//------------------------------------------------- +// flush_wav - flush data to the WAV file +//------------------------------------------------- + +#if (SOUND_DEBUG) +void stream_buffer::flush_wav() +{ + // skip if no file + if (m_wav_file == nullptr) + return; + + // grab a view of the data from the last-written point + read_stream_view view(this, m_last_written, m_end_sample, 1.0f); + m_last_written = m_end_sample; + + // iterate over chunks for conversion + s16 buffer[1024]; + for (int samplebase = 0; samplebase < view.samples(); samplebase += ARRAY_LENGTH(buffer)) + { + // clamp to the buffer size + int cursamples = view.samples() - samplebase; + if (cursamples > ARRAY_LENGTH(buffer)) + cursamples = ARRAY_LENGTH(buffer); + + // convert and fill + for (int sampindex = 0; sampindex < cursamples; sampindex++) + buffer[sampindex] = s16(view.get(samplebase + sampindex) * 32768.0); + + // write to the WAV + wav_add_data_16(m_wav_file, buffer, cursamples); + } } +#endif //------------------------------------------------- -// sample_time - return the emulation time of the -// next sample to be generated on the stream +// close_wav - close the logging WAV file //------------------------------------------------- -attotime sound_stream::sample_time() const +#if (SOUND_DEBUG) +void stream_buffer::close_wav() { - return attotime(m_device.machine().sound().last_update().seconds(), 0) + attotime(0, m_output_sampindex * m_attoseconds_per_sample); + if (m_wav_file != nullptr) + wav_close(m_wav_file); + m_wav_file = nullptr; } +#endif //------------------------------------------------- -// user_gain - return the user-controllable gain -// on a given stream's input +// index_time - return the attotime of a given +// index within the buffer //------------------------------------------------- -float sound_stream::user_gain(int inputnum) const +attotime stream_buffer::index_time(s32 index) const { - assert(inputnum >= 0 && inputnum < m_input.size()); - return float(m_input[inputnum].m_user_gain) / 256.0f; + index = clamp_index(index); + return attotime(m_end_second - ((index > m_end_sample) ? 1 : 0), index * m_sample_attos); } //------------------------------------------------- -// input_gain - return the input gain on a -// given stream's input +// time_to_buffer_index - given an attotime, +// return the buffer index corresponding to it //------------------------------------------------- -float sound_stream::input_gain(int inputnum) const +u32 stream_buffer::time_to_buffer_index(attotime time, bool round_up, bool allow_expansion) { - assert(inputnum >= 0 && inputnum < m_input.size()); - return float(m_input[inputnum].m_gain) / 256.0f; + // compute the sample index within the second + int sample = (time.attoseconds() + (round_up ? (m_sample_attos - 1) : 0)) / m_sample_attos; + sound_assert(sample >= 0 && sample <= size()); + + // if the time is past the current end, make it the end + if (time.seconds() > m_end_second || (time.seconds() == m_end_second && sample > m_end_sample)) + { + sound_assert(allow_expansion); + + m_end_sample = sample; + m_end_second = time.m_seconds; + + // due to round_up, we could tweak over the line into the next second + if (sample >= size()) + { + m_end_sample -= size(); + m_end_second++; + } + } + + // if the time is before the start, fail + if (time.seconds() + 1 < m_end_second || (time.seconds() + 1 == m_end_second && sample < m_end_sample)) + throw emu_fatalerror("Attempt to create an out-of-bounds view"); + + return clamp_index(sample); } //------------------------------------------------- -// output_gain - return the output gain on a -// given stream's output +// backfill_downsample - this is called BEFORE +// the sample rate change to downsample from the +// end of the current buffer into a temporary +// holding location //------------------------------------------------- -float sound_stream::output_gain(int outputnum) const +void stream_buffer::backfill_downsample(sample_t *dest, int samples, attotime newend, attotime newperiod) { - assert(outputnum >= 0 && outputnum < m_output.size()); - return float(m_output[outputnum].m_gain) / 256.0f; + // compute the time of the first sample to be backfilled; start one period before + attotime time = newend - newperiod; + + // loop until we run out of buffered data + int dstindex; + for (dstindex = 0; dstindex < samples && time.seconds() >= 0; dstindex++) + { + u32 srcindex = time_to_buffer_index(time, false); +#if (SOUND_DEBUG) + // multiple resamples can occur before clearing out old NaNs so + // neuter them for this specific case + if (std::isnan(m_buffer[srcindex])) + dest[dstindex] = 0; + else +#endif + dest[dstindex] = get(srcindex); + time -= newperiod; + } + for ( ; dstindex < samples; dstindex++) + dest[dstindex] = 0; } //------------------------------------------------- -// input_name - return the original input gain -// on a given stream's input +// backfill_upsample - this is called AFTER the +// sample rate change to take a copied buffer +// of samples at the old rate and upsample them +// to the new (current) rate //------------------------------------------------- -std::string sound_stream::input_name(int inputnum) const +void stream_buffer::backfill_upsample(sample_t const *src, int samples, attotime prevend, attotime prevperiod) { - std::ostringstream str; + // compute the time of the first sample to be backfilled; start one period before + attotime time = end_time() - sample_period(); - // start with our device name and tag - assert(inputnum >= 0 && inputnum < m_input.size()); - util::stream_format(str, "%s '%s': ", m_device.name(), m_device.tag()); + // also adjust the buffered sample end time to point to the sample time of the + // final sample captured + prevend -= prevperiod; - // if we have a source, indicate where the sound comes from by device name and tag - if (m_input[inputnum].m_source != nullptr && m_input[inputnum].m_source->m_stream != nullptr) + // loop until we run out of buffered data + u32 end = m_end_sample; + int srcindex = 0; + while (1) { - device_t &source = m_input[inputnum].m_source->m_stream->device(); - util::stream_format(str, "%s '%s'", source.name(), source.tag()); - - // get the sound interface; if there is more than 1 output we need to figure out which one - device_sound_interface *sound; - if (source.interface(sound) && sound->outputs() > 1) + // if our backfill time is before the current buffered sample time, + // back up until we have a sample that covers this time + while (time < prevend && srcindex < samples) { - // iterate over outputs until we find the stream that matches our source - // then look for a match on the output number - sound_stream *outstream; - int streamoutputnum; - for (int outputnum = 0; (outstream = sound->output_to_stream_output(outputnum, streamoutputnum)) != nullptr; outputnum++) - if (outstream == m_input[inputnum].m_source->m_stream && m_input[inputnum].m_source == &outstream->m_output[streamoutputnum]) - { - util::stream_format(str, " Ch.%d", outputnum); - break; - } + prevend -= prevperiod; + srcindex++; } + + // stop when we run out of source + if (srcindex >= samples) + break; + + // write this sample at the pevious position + end = prev_index(end); + put(end, src[srcindex]); + + // back up to the next sample time + time -= sample_period(); } - return str.str(); } + +//************************************************************************** +// SOUND STREAM OUTPUT +//************************************************************************** + //------------------------------------------------- -// input_source_device - return the device -// attached as a given input's source +// sound_stream_output - constructor //------------------------------------------------- -device_t *sound_stream::input_source_device(int inputnum) const +sound_stream_output::sound_stream_output() : + m_stream(nullptr), + m_index(0), + m_gain(1.0) { - assert(inputnum >= 0 && inputnum < m_input.size()); - return (m_input[inputnum].m_source != nullptr) ? &m_input[inputnum].m_source->m_stream->device() : nullptr; } //------------------------------------------------- -// input_source_device - return the output number -// attached as a given input's source +// init - initialization //------------------------------------------------- -int sound_stream::input_source_outputnum(int inputnum) const +void sound_stream_output::init(sound_stream &stream, u32 index, char const *tag) { - assert(inputnum >= 0 && inputnum < m_input.size()); - return (m_input[inputnum].m_source != nullptr) ? (m_input[inputnum].m_source - &m_input[inputnum].m_source->m_stream->m_output[0]) : -1; + // set the passed-in data + m_stream = &stream; + m_index = index; + + // save our state + auto &save = stream.device().machine().save(); + save.save_item(&stream.device(), "stream.output", tag, index, NAME(m_gain)); + +#if (LOG_OUTPUT_WAV) + std::string filename = stream.device().machine().basename(); + filename += stream.device().tag(); + for (int index = 0; index < filename.size(); index++) + if (filename[index] == ':') + filename[index] = '_'; + if (dynamic_cast(&stream) != nullptr) + filename += "_resampler"; + filename += "_OUT_"; + char buf[10]; + sprintf(buf, "%d", index); + filename += buf; + filename += ".wav"; + m_buffer.open_wav(filename.c_str()); +#endif } //------------------------------------------------- -// set_input - configure a stream's input +// name - return the friendly name of this output //------------------------------------------------- -void sound_stream::set_input(int index, sound_stream *input_stream, int output_index, float gain) +std::string sound_stream_output::name() const { - VPRINTF(("stream_set_input(%p, '%s', %d, %p, %d, %f)\n", (void *)this, m_device.tag(), - index, (void *)input_stream, output_index, (double) gain)); + // start with our owning stream's name + std::ostringstream str; + util::stream_format(str, "%s Ch.%d", m_stream->name(), m_stream->output_base() + m_index); + return str.str(); +} - // make sure it's a valid input - if (index >= m_input.size()) - fatalerror("stream_set_input attempted to configure nonexistent input %d (%d max)\n", index, int(m_input.size())); - // make sure it's a valid output - if (input_stream != nullptr && output_index >= input_stream->m_output.size()) - fatalerror("stream_set_input attempted to use a nonexistent output %d (%d max)\n", output_index, int(m_output.size())); - // if this input is already wired, update the dependent info - stream_input &input = m_input[index]; - if (input.m_source != nullptr) - input.m_source->m_dependents--; +//************************************************************************** +// SOUND STREAM INPUT +//************************************************************************** - // wire it up - input.m_source = (input_stream != nullptr) ? &input_stream->m_output[output_index] : nullptr; - input.m_gain = int(0x100 * gain); - input.m_user_gain = 0x100; +//------------------------------------------------- +// sound_stream_input - constructor +//------------------------------------------------- + +sound_stream_input::sound_stream_input() : + m_owner(nullptr), + m_native_source(nullptr), + m_resampler_source(nullptr), + m_index(0), + m_gain(1.0), + m_user_gain(1.0) +{ +} - // update the dependent info - if (input.m_source != nullptr) - input.m_source->m_dependents++; - // update sample rates now that we know the input - recompute_sample_rate_data(); +//------------------------------------------------- +// init - initialization +//------------------------------------------------- + +void sound_stream_input::init(sound_stream &stream, u32 index, char const *tag, sound_stream_output *resampler) +{ + // set the passed-in values + m_owner = &stream; + m_index = index; + m_resampler_source = resampler; + + // save our state + auto &save = stream.device().machine().save(); + save.save_item(&stream.device(), "stream.input", tag, index, NAME(m_gain)); + save.save_item(&stream.device(), "stream.input", tag, index, NAME(m_user_gain)); } //------------------------------------------------- -// update - force a stream to update to -// the current emulated time +// name - return the friendly name of this input //------------------------------------------------- -void sound_stream::update() +std::string sound_stream_input::name() const { - if (!m_attoseconds_per_sample) - return; + // start with our owning stream's name + std::ostringstream str; + util::stream_format(str, "%s", m_owner->name()); + + // if we have a source, indicate where the sound comes from by device name and tag + if (valid()) + util::stream_format(str, " <- %s", m_native_source->name()); + return str.str(); +} - // determine the number of samples since the start of this second - attotime time = m_device.machine().time(); - s32 update_sampindex = s32(time.attoseconds() / m_attoseconds_per_sample); - // if we're ahead of the last update, then adjust upwards - attotime last_update = m_device.machine().sound().last_update(); - if (time.seconds() > last_update.seconds()) +//------------------------------------------------- +// set_source - wire up the output source for +// our consumption +//------------------------------------------------- + +void sound_stream_input::set_source(sound_stream_output *source) +{ + m_native_source = source; + if (m_resampler_source != nullptr) + m_resampler_source->stream().set_input(0, &source->stream(), source->index()); +} + + +//------------------------------------------------- +// update - update our source's stream to the +// current end time and return a view to its +// contents +//------------------------------------------------- + +read_stream_view sound_stream_input::update(attotime start, attotime end) +{ + // shouldn't get here unless valid + sound_assert(valid()); + + // determine if we need to use the resampler + bool resampled = false; + if (m_resampler_source != nullptr) { - assert(time.seconds() == last_update.seconds() + 1); - update_sampindex += m_sample_rate; + // if sample rates differ, then yet + if (m_owner->sample_rate() != m_native_source->stream().sample_rate()) + resampled = true; + + // if not, keep the resampler's end time up to date + else + m_resampler_source->set_end_time(end); } - // if we're behind the last update, then adjust downwards - if (time.seconds() < last_update.seconds()) + // update the source, returning a view of the needed output over the start and end times + sound_stream_output &source = resampled ? *m_resampler_source : *m_native_source; + return source.stream().update_view(start, end, source.index()).set_gain(m_gain * m_user_gain * m_native_source->gain()); +} + + +//------------------------------------------------- +// apply_sample_rate_changes - tell our sources +// to apply any sample rate changes, informing +// them of our current rate +//------------------------------------------------- + +void sound_stream_input::apply_sample_rate_changes(u32 updatenum, u32 downstream_rate) +{ + // shouldn't get here unless valid + sound_assert(valid()); + + // if we have a resampler, tell it (and it will tell the native source) + if (m_resampler_source != nullptr) + m_resampler_source->stream().apply_sample_rate_changes(updatenum, downstream_rate); + + // otherwise, just tell the native source directly + else + m_native_source->stream().apply_sample_rate_changes(updatenum, downstream_rate); +} + + + +//************************************************************************** +// SOUND STREAM +//************************************************************************** + +//------------------------------------------------- +// sound_stream - private common constructor +//------------------------------------------------- + +sound_stream::sound_stream(device_t &device, u32 inputs, u32 outputs, u32 output_base, u32 sample_rate, sound_stream_flags flags) : + m_device(device), + m_next(nullptr), + m_sample_rate((sample_rate < SAMPLE_RATE_MINIMUM) ? (SAMPLE_RATE_MINIMUM - 1) : (sample_rate < SAMPLE_RATE_OUTPUT_ADAPTIVE) ? sample_rate : 48000), + m_pending_sample_rate(SAMPLE_RATE_INVALID), + m_last_sample_rate_update(0), + m_input_adaptive(sample_rate == SAMPLE_RATE_INPUT_ADAPTIVE), + m_output_adaptive(sample_rate == SAMPLE_RATE_OUTPUT_ADAPTIVE), + m_synchronous((flags & STREAM_SYNCHRONOUS) != 0), + m_sync_timer(nullptr), + m_input(inputs), + m_input_array(inputs), + m_input_view(inputs), + m_empty_buffer(100), + m_output_base(output_base), + m_output(outputs), + m_output_array(outputs), + m_output_view(outputs) +{ + sound_assert(outputs > 0); + + // create a name + m_name = m_device.name(); + m_name += " '"; + m_name += m_device.tag(); + m_name += "'"; + + // create a unique tag for saving + std::string state_tag = string_format("%d", m_device.machine().sound().unique_id()); + auto &save = m_device.machine().save(); + save.register_postload(save_prepost_delegate(FUNC(sound_stream::postload), this)); + + // initialize all inputs + for (unsigned int inputnum = 0; inputnum < m_input.size(); inputnum++) { - assert(time.seconds() == last_update.seconds() - 1); - update_sampindex -= m_sample_rate; + // allocate a resampler stream if needed, and get a pointer to its output + sound_stream_output *resampler = nullptr; + if ((flags & STREAM_DISABLE_INPUT_RESAMPLING) == 0) + { + m_resampler_list.push_back(std::make_unique(m_device)); + resampler = &m_resampler_list.back()->m_output[0]; + } + + // add the new input + m_input[inputnum].init(*this, inputnum, state_tag.c_str(), resampler); } - if (update_sampindex <= m_output_sampindex) - return; + // initialize all outputs + for (unsigned int outputnum = 0; outputnum < m_output.size(); outputnum++) + m_output[outputnum].init(*this, outputnum, state_tag.c_str()); - // generate samples to get us up to the appropriate time - g_profiler.start(PROFILER_SOUND); - assert(m_output_sampindex - m_output_base_sampindex >= 0); - assert(update_sampindex - m_output_base_sampindex <= m_output_bufalloc); - generate_samples(update_sampindex - m_output_sampindex); - g_profiler.stop(); + // create an update timer for synchronous streams + if (synchronous()) + m_sync_timer = m_device.machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sound_stream::sync_update), this)); - // remember this info for next time - m_output_sampindex = update_sampindex; + // force an update to the sample rates + sample_rate_changed(); } -void sound_stream::sync_update(void *, s32) +//------------------------------------------------- +// sound_stream - constructor with old-style +// callback +//------------------------------------------------- + +sound_stream::sound_stream(device_t &device, u32 inputs, u32 outputs, u32 output_base, u32 sample_rate, stream_update_legacy_delegate callback, sound_stream_flags flags) : + sound_stream(device, inputs, outputs, output_base, sample_rate, flags) { - update(); - attotime time = m_device.machine().time(); - attoseconds_t next_edge = m_attoseconds_per_sample - (time.attoseconds() % m_attoseconds_per_sample); - m_sync_timer->adjust(attotime(0, next_edge)); + m_callback = std::move(callback); + m_callback_ex = stream_update_delegate(&sound_stream::stream_update_legacy, this); } //------------------------------------------------- -// output_since_last_update - return a pointer to -// the output buffer and the number of samples -// since the last global update +// sound_stream - constructor with new-style +// callback //------------------------------------------------- -const stream_sample_t *sound_stream::output_since_last_update(int outputnum, int &numsamples) +sound_stream::sound_stream(device_t &device, u32 inputs, u32 outputs, u32 output_base, u32 sample_rate, stream_update_delegate callback, sound_stream_flags flags) : + sound_stream(device, inputs, outputs, output_base, sample_rate, flags) { - // force an update on the stream - update(); + m_callback_ex = std::move(callback); +} + - // compute the number of samples and a pointer to the output buffer - numsamples = m_output_sampindex - m_output_update_sampindex; - return &m_output[outputnum].m_buffer[m_output_update_sampindex - m_output_base_sampindex]; +//------------------------------------------------- +// ~sound_stream - destructor +//------------------------------------------------- + +sound_stream::~sound_stream() +{ } @@ -332,93 +642,126 @@ const stream_sample_t *sound_stream::output_since_last_update(int outputnum, int // given stream //------------------------------------------------- -void sound_stream::set_sample_rate(int new_rate) +void sound_stream::set_sample_rate(u32 new_rate) { // we will update this on the next global update if (new_rate != sample_rate()) - m_new_sample_rate = new_rate; + m_pending_sample_rate = new_rate; } //------------------------------------------------- -// set_user_gain - set the user-controllable gain -// on a given stream's input +// set_input - configure a stream's input //------------------------------------------------- -void sound_stream::set_user_gain(int inputnum, float gain) +void sound_stream::set_input(int index, sound_stream *input_stream, int output_index, float gain) { - update(); - assert(inputnum >= 0 && inputnum < m_input.size()); - m_input[inputnum].m_user_gain = int(0x100 * gain); -} + VPRINTF(("stream_set_input(%p, '%s', %d, %p, %d, %f)\n", (void *)this, m_device.tag(), + index, (void *)input_stream, output_index, (double) gain)); + // make sure it's a valid input + if (index >= m_input.size()) + fatalerror("stream_set_input attempted to configure nonexistent input %d (%d max)\n", index, int(m_input.size())); -//------------------------------------------------- -// set_input_gain - set the input gain on a -// given stream's input -//------------------------------------------------- + // make sure it's a valid output + if (input_stream != nullptr && output_index >= input_stream->m_output.size()) + fatalerror("stream_set_input attempted to use a nonexistent output %d (%d max)\n", output_index, int(m_output.size())); -void sound_stream::set_input_gain(int inputnum, float gain) -{ - update(); - assert(inputnum >= 0 && inputnum < m_input.size()); - m_input[inputnum].m_gain = int(0x100 * gain); + // wire it up + m_input[index].set_source((input_stream != nullptr) ? &input_stream->m_output[output_index] : nullptr); + m_input[index].set_gain(gain); + + // update sample rates now that we know the input + sample_rate_changed(); } //------------------------------------------------- -// set_output_gain - set the output gain on a -// given stream's output +// update - force a stream to update to +// the current emulated time //------------------------------------------------- -void sound_stream::set_output_gain(int outputnum, float gain) +void sound_stream::update() { - update(); - assert(outputnum >= 0 && outputnum < m_output.size()); - m_output[outputnum].m_gain = int(0x100 * gain); + // ignore any update requests if we're already up to date + attotime start = m_output[0].end_time(); + attotime end = m_device.machine().time(); + if (start >= end) + return; + + // regular update then + update_view(start, end); } //------------------------------------------------- -// update_with_accounting - do a regular update, -// but also do periodic accounting +// update_view - force a stream to update to +// the current emulated time and return a view +// to the generated samples from the given +// output number //------------------------------------------------- -void sound_stream::update_with_accounting(bool second_tick) +read_stream_view sound_stream::update_view(attotime start, attotime end, u32 outputnum) { - // do the normal update - update(); + sound_assert(start <= end); + sound_assert(outputnum < m_output.size()); - // if we've ticked over another second, adjust all the counters that are relative to - // the current second - s32 output_bufindex = m_output_sampindex - m_output_base_sampindex; - if (second_tick) - { - m_output_sampindex -= m_sample_rate; - m_output_base_sampindex -= m_sample_rate; - } + // clean up parameters for when the asserts go away + if (outputnum >= m_output.size()) + outputnum = 0; + if (start > end) + start = end; - // note our current output sample - m_output_update_sampindex = m_output_sampindex; + g_profiler.start(PROFILER_SOUND); - // if we don't have enough output buffer space to hold two updates' worth of samples, - // we need to shuffle things down - if (m_output_bufalloc - output_bufindex < 2 * m_max_samples_per_update) + // reposition our start to coincide with the current buffer end + attotime update_start = m_output[outputnum].end_time(); + if (update_start <= end) { - s32 samples_to_lose = output_bufindex - m_max_samples_per_update; - if (samples_to_lose > 0) + // create views for all the outputs + for (unsigned int outindex = 0; outindex < m_output.size(); outindex++) + m_output_view[outindex] = m_output[outindex].view(update_start, end); + + // skip if nothing to do + u32 samples = m_output_view[0].samples(); + sound_assert(samples >= 0); + if (samples != 0 && m_sample_rate >= SAMPLE_RATE_MINIMUM) { - // if we have samples to move, do so for each output - if (output_bufindex > 0) - for (auto &output : m_output) - { - memmove(&output.m_buffer[0], &output.m_buffer[samples_to_lose], sizeof(output.m_buffer[0]) * (output_bufindex - samples_to_lose)); - } + sound_assert(!synchronous() || samples == 1); + + // ensure all input streams are up to date, and create views for them as well + for (unsigned int inputnum = 0; inputnum < m_input.size(); inputnum++) + { + if (m_input[inputnum].valid()) + m_input_view[inputnum] = m_input[inputnum].update(update_start, end); + else + m_input_view[inputnum] = empty_view(update_start, end); + } + +#if (SOUND_DEBUG) + // clear each output view to NANs before we call the callback + for (unsigned int outindex = 0; outindex < m_output.size(); outindex++) + m_output_view[outindex].fill(NAN); +#endif + + // if we have an extended callback, that's all we need + m_callback_ex(*this, m_input_view, m_output_view); - // update the base position - m_output_base_sampindex += samples_to_lose; +#if (SOUND_DEBUG) + // make sure everything was overwritten + for (unsigned int outindex = 0; outindex < m_output.size(); outindex++) + for (int sampindex = 0; sampindex < m_output_view[outindex].samples(); sampindex++) + m_output_view[outindex].get(sampindex); + + for (unsigned int outindex = 0; outindex < m_output.size(); outindex++) + m_output[outindex].m_buffer.flush_wav(); +#endif } } + g_profiler.stop(); + + // return the requested view + return read_stream_view(m_output[outputnum].view(start, end)); } @@ -427,398 +770,337 @@ void sound_stream::update_with_accounting(bool second_tick) // pending sample rate change, apply it now //------------------------------------------------- -void sound_stream::apply_sample_rate_changes() +void sound_stream::apply_sample_rate_changes(u32 updatenum, u32 downstream_rate) { - // skip if nothing to do - if (m_new_sample_rate == 0xffffffff) - return; + // grab the new rate and invalidate + u32 new_rate = (m_pending_sample_rate != SAMPLE_RATE_INVALID) ? m_pending_sample_rate : m_sample_rate; + m_pending_sample_rate = SAMPLE_RATE_INVALID; - // update to the new rate and remember the old rate - u32 old_rate = m_sample_rate; - m_sample_rate = m_new_sample_rate; - m_new_sample_rate = 0xffffffff; + // clamp to the minimum - 1 (anything below minimum means "off" and + // will not call the sound callback at all) + if (new_rate < SAMPLE_RATE_MINIMUM) + new_rate = SAMPLE_RATE_MINIMUM - 1; - // recompute all the data - recompute_sample_rate_data(); + // if we're input adaptive, override with the rate of our input + if (input_adaptive() && m_input.size() > 0 && m_input[0].valid()) + new_rate = m_input[0].source().stream().sample_rate(); - // reset our sample indexes to the current time - if (old_rate) + // if we're output adaptive, override with the rate of our output + if (output_adaptive()) { - m_output_sampindex = s64(m_output_sampindex) * s64(m_sample_rate) / old_rate; - m_output_update_sampindex = s64(m_output_update_sampindex) * s64(m_sample_rate) / old_rate; + if (m_last_sample_rate_update == updatenum) + sound_assert(new_rate == m_sample_rate); + else + m_last_sample_rate_update = updatenum; + new_rate = downstream_rate; } - else + + // if something is different, process the change + if (new_rate != SAMPLE_RATE_INVALID && new_rate != m_sample_rate) { - m_output_sampindex = m_attoseconds_per_sample ? m_device.machine().sound().last_update().attoseconds() / m_attoseconds_per_sample : 0; - m_output_update_sampindex = m_output_sampindex; + // update to the new rate and notify everyone +#if (SOUND_DEBUG) + printf("stream %s changing rates %d -> %d\n", name().c_str(), m_sample_rate, new_rate); +#endif + m_sample_rate = new_rate; + sample_rate_changed(); } - m_output_base_sampindex = m_output_sampindex - m_max_samples_per_update; - - // clear out the buffer - if (m_max_samples_per_update) - for (auto &elem : m_output) - std::fill_n(&elem.m_buffer[0], m_max_samples_per_update, 0); + // now call through our inputs and apply the rate change there + for (auto &input : m_input) + if (input.valid()) + input.apply_sample_rate_changes(updatenum, m_sample_rate); } //------------------------------------------------- -// recompute_sample_rate_data - recompute sample -// rate data, and all streams that are affected -// by this stream +// print_graph_recursive - helper for debugging; +// prints info on this stream and then recursively +// prints info on all inputs //------------------------------------------------- -void sound_stream::recompute_sample_rate_data() +#if (SOUND_DEBUG) +void sound_stream::print_graph_recursive(int indent) { - if (m_synchronous) - { - m_sample_rate = 0; - // When synchronous, pick the sample rate for the inputs, if any - for (auto &input : m_input) + osd_printf_info("%c %*s%s @ %d\n", m_callback.isnull() ? ' ' : '!', indent, "", name().c_str(), sample_rate()); + for (int index = 0; index < m_input.size(); index++) + if (m_input[index].valid()) { - if (input.m_source != nullptr) - { - if (!m_sample_rate) - m_sample_rate = input.m_source->m_stream->m_sample_rate; - else if (m_sample_rate != input.m_source->m_stream->m_sample_rate) - throw emu_fatalerror("Incompatible sample rates as input of a synchronous stream: %d and %d\n", m_sample_rate, input.m_source->m_stream->m_sample_rate); - } + if (m_input[index].m_resampler_source != nullptr) + m_input[index].m_resampler_source->stream().print_graph_recursive(indent + 2); + else + m_input[index].m_native_source->stream().print_graph_recursive(indent + 2); } - } - - - // recompute the timing parameters - attoseconds_t update_attoseconds = m_device.machine().sound().update_attoseconds(); +} +#endif - if (m_sample_rate) - { - m_attoseconds_per_sample = ATTOSECONDS_PER_SECOND / m_sample_rate; - m_max_samples_per_update = (update_attoseconds + m_attoseconds_per_sample - 1) / m_attoseconds_per_sample; - } - else - { - m_attoseconds_per_sample = 0; - m_max_samples_per_update = 0; - } - // update resample and output buffer sizes - allocate_resample_buffers(); - allocate_output_buffers(); +//------------------------------------------------- +// sample_rate_changed - recompute sample +// rate data, and all streams that are affected +// by this stream +//------------------------------------------------- - // iterate over each input - for (auto &input : m_input) - { - // if we have a source, see if its sample rate changed +void sound_stream::sample_rate_changed() +{ + // if invalid, just punt + if (m_sample_rate == SAMPLE_RATE_INVALID) + return; - if (input.m_source != nullptr && input.m_source->m_stream->m_sample_rate) - { - // okay, we have a new sample rate; recompute the latency to be the maximum - // sample period between us and our input - attoseconds_t new_attosecs_per_sample = ATTOSECONDS_PER_SECOND / input.m_source->m_stream->m_sample_rate; - attoseconds_t latency = std::max(new_attosecs_per_sample, m_attoseconds_per_sample); - - // if the input stream's sample rate is lower, we will use linear interpolation - // this requires an extra sample from the source - if (input.m_source->m_stream->m_sample_rate < m_sample_rate) - latency += new_attosecs_per_sample; - - // if our sample rates match exactly, we don't need any latency - else if (input.m_source->m_stream->m_sample_rate == m_sample_rate) - latency = 0; - - // we generally don't want to tweak the latency, so we just keep the greatest - // one we've computed thus far - input.m_latency_attoseconds = std::max(input.m_latency_attoseconds, latency); - assert(input.m_latency_attoseconds < update_attoseconds); - } - else - { - input.m_latency_attoseconds = 0; - } - } + // update all output buffers + for (auto &output : m_output) + output.sample_rate_changed(m_sample_rate); - // If synchronous, prime the timer - if (m_synchronous) - { - attotime time = m_device.machine().time(); - if (m_attoseconds_per_sample) - { - attoseconds_t next_edge = m_attoseconds_per_sample - (time.attoseconds() % m_attoseconds_per_sample); - m_sync_timer->adjust(attotime(0, next_edge)); - } - else - m_sync_timer->adjust(attotime::never); - } + // if synchronous, prime the timer + if (synchronous()) + reprime_sync_timer(); } //------------------------------------------------- -// allocate_resample_buffers - recompute the -// resample buffer sizes and expand if necessary +// postload - save/restore callback //------------------------------------------------- -void sound_stream::allocate_resample_buffers() +void sound_stream::postload() { - // compute the target number of samples - s32 bufsize = 2 * m_max_samples_per_update; + // recompute the sample rate information + sample_rate_changed(); +} - // if we don't have enough room, allocate more - if (m_resample_bufalloc < bufsize) - { - // this becomes the new allocation size - m_resample_bufalloc = bufsize; - // iterate over outputs and realloc their buffers - for (auto &elem : m_input) - elem.m_resample.resize(m_resample_bufalloc, 0); - } +//------------------------------------------------- +// reprime_sync_timer - set up the next sync +// timer to go off just a hair after the end of +// the current sample period +//------------------------------------------------- + +void sound_stream::reprime_sync_timer() +{ + attotime curtime = m_device.machine().time(); + attotime target = m_output[0].end_time() + attotime(0, 1); + m_sync_timer->adjust(target - curtime); } //------------------------------------------------- -// allocate_output_buffers - recompute the -// output buffer sizes and expand if necessary +// sync_update - timer callback to handle a +// synchronous stream //------------------------------------------------- -void sound_stream::allocate_output_buffers() +void sound_stream::sync_update(void *, s32) { - // if we don't have enough room, allocate more - s32 bufsize = OUTPUT_BUFFER_UPDATES * m_max_samples_per_update; - if (m_output_bufalloc < bufsize) - { - // this becomes the new allocation size - m_output_bufalloc = bufsize; - - // iterate over outputs and realloc their buffers - for (auto &elem : m_output) - elem.m_buffer.resize(m_output_bufalloc, 0); - } + update(); + reprime_sync_timer(); } //------------------------------------------------- -// postload - save/restore callback +// stream_update_legacy - new-style callback which +// forwards on to the old-style traditional +// callback, converting to/from floats //------------------------------------------------- -void sound_stream::postload() +void sound_stream::stream_update_legacy(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - // recompute the same rate information - recompute_sample_rate_data(); + // temporary buffer to hold stream_sample_t inputs and outputs + stream_sample_t temp_buffer[1024]; + int chunksize = ARRAY_LENGTH(temp_buffer) / (inputs.size() + outputs.size()); + int chunknum = 0; + + // create the arrays to pass to the callback + stream_sample_t **inputptr = m_input.empty() ? nullptr : &m_input_array[0]; + stream_sample_t **outputptr = &m_output_array[0]; + for (unsigned int inputnum = 0; inputnum < inputs.size(); inputnum++) + inputptr[inputnum] = &temp_buffer[chunksize * chunknum++]; + for (unsigned int outputnum = 0; outputnum < m_output.size(); outputnum++) + outputptr[outputnum] = &temp_buffer[chunksize * chunknum++]; - // make sure our output buffers are fully cleared - for (auto &elem : m_output) - std::fill_n(&elem.m_buffer[0], m_output_bufalloc, 0); + // loop until all chunks done + for (int baseindex = 0; baseindex < outputs[0].samples(); baseindex += chunksize) + { + // determine the number of samples to process this time + int cursamples = outputs[0].samples() - baseindex; + if (cursamples > chunksize) + cursamples = chunksize; - // recompute the sample indexes to make sense - m_output_sampindex = m_attoseconds_per_sample ? m_device.machine().sound().last_update().attoseconds() / m_attoseconds_per_sample : 0; - m_output_update_sampindex = m_output_sampindex; - m_output_base_sampindex = m_output_sampindex - m_max_samples_per_update; + // copy in the input data + for (unsigned int inputnum = 0; inputnum < inputs.size(); inputnum++) + { + stream_sample_t *dest = inputptr[inputnum]; + for (int index = 0; index < cursamples; index++) + dest[index] = stream_sample_t(inputs[inputnum].get(baseindex + index) * stream_buffer::sample_t(32768.0)); + } + + // run the callback + m_callback(*this, inputptr, outputptr, cursamples); + + // copy out the output data + for (unsigned int outputnum = 0; outputnum < m_output.size(); outputnum++) + { + stream_sample_t *src = outputptr[outputnum]; + for (int index = 0; index < cursamples; index++) + outputs[outputnum].put(baseindex + index, stream_buffer::sample_t(src[index]) * stream_buffer::sample_t(1.0 / 32768.0)); + } + } } //------------------------------------------------- -// generate_samples - generate the requested -// number of samples for a stream, making sure -// all inputs have the appropriate number of -// samples generated +// empty_view - return an empty view covering the +// given time period as a substitute for invalid +// inputs //------------------------------------------------- -void sound_stream::generate_samples(int samples) +read_stream_view sound_stream::empty_view(attotime start, attotime end) { - stream_sample_t **inputs = nullptr; - stream_sample_t **outputs = nullptr; - - VPRINTF(("generate_samples(%p, %d)\n", (void *) this, samples)); - assert(samples > 0); + // if our dummy buffer doesn't match our sample rate, update and clear it + if (m_empty_buffer.sample_rate() != m_sample_rate) + m_empty_buffer.set_sample_rate(m_sample_rate, false); - // ensure all inputs are up to date and generate resampled data - for (unsigned int inputnum = 0; inputnum < m_input.size(); inputnum++) - { - // update the stream to the current time - stream_input &input = m_input[inputnum]; - if (input.m_source != nullptr) - input.m_source->m_stream->update(); + // allocate a write view so that it can expand, and convert back to a read view + // on the return + return write_stream_view(m_empty_buffer, start, end); +} - // generate the resampled data - m_input_array[inputnum] = generate_resampled_data(input, samples); - } - if (!m_input.empty()) - { - inputs = &m_input_array[0]; - } - // loop over all outputs and compute the output pointer - for (unsigned int outputnum = 0; outputnum < m_output.size(); outputnum++) - { - stream_output &output = m_output[outputnum]; - m_output_array[outputnum] = &output.m_buffer[m_output_sampindex - m_output_base_sampindex]; - } +//************************************************************************** +// RESAMPLER STREAM +//************************************************************************** - if (!m_output.empty()) - { - outputs = &m_output_array[0]; - } +//------------------------------------------------- +// default_resampler_stream - derived sound_stream +// class that handles resampling +//------------------------------------------------- - // run the callback - VPRINTF((" callback(%p, %d)\n", (void *)this, samples)); - m_callback(*this, inputs, outputs, samples); - VPRINTF((" callback done\n")); +default_resampler_stream::default_resampler_stream(device_t &device) : + sound_stream(device, 1, 1, 0, SAMPLE_RATE_OUTPUT_ADAPTIVE, stream_update_delegate(&default_resampler_stream::resampler_sound_update, this), STREAM_DISABLE_INPUT_RESAMPLING), + m_max_latency(0) +{ + // create a name + m_name = "Default Resampler '"; + m_name += device.tag(); + m_name += "'"; } //------------------------------------------------- -// generate_resampled_data - generate the -// resample buffer for a given input +// resampler_sound_update - stream callback +// handler for resampling an input stream to the +// target sample rate of the output //------------------------------------------------- -stream_sample_t *sound_stream::generate_resampled_data(stream_input &input, u32 numsamples) +void default_resampler_stream::resampler_sound_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - // if we don't have an output to pull data from, generate silence - stream_sample_t *dest = &input.m_resample[0]; - if (input.m_source == nullptr || input.m_source->m_stream->m_attoseconds_per_sample == 0) + sound_assert(inputs.size() == 1); + sound_assert(outputs.size() == 1); + + auto &input = inputs[0]; + auto &output = outputs[0]; + + // if the input has an invalid rate, just fill with zeros + if (input.sample_rate() <= 1) { - std::fill_n(dest, numsamples, 0); - return &input.m_resample[0]; + output.fill(0); + return; } - // grab data from the output - stream_output &output = *input.m_source; - sound_stream &input_stream = *output.m_stream; - s64 gain = (input.m_gain * input.m_user_gain * output.m_gain) >> 16; + // if we have equal sample rates, we just need to copy + auto numsamples = output.samples(); + if (input.sample_rate() == output.sample_rate()) + { + output.copy(input); + return; + } - // determine the time at which the current sample begins, accounting for the - // latency we calculated between the input and output streams - attoseconds_t basetime = m_output_sampindex * m_attoseconds_per_sample - input.m_latency_attoseconds; + // compute the stepping value and the inverse + stream_buffer::sample_t step = stream_buffer::sample_t(input.sample_rate()) / stream_buffer::sample_t(output.sample_rate()); + stream_buffer::sample_t stepinv = 1.0 / step; - // now convert that time into a sample in the input stream - s32 basesample; - if (basetime >= 0) - basesample = basetime / input_stream.m_attoseconds_per_sample; + // determine the latency we need to introduce, in input samples: + // 1 input sample for undersampled inputs + // 1 + step input samples for oversampled inputs + s64 latency_samples = 1 + ((step < 1.0) ? 0 : s32(step)); + if (latency_samples <= m_max_latency) + latency_samples = m_max_latency; else - basesample = -(-basetime / input_stream.m_attoseconds_per_sample) - 1; - - // compute a source pointer to the first sample - assert(basesample >= input_stream.m_output_base_sampindex); - stream_sample_t *source = &output.m_buffer[basesample - input_stream.m_output_base_sampindex]; + m_max_latency = latency_samples; + attotime latency = latency_samples * input.sample_period(); - // determine the current fraction of a sample, expressed as a fraction of FRAC_ONE - // (Note: this formula is valid as long as input_stream.m_attoseconds_per_sample significantly exceeds FRAC_ONE > attoseconds = 4.2E-12 s) - u32 basefrac = (basetime - basesample * input_stream.m_attoseconds_per_sample) / ((input_stream.m_attoseconds_per_sample + FRAC_ONE - 1) >> FRAC_BITS); - assert(basefrac < FRAC_ONE); - - // compute the stepping fraction - u32 step = (u64(input_stream.m_sample_rate) << FRAC_BITS) / m_sample_rate; - - // if we have equal sample rates, we just need to copy - if (step == FRAC_ONE) + // clamp the latency to the start (only relevant at the beginning) + s32 dstindex = 0; + attotime output_start = output.start_time(); + while (latency > output_start && dstindex < numsamples) { - while (numsamples--) - { - // compute the sample - s64 sample = *source++; - *dest++ = (sample * gain) >> 8; - } + output.put(dstindex++, 0); + output_start += output.sample_period(); } + if (dstindex >= numsamples) + return; + + // create a rebased input buffer around the adjusted start time + read_stream_view rebased(input, output_start - latency); + sound_assert(rebased.start_time() + latency <= output_start); + + // compute the fractional input start position + attotime delta = output_start - (rebased.start_time() + latency); + sound_assert(delta.seconds() == 0); + stream_buffer::sample_t srcpos = stream_buffer::sample_t(double(delta.attoseconds()) / double(rebased.sample_period_attoseconds())); + sound_assert(srcpos <= 1.0f); // input is undersampled: point sample except where our sample period covers a boundary - else if (step < FRAC_ONE) + s32 srcindex = 0; + if (step < 1.0) { - while (numsamples != 0) + stream_buffer::sample_t cursample = rebased.get(srcindex++); + for ( ; dstindex < numsamples; dstindex++) { - // fill in with point samples until we hit a boundary - int nextfrac; - while ((nextfrac = basefrac + step) < FRAC_ONE && numsamples--) + // if still within the current sample, just replicate + if (srcpos <= 1.0) + output.put(dstindex, cursample); + + // if crossing a sample boundary, blend with the neighbor + else { - *dest++ = (source[0] * gain) >> 8; - basefrac = nextfrac; + srcpos -= 1.0; + sound_assert(srcpos <= step + 1e-5); + stream_buffer::sample_t prevsample = cursample; + cursample = rebased.get(srcindex++); + output.put(dstindex, stepinv * (prevsample * (step - srcpos) + srcpos * cursample)); } - - // if we're done, we're done - if (s32(numsamples--) < 0) - break; - - // compute starting and ending fractional positions - int startfrac = basefrac >> (FRAC_BITS - 12); - int endfrac = nextfrac >> (FRAC_BITS - 12); - - // blend between the two samples accordingly - s64 sample = (s64(source[0]) * (0x1000 - startfrac) + s64(source[1]) * (endfrac - 0x1000)) / (endfrac - startfrac); - *dest++ = (sample * gain) >> 8; - - // advance - basefrac = nextfrac & FRAC_MASK; - source++; + srcpos += step; } + sound_assert(srcindex <= rebased.samples()); } // input is oversampled: sum the energy else { - // use 8 bits to allow some extra headroom - int smallstep = step >> (FRAC_BITS - 8); - while (numsamples--) + float cursample = rebased.get(srcindex++); + for ( ; dstindex < numsamples; dstindex++) { - s64 remainder = smallstep; - int tpos = 0; - - // compute the sample - s64 scale = (FRAC_ONE - basefrac) >> (FRAC_BITS - 8); - s64 sample = s64(source[tpos++]) * scale; - remainder -= scale; - while (remainder > 0x100) + // compute the partial first sample and advance + stream_buffer::sample_t scale = 1.0 - srcpos; + stream_buffer::sample_t sample = cursample * scale; + + // add in complete samples until we only have a fraction left + stream_buffer::sample_t remaining = step - scale; + while (remaining >= 1.0) { - sample += s64(source[tpos++]) * s64(0x100); - remainder -= 0x100; + sample += rebased.get(srcindex++); + remaining -= 1.0; } - sample += s64(source[tpos]) * remainder; - sample /= smallstep; - *dest++ = (sample * gain) >> 8; + // add in the final partial sample + cursample = rebased.get(srcindex++); + sample += cursample * remaining; + output.put(dstindex, sample * stepinv); - // advance - basefrac += step; - source += basefrac >> FRAC_BITS; - basefrac &= FRAC_MASK; + // our position is now the remainder + srcpos = remaining; + sound_assert(srcindex <= rebased.samples()); } } - - return &input.m_resample[0]; -} - - - -//************************************************************************** -// STREAM INPUT -//************************************************************************** - -//------------------------------------------------- -// stream_input - constructor -//------------------------------------------------- - -sound_stream::stream_input::stream_input() - : m_source(nullptr), - m_latency_attoseconds(0), - m_gain(0x100), - m_user_gain(0x100) -{ -} - - - -//************************************************************************** -// STREAM OUTPUT -//************************************************************************** - -//------------------------------------------------- -// stream_output - constructor -//------------------------------------------------- - -sound_stream::stream_output::stream_output() - : m_stream(nullptr), - m_dependents(0), - m_gain(0x100) -{ } @@ -831,20 +1113,24 @@ sound_stream::stream_output::stream_output() // sound_manager - constructor //------------------------------------------------- -sound_manager::sound_manager(running_machine &machine) - : m_machine(machine), - m_update_timer(nullptr), - m_finalmix_leftover(0), - m_finalmix(machine.sample_rate()), - m_leftmix(machine.sample_rate()), - m_rightmix(machine.sample_rate()), - m_samples_this_update(0), - m_muted(0), - m_attenuation(0), - m_nosound_mode(machine.osd().no_sound()), - m_wavfile(nullptr), - m_update_attoseconds(STREAMS_UPDATE_ATTOTIME.attoseconds()), - m_last_update(attotime::zero) +sound_manager::sound_manager(running_machine &machine) : + m_machine(machine), + m_update_timer(nullptr), + m_update_number(0), + m_last_update(attotime::zero), + m_finalmix_leftover(0), + m_samples_this_update(0), + m_finalmix(machine.sample_rate()), + m_leftmix(machine.sample_rate()), + m_rightmix(machine.sample_rate()), + m_compressor_scale(1.0), + m_compressor_counter(0), + m_muted(0), + m_nosound_mode(machine.osd().no_sound()), + m_attenuation(0), + m_unique_id(0), + m_wavfile(nullptr), + m_first_reset(true) { // get filename for WAV file or AVI file if specified const char *wavfile = machine.options().wav_write(); @@ -888,6 +1174,41 @@ sound_manager::~sound_manager() } +//------------------------------------------------- +// stream_alloc_legacy - allocate a new stream +//------------------------------------------------- + +sound_stream *sound_manager::stream_alloc_legacy(device_t &device, u32 inputs, u32 outputs, u32 sample_rate, stream_update_legacy_delegate callback) +{ + // determine output base + u32 output_base = 0; + for (auto &stream : m_stream_list) + if (&stream->device() == &device) + output_base += stream->output_count(); + + m_stream_list.push_back(std::make_unique(device, inputs, outputs, output_base, sample_rate, callback)); + return m_stream_list.back().get(); +} + + +//------------------------------------------------- +// stream_alloc - allocate a new stream with the +// new-style callback and flags +//------------------------------------------------- + +sound_stream *sound_manager::stream_alloc(device_t &device, u32 inputs, u32 outputs, u32 sample_rate, stream_update_delegate callback, sound_stream_flags flags) +{ + // determine output base + u32 output_base = 0; + for (auto &stream : m_stream_list) + if (&stream->device() == &device) + output_base += stream->output_count(); + + m_stream_list.push_back(std::make_unique(device, inputs, outputs, output_base, sample_rate, callback, flags)); + return m_stream_list.back().get(); +} + + //------------------------------------------------- // start_recording - begin audio recording //------------------------------------------------- @@ -914,24 +1235,14 @@ void sound_manager::stop_recording() } -//------------------------------------------------- -// stream_alloc - allocate a new stream -//------------------------------------------------- - -sound_stream *sound_manager::stream_alloc(device_t &device, int inputs, int outputs, int sample_rate, stream_update_delegate callback) -{ - m_stream_list.push_back(std::make_unique(device, inputs, outputs, sample_rate, callback)); - return m_stream_list.back().get(); -} - - //------------------------------------------------- // set_attenuation - set the global volume //------------------------------------------------- -void sound_manager::set_attenuation(int attenuation) +void sound_manager::set_attenuation(float attenuation) { - m_attenuation = attenuation; + // currently OSD only supports integral attenuation + m_attenuation = int(attenuation); machine().osd().set_mastervolume(m_muted ? -32 : m_attenuation); } @@ -951,7 +1262,7 @@ bool sound_manager::indexed_mixer_input(int index, mixer_input &info) const { info.mixer = &mixer; info.stream = mixer.input_to_stream_input(index, info.inputnum); - assert(info.stream != nullptr); + sound_assert(info.stream != nullptr); return true; } index -= mixer.inputs(); @@ -963,6 +1274,19 @@ bool sound_manager::indexed_mixer_input(int index, mixer_input &info) const } +//------------------------------------------------- +// samples - fills the specified buffer with +// 16-bit stereo audio samples generated during +// the current frame +//------------------------------------------------- + +void sound_manager::samples(s16 *buffer) +{ + for (int sample = 0; sample < m_samples_this_update * 2; sample++) + *buffer++ = m_finalmix[sample]; +} + + //------------------------------------------------- // mute - mute sound output //------------------------------------------------- @@ -977,6 +1301,47 @@ void sound_manager::mute(bool mute, u8 reason) } +//------------------------------------------------- +// recursive_remove_stream_from_orphan_list - +// remove the given stream from the orphan list +// and recursively remove all our inputs +//------------------------------------------------- + +void sound_manager::recursive_remove_stream_from_orphan_list(sound_stream *which) +{ + m_orphan_stream_list.erase(which); + for (int inputnum = 0; inputnum < which->input_count(); inputnum++) + { + auto &input = which->input(inputnum); + if (input.valid()) + recursive_remove_stream_from_orphan_list(&input.source().stream()); + } +} + + +//------------------------------------------------- +// apply_sample_rate_changes - recursively +// update sample rates throughout the system +//------------------------------------------------- + +void sound_manager::apply_sample_rate_changes() +{ + // update sample rates if they have changed + for (speaker_device &speaker : speaker_device_iterator(machine().root_device())) + { + int stream_out; + sound_stream *stream = speaker.output_to_stream_output(0, stream_out); + + // due to device removal, some speakers may end up with no outputs; just skip those + if (stream != nullptr) + { + sound_assert(speaker.outputs() == 1); + stream->apply_sample_rate_changes(m_update_number, machine().sample_rate()); + } + } +} + + //------------------------------------------------- // reset - reset all sound chips //------------------------------------------------- @@ -986,6 +1351,47 @@ void sound_manager::reset() // reset all the sound chips for (device_sound_interface &sound : sound_interface_iterator(machine().root_device())) sound.device().reset(); + + // apply any sample rate changes now + apply_sample_rate_changes(); + + // on first reset, identify any orphaned streams + if (m_first_reset) + { + m_first_reset = false; + + // put all the streams on the orphan list to start + for (auto &stream : m_stream_list) + m_orphan_stream_list[stream.get()] = 0; + + // then walk the graph like we do on update and remove any we touch + for (speaker_device &speaker : speaker_device_iterator(machine().root_device())) + { + int dummy; + sound_stream *output = speaker.output_to_stream_output(0, dummy); + if (output != nullptr) + recursive_remove_stream_from_orphan_list(output); + } + +#if (SOUND_DEBUG) + // dump the sound graph when we start up + for (speaker_device &speaker : speaker_device_iterator(machine().root_device())) + { + int dummy; + sound_stream *output = speaker.output_to_stream_output(0, dummy); + if (output) + output->print_graph_recursive(0); + } + + // dump the orphan list as well + if (m_orphan_stream_list.size() != 0) + { + osd_printf_info("\nOrphaned streams:\n"); + for (auto &stream : m_orphan_stream_list) + osd_printf_info(" %s\n", stream.first->name()); + } +#endif + } } @@ -1033,7 +1439,7 @@ void sound_manager::config_load(config_type cfg_type, util::xml::data_node const float defvol = channelnode->get_attribute_float("defvol", 1.0f); float newvol = channelnode->get_attribute_float("newvol", -1000.0f); if (newvol != -1000.0f) - info.stream->set_user_gain(info.inputnum, newvol / defvol); + info.stream->input(info.inputnum).set_user_gain(newvol / defvol); } } } @@ -1057,7 +1463,7 @@ void sound_manager::config_save(config_type cfg_type, util::xml::data_node *pare mixer_input info; if (!indexed_mixer_input(mixernum, info)) break; - float newvol = info.stream->user_gain(info.inputnum); + float newvol = info.stream->input(info.inputnum).user_gain(); if (newvol != 1.0f) { @@ -1072,6 +1478,45 @@ void sound_manager::config_save(config_type cfg_type, util::xml::data_node *pare } +//------------------------------------------------- +// adjust_toward_compressor_scale - adjust the +// current scale factor toward the current goal, +// in small increments +//------------------------------------------------- + +stream_buffer::sample_t sound_manager::adjust_toward_compressor_scale(stream_buffer::sample_t curscale, stream_buffer::sample_t prevsample, stream_buffer::sample_t rawsample) +{ + stream_buffer::sample_t proposed_scale = curscale; + + // if we want to get larger, increment by 0.01 + if (curscale < m_compressor_scale) + { + proposed_scale += 0.01f; + if (proposed_scale > m_compressor_scale) + proposed_scale = m_compressor_scale; + } + + // otherwise, decrement by 0.01 + else + { + proposed_scale -= 0.01f; + if (proposed_scale < m_compressor_scale) + proposed_scale = m_compressor_scale; + } + + // compute the sample at the current scale and at the proposed scale + stream_buffer::sample_t cursample = rawsample * curscale; + stream_buffer::sample_t proposed_sample = rawsample * proposed_scale; + + // if they trend in the same direction, it's ok to take the step + if ((cursample < prevsample && proposed_sample < prevsample) || (cursample > prevsample && proposed_sample > prevsample)) + curscale = proposed_scale; + + // return the current scale + return curscale; +} + + //------------------------------------------------- // update - mix everything down to its final form // and send it to the OSD layer @@ -1088,6 +1533,54 @@ void sound_manager::update(void *ptr, int param) for (speaker_device &speaker : speaker_device_iterator(machine().root_device())) speaker.mix(&m_leftmix[0], &m_rightmix[0], m_samples_this_update, (m_muted & MUTE_REASON_SYSTEM)); + // determine the maximum in this section + stream_buffer::sample_t curmax = 0; + for (int sampindex = 0; sampindex < m_samples_this_update; sampindex++) + { + auto sample = m_leftmix[sampindex]; + if (sample < 0) + sample = -sample; + if (sample > curmax) + curmax = sample; + + sample = m_rightmix[sampindex]; + if (sample < 0) + sample = -sample; + if (sample > curmax) + curmax = sample; + } + + // pull in current compressor scale factor before modifying + stream_buffer::sample_t lscale = m_compressor_scale; + stream_buffer::sample_t rscale = m_compressor_scale; + + // if we're above what the compressor will handle, adjust the compression + if (curmax * m_compressor_scale > 1.0) + { + m_compressor_scale = 1.0 / curmax; + m_compressor_counter = STREAMS_UPDATE_FREQUENCY / 5; + } + + // if we're currently scaled, wait a bit to see if we can trend back toward 1.0 + else if (m_compressor_counter != 0) + m_compressor_counter--; + + // try to migrate toward 0 unless we're going to introduce clipping + else if (m_compressor_scale < 1.0 && curmax * 1.01 * m_compressor_scale < 1.0) + { + m_compressor_scale *= 1.01f; + if (m_compressor_scale > 1.0) + m_compressor_scale = 1.0; + } + +#if (SOUND_DEBUG) + if (lscale != m_compressor_scale) + printf("scale=%.5f\n", m_compressor_scale); +#endif + + // track whether there are pending scale changes in left/right + stream_buffer::sample_t lprev = 0, rprev = 0; + // now downmix the final result u32 finalmix_step = machine().video().speed_factor(); u32 finalmix_offset = 0; @@ -1097,21 +1590,31 @@ void sound_manager::update(void *ptr, int param) { int sampindex = sample / 1000; + // ensure that changing the compression won't reverse direction to reduce "pops" + stream_buffer::sample_t lsamp = m_leftmix[sampindex]; + if (lscale != m_compressor_scale && sample != m_finalmix_leftover) + lscale = adjust_toward_compressor_scale(lscale, lprev, lsamp); + + // clamp the left side + lprev = lsamp *= lscale; + if (lsamp > 1.0) + lsamp = 1.0; + else if (lsamp < -1.0) + lsamp = -1.0; + finalmix[finalmix_offset++] = s16(lsamp * 32767.0); + + // ensure that changing the compression won't reverse direction to reduce "pops" + stream_buffer::sample_t rsamp = m_rightmix[sampindex]; + if (rscale != m_compressor_scale && sample != m_finalmix_leftover) + rscale = adjust_toward_compressor_scale(rscale, rprev, rsamp); + // clamp the left side - s32 samp = m_leftmix[sampindex]; - if (samp < -32768) - samp = -32768; - else if (samp > 32767) - samp = 32767; - finalmix[finalmix_offset++] = samp; - - // clamp the right side - samp = m_rightmix[sampindex]; - if (samp < -32768) - samp = -32768; - else if (samp > 32767) - samp = 32767; - finalmix[finalmix_offset++] = samp; + rprev = rsamp *= rscale; + if (rsamp > 1.0) + rsamp = 1.0; + else if (rsamp < -1.0) + rsamp = -1.0; + finalmix[finalmix_offset++] = s16(rsamp * 32767.0); } m_finalmix_leftover = sample - m_samples_this_update * 1000; @@ -1126,43 +1629,24 @@ void sound_manager::update(void *ptr, int param) wav_add_data_16(m_wavfile, finalmix, finalmix_offset); } + // update any orphaned streams so they don't get too far behind + for (auto &stream : m_orphan_stream_list) + stream.first->update(); + // see if we ticked over to the next second attotime curtime = machine().time(); - bool second_tick = false; if (curtime.seconds() != m_last_update.seconds()) - { - assert(curtime.seconds() == m_last_update.seconds() + 1); - second_tick = true; - } - - // iterate over all the streams and update them - for (auto &stream : m_stream_list) - stream->update_with_accounting(second_tick); + sound_assert(curtime.seconds() == m_last_update.seconds() + 1); // remember the update time m_last_update = curtime; + m_update_number++; - // update sample rates if they have changed - for (auto &stream : m_stream_list) - stream->apply_sample_rate_changes(); + // apply sample rate changes + apply_sample_rate_changes(); // notify that new samples have been generated emulator_info::sound_hook(); g_profiler.stop(); } - - -//------------------------------------------------- -// samples - fills the specified buffer with -// 16-bit stereo audio samples generated during -// the current frame -//------------------------------------------------- - -void sound_manager::samples(s16 *buffer) -{ - for (int sample = 0; sample < m_samples_this_update * 2; sample++) - { - *buffer++ = m_finalmix[sample]; - } -} diff --git a/src/emu/sound.h b/src/emu/sound.h index 7301a4d69ba..f7d83093ea6 100644 --- a/src/emu/sound.h +++ b/src/emu/sound.h @@ -6,6 +6,50 @@ Core sound interface functions and definitions. +**************************************************************************** + + In MAME, sound is represented as a graph of sound "streams". Each + stream has a fixed number of inputs and outputs, and is responsible + for producing sound on demand. + + The graph is driven from the outputs, which are speaker devices. + These devices are updated on a regular basis (~50 times per second), + and when an update occurs, the graph is walked from the speaker + through each input, until all connected streams are up to date. + + Individual streams can also be updated manually. This is important + for sound chips and CPU-driven devices, who should force any + affected streams to update prior to making changes. + + Sound streams are *not* part of the device execution model. This is + very important to understand. If the process of producing the ouput + stream affects state that might be consumed by an executing device + (e.g., a CPU), then care must be taken to ensure that the stream is + updated frequently enough + + The model for timing sound samples is very important and explained + here. Each stream source has a clock (aka sample rate). Each clock + edge represents a sample that is held for the duration of one clock + period. This model has interesting effects: + + For example, if you have a 10Hz clock, and call stream.update() at + t=0.91, it will compute 10 samples (for clock edges 0.0, 0.1, 0.2, + ..., 0.7, 0.8, and 0.9). And then if you ask the stream what its + current end time is (via stream.sample_time()), it will say t=1.0, + which is in the future, because it knows it will hold that last + sample until 1.0s. + + Sound generation callbacks are presented with a std::vector of inputs + and outputs. The vectors contain objects of read_stream_view and + write_stream_view respectively, which wrap access to a circular buffer + of samples. Sound generation callbacks are expected to fill all the + samples described by the outputs' write_stream_view objects. At the + moment, all outputs have the same sample rate, so the number of samples + that need to be generated will be consistent across all outputs. + + By default, the inputs will have been resampled to match the output + sample rate, unless otherwise specified. + ***************************************************************************/ #pragma once @@ -22,26 +66,498 @@ // CONSTANTS //************************************************************************** -constexpr int STREAM_SYNC = -1; // special rate value indicating a one-sample-at-a-time stream - // with actual rate defined by its input +// special sample-rate values +constexpr u32 SAMPLE_RATE_INVALID = 0xffffffff; +constexpr u32 SAMPLE_RATE_INPUT_ADAPTIVE = 0xfffffffe; +constexpr u32 SAMPLE_RATE_OUTPUT_ADAPTIVE = 0xfffffffd; + +// anything below this sample rate is effectively treated as "off" +constexpr u32 SAMPLE_RATE_MINIMUM = 50; + + //************************************************************************** -// MACROS +// DEBUGGING //************************************************************************** -typedef delegate stream_update_delegate; +// turn this on to enable aggressive assertions and other checks +#define SOUND_DEBUG (1) + +// if SOUND_DEBUG is on, make assertions fire regardless of MAME_DEBUG +#if (SOUND_DEBUG) +#define sound_assert(x) do { if (!(x)) { osd_printf_error("sound_assert: " #x "\n"); osd_break_into_debugger("sound_assert: " #x "\n"); } } while (0) +#else +#define sound_assert assert +#endif + + //************************************************************************** // TYPE DEFINITIONS //************************************************************************** +// ======================> stream_buffer -// structure describing an indexed mixer -struct mixer_input +class stream_buffer { - device_mixer_interface *mixer; // owning device interface - sound_stream * stream; // stream within the device - int inputnum; // input on the stream + // stream_buffer is an internal class, not directly accessed + // outside of the classes below + friend class read_stream_view; + friend class write_stream_view; + friend class sound_stream; + friend class sound_stream_output; + +public: + // the one public bit is the sample type + using sample_t = float; + +private: + // constructor/destructor + stream_buffer(u32 sample_rate = 48000); + ~stream_buffer(); + + // disable copying of stream_buffers directly + stream_buffer(stream_buffer const &src) = delete; + stream_buffer &operator=(stream_buffer const &rhs) = delete; + + // return the current sample rate + u32 sample_rate() const { return m_sample_rate; } + + // set a new sample rate + void set_sample_rate(u32 rate, bool resample); + + // return the current sample period in attoseconds + attoseconds_t sample_period_attoseconds() const { return m_sample_attos; } + attotime sample_period() const { return attotime(0, m_sample_attos); } + + // return the attotime of the current end of buffer + attotime end_time() const { return index_time(m_end_sample); } + + // set the ending time (for forced resyncs; generally not used) + void set_end_time(attotime time) + { + m_end_second = time.seconds(); + m_end_sample = u32(time.attoseconds() / m_sample_attos); + } + + // return the effective buffer size; currently it is a full second of audio + // at the current sample rate, but this maybe change in the future + u32 size() const { return m_sample_rate; } + + // read the sample at the given index (clamped); should be valid in all cases + sample_t get(s32 index) const + { + sound_assert(u32(index) < size()); + sample_t value = m_buffer[index]; +#if (SOUND_DEBUG) + sound_assert(!std::isnan(value)); +#endif + return value; + } + + // write the sample at the given index (clamped) + void put(s32 index, sample_t data) + { + sound_assert(u32(index) < size()); + m_buffer[index] = data; + } + + // simple helpers to step indexes + u32 next_index(u32 index) { index++; return (index == size()) ? 0 : index; } + u32 prev_index(u32 index) { return (index == 0) ? (size() - 1) : (index - 1); } + + // clamp an index to the size of the buffer; allows for indexing +/- one + // buffers' worth of range + u32 clamp_index(s32 index) const + { + if (index < 0) + index += size(); + else if (index >= size()) + index -= size(); + sound_assert(index >= 0 && index < size()); + return index; + } + + // fill the buffer with the given value + void fill(sample_t value) { std::fill_n(&m_buffer[0], m_buffer.size(), value); } + + // return the attotime of a given index within the buffer + attotime index_time(s32 index) const; + + // given an attotime, return the buffer index corresponding to it + u32 time_to_buffer_index(attotime time, bool round_up, bool allow_expansion = false); + + // downsample from our buffer into a temporary buffer + void backfill_downsample(sample_t *dest, int samples, attotime newend, attotime newperiod); + + // upsample from a temporary buffer into our buffer + void backfill_upsample(sample_t const *src, int samples, attotime prevend, attotime prevperiod); + + // internal state + u32 m_end_second; // current full second of the buffer end + u32 m_end_sample; // current sample number within the final second + u32 m_sample_rate; // sample rate of the data in the buffer + attoseconds_t m_sample_attos; // pre-computed attoseconds per sample + std::vector m_buffer; // vector of actual buffer data + +#if (SOUND_DEBUG) +public: + // for debugging, provide an interface to write a WAV stream + void open_wav(char const *filename); + void flush_wav(); + void close_wav(); + +private: + // internal debugging state + wav_file *m_wav_file = nullptr; // pointer to the current WAV file + u32 m_last_written = 0; // last written sample index +#endif +}; + + +// ======================> read_stream_view + +class read_stream_view +{ +public: + using sample_t = stream_buffer::sample_t; + +protected: + // private constructor used by write_stream_view that allows for expansion + read_stream_view(stream_buffer &buffer, attotime start, attotime end) : + read_stream_view(&buffer, 0, buffer.time_to_buffer_index(end, true, true), 1.0) + { + // start has to be set after end, since end can expand the buffer and + // potentially invalidate start + m_start = buffer.time_to_buffer_index(start, false); + normalize_start_end(); + } + +public: + // base constructor to simplify some of the code + read_stream_view(stream_buffer *buffer, s32 start, s32 end, sample_t gain) : + m_buffer(buffer), + m_end(end), + m_start(start), + m_gain(gain) + { + normalize_start_end(); + } + + // empty constructor so we can live in an array or vector + read_stream_view() : + read_stream_view(nullptr, 0, 0, 1.0) + { + } + + // constructor that covers the given time period + read_stream_view(stream_buffer &buffer, attotime start, attotime end, sample_t gain) : + read_stream_view(&buffer, buffer.time_to_buffer_index(start, false), buffer.time_to_buffer_index(end, true), gain) + { + } + + // copy constructor + read_stream_view(read_stream_view const &src) : + read_stream_view(src.m_buffer, src.m_start, src.m_end, src.m_gain) + { + } + + // copy constructor that sets a different start time + read_stream_view(read_stream_view const &src, attotime start) : + read_stream_view(src.m_buffer, src.m_buffer->time_to_buffer_index(start, false), src.m_end, src.m_gain) + { + } + + // copy assignment + read_stream_view &operator=(read_stream_view const &rhs) + { + m_buffer = rhs.m_buffer; + m_start = rhs.m_start; + m_end = rhs.m_end; + m_gain = rhs.m_gain; + normalize_start_end(); + return *this; + } + + // return the local gain + sample_t gain() const { return m_gain; } + + // return the sample rate of the data + u32 sample_rate() const { return m_buffer->sample_rate(); } + + // return the sample period (in attoseconds) of the data + attoseconds_t sample_period_attoseconds() const { return m_buffer->sample_period_attoseconds(); } + attotime sample_period() const { return m_buffer->sample_period(); } + + // return the number of samples represented by the buffer + u32 samples() const { return m_end - m_start; } + + // return the starting or ending time of the buffer + attotime start_time() const { return m_buffer->index_time(m_start); } + attotime end_time() const { return m_buffer->index_time(m_end); } + + // set the gain + read_stream_view &set_gain(float gain) { m_gain = gain; return *this; } + + // apply an additional gain factor + read_stream_view &apply_gain(float gain) { m_gain *= gain; return *this; } + + // safely fetch a gain-scaled sample from the buffer + sample_t get(s32 index) const + { + sound_assert(u32(index) < samples()); + index += m_start; + if (index >= m_buffer->size()) + index -= m_buffer->size(); + return m_buffer->get(index) * m_gain; + } + + // safely fetch a raw sample from the buffer; if you use this, you need to + // apply the gain yourself for correctness + sample_t getraw(s32 index) const + { + sound_assert(u32(index) < samples()); + index += m_start; + if (index >= m_buffer->size()) + index -= m_buffer->size(); + return m_buffer->get(index); + } + +protected: + // normalize start/end + void normalize_start_end() + { + // ensure that end is always greater than start; we'll + // wrap to the buffer length as needed + if (m_end < m_start && m_buffer != nullptr) + m_end += m_buffer->size(); + sound_assert(m_end >= m_start); + } + + // internal state + stream_buffer *m_buffer; // pointer to the stream buffer we're viewing + s32 m_end; // ending sample index (always >= start) + s32 m_start; // starting sample index + sample_t m_gain; // overall gain factor +}; + + +// ======================> write_stream_view + +class write_stream_view : public read_stream_view +{ +public: + // empty constructor so we can live in an array or vector + write_stream_view() + { + } + + // constructor that covers the given time period + write_stream_view(stream_buffer &buffer, attotime start, attotime end) : + read_stream_view(buffer, start, end) + { + } + + // constructor that converts from a read_stream_view + write_stream_view(read_stream_view &src) : + read_stream_view(src) + { + } + + // safely write a gain-applied sample to the buffer + void put(s32 index, sample_t sample) + { + sound_assert(u32(index) < samples()); + index += m_start; + if (index >= m_buffer->size()) + index -= m_buffer->size(); + m_buffer->put(index, sample); + } + + // safely add a gain-applied sample to the buffer + void add(s32 index, sample_t sample) + { + sound_assert(u32(index) < samples()); + index += m_start; + if (index >= m_buffer->size()) + index -= m_buffer->size(); + m_buffer->put(index, m_buffer->get(index) + sample); + } + + // fill part of the view with the given value + void fill(sample_t value, s32 start, s32 count) + { + if (start + count > samples()) + count = samples() - start; + u32 index = start + m_start; + for (s32 sampindex = 0; sampindex < count; sampindex++) + { + m_buffer->put(index, value); + index = m_buffer->next_index(index); + } + } + void fill(sample_t value, s32 start) { fill(value, start, samples() - start); } + void fill(sample_t value) { fill(value, 0, samples()); } + + // copy data from another view + void copy(read_stream_view const &src, s32 start, s32 count) + { + if (start + count > samples()) + count = samples() - start; + u32 index = start + m_start; + for (s32 sampindex = 0; sampindex < count; sampindex++) + { + m_buffer->put(index, src.get(start + sampindex)); + index = m_buffer->next_index(index); + } + } + void copy(read_stream_view const &src, s32 start) { copy(src, start, samples() - start); } + void copy(read_stream_view const &src) { copy(src, 0, samples()); } + + // add data from another view to our current values + void add(read_stream_view const &src, s32 start, s32 count) + { + if (start + count > samples()) + count = samples() - start; + u32 index = start + m_start; + for (s32 sampindex = 0; sampindex < count; sampindex++) + { + m_buffer->put(index, m_buffer->get(index) + src.get(start + sampindex)); + index = m_buffer->next_index(index); + } + } + void add(read_stream_view const &src, s32 start) { add(src, start, samples() - start); } + void add(read_stream_view const &src) { add(src, 0, samples()); } +}; + + +// ======================> sound_stream_output + +class sound_stream_output +{ +#if (SOUND_DEBUG) + friend class sound_stream; +#endif + +public: + // construction/destruction + sound_stream_output(); + + // initialization + void init(sound_stream &stream, u32 index, char const *tag_base); + + // no copying allowed + sound_stream_output(sound_stream_output const &src) = delete; + sound_stream_output &operator=(sound_stream_output const &rhs) = delete; + + // simple getters + sound_stream &stream() const { sound_assert(m_stream != nullptr); return *m_stream; } + attotime end_time() const { return m_buffer.end_time(); } + u32 index() const { return m_index; } + stream_buffer::sample_t gain() const { return m_gain; } + + // simple setters + void set_gain(float gain) { m_gain = gain; } + + // return a friendly name + std::string name() const; + + // handle a changing sample rate + void sample_rate_changed(u32 rate) { m_buffer.set_sample_rate(rate, true); } + + // return an output view covering a time period + write_stream_view view(attotime start, attotime end) { return write_stream_view(m_buffer, start, end); } + + // resync the buffer to the given end time + void set_end_time(attotime end) { m_buffer.set_end_time(end); } + +private: + // internal state + sound_stream *m_stream; // owning stream + stream_buffer m_buffer; // output buffer + u32 m_index; // output index within the stream + stream_buffer::sample_t m_gain; // gain to apply to the output +}; + + +// ======================> sound_stream_input + +class sound_stream_input +{ +#if (SOUND_DEBUG) + friend class sound_stream; +#endif + +public: + // construction/destruction + sound_stream_input(); + + // initialization + void init(sound_stream &stream, u32 index, char const *tag_base, sound_stream_output *resampler); + + // no copying allowed + sound_stream_input(sound_stream_input const &src) = delete; + sound_stream_input &operator=(sound_stream_input const &rhs) = delete; + + // simple getters + bool valid() const { return (m_native_source != nullptr); } + sound_stream &owner() const { sound_assert(valid()); return *m_owner; } + sound_stream_output &source() const { sound_assert(valid()); return *m_native_source; } + u32 index() const { return m_index; } + stream_buffer::sample_t gain() const { return m_gain; } + stream_buffer::sample_t user_gain() const { return m_user_gain; } + + // simple setters + void set_gain(float gain) { m_gain = gain; } + void set_user_gain(float gain) { m_user_gain = gain; } + + // return a friendly name + std::string name() const; + + // connect the source + void set_source(sound_stream_output *source); + + // update and return an reading view + read_stream_view update(attotime start, attotime end); + + // tell inputs to apply sample rate changes + void apply_sample_rate_changes(u32 updatenum, u32 downstream_rate); + +private: + // internal state + sound_stream *m_owner; // pointer to the owning stream + sound_stream_output *m_native_source; // pointer to the native sound_stream_output + sound_stream_output *m_resampler_source; // pointer to the resampler output + u32 m_index; // input index within the stream + stream_buffer::sample_t m_gain; // gain to apply to this input + stream_buffer::sample_t m_user_gain; // user-controlled gain to apply to this input +}; + + +// ======================> stream_update_legacy_delegate/stream_update_delegate + +// old-style callback; eventually should be deprecated +using stream_update_legacy_delegate = delegate; + +// new-style callback +using stream_update_delegate = delegate const &inputs, std::vector &outputs)>; + + +// ======================> sound_stream_flags + +enum sound_stream_flags : u32 +{ + // default is no special flags + STREAM_DEFAULT_FLAGS = 0x00, + + // specify that updates should be forced to one sample at a time, in real time + // this implicitly creates a timer that runs at the stream's output frequency + // so only use when strictly necessary + STREAM_SYNCHRONOUS = 0x01, + + // specify that input streams should not be resampled; stream update handler + // must be able to accommodate multiple strams of differing input rates + STREAM_DISABLE_INPUT_RESAMPLING = 0x02 }; @@ -51,127 +567,141 @@ class sound_stream { friend class sound_manager; - typedef void (*stream_update_func)(device_t *device, sound_stream *stream, void *param, stream_sample_t **inputs, stream_sample_t **outputs, int samples); - - // stream output class - class stream_output - { - public: - // construction/destruction - stream_output(); - stream_output &operator=(const stream_output &rhs) { assert(false); return *this; } - - // internal state - sound_stream * m_stream; // owning stream - std::vector m_buffer; // output buffer - int m_dependents; // number of dependents - s16 m_gain; // gain to apply to the output - }; - - // stream input class - class stream_input - { - public: - // construction/destruction - stream_input(); - stream_input &operator=(const stream_input &rhs) { assert(false); return *this; } - - // internal state - stream_output * m_source; // pointer to the sound_output for this source - std::vector m_resample; // buffer for resampling to the stream's sample rate - attoseconds_t m_latency_attoseconds; // latency between this stream and the input stream - s16 m_gain; // gain to apply to this input - s16 m_user_gain; // user-controlled gain to apply to this input - }; - - // constants - static constexpr int OUTPUT_BUFFER_UPDATES = 5; - static constexpr u32 FRAC_BITS = 22; - static constexpr u32 FRAC_ONE = 1 << FRAC_BITS; - static constexpr u32 FRAC_MASK = FRAC_ONE - 1; + // private common constructopr + sound_stream(device_t &device, u32 inputs, u32 outputs, u32 output_base, u32 sample_rate, sound_stream_flags flags); public: // construction/destruction - sound_stream(device_t &device, int inputs, int outputs, int sample_rate, stream_update_delegate callback); + sound_stream(device_t &device, u32 inputs, u32 outputs, u32 output_base, u32 sample_rate, stream_update_legacy_delegate callback, sound_stream_flags flags = STREAM_DEFAULT_FLAGS); + sound_stream(device_t &device, u32 inputs, u32 outputs, u32 output_base, u32 sample_rate, stream_update_delegate callback, sound_stream_flags flags = STREAM_DEFAULT_FLAGS); + virtual ~sound_stream(); - // getters + // simple getters sound_stream *next() const { return m_next; } device_t &device() const { return m_device; } - int sample_rate() const { return (m_new_sample_rate != 0xffffffff) ? m_new_sample_rate : m_sample_rate; } - attotime sample_time() const; - attotime sample_period() const { return attotime(0, m_attoseconds_per_sample); } - int input_count() const { return m_input.size(); } - int output_count() const { return m_output.size(); } - std::string input_name(int inputnum) const; - device_t *input_source_device(int inputnum) const; - int input_source_outputnum(int inputnum) const; - float user_gain(int inputnum) const; - float input_gain(int inputnum) const; - float output_gain(int outputnum) const; - - // operations + std::string name() const { return m_name; } + bool synchronous() const { return m_synchronous; } + bool input_adaptive() const { return m_input_adaptive || m_synchronous; } + bool output_adaptive() const { return m_output_adaptive; } + + // input and output getters + u32 input_count() const { return m_input.size(); } + u32 output_count() const { return m_output.size(); } + u32 output_base() const { return m_output_base; } + sound_stream_input &input(int index) { sound_assert(index >= 0 && index < m_input.size()); return m_input[index]; } + sound_stream_output &output(int index) { sound_assert(index >= 0 && index < m_output.size()); return m_output[index]; } + + // sample rate and timing getters + u32 sample_rate() const { return (m_pending_sample_rate != SAMPLE_RATE_INVALID) ? m_pending_sample_rate : m_sample_rate; } + attotime sample_time() const { return m_output[0].end_time(); } + attotime sample_period() const { return attotime(0, sample_period_attoseconds()); } + attoseconds_t sample_period_attoseconds() const { return (m_sample_rate != SAMPLE_RATE_INVALID) ? HZ_TO_ATTOSECONDS(m_sample_rate) : ATTOSECONDS_PER_SECOND; } + + // set the sample rate of the stream; will kick in at the next global update + void set_sample_rate(u32 sample_rate); + + // connect the output 'outputnum' of given input_stream to this stream's input 'inputnum' void set_input(int inputnum, sound_stream *input_stream, int outputnum = 0, float gain = 1.0f); + + // force an update to the current time void update(); - const stream_sample_t *output_since_last_update(int outputnum, int &numsamples); - // timing - void set_sample_rate(int sample_rate); - void set_user_gain(int inputnum, float gain); - void set_input_gain(int inputnum, float gain); - void set_output_gain(int outputnum, float gain); + // force an update to the current time, returning a view covering the given time period + read_stream_view update_view(attotime start, attotime end, u32 outputnum = 0); + + // apply any pending sample rate changes; should only be called by the sound manager + void apply_sample_rate_changes(u32 updatenum, u32 downstream_rate); + +#if (SOUND_DEBUG) + // print one level of the sound graph and recursively tell our inputs to do the same + void print_graph_recursive(int indent); +#endif + +protected: + // protected state + std::string m_name; // name of this stream private: - // helpers called by our friends only - void update_with_accounting(bool second_tick); - void apply_sample_rate_changes(); + // perform most of the initialization here + void init_common(u32 inputs, u32 outputs, u32 sample_rate, sound_stream_flags flags); + + // if the sample rate has changed, this gets called to update internals + void sample_rate_changed(); - // internal helpers - void recompute_sample_rate_data(); - void allocate_resample_buffers(); - void allocate_output_buffers(); + // handle updates after a save state load void postload(); - void generate_samples(int samples); - stream_sample_t *generate_resampled_data(stream_input &input, u32 numsamples); + + // re-print the synchronization timer + void reprime_sync_timer(); + + // timer callback for synchronous streams void sync_update(void *, s32); + // new callback which wrapps calls through to the old-style callbacks + void stream_update_legacy(sound_stream &stream, std::vector const &inputs, std::vector &outputs); + + // return a view of 0 data covering the given time period + read_stream_view empty_view(attotime start, attotime end); + // linking information - device_t & m_device; // owning device - sound_stream * m_next; // next stream in the chain + device_t &m_device; // owning device + sound_stream *m_next; // next stream in the chain // general information - u32 m_sample_rate; // sample rate of this stream - u32 m_new_sample_rate; // newly-set sample rate for the stream - bool m_synchronous; // synchronous stream that runs at the rate of its input - - // timing information - attoseconds_t m_attoseconds_per_sample; // number of attoseconds per sample - s32 m_max_samples_per_update; // maximum samples per update - emu_timer * m_sync_timer; // update timer for synchronous streams + u32 m_sample_rate; // current live sample rate + u32 m_pending_sample_rate; // pending sample rate for dynamic changes + u32 m_last_sample_rate_update; // update number of last sample rate change + bool m_input_adaptive; // adaptive stream that runs at the sample rate of its input + bool m_output_adaptive; // adaptive stream that runs at the sample rate of its output + bool m_synchronous; // synchronous stream that runs at the rate of its input + emu_timer *m_sync_timer; // update timer for synchronous streams // input information - std::vector m_input; // list of streams we directly depend upon - std::vector m_input_array; // array of inputs for passing to the callback - - // resample buffer information - u32 m_resample_bufalloc; // allocated size of each resample buffer + std::vector m_input; // list of streams we directly depend upon + std::vector m_input_array; // array of inputs for passing to the callback + std::vector m_input_view; // array of output views for passing to the callback + std::vector> m_resampler_list; // internal list of resamplers + stream_buffer m_empty_buffer; // empty buffer for invalid inputs // output information - std::vector m_output; // list of streams which directly depend upon us - std::vector m_output_array; // array of outputs for passing to the callback - - // output buffer information - u32 m_output_bufalloc; // allocated size of each output buffer - s32 m_output_sampindex; // current position within each output buffer - s32 m_output_update_sampindex; // position at time of last global update - s32 m_output_base_sampindex; // sample at base of buffer, relative to the current emulated second + u32 m_output_base; // base index of our outputs, relative to our device + std::vector m_output; // list of streams which directly depend upon us + std::vector m_output_array; // array of outputs for passing to the callback + std::vector m_output_view; // array of output views for passing to the callback // callback information - stream_update_delegate m_callback; // callback function + stream_update_legacy_delegate m_callback; // callback function + stream_update_delegate m_callback_ex; // extended callback function +}; + + +// ======================> default_resampler_stream + +class default_resampler_stream : public sound_stream +{ +public: + // construction/destruction + default_resampler_stream(device_t &device); + + // update handler + void resampler_sound_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs); + +private: + // internal state + u32 m_max_latency; }; // ======================> sound_manager +// structure describing an indexed mixer +struct mixer_input +{ + device_mixer_interface *mixer; // owning device interface + sound_stream * stream; // stream within the device + int inputnum; // input on the stream +}; + class sound_manager { friend class sound_stream; @@ -197,56 +727,88 @@ public: int attenuation() const { return m_attenuation; } const std::vector> &streams() const { return m_stream_list; } attotime last_update() const { return m_last_update; } - attoseconds_t update_attoseconds() const { return m_update_attoseconds; } int sample_count() const { return m_samples_this_update; } - void samples(s16 *buffer); + int unique_id() { return m_unique_id++; } + + // allocate a new stream with the old-style callback + sound_stream *stream_alloc_legacy(device_t &device, u32 inputs, u32 outputs, u32 sample_rate, stream_update_legacy_delegate callback); - // stream creation - sound_stream *stream_alloc(device_t &device, int inputs, int outputs, int sample_rate, stream_update_delegate callback = stream_update_delegate()); + // allocate a new stream with a new-style callback + sound_stream *stream_alloc(device_t &device, u32 inputs, u32 outputs, u32 sample_rate, stream_update_delegate callback, sound_stream_flags flags); - // global controls + // begin recording a WAV file if options has requested it void start_recording(); + + // stop recording the WAV file void stop_recording(); - void set_attenuation(int attenuation); + + // set the global OSD attenuation level + void set_attenuation(float attenuation); + + // mute sound for one of various independent reasons void ui_mute(bool turn_off = true) { mute(turn_off, MUTE_REASON_UI); } void debugger_mute(bool turn_off = true) { mute(turn_off, MUTE_REASON_DEBUGGER); } void system_mute(bool turn_off = true) { mute(turn_off, MUTE_REASON_SYSTEM); } void system_enable(bool turn_on = true) { mute(!turn_on, MUTE_REASON_SYSTEM); } - // user gain controls + // return information about the given mixer input, by index bool indexed_mixer_input(int index, mixer_input &info) const; + // fill the given buffer with 16-bit stereo audio samples + void samples(s16 *buffer); + private: - // internal helpers + // set/reset the mute state for the given reason void mute(bool mute, u8 reason); + + // helper to remove items from the orphan list + void recursive_remove_stream_from_orphan_list(sound_stream *stream); + + // apply pending sample rate changes + void apply_sample_rate_changes(); + + // reset all sound chips void reset(); + + // pause/resume sound output void pause(); void resume(); + + // handle configuration load/save void config_load(config_type cfg_type, util::xml::data_node const *parentnode); void config_save(config_type cfg_type, util::xml::data_node *parentnode); + // helper to adjust scale factor toward a goal + stream_buffer::sample_t adjust_toward_compressor_scale(stream_buffer::sample_t curscale, stream_buffer::sample_t prevsample, stream_buffer::sample_t rawsample); + + // periodic sound update, called STREAMS_UPDATE_FREQUENCY per second void update(void *ptr = nullptr, s32 param = 0); // internal state - running_machine & m_machine; // reference to our machine - emu_timer * m_update_timer; // timer to drive periodic updates - - u32 m_finalmix_leftover; - std::vector m_finalmix; - std::vector m_leftmix; - std::vector m_rightmix; - int m_samples_this_update; - - u8 m_muted; - int m_attenuation; - int m_nosound_mode; - - wav_file * m_wavfile; + running_machine &m_machine; // reference to the running machine + emu_timer *m_update_timer; // timer that runs the update function + + u32 m_update_number; // current update index; used for sample rate updates + attotime m_last_update; // time of the last update + u32 m_finalmix_leftover; // leftover samples in the final mix + u32 m_samples_this_update; // number of samples this update + std::vector m_finalmix; // final mix, in 16-bit signed format + std::vector m_leftmix; // left speaker mix, in native format + std::vector m_rightmix; // right speaker mix, in native format + + stream_buffer::sample_t m_compressor_scale; // current compressor scale factor + int m_compressor_counter; // compressor update counter for backoff + + u8 m_muted; // bitmask of muting reasons + bool m_nosound_mode; // true if we're in "nosound" mode + int m_attenuation; // current attentuation level (at the OSD) + int m_unique_id; // unique ID used for stream identification + wav_file *m_wavfile; // WAV file for streaming // streams data - std::vector> m_stream_list; // list of streams - attoseconds_t m_update_attoseconds; // attoseconds between global updates - attotime m_last_update; // last update time + std::vector> m_stream_list; // list of streams + std::map m_orphan_stream_list; // list of orphaned streams + bool m_first_reset; // is this our first reset? }; diff --git a/src/emu/speaker.cpp b/src/emu/speaker.cpp index f5f507d242b..fbbc243e469 100644 --- a/src/emu/speaker.cpp +++ b/src/emu/speaker.cpp @@ -56,26 +56,28 @@ speaker_device::~speaker_device() // mix - mix in samples from the speaker's stream //------------------------------------------------- -void speaker_device::mix(s32 *leftmix, s32 *rightmix, int &samples_this_update, bool suppress) +void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample_t *rightmix, u32 &samples_this_update, bool suppress) { // skip if no stream if (m_mixer_stream == nullptr) return; // update the stream, getting the start/end pointers around the operation - int numsamples; - const stream_sample_t *stream_buf = m_mixer_stream->output_since_last_update(0, numsamples); + attotime start = m_mixer_stream->sample_time(); + attotime end = machine().time(); + if (start > end) + return; + read_stream_view view = m_mixer_stream->update_view(start, end); // set or assert that all streams have the same count if (samples_this_update == 0) { - samples_this_update = numsamples; + samples_this_update = view.samples(); // reset the mixing streams std::fill_n(leftmix, samples_this_update, 0); std::fill_n(rightmix, samples_this_update, 0); } - assert(samples_this_update == numsamples); // track maximum sample value for each 0.1s bucket if (machine().options().speaker_report() != 0) @@ -83,11 +85,11 @@ void speaker_device::mix(s32 *leftmix, s32 *rightmix, int &samples_this_update, u32 samples_per_bucket = m_mixer_stream->sample_rate() / BUCKETS_PER_SECOND; for (int sample = 0; sample < samples_this_update; sample++) { - m_current_max = std::max(m_current_max, abs(stream_buf[sample])); + m_current_max = std::max(m_current_max, fabsf(view.get(sample))); if (++m_samples_this_bucket >= samples_per_bucket) { m_max_sample.push_back(m_current_max); - m_current_max = 0; + m_current_max = 0.0f; m_samples_this_bucket = 0; } } @@ -100,19 +102,20 @@ void speaker_device::mix(s32 *leftmix, s32 *rightmix, int &samples_this_update, if (m_x == 0) for (int sample = 0; sample < samples_this_update; sample++) { - leftmix[sample] += stream_buf[sample]; - rightmix[sample] += stream_buf[sample]; + stream_buffer::sample_t cursample = view.get(sample); + leftmix[sample] += cursample; + rightmix[sample] += cursample; } // if the speaker is to the left, send only to the left else if (m_x < 0) for (int sample = 0; sample < samples_this_update; sample++) - leftmix[sample] += stream_buf[sample]; + leftmix[sample] += view.get(sample); // if the speaker is to the right, send only to the right else for (int sample = 0; sample < samples_this_update; sample++) - rightmix[sample] += stream_buf[sample]; + rightmix[sample] += view.get(sample); } } @@ -143,27 +146,51 @@ void speaker_device::device_stop() m_max_sample.push_back(m_current_max); // determine overall maximum and number of clipped buckets - s32 overallmax = 0; + stream_buffer::sample_t overallmax = 0; u32 clipped = 0; for (auto &curmax : m_max_sample) { overallmax = std::max(overallmax, curmax); - if (curmax > 32767) + if (curmax > stream_buffer::sample_t(1.0)) clipped++; } // levels 1 and 2 just get a summary if (clipped != 0 || report == 2 || report == 4) - osd_printf_info("Speaker \"%s\" - max = %d (gain *= %.3f) - clipped in %d/%d (%d%%) buckets\n", tag(), overallmax, 32767.0 / (overallmax ? overallmax : 1), clipped, m_max_sample.size(), clipped * 100 / m_max_sample.size()); + osd_printf_info("Speaker \"%s\" - max = %.5f (gain *= %.3f) - clipped in %d/%d (%d%%) buckets\n", tag(), overallmax, 1 / (overallmax ? overallmax : 1), clipped, m_max_sample.size(), clipped * 100 / m_max_sample.size()); // levels 3 and 4 get a full dump if (report >= 3) { + static char const * const s_stars = "************************************************************"; + static char const * const s_spaces = " "; + int totalstars = strlen(s_stars); double t = 0; + if (overallmax < 1.0) + overallmax = 1.0; + int leftstars = totalstars / overallmax; for (auto &curmax : m_max_sample) { - if (curmax > 32767 || report == 4) - osd_printf_info(" t=%5.1f max=%6d\n", t, curmax); + if (curmax > stream_buffer::sample_t(1.0) || report == 4) + { + osd_printf_info("%6.1f: %9.5f |", t, curmax); + if (curmax == 0) + osd_printf_info("%.*s|\n", leftstars, s_spaces); + else if (curmax <= 1.0) + { + int stars = std::max(1, std::min(leftstars, int(curmax * totalstars / overallmax))); + osd_printf_info("%.*s", stars, s_stars); + int spaces = leftstars - stars; + if (spaces != 0) + osd_printf_info("%.*s", spaces, s_spaces); + osd_printf_info("|\n"); + } + else + { + int rightstars = std::max(1, std::min(totalstars, int(curmax * totalstars / overallmax)) - leftstars); + osd_printf_info("%.*s|%.*s\n", leftstars, s_stars, rightstars, s_stars); + } + } t += 1.0 / double(BUCKETS_PER_SECOND); } } diff --git a/src/emu/speaker.h b/src/emu/speaker.h index 7cf27d12471..7747622ca34 100644 --- a/src/emu/speaker.h +++ b/src/emu/speaker.h @@ -69,7 +69,7 @@ public: speaker_device &backrest() { set_position( 0.0, -0.2, 0.1); return *this; } // internally for use by the sound system - void mix(s32 *leftmix, s32 *rightmix, int &samples_this_update, bool suppress); + void mix(stream_buffer::sample_t *leftmix, stream_buffer::sample_t *rightmix, u32 &samples_this_update, bool suppress); protected: // device-level overrides @@ -77,20 +77,20 @@ protected: virtual void device_stop() override ATTR_COLD; // inline configuration state - double m_x; - double m_y; - double m_z; + double m_x; + double m_y; + double m_z; // internal state static constexpr int BUCKETS_PER_SECOND = 10; - std::vector m_max_sample; - s32 m_current_max; - u32 m_samples_this_bucket; + std::vector m_max_sample; + stream_buffer::sample_t m_current_max; + u32 m_samples_this_bucket; }; // speaker device iterator -typedef device_type_iterator speaker_device_iterator; +using speaker_device_iterator = device_type_iterator; #endif // MAME_EMU_SPEAKER_H diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp index 40a5651430d..ff16d117117 100644 --- a/src/frontend/mame/ui/ui.cpp +++ b/src/frontend/mame/ui/ui.cpp @@ -1524,7 +1524,7 @@ std::vector mame_ui_manager::slider_init(running_machine &machine int32_t maxval = 2000; int32_t defval = 1000; - std::string str = string_format(_("%1$s Volume"), info.stream->input_name(info.inputnum)); + std::string str = string_format(_("%1$s Volume"), info.stream->input(info.inputnum).name()); m_sliders.push_back(slider_alloc(SLIDER_ID_MIXERVOL + item, str.c_str(), 0, defval, maxval, 20, (void *)(uintptr_t)item)); } @@ -1762,13 +1762,13 @@ int32_t mame_ui_manager::slider_mixervol(running_machine &machine, void *arg, in return 0; if (newval != SLIDER_NOCHANGE) { - int32_t curval = floor(info.stream->user_gain(info.inputnum) * 1000.0f + 0.5f); + int32_t curval = floor(info.stream->input(info.inputnum).user_gain() * 1000.0f + 0.5f); if (newval > curval && (newval - curval) <= 4) newval += 4; // round up on increment - info.stream->set_user_gain(info.inputnum, (float)newval * 0.001f); + info.stream->input(info.inputnum).set_user_gain((float)newval * 0.001f); } if (str) - *str = string_format("%4.2f", info.stream->user_gain(info.inputnum)); - return floorf(info.stream->user_gain(info.inputnum) * 1000.0f + 0.5f); + *str = string_format("%4.2f", info.stream->input(info.inputnum).user_gain()); + return floorf(info.stream->input(info.inputnum).user_gain() * 1000.0f + 0.5f); } diff --git a/src/mame/audio/arcadia.cpp b/src/mame/audio/arcadia.cpp index aa0bc4b8616..19adb9fac4e 100644 --- a/src/mame/audio/arcadia.cpp +++ b/src/mame/audio/arcadia.cpp @@ -59,7 +59,7 @@ arcadia_sound_device::arcadia_sound_device(const machine_config &mconfig, const //------------------------------------------------- void arcadia_sound_device::device_start() { - m_channel = machine().sound().stream_alloc(*this, 0, 1, UVI_PAL*OSAMP); + m_channel = stream_alloc_legacy(0, 1, UVI_PAL*OSAMP); m_lfsr = LFSR_INIT; m_tval = 1; logerror("arcadia_sound start\n"); @@ -76,11 +76,11 @@ void arcadia_sound_device::device_reset() } //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void arcadia_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void arcadia_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int i; stream_sample_t *buffer = outputs[0]; diff --git a/src/mame/audio/arcadia.h b/src/mame/audio/arcadia.h index 3452b755d5d..de67b71705d 100644 --- a/src/mame/audio/arcadia.h +++ b/src/mame/audio/arcadia.h @@ -21,7 +21,7 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; sound_stream *m_channel; uint8_t m_reg[3]; diff --git a/src/mame/audio/channelf.cpp b/src/mame/audio/channelf.cpp index 8823294c75e..5003f28ae3a 100644 --- a/src/mame/audio/channelf.cpp +++ b/src/mame/audio/channelf.cpp @@ -30,7 +30,7 @@ void channelf_sound_device::device_start() { int rate; - m_channel = stream_alloc(0, 1, machine().sample_rate()); + m_channel = stream_alloc_legacy(0, 1, machine().sample_rate()); rate = machine().sample_rate(); /* @@ -67,10 +67,10 @@ void channelf_sound_device::device_start() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void channelf_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void channelf_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { uint32_t mask = 0, target = 0; stream_sample_t *buffer = outputs[0]; diff --git a/src/mame/audio/channelf.h b/src/mame/audio/channelf.h index 26e3b85b52d..36c98aa47ed 100644 --- a/src/mame/audio/channelf.h +++ b/src/mame/audio/channelf.h @@ -20,7 +20,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: // internal state sound_stream *m_channel; diff --git a/src/mame/audio/cheekyms.cpp b/src/mame/audio/cheekyms.cpp index e0c777a3e30..1ff076de3c0 100644 --- a/src/mame/audio/cheekyms.cpp +++ b/src/mame/audio/cheekyms.cpp @@ -55,7 +55,7 @@ void cheekyms_audio_device::device_add_mconfig(machine_config &config) NETLIST_LOGIC_INPUT(config, "sound_nl:pest_dies", "I_PEST_DIES.IN", 0); NETLIST_LOGIC_INPUT(config, "sound_nl:coin_extra", "I_COIN_EXTRA.IN", 0); - NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "VR1.2").set_mult_offset(30000.0 * 10.0, 0.0); + NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "VR1.2").set_mult_offset(30000.0 * 10.0 / 32768.0, 0.0); } diff --git a/src/mame/audio/cinemat.cpp b/src/mame/audio/cinemat.cpp index c7b75f31311..4b9168aa949 100644 --- a/src/mame/audio/cinemat.cpp +++ b/src/mame/audio/cinemat.cpp @@ -145,7 +145,7 @@ void cinemat_audio_device_base::input_set(int bit, int state) DEFINE_DEVICE_TYPE(SPACE_WARS_AUDIO, spacewar_audio_device, "spacewar_audio", "Space Wars Sound Board") spacewar_audio_device::spacewar_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, SPACE_WARS_AUDIO, tag, owner, clock, 0x1f, NETLIST_NAME(spacewar), 150000.0) + : cinemat_audio_device_base(mconfig, SPACE_WARS_AUDIO, tag, owner, clock, 0x1f, NETLIST_NAME(spacewar), 4.5) { } @@ -160,7 +160,7 @@ spacewar_audio_device::spacewar_audio_device(const machine_config &mconfig, cons DEFINE_DEVICE_TYPE(BARRIER_AUDIO, barrier_audio_device, "barrier_audio", "Barrier Sound Board") barrier_audio_device::barrier_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, BARRIER_AUDIO, tag, owner, clock, 0x07, NETLIST_NAME(barrier), 200000.0) + : cinemat_audio_device_base(mconfig, BARRIER_AUDIO, tag, owner, clock, 0x07, NETLIST_NAME(barrier), 6.1) { } @@ -175,7 +175,7 @@ barrier_audio_device::barrier_audio_device(const machine_config &mconfig, const DEFINE_DEVICE_TYPE(SPEED_FREAK_AUDIO, speedfrk_audio_device, "speedfrk_audio", "Speed Freak Sound Board") speedfrk_audio_device::speedfrk_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, SPEED_FREAK_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(speedfrk), 12000.0) + : cinemat_audio_device_base(mconfig, SPEED_FREAK_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(speedfrk), 0.35) { } @@ -190,7 +190,7 @@ speedfrk_audio_device::speedfrk_audio_device(const machine_config &mconfig, cons DEFINE_DEVICE_TYPE(STAR_HAWK_AUDIO, starhawk_audio_device, "starhawk_audio", "Star Hawk Sound Board") starhawk_audio_device::starhawk_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, STAR_HAWK_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(starhawk), 50000.0) + : cinemat_audio_device_base(mconfig, STAR_HAWK_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(starhawk), 1.5) { } @@ -205,7 +205,7 @@ starhawk_audio_device::starhawk_audio_device(const machine_config &mconfig, cons DEFINE_DEVICE_TYPE(SUNDANCE_AUDIO, sundance_audio_device, "sundance_audio", "Sundance Sound Board") sundance_audio_device::sundance_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, SUNDANCE_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(sundance), 45000.0) + : cinemat_audio_device_base(mconfig, SUNDANCE_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(sundance), 1.0) { } @@ -220,7 +220,7 @@ sundance_audio_device::sundance_audio_device(const machine_config &mconfig, cons DEFINE_DEVICE_TYPE(TAIL_GUNNER_AUDIO, tailg_audio_device, "tailg_audio", "Tail Gunner Sound Board") tailg_audio_device::tailg_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, TAIL_GUNNER_AUDIO, tag, owner, clock, 0x1f, NETLIST_NAME(tailg), 75000.0) + : cinemat_audio_device_base(mconfig, TAIL_GUNNER_AUDIO, tag, owner, clock, 0x1f, NETLIST_NAME(tailg), 2.2) { } @@ -235,7 +235,7 @@ tailg_audio_device::tailg_audio_device(const machine_config &mconfig, const char DEFINE_DEVICE_TYPE(WARRIOR_AUDIO, warrior_audio_device, "warrior_audio", "Warrior Sound Board") warrior_audio_device::warrior_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, WARRIOR_AUDIO, tag, owner, clock, 0x1f, NETLIST_NAME(warrior), 50000.0) + : cinemat_audio_device_base(mconfig, WARRIOR_AUDIO, tag, owner, clock, 0x1f, NETLIST_NAME(warrior), 1.5) { } @@ -250,7 +250,7 @@ warrior_audio_device::warrior_audio_device(const machine_config &mconfig, const DEFINE_DEVICE_TYPE(ARMOR_ATTACK_AUDIO, armora_audio_device, "armora_audio", "Armor Atrack Sound Board") armora_audio_device::armora_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, ARMOR_ATTACK_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(armora), 5000.0) + : cinemat_audio_device_base(mconfig, ARMOR_ATTACK_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(armora), 0.15) { } @@ -265,7 +265,7 @@ armora_audio_device::armora_audio_device(const machine_config &mconfig, const ch DEFINE_DEVICE_TYPE(RIPOFF_AUDIO, ripoff_audio_device, "ripoff_audio", "Rip Off Sound Board") ripoff_audio_device::ripoff_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, RIPOFF_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(ripoff), 20000.0) + : cinemat_audio_device_base(mconfig, RIPOFF_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(ripoff), 0.61) { } @@ -280,7 +280,7 @@ ripoff_audio_device::ripoff_audio_device(const machine_config &mconfig, const ch DEFINE_DEVICE_TYPE(STAR_CASTLE_AUDIO, starcas_audio_device, "starcas_audio", "Star Castle Sound Board") starcas_audio_device::starcas_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, STAR_CASTLE_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(starcas), 5000.0) + : cinemat_audio_device_base(mconfig, STAR_CASTLE_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(starcas), 0.15) { } @@ -295,7 +295,7 @@ starcas_audio_device::starcas_audio_device(const machine_config &mconfig, const DEFINE_DEVICE_TYPE(SOLAR_QUEST_AUDIO, solarq_audio_device, "solarq_audio", "Solar Quest Sound Board") solarq_audio_device::solarq_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, SOLAR_QUEST_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(solarq), 5000.0) + : cinemat_audio_device_base(mconfig, SOLAR_QUEST_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(solarq), 0.15) { } @@ -310,7 +310,7 @@ solarq_audio_device::solarq_audio_device(const machine_config &mconfig, const ch DEFINE_DEVICE_TYPE(BOXING_BUGS_AUDIO, boxingb_audio_device, "boxingb_audio", "Boxing Bugs Sound Board") boxingb_audio_device::boxingb_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, BOXING_BUGS_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(boxingb), 5000.0) + : cinemat_audio_device_base(mconfig, BOXING_BUGS_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(boxingb), 0.15) { } @@ -325,7 +325,7 @@ boxingb_audio_device::boxingb_audio_device(const machine_config &mconfig, const DEFINE_DEVICE_TYPE(WAR_OF_THE_WORLDS_AUDIO, wotw_audio_device, "wotw_audio", "War of the Worlds Sound Board") wotw_audio_device::wotw_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : cinemat_audio_device_base(mconfig, WAR_OF_THE_WORLDS_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(wotw), 5000.0) + : cinemat_audio_device_base(mconfig, WAR_OF_THE_WORLDS_AUDIO, tag, owner, clock, 0x9f, NETLIST_NAME(wotw), 0.15) { } diff --git a/src/mame/audio/cmi01a.cpp b/src/mame/audio/cmi01a.cpp index 8a45582d2fd..dbb180c2247 100644 --- a/src/mame/audio/cmi01a.cpp +++ b/src/mame/audio/cmi01a.cpp @@ -132,7 +132,7 @@ void cmi01a_device::device_add_mconfig(machine_config &config) } -void cmi01a_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void cmi01a_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { if (m_run) { @@ -175,7 +175,7 @@ void cmi01a_device::device_start() m_zx_timer->adjust(attotime::never); m_eosi_timer->adjust(attotime::never); - m_stream = stream_alloc(0, 1, 44100); + m_stream = stream_alloc_legacy(0, 1, 44100); m_ptm->set_external_clocks(clock() / 8, clock() / 4, clock() / 4); diff --git a/src/mame/audio/cmi01a.h b/src/mame/audio/cmi01a.h index 61e294111db..7e5da0b56a8 100644 --- a/src/mame/audio/cmi01a.h +++ b/src/mame/audio/cmi01a.h @@ -34,7 +34,7 @@ public: void write(offs_t offset, uint8_t data); uint8_t read(offs_t offset); - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; protected: virtual void device_resolve_objects() override; diff --git a/src/mame/audio/cps3.cpp b/src/mame/audio/cps3.cpp index f800aa0e598..aa7eb8340f0 100644 --- a/src/mame/audio/cps3.cpp +++ b/src/mame/audio/cps3.cpp @@ -39,7 +39,7 @@ cps3_sound_device::cps3_sound_device(const machine_config &mconfig, const char * void cps3_sound_device::device_start() { /* Allocate the stream */ - m_stream = stream_alloc(0, 2, clock() / 384); + m_stream = stream_alloc_legacy(0, 2, clock() / 384); save_item(NAME(m_key)); for (int i = 0; i < 16; i++) @@ -52,10 +52,10 @@ void cps3_sound_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void cps3_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void cps3_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { /* Clear the buffers */ memset(outputs[0], 0, samples*sizeof(*outputs[0])); diff --git a/src/mame/audio/cps3.h b/src/mame/audio/cps3.h index 482b156a755..4e3fe471c8d 100644 --- a/src/mame/audio/cps3.h +++ b/src/mame/audio/cps3.h @@ -46,7 +46,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream *m_stream; diff --git a/src/mame/audio/dai_snd.cpp b/src/mame/audio/dai_snd.cpp index 72dd3f75b41..37004da5644 100644 --- a/src/mame/audio/dai_snd.cpp +++ b/src/mame/audio/dai_snd.cpp @@ -33,7 +33,7 @@ dai_sound_device::dai_sound_device(const machine_config &mconfig, const char *ta void dai_sound_device::device_start() { - m_mixer_channel = machine().sound().stream_alloc(*this, 0, 2, machine().sample_rate()); + m_mixer_channel = stream_alloc_legacy(0, 2, machine().sample_rate()); } //------------------------------------------------- @@ -115,11 +115,11 @@ WRITE_LINE_MEMBER(dai_sound_device::set_input_ch2) } //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void dai_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void dai_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *sample_left = outputs[0]; stream_sample_t *sample_right = outputs[1]; diff --git a/src/mame/audio/dai_snd.h b/src/mame/audio/dai_snd.h index d82bc000d8a..cea0e1c6c71 100644 --- a/src/mame/audio/dai_snd.h +++ b/src/mame/audio/dai_snd.h @@ -27,7 +27,7 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream * m_mixer_channel; diff --git a/src/mame/audio/dsbz80.cpp b/src/mame/audio/dsbz80.cpp index ae0e4b216a4..7643face54b 100644 --- a/src/mame/audio/dsbz80.cpp +++ b/src/mame/audio/dsbz80.cpp @@ -85,7 +85,7 @@ void dsbz80_device::device_start() m_rxd_handler.resolve_safe(); uint8_t *rom_base = machine().root_device().memregion("mpeg")->base(); decoder = new mpeg_audio(rom_base, mpeg_audio::L2, false, 0); - machine().sound().stream_alloc(*this, 0, 2, 32000); + stream_alloc_legacy(0, 2, 32000); } //------------------------------------------------- @@ -232,7 +232,7 @@ void dsbz80_device::mpeg_stereo_w(uint8_t data) mp_pan = data & 3; // 0 = stereo, 1 = left on both channels, 2 = right on both channels } -void dsbz80_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void dsbz80_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *out_l = outputs[0]; stream_sample_t *out_r = outputs[1]; diff --git a/src/mame/audio/dsbz80.h b/src/mame/audio/dsbz80.h index 0c62482100b..92e0c4f3f2f 100644 --- a/src/mame/audio/dsbz80.h +++ b/src/mame/audio/dsbz80.h @@ -37,7 +37,7 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_add_mconfig(machine_config &config) override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: mpeg_audio *decoder; diff --git a/src/mame/audio/elan_eu3a05.cpp b/src/mame/audio/elan_eu3a05.cpp index d11039df082..39ab90a08fb 100644 --- a/src/mame/audio/elan_eu3a05.cpp +++ b/src/mame/audio/elan_eu3a05.cpp @@ -54,7 +54,7 @@ void elan_eu3a05_sound_device::map(address_map &map) void elan_eu3a05_sound_device::device_start() { m_space_read_cb.resolve_safe(0); - m_stream = stream_alloc(0, 1, 8000); + m_stream = stream_alloc_legacy(0, 1, 8000); m_sound_end_cb.resolve_all_safe(); @@ -92,10 +92,10 @@ void elan_eu3a05_sound_device::device_reset() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void elan_eu3a05_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void elan_eu3a05_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // reset the output stream memset(outputs[0], 0, samples * sizeof(*outputs[0])); diff --git a/src/mame/audio/elan_eu3a05.h b/src/mame/audio/elan_eu3a05.h index ddd6c370033..c9ef2e83ab3 100644 --- a/src/mame/audio/elan_eu3a05.h +++ b/src/mame/audio/elan_eu3a05.h @@ -30,7 +30,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; virtual space_config_vector memory_space_config() const override; const address_space_config m_space_config; diff --git a/src/mame/audio/exidy.cpp b/src/mame/audio/exidy.cpp index 55dda4ea22b..8220c3e1af7 100644 --- a/src/mame/audio/exidy.cpp +++ b/src/mame/audio/exidy.cpp @@ -180,7 +180,7 @@ void exidy_sound_device::common_sh_start() m_sh6840_clocks_per_sample = (int)(SH6840_CLOCK.dvalue() / (double)sample_rate * (double)(1 << 24)); /* allocate the stream */ - m_stream = machine().sound().stream_alloc(*this, 0, 1, sample_rate); + m_stream = stream_alloc_legacy(0, 1, sample_rate); sh6840_register_state_globals(); } @@ -239,10 +239,10 @@ void exidy_sound_device::device_reset() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void exidy_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void exidy_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { sh6840_timer_channel *sh6840_timer = m_sh6840_timer; diff --git a/src/mame/audio/exidy.h b/src/mame/audio/exidy.h index d3e049f7f2b..86ed7b145cd 100644 --- a/src/mame/audio/exidy.h +++ b/src/mame/audio/exidy.h @@ -54,7 +54,7 @@ protected: void sh6840_register_state_globals(); // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; virtual stream_sample_t generate_music_sample(); static inline void sh6840_apply_clock(sh6840_timer_channel *t, int clocks); diff --git a/src/mame/audio/exidy440.cpp b/src/mame/audio/exidy440.cpp index fb221df1e4b..a4ca2d10339 100644 --- a/src/mame/audio/exidy440.cpp +++ b/src/mame/audio/exidy440.cpp @@ -146,7 +146,7 @@ void exidy440_sound_device::device_start() m_channel_frequency[3] = clock()/2; /* get stream channels */ - m_stream = machine().sound().stream_alloc(*this, 0, 2, clock()); + m_stream = stream_alloc_legacy(0, 2, clock()); /* allocate the sample cache */ length = m_samples.bytes() * 16 + MAX_CACHE_ENTRIES * sizeof(sound_cache_entry); @@ -836,10 +836,10 @@ void exidy440_sound_device::sound_banks_w(offs_t offset, uint8_t data) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void exidy440_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void exidy440_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int ch; diff --git a/src/mame/audio/exidy440.h b/src/mame/audio/exidy440.h index 826ed3467ea..9f8861bdfe3 100644 --- a/src/mame/audio/exidy440.h +++ b/src/mame/audio/exidy440.h @@ -29,7 +29,7 @@ protected: virtual void device_stop() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: void exidy440_audio_map(address_map &map); diff --git a/src/mame/audio/flower.cpp b/src/mame/audio/flower.cpp index d708bc1fd35..4ade0d864a9 100644 --- a/src/mame/audio/flower.cpp +++ b/src/mame/audio/flower.cpp @@ -63,7 +63,7 @@ flower_sound_device::flower_sound_device(const machine_config &mconfig, const ch void flower_sound_device::device_start() { m_iospace = &space(AS_IO); - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock()/2); + m_stream = stream_alloc_legacy(0, 1, clock()/2); m_mixer_buffer = make_unique_clear(clock()/2); make_mixer_table(MAX_VOICES, defgain); @@ -127,7 +127,7 @@ void flower_sound_device::device_reset() } } -void flower_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void flower_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; short *mix; diff --git a/src/mame/audio/flower.h b/src/mame/audio/flower.h index d595a2dfa6c..8fad33679c6 100644 --- a/src/mame/audio/flower.h +++ b/src/mame/audio/flower.h @@ -39,7 +39,7 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual space_config_vector memory_space_config() const override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; address_space *m_iospace; private: diff --git a/src/mame/audio/geebee.cpp b/src/mame/audio/geebee.cpp index 037a398dc3b..63859916d7c 100644 --- a/src/mame/audio/geebee.cpp +++ b/src/mame/audio/geebee.cpp @@ -42,7 +42,7 @@ void geebee_sound_device::device_start() m_decay[0x7fff - i] = (int16_t) (0x7fff/exp(1.0*i/4096)); /* 1V = HSYNC = 18.432MHz / 3 / 2 / 384 = 8000Hz */ - m_channel = machine().sound().stream_alloc(*this, 0, 1, clock() / 3 / 2 / 384); + m_channel = stream_alloc_legacy(0, 1, clock() / 3 / 2 / 384); m_vcount = 0; m_volume_timer = timer_alloc(TIMER_VOLUME_DECAY); @@ -103,10 +103,10 @@ void geebee_sound_device::sound_w(u8 data) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void geebee_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void geebee_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; diff --git a/src/mame/audio/geebee.h b/src/mame/audio/geebee.h index 56fde3cacf2..1cca0fc6dd0 100644 --- a/src/mame/audio/geebee.h +++ b/src/mame/audio/geebee.h @@ -22,7 +22,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + 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 device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; diff --git a/src/mame/audio/gomoku.cpp b/src/mame/audio/gomoku.cpp index 197b2d77827..6aeb288f6db 100644 --- a/src/mame/audio/gomoku.cpp +++ b/src/mame/audio/gomoku.cpp @@ -52,7 +52,7 @@ void gomoku_sound_device::device_start() int ch; // get stream channels - m_stream = stream_alloc(0, 1, clock()); + m_stream = stream_alloc_legacy(0, 1, clock()); // allocate a pair of buffers to mix into - 1 second's worth should be more than enough m_mixer_buffer = std::make_unique(2 * clock()); @@ -87,10 +87,10 @@ void gomoku_sound_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update in mono +// sound_stream_update_legacy - handle a stream update in mono //------------------------------------------------- -void gomoku_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void gomoku_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; sound_channel *voice; diff --git a/src/mame/audio/gomoku.h b/src/mame/audio/gomoku.h index 5947bfc40b8..75de8a2c09c 100644 --- a/src/mame/audio/gomoku.h +++ b/src/mame/audio/gomoku.h @@ -23,7 +23,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: void make_mixer_table(int voices, int gain); diff --git a/src/mame/audio/gridlee.cpp b/src/mame/audio/gridlee.cpp index ad002ddf731..429518b39d0 100644 --- a/src/mame/audio/gridlee.cpp +++ b/src/mame/audio/gridlee.cpp @@ -43,17 +43,17 @@ gridlee_sound_device::gridlee_sound_device(const machine_config &mconfig, const void gridlee_sound_device::device_start() { /* allocate the stream */ - m_stream = stream_alloc(0, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 1, machine().sample_rate()); m_freq_to_step = (double)(1 << 24) / (double)machine().sample_rate(); } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void gridlee_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void gridlee_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; diff --git a/src/mame/audio/hyprolyb.cpp b/src/mame/audio/hyprolyb.cpp index d2bd798286e..77ff8034ae5 100644 --- a/src/mame/audio/hyprolyb.cpp +++ b/src/mame/audio/hyprolyb.cpp @@ -82,11 +82,11 @@ void hyprolyb_adpcm_device::vck_callback( int st ) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void hyprolyb_adpcm_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void hyprolyb_adpcm_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // should never get here - fatalerror("sound_stream_update called; not applicable to legacy sound devices\n"); + fatalerror("sound_stream_update_legacy called; not applicable to legacy sound devices\n"); } diff --git a/src/mame/audio/hyprolyb.h b/src/mame/audio/hyprolyb.h index b3123c3cd52..ac2687b40e4 100644 --- a/src/mame/audio/hyprolyb.h +++ b/src/mame/audio/hyprolyb.h @@ -28,7 +28,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: // internal state diff --git a/src/mame/audio/irem.cpp b/src/mame/audio/irem.cpp index 24f3fbefa32..b10a97a2200 100644 --- a/src/mame/audio/irem.cpp +++ b/src/mame/audio/irem.cpp @@ -457,10 +457,10 @@ void m62_audio_device::device_add_mconfig(machine_config &config) NETLIST_STREAM_INPUT(config, "snd_nl:cin4", 4, "R_AY45L_B.R"); NETLIST_STREAM_INPUT(config, "snd_nl:cin5", 5, "R_AY45L_C.R"); - NETLIST_STREAM_INPUT(config, "snd_nl:cin6", 6, "I_MSM2K0.IN").set_mult_offset(5.0/65535.0, 2.5); - NETLIST_STREAM_INPUT(config, "snd_nl:cin7", 7, "I_MSM3K0.IN").set_mult_offset(5.0/65535.0, 2.5); + NETLIST_STREAM_INPUT(config, "snd_nl:cin6", 6, "I_MSM2K0.IN").set_mult_offset(10.0, 2.5); + NETLIST_STREAM_INPUT(config, "snd_nl:cin7", 7, "I_MSM3K0.IN").set_mult_offset(10.0, 2.5); - NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "R26.1").set_mult_offset(30000.0 * 10.0, 0.0); + NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "R26.1").set_mult_offset(30000.0 * 10.0 / 32768.0, 0.0); } void m52_soundc_audio_device::device_add_mconfig(machine_config &config) diff --git a/src/mame/audio/lynx.cpp b/src/mame/audio/lynx.cpp index 2c36c831157..40369d86d1d 100644 --- a/src/mame/audio/lynx.cpp +++ b/src/mame/audio/lynx.cpp @@ -172,7 +172,7 @@ void lynx_sound_device::init() void lynx_sound_device::device_start() { - m_mixer_channel = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_mixer_channel = stream_alloc_legacy(0, 1, machine().sample_rate()); m_usec_per_sample = 1000000 / machine().sample_rate(); m_timer_delegate.resolve(); init(); @@ -182,7 +182,7 @@ void lynx_sound_device::device_start() void lynx2_sound_device::device_start() { - m_mixer_channel = machine().sound().stream_alloc(*this, 0, 2, machine().sample_rate()); + m_mixer_channel = stream_alloc_legacy(0, 2, machine().sample_rate()); m_usec_per_sample = 1000000 / machine().sample_rate(); m_timer_delegate.resolve(); init(); @@ -467,10 +467,10 @@ void lynx_sound_device::write(offs_t offset, uint8_t data) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void lynx_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void lynx_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int v; stream_sample_t *buffer = outputs[0]; @@ -488,10 +488,10 @@ void lynx_sound_device::sound_stream_update(sound_stream &stream, stream_sample_ } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void lynx2_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void lynx2_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *left=outputs[0], *right=outputs[1]; int v; diff --git a/src/mame/audio/lynx.h b/src/mame/audio/lynx.h index bce0d520ce4..11b983089a7 100644 --- a/src/mame/audio/lynx.h +++ b/src/mame/audio/lynx.h @@ -45,7 +45,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; void reset_channel(LYNX_AUDIO *channel); void shift(int chan_nr); @@ -75,7 +75,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; }; diff --git a/src/mame/audio/mario.cpp b/src/mame/audio/mario.cpp index da4e4f1699a..1bdf1822bcd 100644 --- a/src/mame/audio/mario.cpp +++ b/src/mame/audio/mario.cpp @@ -670,7 +670,7 @@ void mario_state::mario_audio(machine_config &config) NETLIST_LOGIC_INPUT(config, m_audio_snd7, "SOUND7.IN", 0); NETLIST_INT_INPUT(config, m_audio_dac, "DAC.VAL", 0, 255); - NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "ROUT.1").set_mult_offset(150000.0, 0.0); + NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "ROUT.1").set_mult_offset(150000.0 / 32768.0, 0.0); #endif } diff --git a/src/mame/audio/micro3d.cpp b/src/mame/audio/micro3d.cpp index 6e0a4d87db5..52f723ef55f 100644 --- a/src/mame/audio/micro3d.cpp +++ b/src/mame/audio/micro3d.cpp @@ -182,7 +182,7 @@ micro3d_sound_device::micro3d_sound_device(const machine_config &mconfig, const void micro3d_sound_device::device_start() { /* Allocate the stream */ - m_stream = machine().sound().stream_alloc(*this, 0, 2, machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 2, machine().sample_rate()); m_filter.init(machine().sample_rate()); m_noise_filters[0].configure(2.7e3 + 2.7e3, 1.0e-6); @@ -206,10 +206,10 @@ void micro3d_sound_device::device_reset() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void micro3d_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void micro3d_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { lp_filter *iir = &m_filter; float pan_l, pan_r; diff --git a/src/mame/audio/micro3d.h b/src/mame/audio/micro3d.h index e27c57e5bac..937d1fbed74 100644 --- a/src/mame/audio/micro3d.h +++ b/src/mame/audio/micro3d.h @@ -24,7 +24,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: enum dac_registers { diff --git a/src/mame/audio/mw8080bw.cpp b/src/mame/audio/mw8080bw.cpp index 55f8faedddf..28c7320a7a4 100644 --- a/src/mame/audio/mw8080bw.cpp +++ b/src/mame/audio/mw8080bw.cpp @@ -798,8 +798,8 @@ void gunfight_audio_device::device_add_mconfig(machine_config &config) // the outputs before the power amps so that the highest output spikes // of +/- 3 volts just reach the clipping limits for signed 16-bit // samples. - NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "OUT_L").set_mult_offset(32767.0 / 3.0, 0.0); - NETLIST_STREAM_OUTPUT(config, "sound_nl:cout1", 1, "OUT_R").set_mult_offset(32767.0 / 3.0, 0.0); + NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "OUT_L").set_mult_offset(1.0 / 3.0, 0.0); + NETLIST_STREAM_OUTPUT(config, "sound_nl:cout1", 1, "OUT_R").set_mult_offset(1.0 / 3.0, 0.0); // Netlist volume-potentiometer interfaces NETLIST_ANALOG_INPUT(config, "sound_nl:pot_left_master_vol", "R103.DIAL"); @@ -3768,7 +3768,7 @@ void zzzap_common_audio_device::device_add_mconfig(machine_config &config) // just reach the clipping limits for signed 16-bit samples. // So turning the volume up much higher than the default will // give clipped output. - NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "OUTPUT").set_mult_offset(32767.0 / 1.25, -(32767.0 / 1.25) * 2.50); + NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "OUTPUT").set_mult_offset(1.0 / 1.25, -(1.0 / 1.25) * 2.50); // Netlist volume-potentiometer interface NETLIST_ANALOG_INPUT(config, "sound_nl:pot_master_vol", "R70.DIAL"); diff --git a/src/mame/audio/phoenix.cpp b/src/mame/audio/phoenix.cpp index 566c9796525..7c43519c186 100644 --- a/src/mame/audio/phoenix.cpp +++ b/src/mame/audio/phoenix.cpp @@ -89,7 +89,7 @@ void phoenix_sound_device::device_start() m_poly18[i] = bits; } - m_channel = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_channel = stream_alloc_legacy(0, 1, machine().sample_rate()); save_item(NAME(m_sound_latch_a)); save_item(NAME(m_c24_state.counter)); @@ -520,10 +520,10 @@ void phoenix_sound_device::control_b_w(uint8_t data) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void phoenix_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void phoenix_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int samplerate = machine().sample_rate(); stream_sample_t *buffer = outputs[0]; diff --git a/src/mame/audio/phoenix.h b/src/mame/audio/phoenix.h index 43c360871c1..6a02220c30e 100644 --- a/src/mame/audio/phoenix.h +++ b/src/mame/audio/phoenix.h @@ -22,7 +22,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: struct c_state diff --git a/src/mame/audio/pleiads.cpp b/src/mame/audio/pleiads.cpp index cb0d3c89c4f..ee69320e7d6 100644 --- a/src/mame/audio/pleiads.cpp +++ b/src/mame/audio/pleiads.cpp @@ -642,7 +642,7 @@ void pleiads_sound_device::common_start() m_poly18[i] = bits; } - m_channel = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_channel = stream_alloc_legacy(0, 1, machine().sample_rate()); save_item(NAME(m_sound_latch_a)); save_item(NAME(m_sound_latch_b)); @@ -691,10 +691,10 @@ void pleiads_sound_device::common_start() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void pleiads_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void pleiads_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int rate = machine().sample_rate(); stream_sample_t *buffer = outputs[0]; @@ -706,12 +706,12 @@ void pleiads_sound_device::sound_stream_update(sound_stream &stream, stream_samp } } -void naughtyb_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void naughtyb_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { - pleiads_sound_device::sound_stream_update(stream, inputs, outputs, samples); + pleiads_sound_device::sound_stream_update_legacy(stream, inputs, outputs, samples); } -void popflame_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void popflame_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { - pleiads_sound_device::sound_stream_update(stream, inputs, outputs, samples); + pleiads_sound_device::sound_stream_update_legacy(stream, inputs, outputs, samples); } diff --git a/src/mame/audio/pleiads.h b/src/mame/audio/pleiads.h index 103c1d5121e..0c4ef99b4a9 100644 --- a/src/mame/audio/pleiads.h +++ b/src/mame/audio/pleiads.h @@ -51,7 +51,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; void common_start(); inline int tone1(int samplerate); @@ -105,7 +105,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; }; @@ -119,7 +119,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; }; diff --git a/src/mame/audio/polepos.cpp b/src/mame/audio/polepos.cpp index b8e08fc588d..48865d300e0 100644 --- a/src/mame/audio/polepos.cpp +++ b/src/mame/audio/polepos.cpp @@ -225,7 +225,7 @@ polepos_sound_device::polepos_sound_device(const machine_config &mconfig, const void polepos_sound_device::device_start() { - m_stream = stream_alloc(0, 1, OUTPUT_RATE); + m_stream = stream_alloc_legacy(0, 1, OUTPUT_RATE); m_sample_msb = m_sample_lsb = 0; m_sample_enable = 0; @@ -251,10 +251,10 @@ void polepos_sound_device::device_reset() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void polepos_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void polepos_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { uint32_t step, clock, slot; uint8_t *base; diff --git a/src/mame/audio/polepos.h b/src/mame/audio/polepos.h index 69c8852ac75..430078088b2 100644 --- a/src/mame/audio/polepos.h +++ b/src/mame/audio/polepos.h @@ -19,7 +19,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; public: DECLARE_WRITE_LINE_MEMBER(clson_w); diff --git a/src/mame/audio/redbaron.cpp b/src/mame/audio/redbaron.cpp index 486dffb4cea..c08036c7d3b 100644 --- a/src/mame/audio/redbaron.cpp +++ b/src/mame/audio/redbaron.cpp @@ -102,16 +102,16 @@ void redbaron_sound_device::device_start() m_vol_crash[i] = 32767 * r0 / (r0 + r1); } - m_channel = stream_alloc(0, 1, OUTPUT_RATE); + m_channel = stream_alloc_legacy(0, 1, OUTPUT_RATE); } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void redbaron_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void redbaron_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; while( samples-- ) diff --git a/src/mame/audio/redbaron.h b/src/mame/audio/redbaron.h index c5c81cb3264..a66b74dff21 100644 --- a/src/mame/audio/redbaron.h +++ b/src/mame/audio/redbaron.h @@ -21,7 +21,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: std::unique_ptr m_vol_lookup; diff --git a/src/mame/audio/segag80.cpp b/src/mame/audio/segag80.cpp index 6d266f3ba24..aa377894643 100644 --- a/src/mame/audio/segag80.cpp +++ b/src/mame/audio/segag80.cpp @@ -127,7 +127,7 @@ void segag80_audio_device_base::write_ay(offs_t addr, uint8_t data) DEFINE_DEVICE_TYPE(ELIMINATOR_AUDIO, elim_audio_device, "elim_audio", "Eliminator Sound Board") elim_audio_device::elim_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : - segag80_audio_device_base(mconfig, ELIMINATOR_AUDIO, tag, owner, clock, 0xfe, 0xff, false, NETLIST_NAME(elim), 5000.0) + segag80_audio_device_base(mconfig, ELIMINATOR_AUDIO, tag, owner, clock, 0xfe, 0xff, false, NETLIST_NAME(elim), 0.15) { } @@ -142,7 +142,7 @@ elim_audio_device::elim_audio_device(const machine_config &mconfig, const char * DEFINE_DEVICE_TYPE(ZEKTOR_AUDIO, zektor_audio_device, "zektor_audio", "Zektor Sound Board") zektor_audio_device::zektor_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : - segag80_audio_device_base(mconfig, ZEKTOR_AUDIO, tag, owner, clock, 0xfe, 0xff, true, NETLIST_NAME(zektor), 5000.0) + segag80_audio_device_base(mconfig, ZEKTOR_AUDIO, tag, owner, clock, 0xfe, 0xff, true, NETLIST_NAME(zektor), 0.15) { } @@ -157,7 +157,7 @@ zektor_audio_device::zektor_audio_device(const machine_config &mconfig, const ch DEFINE_DEVICE_TYPE(SPACE_FURY_AUDIO, spacfury_audio_device, "spcfury_audio", "Space Fury Sound Board") spacfury_audio_device::spacfury_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : - segag80_audio_device_base(mconfig, SPACE_FURY_AUDIO, tag, owner, clock, 0xc7, 0x3f, false, NETLIST_NAME(spacfury), 60000.0) + segag80_audio_device_base(mconfig, SPACE_FURY_AUDIO, tag, owner, clock, 0xc7, 0x3f, false, NETLIST_NAME(spacfury), 2.0) { } @@ -172,6 +172,6 @@ spacfury_audio_device::spacfury_audio_device(const machine_config &mconfig, cons DEFINE_DEVICE_TYPE(ASTRO_BLASTER_AUDIO, astrob_audio_device, "astrob_audio", "Astro Blaster Sound Board") astrob_audio_device::astrob_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : - segag80_audio_device_base(mconfig, ASTRO_BLASTER_AUDIO, tag, owner, clock, 0xff, 0xff, false, NETLIST_NAME(astrob), 25000.0) + segag80_audio_device_base(mconfig, ASTRO_BLASTER_AUDIO, tag, owner, clock, 0xff, 0xff, false, NETLIST_NAME(astrob), 1.0) { } diff --git a/src/mame/audio/segag80r.cpp b/src/mame/audio/segag80r.cpp index 1662c2f2258..90a8463cbad 100644 --- a/src/mame/audio/segag80r.cpp +++ b/src/mame/audio/segag80r.cpp @@ -46,7 +46,7 @@ void sega005_sound_device::device_start() segag80r_state *state = machine().driver_data(); /* create the stream */ - m_sega005_stream = machine().sound().stream_alloc(*this, 0, 1, SEGA005_COUNTER_FREQ); + m_sega005_stream = stream_alloc_legacy(0, 1, SEGA005_COUNTER_FREQ); /* create a timer for the 555 */ m_sega005_sound_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sega005_sound_device::sega005_auto_timer), this)); @@ -57,10 +57,10 @@ void sega005_sound_device::device_start() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void sega005_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void sega005_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { segag80r_state *state = machine().driver_data(); const uint8_t *sound_prom = state->memregion("proms")->base(); diff --git a/src/mame/audio/segausb.cpp b/src/mame/audio/segausb.cpp index 16293500ed0..ef6343e945d 100644 --- a/src/mame/audio/segausb.cpp +++ b/src/mame/audio/segausb.cpp @@ -100,7 +100,7 @@ void usb_sound_device::device_start() #else - m_stream = stream_alloc(0, 1, USB_2MHZ_CLOCK); + m_stream = stream_alloc_legacy(0, 1, USB_2MHZ_CLOCK); m_noise_shift = 0x15555; @@ -451,10 +451,10 @@ void usb_sound_device::env_w(int which, u8 offset, u8 data) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void usb_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void usb_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *dest = outputs[0]; diff --git a/src/mame/audio/segausb.h b/src/mame/audio/segausb.h index afed3b688af..e34d892142d 100644 --- a/src/mame/audio/segausb.h +++ b/src/mame/audio/segausb.h @@ -62,7 +62,7 @@ protected: #if (!ENABLE_SEGAUSB_NETLIST) // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; #endif private: diff --git a/src/mame/audio/seibu.cpp b/src/mame/audio/seibu.cpp index 798338a29a6..17075367960 100644 --- a/src/mame/audio/seibu.cpp +++ b/src/mame/audio/seibu.cpp @@ -385,7 +385,7 @@ seibu_adpcm_device::seibu_adpcm_device(const machine_config &mconfig, const char void seibu_adpcm_device::device_start() { m_playing = 0; - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock()); + m_stream = stream_alloc_legacy(0, 1, clock()); m_adpcm.reset(); save_item(NAME(m_current)); @@ -443,10 +443,10 @@ void seibu_adpcm_device::ctl_w(u8 data) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void seibu_adpcm_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void seibu_adpcm_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *dest = outputs[0]; diff --git a/src/mame/audio/seibu.h b/src/mame/audio/seibu.h index 396f4612d0b..9954b462205 100644 --- a/src/mame/audio/seibu.h +++ b/src/mame/audio/seibu.h @@ -145,7 +145,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: // internal state diff --git a/src/mame/audio/snk6502.cpp b/src/mame/audio/snk6502.cpp index 70247ff9c5e..4d5550e08c3 100644 --- a/src/mame/audio/snk6502.cpp +++ b/src/mame/audio/snk6502.cpp @@ -165,7 +165,7 @@ void snk6502_sound_device::device_start() // 38.99 Hz update (according to schematic) set_music_clock(M_LN2 * (RES_K(18) * 2 + RES_K(1)) * CAP_U(1)); - m_tone_stream = machine().sound().stream_alloc(*this, 0, 1, SAMPLE_RATE); + m_tone_stream = stream_alloc_legacy(0, 1, SAMPLE_RATE); for (int i = 0; i < NUM_CHANNELS; i++) { @@ -509,10 +509,10 @@ void snk6502_sound_device::speech_w(uint8_t data, const uint16_t *table, int sta */ //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void snk6502_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void snk6502_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; diff --git a/src/mame/audio/snk6502.h b/src/mame/audio/snk6502.h index dab65476835..99c0178120c 100644 --- a/src/mame/audio/snk6502.h +++ b/src/mame/audio/snk6502.h @@ -40,7 +40,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: static constexpr unsigned NUM_CHANNELS = 3; diff --git a/src/mame/audio/socrates.cpp b/src/mame/audio/socrates.cpp index 0b86830d412..4b49ec0b5bd 100644 --- a/src/mame/audio/socrates.cpp +++ b/src/mame/audio/socrates.cpp @@ -43,15 +43,15 @@ void socrates_snd_device::device_start() m_DAC_output = 0x00; /* output */ m_state[0] = m_state[1] = m_state[2] = 0; m_accum[0] = m_accum[1] = m_accum[2] = 0xFF; - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock() ? clock() : machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 1, clock() ? clock() : machine().sample_rate()); } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void socrates_snd_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void socrates_snd_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { for (int i = 0; i < samples; i++) { diff --git a/src/mame/audio/socrates.h b/src/mame/audio/socrates.h index 4f840bca384..cd2d240079c 100644 --- a/src/mame/audio/socrates.h +++ b/src/mame/audio/socrates.h @@ -22,7 +22,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: void snd_clock(); static const uint8_t s_volumeLUT[]; diff --git a/src/mame/audio/special.cpp b/src/mame/audio/special.cpp index e48d8a37c4a..9a1383bfec0 100644 --- a/src/mame/audio/special.cpp +++ b/src/mame/audio/special.cpp @@ -41,15 +41,15 @@ specimx_sound_device::specimx_sound_device(const machine_config &mconfig, const void specimx_sound_device::device_start() { m_specimx_input[0] = m_specimx_input[1] = m_specimx_input[2] = 0; - m_mixer_channel = stream_alloc(0, 1, machine().sample_rate()); + m_mixer_channel = stream_alloc_legacy(0, 1, machine().sample_rate()); } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void specimx_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void specimx_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int16_t channel_0_signal; int16_t channel_1_signal; diff --git a/src/mame/audio/special.h b/src/mame/audio/special.h index 8fbcfe176cc..daaa983a2d7 100644 --- a/src/mame/audio/special.h +++ b/src/mame/audio/special.h @@ -26,7 +26,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream *m_mixer_channel; diff --git a/src/mame/audio/svis_snd.cpp b/src/mame/audio/svis_snd.cpp index a51dbb15d35..91fdd2dcce1 100644 --- a/src/mame/audio/svis_snd.cpp +++ b/src/mame/audio/svis_snd.cpp @@ -45,15 +45,15 @@ void svision_sound_device::device_start() memset(&m_noise, 0, sizeof(m_noise)); memset(m_channel, 0, sizeof(m_channel)); - m_mixer_channel = stream_alloc(0, 2, machine().sample_rate()); + m_mixer_channel = stream_alloc_legacy(0, 2, machine().sample_rate()); } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void svision_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void svision_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *left=outputs[0], *right=outputs[1]; diff --git a/src/mame/audio/svis_snd.h b/src/mame/audio/svis_snd.h index fc761ba73ba..9b7efad6353 100644 --- a/src/mame/audio/svis_snd.h +++ b/src/mame/audio/svis_snd.h @@ -41,7 +41,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: struct NOISE diff --git a/src/mame/audio/tiamc1.cpp b/src/mame/audio/tiamc1.cpp index 0bfc371802a..d99de897c22 100644 --- a/src/mame/audio/tiamc1.cpp +++ b/src/mame/audio/tiamc1.cpp @@ -77,7 +77,7 @@ void tiamc1_sound_device::device_start() timer8253_reset(&m_timer0); timer8253_reset(&m_timer1); - m_channel = stream_alloc(0, 1, clock() / CLOCK_DIVIDER); + m_channel = stream_alloc_legacy(0, 1, clock() / CLOCK_DIVIDER); m_timer1_divider = 0; @@ -104,10 +104,10 @@ void tiamc1_sound_device::device_start() //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void tiamc1_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void tiamc1_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int count, o0, o1, o2, len, orval = 0; diff --git a/src/mame/audio/tiamc1.h b/src/mame/audio/tiamc1.h index 83ae793d08a..d8834816899 100644 --- a/src/mame/audio/tiamc1.h +++ b/src/mame/audio/tiamc1.h @@ -25,7 +25,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: struct timer8253chan diff --git a/src/mame/audio/timeplt.cpp b/src/mame/audio/timeplt.cpp index f0302ec0be2..7fe94dd46c7 100644 --- a/src/mame/audio/timeplt.cpp +++ b/src/mame/audio/timeplt.cpp @@ -228,11 +228,11 @@ void locomotn_audio_device::device_add_mconfig(machine_config &config) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void timeplt_audio_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void timeplt_audio_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // should never get here - fatalerror("sound_stream_update called; not applicable to legacy sound devices\n"); + fatalerror("sound_stream_update_legacy called; not applicable to legacy sound devices\n"); } diff --git a/src/mame/audio/timeplt.h b/src/mame/audio/timeplt.h index 195c6c79830..8e69d20caa1 100644 --- a/src/mame/audio/timeplt.h +++ b/src/mame/audio/timeplt.h @@ -27,7 +27,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; void filter_w(offs_t offset, uint8_t data); uint8_t portB_r(); diff --git a/src/mame/audio/trackfld.cpp b/src/mame/audio/trackfld.cpp index 77c474809c5..bf139f858e9 100644 --- a/src/mame/audio/trackfld.cpp +++ b/src/mame/audio/trackfld.cpp @@ -132,11 +132,11 @@ WRITE_LINE_MEMBER(trackfld_audio_device::sh_irqtrigger_w) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void trackfld_audio_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void trackfld_audio_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // should never get here - fatalerror("sound_stream_update called; not applicable to legacy sound devices\n"); + fatalerror("sound_stream_update_legacy called; not applicable to legacy sound devices\n"); } diff --git a/src/mame/audio/trackfld.h b/src/mame/audio/trackfld.h index fbcff2817b1..f1502443562 100644 --- a/src/mame/audio/trackfld.h +++ b/src/mame/audio/trackfld.h @@ -34,7 +34,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: optional_device m_audiocpu; diff --git a/src/mame/audio/turrett.cpp b/src/mame/audio/turrett.cpp index 397c27c55e1..4d8414b0118 100644 --- a/src/mame/audio/turrett.cpp +++ b/src/mame/audio/turrett.cpp @@ -47,7 +47,7 @@ void turrett_device::device_start() space().cache(m_cache); // Create the sound stream - m_stream = machine().sound().stream_alloc(*this, 0, 2, 44100); + m_stream = stream_alloc_legacy(0, 2, 44100); // Create the volume table for (int i = 0; i < 0x4f; ++i) @@ -78,10 +78,10 @@ void turrett_device::device_reset() //------------------------------------------------- -// sound_stream_update - update sound stream +// sound_stream_update_legacy - update sound stream //------------------------------------------------- -void turrett_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void turrett_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // Silence the buffers memset(outputs[0], 0x00, sizeof(stream_sample_t) * samples); diff --git a/src/mame/audio/tvc.cpp b/src/mame/audio/tvc.cpp index 0d05b871361..e30c79ef959 100644 --- a/src/mame/audio/tvc.cpp +++ b/src/mame/audio/tvc.cpp @@ -31,7 +31,7 @@ void tvc_sound_device::device_start() // resolve callbacks m_write_sndint.resolve_safe(); - m_stream = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 1, machine().sample_rate()); m_sndint_timer = timer_alloc(TIMER_SNDINT); } @@ -58,19 +58,19 @@ void tvc_sound_device::device_timer(emu_timer &timer, device_timer_id id, int pa } //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void tvc_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void tvc_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int rate = machine().sample_rate() / 2; - + stream_sample_t *output = outputs[0]; if (m_enabled && m_freq) { while( samples-- > 0 ) { - *outputs[0]++ = m_signal * (m_volume * 0x0800); + *output++ = m_signal * (m_volume * 0x0800); m_incr -= m_freq; while(m_incr < 0) { @@ -82,7 +82,7 @@ void tvc_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t else { // fill output with 0 if the sound is disabled - memset(outputs[0], 0, samples * sizeof(stream_sample_t)); + memset(output, 0, samples * sizeof(stream_sample_t)); } } diff --git a/src/mame/audio/tvc.h b/src/mame/audio/tvc.h index 04358375304..669184a0a2b 100644 --- a/src/mame/audio/tvc.h +++ b/src/mame/audio/tvc.h @@ -34,7 +34,7 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: static const device_timer_id TIMER_SNDINT = 0; diff --git a/src/mame/audio/tx1.cpp b/src/mame/audio/tx1.cpp index e415fb54669..a6dd9d2aeb6 100644 --- a/src/mame/audio/tx1.cpp +++ b/src/mame/audio/tx1.cpp @@ -111,7 +111,7 @@ void tx1_sound_device::device_start() /* Allocate the stream */ - m_stream = machine().sound().stream_alloc(*this, 0, 2, machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 2, machine().sample_rate()); m_freq_to_step = (double)(1 << TX1_FRAC) / (double)machine().sample_rate(); /* Compute the engine resistor weights */ @@ -356,10 +356,10 @@ static inline void update_engine(int eng[4]) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void tx1_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void tx1_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { uint32_t step_0, step_1, step_2; double /*gain_0, gain_1,*/ gain_2, gain_3; @@ -662,7 +662,7 @@ void buggyboy_sound_device::device_start() m_eng_voltages[i] = combine_weights(aweights, BIT(tmp[i], 0), BIT(tmp[i], 1), BIT(tmp[i], 2), BIT(tmp[i], 3)); /* Allocate the stream */ - m_stream = machine().sound().stream_alloc(*this, 0, 2, machine().sample_rate()); + m_stream = stream_alloc_legacy(0, 2, machine().sample_rate()); m_freq_to_step = (double)(1 << 24) / (double)machine().sample_rate(); } @@ -763,10 +763,10 @@ void buggyboy_sound_device::ym2_b_w(uint8_t data) //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void buggyboy_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void buggyboy_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { /* This is admittedly a bit of a hack job... */ diff --git a/src/mame/audio/tx1.h b/src/mame/audio/tx1.h index b27ddd0fa73..71e228e324c 100644 --- a/src/mame/audio/tx1.h +++ b/src/mame/audio/tx1.h @@ -73,7 +73,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; void tx1_sound_io(address_map &map); void tx1_sound_prg(address_map &map); @@ -155,7 +155,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; void ym1_a_w(uint8_t data); diff --git a/src/mame/audio/vboy.cpp b/src/mame/audio/vboy.cpp index 05d9c3a3779..37eec2ee80b 100644 --- a/src/mame/audio/vboy.cpp +++ b/src/mame/audio/vboy.cpp @@ -209,7 +209,7 @@ void vboysnd_device::device_start() { uint32_t rate = clock() / 120; // create the stream - m_stream = machine().sound().stream_alloc(*this, 0, 2, rate); + m_stream = stream_alloc_legacy(0, 2, rate); m_timer = timer_alloc(0, nullptr); m_timer->adjust(attotime::zero, 0, rate ? attotime::from_hz(rate / 4) : attotime::never); @@ -265,11 +265,11 @@ void vboysnd_device::device_timer(emu_timer &timer, device_timer_id tid, int par } //------------------------------------------------- -// sound_stream_update - handle update requests for +// sound_stream_update_legacy - handle update requests for // our sound stream //------------------------------------------------- -void vboysnd_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void vboysnd_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *outL, *outR; int len, i, j, channel; diff --git a/src/mame/audio/vboy.h b/src/mame/audio/vboy.h index 6ee190b83b2..f8d3a050272 100644 --- a/src/mame/audio/vboy.h +++ b/src/mame/audio/vboy.h @@ -72,7 +72,7 @@ protected: virtual void device_reset() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; s_snd_channel snd_channel[5]; diff --git a/src/mame/audio/vc4000.cpp b/src/mame/audio/vc4000.cpp index df4a308f619..84c19a2d942 100644 --- a/src/mame/audio/vc4000.cpp +++ b/src/mame/audio/vc4000.cpp @@ -31,15 +31,15 @@ vc4000_sound_device::vc4000_sound_device(const machine_config &mconfig, const ch void vc4000_sound_device::device_start() { - m_channel = stream_alloc(0, 1, machine().sample_rate()); + m_channel = stream_alloc_legacy(0, 1, machine().sample_rate()); } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void vc4000_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void vc4000_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int i; stream_sample_t *buffer = outputs[0]; diff --git a/src/mame/audio/vc4000.h b/src/mame/audio/vc4000.h index e906dc601c4..3917ffa2776 100644 --- a/src/mame/audio/vc4000.h +++ b/src/mame/audio/vc4000.h @@ -28,7 +28,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; public: void soundport_w(int mode, int data); diff --git a/src/mame/audio/warpwarp.cpp b/src/mame/audio/warpwarp.cpp index 2e4075771ea..9e00ff069fd 100644 --- a/src/mame/audio/warpwarp.cpp +++ b/src/mame/audio/warpwarp.cpp @@ -52,7 +52,7 @@ void warpwarp_sound_device::device_start() m_clock_16h = clock() / 3 / 2 / 16; m_clock_1v = clock() / 3 / 2 / 384; - m_channel = machine().sound().stream_alloc(*this, 0, 1, m_clock_16h); + m_channel = stream_alloc_legacy(0, 1, m_clock_16h); m_sound_volume_timer = timer_alloc(TIMER_SOUND_VOLUME_DECAY); m_music_volume_timer = timer_alloc(TIMER_MUSIC_VOLUME_DECAY); @@ -169,10 +169,10 @@ void warpwarp_sound_device::music2_w(u8 data) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void warpwarp_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void warpwarp_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; diff --git a/src/mame/audio/warpwarp.h b/src/mame/audio/warpwarp.h index c8ca872d239..7bf06a4dc25 100644 --- a/src/mame/audio/warpwarp.h +++ b/src/mame/audio/warpwarp.h @@ -27,7 +27,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + 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 device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; diff --git a/src/mame/audio/wiping.cpp b/src/mame/audio/wiping.cpp index 56a0c56ee96..0b83b88f8ac 100644 --- a/src/mame/audio/wiping.cpp +++ b/src/mame/audio/wiping.cpp @@ -42,7 +42,7 @@ void wiping_sound_device::device_start() wp_sound_channel *voice; /* get stream channels */ - m_stream = machine().sound().stream_alloc(*this, 0, 1, clock()/2); + m_stream = stream_alloc_legacy(0, 1, clock()/2); /* allocate a buffer to mix into - 1 second's worth should be more than enough */ m_mixer_buffer = make_unique_clear(clock()/2); @@ -150,10 +150,10 @@ void wiping_sound_device::sound_w(offs_t offset, uint8_t data) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void wiping_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void wiping_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; wp_sound_channel *voice; diff --git a/src/mame/audio/wiping.h b/src/mame/audio/wiping.h index 43ae2caf98a..d10a26d2848 100644 --- a/src/mame/audio/wiping.h +++ b/src/mame/audio/wiping.h @@ -17,7 +17,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: /* 8 voices max */ diff --git a/src/mame/audio/wswan.cpp b/src/mame/audio/wswan.cpp index 8089d01a6d1..0e6442cea6d 100644 --- a/src/mame/audio/wswan.cpp +++ b/src/mame/audio/wswan.cpp @@ -62,7 +62,7 @@ constexpr int clk_div = 64; void wswan_sound_device::device_start() { - m_channel = stream_alloc(0, 2, clock() / clk_div); + m_channel = stream_alloc_legacy(0, 2, clock() / clk_div); save_item(NAME(m_sweep_step)); save_item(NAME(m_sweep_time)); @@ -164,13 +164,15 @@ int wswan_sound_device::fetch_sample(int channel, int offset) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void wswan_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void wswan_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t sample, left, right; + stream_sample_t *outputl = outputs[0]; + stream_sample_t *outputr = outputs[1]; while( samples-- > 0 ) { left = right = 0; @@ -269,8 +271,8 @@ void wswan_sound_device::sound_stream_update(sound_stream &stream, stream_sample left <<= 5; right <<= 5; - *(outputs[0]++) = left; - *(outputs[1]++) = right; + *outputl++ = left; + *outputr++ = right; } } diff --git a/src/mame/audio/wswan.h b/src/mame/audio/wswan.h index a23655e0b0b..e3c4974bf54 100644 --- a/src/mame/audio/wswan.h +++ b/src/mame/audio/wswan.h @@ -59,7 +59,7 @@ protected: virtual void rom_bank_updated() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: void wswan_ch_set_freq( CHAN *ch, uint16_t freq ); diff --git a/src/mame/audio/xavix.cpp b/src/mame/audio/xavix.cpp index 3d01d8812fd..a4b2d12dccb 100644 --- a/src/mame/audio/xavix.cpp +++ b/src/mame/audio/xavix.cpp @@ -27,7 +27,7 @@ void xavix_sound_device::device_start() m_readregs_cb.resolve_safe(0xff); m_readsamples_cb.resolve_safe(0x80); - m_stream = stream_alloc(0, 2, 163840); + m_stream = stream_alloc_legacy(0, 2, 163840); } void xavix_sound_device::device_reset() @@ -43,7 +43,7 @@ void xavix_sound_device::device_reset() } -void xavix_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void xavix_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { // reset the output stream memset(outputs[0], 0, samples * sizeof(*outputs[0])); diff --git a/src/mame/audio/zaccaria.cpp b/src/mame/audio/zaccaria.cpp index e597c48eeab..f7b31e245e5 100644 --- a/src/mame/audio/zaccaria.cpp +++ b/src/mame/audio/zaccaria.cpp @@ -472,14 +472,14 @@ void zac1b11142_audio_device::device_add_mconfig(machine_config &config) * The 5200 output is a current source providing between 0 and 1.5mA. * This is explained in detail in the datasheet. */ - NETLIST_STREAM_INPUT(config, "sound_nl:cin6", 6, "I_SP.I").set_mult_offset(750e-6 / 16384.0, 750e-6); + NETLIST_STREAM_INPUT(config, "sound_nl:cin6", 6, "I_SP.I").set_mult_offset(2.0 * 750e-6, 750e-6); /* DAC * The 1408 output is a current sink providing between 0 and 2.0mA. * This is explained in detail in the datasheet. */ - NETLIST_STREAM_INPUT(config, "sound_nl:cin7", 7, "I_DAC.I").set_mult_offset(1e-3 / 32768.0, 1e-3); + NETLIST_STREAM_INPUT(config, "sound_nl:cin7", 7, "I_DAC.I").set_mult_offset(1e-3, 1e-3); - NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "C7.2").set_mult_offset(3000.0 * 10.0, 0.0); // FIXME: no clue what numbers to use here + NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "C7.2").set_mult_offset(3000.0 * 10.0 / 32768.0, 0.0); // FIXME: no clue what numbers to use here // Potentiometers NETLIST_ANALOG_INPUT(config, "sound_nl:pot1", "P1.DIAL"); diff --git a/src/mame/drivers/1942.cpp b/src/mame/drivers/1942.cpp index 974a67710da..ee44a0caaf0 100644 --- a/src/mame/drivers/1942.cpp +++ b/src/mame/drivers/1942.cpp @@ -552,7 +552,7 @@ void _1942_state::_1942(machine_config &config) NETLIST_STREAM_INPUT(config, "snd_nl:cin4", 4, "R_AY2_2.R"); NETLIST_STREAM_INPUT(config, "snd_nl:cin5", 5, "R_AY2_3.R"); - NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "R1.1").set_mult_offset(70000.0, 0.0); + NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "R1.1").set_mult_offset(70000.0 / 32768.0, 0.0); //NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "VR.2"); } diff --git a/src/mame/drivers/carpolo.cpp b/src/mame/drivers/carpolo.cpp index 7af10d7fb75..3d878d9abc6 100644 --- a/src/mame/drivers/carpolo.cpp +++ b/src/mame/drivers/carpolo.cpp @@ -304,7 +304,7 @@ void carpolo_state::carpolo(machine_config &config) NETLIST_LOGIC_INPUT(config, "sound_nl:player_crash4", "PL4_CRASH.IN", 0); // Temporarily just tied to an arbitrary value to preserve lack of audio. - NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "PL1_CRASH.GND").set_mult_offset(10000.0, 0.0); + NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "PL1_CRASH.GND").set_mult_offset(10000.0 / 32768.0, 0.0); } diff --git a/src/mame/drivers/cocoloco.cpp b/src/mame/drivers/cocoloco.cpp index 525a33b46be..37e9ac204ba 100644 --- a/src/mame/drivers/cocoloco.cpp +++ b/src/mame/drivers/cocoloco.cpp @@ -503,7 +503,7 @@ void cocoloco_state::cocoloco(machine_config &config) NETLIST_STREAM_INPUT(config, "snd_nl:cin1", 1, "R_AY1_2.R"); NETLIST_STREAM_INPUT(config, "snd_nl:cin2", 2, "R_AY1_3.R"); - NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "RAMP.1").set_mult_offset(30000.0 * 1.5, 0); + NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "RAMP.1").set_mult_offset(30000.0 * 1.5 / 32768.0, 0); } diff --git a/src/mame/drivers/destroyr.cpp b/src/mame/drivers/destroyr.cpp index dc2c362a920..8d328ae2003 100644 --- a/src/mame/drivers/destroyr.cpp +++ b/src/mame/drivers/destroyr.cpp @@ -532,7 +532,7 @@ void destroyr_state::destroyr(machine_config &config) NETLIST_LOGIC_INPUT(config, "sound_nl:hexplo", "HE.IN", 0); NETLIST_LOGIC_INPUT(config, "sound_nl:lexplo", "LE.IN", 0); - NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "OUTPUT").set_mult_offset(32767.0, 0.0); + NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "OUTPUT").set_mult_offset(1.0, 0.0); } diff --git a/src/mame/drivers/esq1.cpp b/src/mame/drivers/esq1.cpp index 55eca4c0d23..b0a9e97a293 100644 --- a/src/mame/drivers/esq1.cpp +++ b/src/mame/drivers/esq1.cpp @@ -210,7 +210,7 @@ protected: virtual void device_start() override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: struct filter { @@ -334,13 +334,13 @@ void esq1_filters::recalc_filter(filter &f) void esq1_filters::device_start() { - stream = stream_alloc(8, 2, 44100); + stream = stream_alloc_legacy(8, 2, 44100); memset(filters, 0, sizeof(filters)); for(auto & elem : filters) recalc_filter(elem); } -void esq1_filters::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void esq1_filters::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { /* if(0) { for(int i=0; i<8; i++) diff --git a/src/mame/drivers/flyball.cpp b/src/mame/drivers/flyball.cpp index ad9cccec8e1..a45064ae13f 100644 --- a/src/mame/drivers/flyball.cpp +++ b/src/mame/drivers/flyball.cpp @@ -515,7 +515,7 @@ void flyball_state::flyball(machine_config &config) NETLIST_ANALOG_INPUT(config, "sound_nl:bat_volume", "R75.DIAL"); NETLIST_ANALOG_INPUT(config, "sound_nl:main_volume", "R95.DIAL"); - NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "OUTPUT").set_mult_offset(32767.0 / 0.13, -(32767.0 / 0.13) * 0.78); + NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "OUTPUT").set_mult_offset(1.0 / 0.13, -(1.0 / 0.13) * 0.78); } diff --git a/src/mame/drivers/galaxian.cpp b/src/mame/drivers/galaxian.cpp index b5c515b2342..9a3b5b9f375 100644 --- a/src/mame/drivers/galaxian.cpp +++ b/src/mame/drivers/galaxian.cpp @@ -6129,7 +6129,7 @@ void galaxian_state::konami_sound_1x_ay8910(machine_config &config) NETLIST_STREAM_INPUT(config, "konami:cin1", 1, "R_AY3D_B.R"); NETLIST_STREAM_INPUT(config, "konami:cin2", 2, "R_AY3D_C.R"); - NETLIST_STREAM_OUTPUT(config, "konami:cout0", 0, "OUT").set_mult_offset(30000.0 / 0.05, 0.0); + NETLIST_STREAM_OUTPUT(config, "konami:cout0", 0, "OUT").set_mult_offset(1.0 / 0.05, 0.0); } @@ -6186,7 +6186,7 @@ void galaxian_state::konami_sound_2x_ay8910(machine_config &config) NETLIST_STREAM_INPUT(config, "konami:cin3", 3, "R_AY3C_A.R"); NETLIST_STREAM_INPUT(config, "konami:cin4", 4, "R_AY3C_B.R"); NETLIST_STREAM_INPUT(config, "konami:cin5", 5, "R_AY3C_C.R"); - NETLIST_STREAM_OUTPUT(config, "konami:cout0", 0, "OUT").set_mult_offset(30000.0 / 0.05, 0.0); + NETLIST_STREAM_OUTPUT(config, "konami:cout0", 0, "OUT").set_mult_offset(1.0 / 0.05, 0.0); } diff --git a/src/mame/drivers/gamemachine.cpp b/src/mame/drivers/gamemachine.cpp index e0c8e355916..c0e28fd8661 100644 --- a/src/mame/drivers/gamemachine.cpp +++ b/src/mame/drivers/gamemachine.cpp @@ -278,7 +278,7 @@ void tgm_state::tgm(machine_config &config) .set_source(NETLIST_NAME(gamemachine)) .add_route(ALL_OUTPUTS, "speaker", 1.0); - NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "SPK1.2").set_mult_offset(-10000.0, 10000.0 * 3.75); + NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "SPK1.2").set_mult_offset(-10000.0 / 32768.0, 10000.0 * 3.75 / 32768.0); NETLIST_LOGIC_INPUT(config, "snd_nl:p08", "P08.IN", 0); NETLIST_LOGIC_INPUT(config, "snd_nl:p09", "P09.IN", 0); diff --git a/src/mame/drivers/istrebiteli.cpp b/src/mame/drivers/istrebiteli.cpp index fe591d8b347..a1ba11ca972 100644 --- a/src/mame/drivers/istrebiteli.cpp +++ b/src/mame/drivers/istrebiteli.cpp @@ -45,7 +45,7 @@ protected: virtual void device_start() override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: // internal state @@ -81,11 +81,11 @@ istrebiteli_sound_device::istrebiteli_sound_device(const machine_config &mconfig void istrebiteli_sound_device::device_start() { - m_channel = stream_alloc(0, 1, clock() / 2); + m_channel = stream_alloc_legacy(0, 1, clock() / 2); m_rom = machine().root_device().memregion("soundrom")->base(); } -void istrebiteli_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void istrebiteli_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *sample = outputs[0]; diff --git a/src/mame/drivers/milton6805.cpp b/src/mame/drivers/milton6805.cpp index 3142c3c6493..efda2a0886d 100644 --- a/src/mame/drivers/milton6805.cpp +++ b/src/mame/drivers/milton6805.cpp @@ -90,7 +90,7 @@ public: protected: virtual void device_start() override; - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream *m_stream; @@ -108,11 +108,11 @@ milton_filter_device::milton_filter_device(const machine_config &mconfig, const void milton_filter_device::device_start() { - m_stream = stream_alloc(1, 1, machine().sample_rate()); + m_stream = stream_alloc_legacy(1, 1, machine().sample_rate()); m_led_out.resolve(); } -void milton_filter_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void milton_filter_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { int level = 0; diff --git a/src/mame/drivers/ninjaw.cpp b/src/mame/drivers/ninjaw.cpp index 6045f8daf5e..3cff502baf7 100644 --- a/src/mame/drivers/ninjaw.cpp +++ b/src/mame/drivers/ninjaw.cpp @@ -618,7 +618,7 @@ protected: virtual void device_start(); // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples); private: // internal state @@ -654,10 +654,10 @@ void subwoofer_device::device_start() } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void subwoofer_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void subwoofer_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { } diff --git a/src/mame/drivers/popeye.cpp b/src/mame/drivers/popeye.cpp index 19429df5a63..3d240a079c7 100644 --- a/src/mame/drivers/popeye.cpp +++ b/src/mame/drivers/popeye.cpp @@ -576,7 +576,7 @@ void tpp2_state::config(machine_config &config) NETLIST_STREAM_INPUT(config, "snd_nl:cin1", 1, "R_AY1_2.R"); NETLIST_STREAM_INPUT(config, "snd_nl:cin2", 2, "R_AY1_3.R"); - NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "ROUT.1").set_mult_offset(30000.0, -65000.0); + NETLIST_STREAM_OUTPUT(config, "snd_nl:cout0", 0, "ROUT.1").set_mult_offset(1.0, -2.0); } void popeyebl_state::config(machine_config& config) diff --git a/src/mame/drivers/pv1000.cpp b/src/mame/drivers/pv1000.cpp index 682fb7632b4..a78004c2ad4 100644 --- a/src/mame/drivers/pv1000.cpp +++ b/src/mame/drivers/pv1000.cpp @@ -31,7 +31,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: @@ -60,7 +60,7 @@ pv1000_sound_device::pv1000_sound_device(const machine_config &mconfig, const ch void pv1000_sound_device::device_start() { - m_sh_channel = machine().sound().stream_alloc(*this, 0, 1, clock() / 1024); + m_sh_channel = stream_alloc_legacy(0, 1, clock() / 1024); save_item(NAME(m_voice[0].count)); save_item(NAME(m_voice[0].period)); @@ -84,7 +84,7 @@ void pv1000_sound_device::voice_w(offs_t offset, uint8_t data) } //------------------------------------------------- -// sound_stream_update - handle a stream update +// sound_stream_update_legacy - handle a stream update //------------------------------------------------- @@ -98,7 +98,7 @@ void pv1000_sound_device::voice_w(offs_t offset, uint8_t data) Note: the register periods are inverted. */ -void pv1000_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void pv1000_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; diff --git a/src/mame/drivers/segas16b.cpp b/src/mame/drivers/segas16b.cpp index 280d33a625d..4dfaac8ae8c 100644 --- a/src/mame/drivers/segas16b.cpp +++ b/src/mame/drivers/segas16b.cpp @@ -3991,13 +3991,13 @@ void segas16b_state::system16b(machine_config &config) // please refer to the netlist code for details about // the multipliers and offsets. NETLIST_STREAM_INPUT(config, "netlist:cin0", 0, "CH1.IN") - .set_mult_offset(0.5/32768.0, 2.5); + .set_mult_offset(0.5, 2.5); NETLIST_STREAM_INPUT(config, "netlist:cin1", 1, "CH2.IN") - .set_mult_offset(0.5/32768.0, 2.5); + .set_mult_offset(0.5, 2.5); NETLIST_STREAM_INPUT(config, "netlist:cin2", 2, "SPEECH.I") - .set_mult_offset(0.001020/32768.0/2.0, 0.001020/2.0); + .set_mult_offset(0.001020/2.0, 0.001020/2.0); - NETLIST_STREAM_OUTPUT(config, "netlist:cout0", 0, "OUT").set_mult_offset(30000.0 / 0.2, 0.0); + NETLIST_STREAM_OUTPUT(config, "netlist:cout0", 0, "OUT").set_mult_offset(1.0 / 0.2, 0.0); #else YM2151(config, m_ym2151, MASTER_CLOCK_8MHz/2).add_route(ALL_OUTPUTS, "mono", 0.43); diff --git a/src/mame/drivers/starcrus.cpp b/src/mame/drivers/starcrus.cpp index 4e1cc1c9e25..d76011e7c24 100644 --- a/src/mame/drivers/starcrus.cpp +++ b/src/mame/drivers/starcrus.cpp @@ -172,7 +172,7 @@ void starcrus_state::starcrus(machine_config &config) NETLIST_ANALOG_INPUT(config, "sound_nl:noise_volume", "R23.DIAL"); NETLIST_ANALOG_INPUT(config, "sound_nl:volume", "R75.DIAL"); - NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "R77.2").set_mult_offset(100000.0, 0.0); + NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "R77.2").set_mult_offset(100000.0 / 32768.0, 0.0); } /*************************************************************************** diff --git a/src/mame/drivers/starfire.cpp b/src/mame/drivers/starfire.cpp index 54b2b7c3453..f8d3ba57a7f 100644 --- a/src/mame/drivers/starfire.cpp +++ b/src/mame/drivers/starfire.cpp @@ -457,8 +457,8 @@ void fireone_state::fireone(machine_config &config) NETLIST_ANALOG_INPUT(config, "sound_nl:volume_l", "R64.DIAL"); NETLIST_ANALOG_INPUT(config, "sound_nl:volume_r", "R65.DIAL"); - NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "OUT_L").set_mult_offset(100000.0, 0.0); - NETLIST_STREAM_OUTPUT(config, "sound_nl:cout1", 1, "OUT_R").set_mult_offset(100000.0, 0.0); + NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "OUT_L").set_mult_offset(100000.0 / 32768.0, 0.0); + NETLIST_STREAM_OUTPUT(config, "sound_nl:cout1", 1, "OUT_R").set_mult_offset(100000.0 / 32768.0, 0.0); } void starfire_state::starfire(machine_config &config) diff --git a/src/mame/drivers/tankbatt.cpp b/src/mame/drivers/tankbatt.cpp index 8dab5811de0..85880fbee91 100644 --- a/src/mame/drivers/tankbatt.cpp +++ b/src/mame/drivers/tankbatt.cpp @@ -266,7 +266,7 @@ void tankbatt_state::tankbatt(machine_config &config) NETLIST_LOGIC_INPUT(config, "sound_nl:shoot", "SHOOT.IN", 0); NETLIST_LOGIC_INPUT(config, "sound_nl:hit", "HIT.IN", 0); - NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "R35.2").set_mult_offset(10000.0, 0.0); + NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "R35.2").set_mult_offset(10000.0 / 32768.0, 0.0); } diff --git a/src/mame/includes/gridlee.h b/src/mame/includes/gridlee.h index 2e420f74846..59314a1e903 100644 --- a/src/mame/includes/gridlee.h +++ b/src/mame/includes/gridlee.h @@ -101,7 +101,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; public: void gridlee_sound_w(offs_t offset, uint8_t data); diff --git a/src/mame/includes/segag80r.h b/src/mame/includes/segag80r.h index 7846fab93b3..14bb5af7651 100644 --- a/src/mame/includes/segag80r.h +++ b/src/mame/includes/segag80r.h @@ -211,7 +211,7 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: // internal state diff --git a/src/mame/includes/turrett.h b/src/mame/includes/turrett.h index c77c26f70c7..cce1f821f56 100644 --- a/src/mame/includes/turrett.h +++ b/src/mame/includes/turrett.h @@ -121,7 +121,7 @@ protected: virtual void device_reset() override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; // device_memory_interface overrides virtual space_config_vector memory_space_config() const override; diff --git a/src/mame/includes/xavix.h b/src/mame/includes/xavix.h index f6ddc11e8e3..22d4b584d3a 100644 --- a/src/mame/includes/xavix.h +++ b/src/mame/includes/xavix.h @@ -48,7 +48,7 @@ protected: virtual void device_reset() override; // sound stream update overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; private: sound_stream *m_stream; diff --git a/src/mame/machine/mega32x.cpp b/src/mame/machine/mega32x.cpp index f16e2318705..b8607d8506a 100644 --- a/src/mame/machine/mega32x.cpp +++ b/src/mame/machine/mega32x.cpp @@ -935,7 +935,7 @@ void sega_32x_device::m68k_pwm_w(offs_t offset, uint16_t data) pwm_w(offset,data); } -void sega_32x_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void sega_32x_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { for (int s = 0; s < samples; s++) { @@ -1742,7 +1742,7 @@ void sega_32x_device::device_start() set_pen_color(i, pal5bit(r), pal5bit(g), pal5bit(b)); } - m_stream = stream_alloc(2, 2, 48000 * 4); + m_stream = stream_alloc_legacy(2, 2, 48000 * 4); m_32x_pwm_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sega_32x_device::handle_pwm_callback), this)); m_32x_dram0 = std::make_unique(0x40000/2); diff --git a/src/mame/machine/mega32x.h b/src/mame/machine/mega32x.h index 97c7512ca13..e56db24fdb3 100644 --- a/src/mame/machine/mega32x.h +++ b/src/mame/machine/mega32x.h @@ -110,7 +110,7 @@ protected: virtual uint32_t palette_entries() const override { return 32*32*32/**2*/; } // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; void update_total_scanlines(bool mode3) { m_total_scanlines = mode3 ? (m_base_total_scanlines * 2) : m_base_total_scanlines; } // this gets set at each EOF diff --git a/src/mame/video/gic.cpp b/src/mame/video/gic.cpp index 54691b43e3c..9f9f8d8aff8 100644 --- a/src/mame/video/gic.cpp +++ b/src/mame/video/gic.cpp @@ -118,7 +118,7 @@ void gic_device::device_start() m_vblank_timer->adjust( screen().time_until_pos(1, END_ACTIVE_SCAN + 18 ), 0, screen().scan_period() ); // allocate the audio stream - m_stream = stream_alloc( 0, 1, clock()/(2*228) ); + m_stream = stream_alloc_legacy( 0, 1, clock()/(2*228) ); m_ram.resolve_safe(0xff); } @@ -252,7 +252,7 @@ void gic_device::device_timer(emu_timer &timer, device_timer_id id, int param, v #define GIC_AUDIO_BYTE 0x96 -void gic_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void gic_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) { stream_sample_t *buffer = outputs[0]; diff --git a/src/mame/video/gic.h b/src/mame/video/gic.h index 7735535d122..a393b88c4e2 100644 --- a/src/mame/video/gic.h +++ b/src/mame/video/gic.h @@ -74,7 +74,7 @@ protected: virtual const tiny_rom_entry *device_rom_region() const override; // device_sound_interface overrides - virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; + virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; /* timers */ static const device_timer_id TIMER_VBLANK = 0; -- cgit v1.2.3