From c94b8c94901066b9f44a1b13d7448502fa147974 Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Thu, 27 Jan 2011 08:06:43 +0000 Subject: [PATCH] C++-ified the sound and streams interfaces. Combined sound.c and streams.c into one file, and separated the speaker device into its own file. Generalized the concept of dynamically assigned inputs and re-wired the speaker to work this way, so it is now treated just like any other sound device. Added methods to the device_sound_interface for controlling output gain and mapping device inputs/outputs to stream inputs/outputs. Also made the sound_stream_update() method pure virtual, so all modern sound devices must use the new mechanism for stream updates. Primary changes outside of the core are: stream_update(stream) == stream->update() stream_create(device,...) == machine->sound().stream_alloc(*device,...) sound_global_enable(machine,enable) == machine->sound().system_enable(enable) Beyond this, the patterns are relatively obvious for the remaining calls. --- .gitattributes | 2 - src/emu/debug/debugcpu.c | 4 +- src/emu/disound.c | 226 +++-- src/emu/disound.h | 50 +- src/emu/emu.h | 2 +- src/emu/emu.mak | 2 +- src/emu/info.c | 2 +- src/emu/machine.c | 10 +- src/emu/machine.h | 5 +- src/emu/machine/ldcore.c | 7 +- src/emu/mame.c | 1 - src/emu/sound.c | 1584 ++++++++++++++++++++--------------- src/emu/sound.h | 410 ++++----- src/emu/sound/2151intf.c | 7 +- src/emu/sound/2203intf.c | 5 +- src/emu/sound/2413intf.c | 7 +- src/emu/sound/2608intf.c | 5 +- src/emu/sound/2610intf.c | 5 +- src/emu/sound/2612intf.c | 5 +- src/emu/sound/262intf.c | 5 +- src/emu/sound/3526intf.c | 5 +- src/emu/sound/3812intf.c | 5 +- src/emu/sound/8950intf.c | 6 +- src/emu/sound/aica.c | 3 +- src/emu/sound/asc.c | 11 +- src/emu/sound/asc.h | 1 - src/emu/sound/astrocde.c | 5 +- src/emu/sound/ay8910.c | 11 +- src/emu/sound/beep.c | 11 +- src/emu/sound/bsmt2000.c | 13 +- src/emu/sound/c140.c | 5 +- src/emu/sound/c352.c | 7 +- src/emu/sound/c6280.c | 5 +- src/emu/sound/cdda.c | 21 +- src/emu/sound/cdp1863.c | 3 +- src/emu/sound/cdp1864.c | 3 +- src/emu/sound/cdp1869.c | 15 +- src/emu/sound/cdp1869.h | 3 +- src/emu/sound/cem3394.c | 5 +- src/emu/sound/dac.c | 11 +- src/emu/sound/digitalk.c | 3 +- src/emu/sound/disc_inp.c | 7 +- src/emu/sound/discrete.c | 9 +- src/emu/sound/discrete.h | 3 +- src/emu/sound/dmadac.c | 11 +- src/emu/sound/es5503.c | 11 +- src/emu/sound/es5506.c | 19 +- src/emu/sound/es8712.c | 13 +- src/emu/sound/flt_rc.c | 5 +- src/emu/sound/flt_vol.c | 3 +- src/emu/sound/gaelco.c | 5 +- src/emu/sound/hc55516.c | 9 +- src/emu/sound/ics2115.c | 9 +- src/emu/sound/ics2115.h | 4 +- src/emu/sound/iremga20.c | 7 +- src/emu/sound/k005289.c | 5 +- src/emu/sound/k007232.c | 5 +- src/emu/sound/k051649.c | 13 +- src/emu/sound/k053260.c | 5 +- src/emu/sound/k054539.c | 3 +- src/emu/sound/mos6560.c | 5 +- src/emu/sound/msm5205.c | 11 +- src/emu/sound/msm5232.c | 9 +- src/emu/sound/multipcm.c | 3 +- src/emu/sound/n63701x.c | 5 +- src/emu/sound/namco.c | 15 +- src/emu/sound/nes_apu.c | 5 +- src/emu/sound/nile.c | 11 +- src/emu/sound/okim6258.c | 15 +- src/emu/sound/okim6295.c | 15 +- src/emu/sound/okim6295.h | 1 - src/emu/sound/okim6376.c | 11 +- src/emu/sound/pokey.c | 5 +- src/emu/sound/psx.c | 3 +- src/emu/sound/qsound.c | 5 +- src/emu/sound/rf5c400.c | 3 +- src/emu/sound/rf5c68.c | 5 +- src/emu/sound/s14001a.c | 13 +- src/emu/sound/s2636.c | 5 +- src/emu/sound/saa1099.c | 5 +- src/emu/sound/samples.c | 19 +- src/emu/sound/scsp.c | 7 +- src/emu/sound/segapcm.c | 7 +- src/emu/sound/sid.c | 8 +- src/emu/sound/sid.h | 1 - src/emu/sound/sid6581.c | 2 +- src/emu/sound/sn76477.c | 77 +- src/emu/sound/sn76496.c | 9 +- src/emu/sound/snkwave.c | 5 +- src/emu/sound/sp0250.c | 9 +- src/emu/sound/sp0256.c | 3 +- src/emu/sound/speaker.c | 13 +- src/emu/sound/speaker.h | 4 +- src/emu/sound/st0016.c | 3 +- src/emu/sound/t6w28.c | 5 +- src/emu/sound/tiaintf.c | 5 +- src/emu/sound/tiasound.c | 1 - src/emu/sound/tms3615.c | 3 +- src/emu/sound/tms36xx.c | 9 +- src/emu/sound/tms5110.c | 17 +- src/emu/sound/tms5220.c | 19 +- src/emu/sound/upd7759.c | 9 +- src/emu/sound/vlm5030.c | 5 +- src/emu/sound/votrax.c | 9 +- src/emu/sound/vrender0.c | 3 +- src/emu/sound/wave.c | 9 +- src/emu/sound/x1_010.c | 3 +- src/emu/sound/ym2151.c | 1 - src/emu/sound/ymf271.c | 3 +- src/emu/sound/ymf278b.c | 3 +- src/emu/sound/ymz280b.c | 7 +- src/emu/sound/zsg2.c | 5 +- src/emu/streams.c | 1025 ----------------------- src/emu/streams.h | 115 --- src/emu/ui.c | 27 +- src/mame/audio/8080bw.c | 14 +- src/mame/audio/amiga.c | 5 +- src/mame/audio/astrof.c | 4 +- src/mame/audio/beezer.c | 11 +- src/mame/audio/bzone.c | 3 +- src/mame/audio/cchasm.c | 1 - src/mame/audio/cinemat.c | 2 +- src/mame/audio/circus.c | 2 +- src/mame/audio/copsnrob.c | 2 +- src/mame/audio/cps3.c | 7 +- src/mame/audio/exidy.c | 11 +- src/mame/audio/exidy440.c | 9 +- src/mame/audio/flower.c | 7 +- src/mame/audio/galaxian.c | 1 - src/mame/audio/geebee.c | 5 +- src/mame/audio/gomoku.c | 7 +- src/mame/audio/gridlee.c | 5 +- src/mame/audio/leland.c | 43 +- src/mame/audio/micro3d.c | 5 +- src/mame/audio/mw8080bw.c | 25 +- src/mame/audio/phoenix.c | 5 +- src/mame/audio/pleiads.c | 9 +- src/mame/audio/polepos.c | 7 +- src/mame/audio/redbaron.c | 5 +- src/mame/audio/scramble.c | 2 +- src/mame/audio/segag80r.c | 9 +- src/mame/audio/segasnd.c | 7 +- src/mame/audio/seibu.c | 7 +- src/mame/audio/snes_snd.c | 7 +- src/mame/audio/snk6502.c | 3 +- src/mame/audio/tiamc1.c | 3 +- src/mame/audio/turbo.c | 4 +- src/mame/audio/tx1.c | 40 +- src/mame/audio/warpwarp.c | 9 +- src/mame/audio/wiping.c | 5 +- src/mame/drivers/40love.c | 24 +- src/mame/drivers/aleck64.c | 1 - src/mame/drivers/astinvad.c | 4 +- src/mame/drivers/astrocde.c | 4 +- src/mame/drivers/bfm_sc2.c | 20 +- src/mame/drivers/buggychl.c | 2 +- src/mame/drivers/crbaloon.c | 2 +- src/mame/drivers/cubeqst.c | 1 - src/mame/drivers/cubocd32.c | 2 +- src/mame/drivers/dai3wksi.c | 2 +- src/mame/drivers/darius.c | 2 +- src/mame/drivers/equites.c | 26 +- src/mame/drivers/fcrash.c | 8 +- src/mame/drivers/firefox.c | 2 +- src/mame/drivers/flstory.c | 24 +- src/mame/drivers/galaxian.c | 2 +- src/mame/drivers/gottlieb.c | 1 - src/mame/drivers/looping.c | 8 +- src/mame/drivers/m10.c | 6 +- src/mame/drivers/magmax.c | 24 +- src/mame/drivers/maxaflex.c | 2 +- src/mame/drivers/mjkjidai.c | 3 +- src/mame/drivers/msisaac.c | 18 +- src/mame/drivers/ninjaw.c | 2 +- src/mame/drivers/renegade.c | 3 +- src/mame/drivers/segahang.c | 2 +- src/mame/drivers/segaorun.c | 2 +- src/mame/drivers/segaxbd.c | 4 +- src/mame/drivers/segaybd.c | 2 +- src/mame/drivers/system1.c | 2 +- src/mame/drivers/taito_b.c | 8 +- src/mame/drivers/taito_l.c | 4 +- src/mame/drivers/thepit.c | 2 +- src/mame/drivers/tutankhm.c | 2 +- src/mame/drivers/uapce.c | 2 +- src/mame/drivers/warriorb.c | 2 +- src/mame/includes/cps1.h | 6 +- src/mame/includes/equites.h | 4 +- src/mame/includes/snes.h | 1 - src/mame/machine/atarigen.c | 2 +- src/mame/machine/balsente.c | 2 +- src/mame/machine/n64.c | 1 - src/mame/video/bking.c | 2 +- src/mame/video/dday.c | 2 +- 194 files changed, 1975 insertions(+), 2803 deletions(-) delete mode 100644 src/emu/streams.c delete mode 100644 src/emu/streams.h diff --git a/.gitattributes b/.gitattributes index 056451ab1a0..52aa9154628 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1143,8 +1143,6 @@ src/emu/sound/zsg2.c svneol=native#text/plain src/emu/sound/zsg2.h svneol=native#text/plain src/emu/state.c svneol=native#text/plain src/emu/state.h svneol=native#text/plain -src/emu/streams.c svneol=native#text/plain -src/emu/streams.h svneol=native#text/plain src/emu/tilemap.c svneol=native#text/plain src/emu/tilemap.h svneol=native#text/plain src/emu/timer.c svneol=native#text/plain diff --git a/src/emu/debug/debugcpu.c b/src/emu/debug/debugcpu.c index ee2b85a9d5c..dc134ca9526 100644 --- a/src/emu/debug/debugcpu.c +++ b/src/emu/debug/debugcpu.c @@ -1948,7 +1948,7 @@ void device_debug::instruction_hook(offs_t curpc) debugger_refresh_display(m_device.machine); // wait for the debugger; during this time, disable sound output - sound_mute(m_device.machine, true); + m_device.machine->sound().debugger_mute(true); while (global->execution_state == EXECUTION_STATE_STOPPED) { // flush any pending updates before waiting again @@ -1976,7 +1976,7 @@ void device_debug::instruction_hook(offs_t curpc) if (machine.scheduled_event_pending()) global->execution_state = EXECUTION_STATE_RUNNING; } - sound_mute(m_device.machine, false); + m_device.machine->sound().debugger_mute(false); // remember the last visible CPU in the debugger global->visiblecpu = &m_device; diff --git a/src/emu/disound.c b/src/emu/disound.c index 2780f334494..3a37cfe2a15 100644 --- a/src/emu/disound.c +++ b/src/emu/disound.c @@ -38,7 +38,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" @@ -51,8 +50,7 @@ //------------------------------------------------- device_config_sound_interface::device_config_sound_interface(const machine_config &mconfig, device_config &devconfig) - : device_config_interface(mconfig, devconfig), - m_route_list(NULL) + : device_config_interface(mconfig, devconfig) { } @@ -63,7 +61,6 @@ device_config_sound_interface::device_config_sound_interface(const machine_confi device_config_sound_interface::~device_config_sound_interface() { - reset_routes(); } @@ -74,13 +71,13 @@ device_config_sound_interface::~device_config_sound_interface() void device_config_sound_interface::static_add_route(device_config *device, UINT32 output, const char *target, double gain, UINT32 input) { + // find our sound interface device_config_sound_interface *sound = dynamic_cast(device); if (sound == NULL) throw emu_fatalerror("MCFG_SOUND_ROUTE called on device '%s' with no sound interface", device->tag()); - sound_route **routeptr; - for (routeptr = &sound->m_route_list; *routeptr != NULL; routeptr = &(*routeptr)->m_next) ; - *routeptr = global_alloc(sound_route(output, input, gain, target)); + // append a new route to the list + sound->m_route_list.append(*global_alloc(sound_route(output, input, gain, target))); } @@ -91,11 +88,13 @@ void device_config_sound_interface::static_add_route(device_config *device, UINT void device_config_sound_interface::static_reset_routes(device_config *device) { + // find our sound interface device_config_sound_interface *sound = dynamic_cast(device); if (sound == NULL) throw emu_fatalerror("MCFG_SOUND_ROUTES_RESET called on device '%s' with no sound interface", device->tag()); - sound->reset_routes(); + // reset the routine list + sound->m_route_list.reset(); } @@ -110,7 +109,7 @@ bool device_config_sound_interface::interface_validity_check(const game_driver & bool error = false; // loop over all the routes - for (const sound_route *route = m_route_list; route != NULL; route = route->m_next) + for (const sound_route *route = first_route(); route != NULL; route = route->next()) { // find a device with the requested tag const device_config *target = m_machine_config.m_devicelist.find(route->m_target); @@ -132,23 +131,6 @@ bool device_config_sound_interface::interface_validity_check(const game_driver & } -//------------------------------------------------- -// reset_routes - free up all allocated routes -// in this configuration -//------------------------------------------------- - -void device_config_sound_interface::reset_routes() -{ - // loop until all are gone - while (m_route_list != NULL) - { - sound_route *temp = m_route_list; - m_route_list = temp->m_next; - global_free(temp); - } -} - - //------------------------------------------------- // sound_route - constructor //------------------------------------------------- @@ -174,8 +156,9 @@ device_config_sound_interface::sound_route::sound_route(int output, int input, f device_sound_interface::device_sound_interface(running_machine &machine, const device_config &config, device_t &device) : device_interface(machine, config, device), + m_sound_config(dynamic_cast(config)), m_outputs(0), - m_sound_config(dynamic_cast(config)) + m_auto_allocated_inputs(0) { } @@ -190,13 +173,115 @@ device_sound_interface::~device_sound_interface() //------------------------------------------------- -// sound_stream_update - provide data for the -// given sound stream +// inputs - return the total number of inputs +// for the given device //------------------------------------------------- -void device_sound_interface::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +int device_sound_interface::inputs() const { - fatalerror("device_sound_interface::sound_stream_update - this method should have been overridden"); + // scan the list counting streams we own and summing their inputs + int inputs = 0; + for (sound_stream *stream = m_device.machine->sound().first_stream(); stream != NULL; stream = stream->next()) + if (&stream->device() == &m_device) + inputs += stream->input_count(); + return inputs; +} + + +//------------------------------------------------- +// outputs - return the total number of outputs +// for the given device +//------------------------------------------------- + +int device_sound_interface::outputs() const +{ + // scan the list counting streams we own and summing their outputs + int outputs = 0; + for (sound_stream *stream = m_device.machine->sound().first_stream(); stream != NULL; stream = stream->next()) + if (&stream->device() == &m_device) + outputs += stream->output_count(); + return outputs; +} + + +//------------------------------------------------- +// input_to_stream_input - convert a device's +// input index to a stream and the input index +// on that stream +//------------------------------------------------- + +sound_stream *device_sound_interface::input_to_stream_input(int inputnum, int &stream_inputnum) +{ + assert(inputnum >= 0); + + // scan the list looking for streams owned by this device + for (sound_stream *stream = m_device.machine->sound().first_stream(); stream != NULL; stream = stream->next()) + if (&stream->device() == &m_device) + { + if (inputnum < stream->input_count()) + { + stream_inputnum = inputnum; + return stream; + } + inputnum -= stream->input_count(); + } + + // not found + return NULL; +} + + +//------------------------------------------------- +// output_to_stream_output - convert a device's +// output index to a stream and the output index +// on that stream +//------------------------------------------------- + +sound_stream *device_sound_interface::output_to_stream_output(int outputnum, int &stream_outputnum) +{ + assert(outputnum >= 0); + + // scan the list looking for streams owned by this device + for (sound_stream *stream = m_device.machine->sound().first_stream(); stream != NULL; stream = stream->next()) + if (&stream->device() == &device()) + { + if (outputnum < stream->output_count()) + { + stream_outputnum = outputnum; + return stream; + } + outputnum -= stream->output_count(); + } + + // not found + return NULL; +} + + +//------------------------------------------------- +// set_output_gain - set the gain on the given +// output index of the device +//------------------------------------------------- + +void device_sound_interface::set_output_gain(int outputnum, float gain) +{ + // handle ALL_OUTPUTS as a special case + if (outputnum == ALL_OUTPUTS) + { + for (sound_stream *stream = m_device.machine->sound().first_stream(); stream != NULL; stream = stream->next()) + if (&stream->device() == &device()) + for (int outputnum = 0; outputnum < stream->output_count(); outputnum++) + stream->set_output_gain(outputnum, gain); + } + + // look up the stream and stream output index + else + { + int stream_outputnum; + sound_stream *stream = output_to_stream_output(outputnum, stream_outputnum); + if (stream != NULL) + stream->set_output_gain(stream_outputnum, gain); + } } @@ -212,14 +297,31 @@ void device_sound_interface::interface_pre_start() for (bool gotone = m_device.machine->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) { // scan each route on the device - for (const device_config_sound_interface::sound_route *route = sound->sound_config().m_route_list; route != NULL; route = route->m_next) + for (const device_config_sound_interface::sound_route *route = sound->sound_config().first_route(); route != NULL; route = route->next()) { - // if we are the target of this route but the source hasn't yet started, defer our start for later + // see if we are the target of this route; if we are, make sure the source device is started device_t *target_device = m_device.machine->device(route->m_target); if (target_device == &m_device && !sound->device().started()) throw device_missing_dependencies(); } } + + // now iterate through devices again and assign any auto-allocated inputs + m_auto_allocated_inputs = 0; + for (bool gotone = m_device.machine->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) + { + // scan each route on the device + for (const device_config_sound_interface::sound_route *route = sound->sound_config().first_route(); route != NULL; route = route->next()) + { + // see if we are the target of this route + device_t *target_device = m_device.machine->device(route->m_target); + if (target_device == &m_device && route->m_input == AUTO_ALLOC_INPUT) + { + const_cast(route)->m_input = m_auto_allocated_inputs; + m_auto_allocated_inputs += (route->m_output == ALL_OUTPUTS) ? sound->outputs() : 1; + } + } + } } @@ -230,33 +332,12 @@ void device_sound_interface::interface_pre_start() void device_sound_interface::interface_post_start() { - // count the outputs - for (int outputnum = 0; outputnum < MAX_OUTPUTS; outputnum++) - { - // stop when we run out of streams - sound_stream *stream = stream_find_by_device(&m_device, outputnum); - if (stream == NULL) - break; - - // accumulate the number of outputs from this stream - int numoutputs = stream_get_outputs(stream); - assert(m_outputs + numoutputs < MAX_OUTPUTS); - - // fill in the array - for (int curoutput = 0; curoutput < numoutputs; curoutput++) - { - sound_output *output = &m_output[m_outputs++]; - output->stream = stream; - output->output = curoutput; - } - } - // iterate over all the sound devices device_sound_interface *sound = NULL; for (bool gotone = m_device.machine->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) { // scan each route on the device - for (const device_config_sound_interface::sound_route *route = sound->sound_config().m_route_list; route != NULL; route = route->m_next) + for (const device_config_sound_interface::sound_route *route = sound->sound_config().first_route(); route != NULL; route = route->next()) { // if we are the target of this route, hook it up device_t *target_device = m_device.machine->device(route->m_target); @@ -264,19 +345,40 @@ void device_sound_interface::interface_post_start() { // iterate over all outputs, matching any that apply int inputnum = route->m_input; - int numoutputs = stream_get_device_outputs(*sound); + int numoutputs = sound->outputs(); for (int outputnum = 0; outputnum < numoutputs; outputnum++) if (route->m_output == outputnum || route->m_output == ALL_OUTPUTS) { - sound_stream *inputstream, *stream; - int streaminput, streamoutput; + // find the output stream to connect from + int streamoutputnum; + sound_stream *outputstream = sound->output_to_stream_output(outputnum, streamoutputnum); + if (outputstream == NULL) + fatalerror("Sound device '%s' specifies route for non-existant output #%d", route->m_target, outputnum); - // get the input and output streams and wire them together - if (stream_device_input_to_stream_input(target_device, inputnum++, &inputstream, &streaminput)) - if (stream_device_output_to_stream_output(*sound, outputnum, &stream, &streamoutput)) - stream_set_input(inputstream, streaminput, stream, streamoutput, route->m_gain); + // find the input stream to connect to + int streaminputnum; + sound_stream *inputstream = input_to_stream_input(inputnum++, streaminputnum); + if (inputstream == NULL) + fatalerror("Sound device '%s' targeted output #%d to non-existant device '%s' input %d", route->m_target, outputnum, m_device.tag(), inputnum - 1); + + // set the input + inputstream->set_input(streaminputnum, outputstream, streamoutputnum, route->m_gain); } } } } } + + +//------------------------------------------------- +// interface_pre_reset - called prior to +// resetting the device +//------------------------------------------------- + +void device_sound_interface::interface_pre_reset() +{ + // update all streams on this device prior to reset + for (sound_stream *stream = m_device.machine->sound().first_stream(); stream != NULL; stream = stream->next()) + if (&stream->device() == &device()) + stream->update(); +} diff --git a/src/emu/disound.h b/src/emu/disound.h index 4524d49c3e3..c34d9024ad6 100644 --- a/src/emu/disound.h +++ b/src/emu/disound.h @@ -51,8 +51,8 @@ // CONSTANTS //************************************************************************** -const int MAX_OUTPUTS = 4095; // maximum number of outputs a sound chip can support -const int ALL_OUTPUTS = MAX_OUTPUTS; // special value indicating all outputs for the current chip +const int ALL_OUTPUTS = 65535; // special value indicating all outputs for the current chip +const int AUTO_ALLOC_INPUT = 65535; @@ -79,7 +79,7 @@ const int ALL_OUTPUTS = MAX_OUTPUTS; // special value indicating all outputs fo device_config_sound_interface::static_add_route(device, _output, _target, _gain, _input); \ #define MCFG_SOUND_ROUTE(_output, _target, _gain) \ - MCFG_SOUND_ROUTE_EX(_output, _target, _gain, 0) + MCFG_SOUND_ROUTE_EX(_output, _target, _gain, AUTO_ALLOC_INPUT) #define MCFG_SOUND_ROUTES_RESET() \ device_config_sound_interface::static_reset_routes(device); \ @@ -99,14 +99,13 @@ class sound_stream; class device_config_sound_interface : public device_config_interface { public: - // construction/destruction - device_config_sound_interface(const machine_config &mconfig, device_config &devconfig); - virtual ~device_config_sound_interface(); - + // sound route class sound_route { public: sound_route(int output, int input, float gain, const char *target); + + const sound_route *next() const { return m_next; } sound_route * m_next; // pointer to next route UINT32 m_output; // output index, or ALL_OUTPUTS @@ -115,21 +114,26 @@ public: const char * m_target; // target tag }; - sound_route * m_route_list; // list of sound routes + // construction/destruction + device_config_sound_interface(const machine_config &mconfig, device_config &devconfig); + virtual ~device_config_sound_interface(); + + // getters + const sound_route *first_route() const { return m_route_list.first(); } // static inline helpers - static void static_add_route(device_config *device, UINT32 output, const char *target, double gain, UINT32 input = 0); + static void static_add_route(device_config *device, UINT32 output, const char *target, double gain, UINT32 input = AUTO_ALLOC_INPUT); static void static_reset_routes(device_config *device); protected: // optional operation overrides virtual bool interface_validity_check(const game_driver &driver) const; - void reset_routes(); + // internal state + simple_list m_route_list; // list of sound routes }; - // ======================> device_sound_interface class device_sound_interface : public device_interface @@ -143,25 +147,27 @@ public: const device_config_sound_interface &sound_config() const { return m_sound_config; } // 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(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) = 0; + + // helpers + int inputs() const; + int outputs() const; + sound_stream *input_to_stream_input(int inputnum, int &stream_inputnum); + sound_stream *output_to_stream_output(int outputnum, int &stream_outputnum); + void set_output_gain(int outputnum, float gain); protected: // optional operation overrides virtual void interface_pre_start(); virtual void interface_post_start(); - - struct sound_output - { - sound_stream * stream; // associated stream - int output; // output number - }; + virtual void interface_pre_reset(); + + // internal state + const device_config_sound_interface &m_sound_config; int m_outputs; // number of outputs from this instance - sound_output m_output[MAX_OUTPUTS]; // array of output information - - const device_config_sound_interface &m_sound_config; + int m_auto_allocated_inputs; // number of auto-allocated inputs targeting us }; - #endif /* __DISOUND_H__ */ diff --git a/src/emu/emu.h b/src/emu/emu.h index 4b03a6ee55a..691a7e3ef1d 100644 --- a/src/emu/emu.h +++ b/src/emu/emu.h @@ -122,8 +122,8 @@ typedef device_config * (*machine_config_constructor)(machine_config &config, de #include "video.h" // sound-related -#include "streams.h" #include "sound.h" +#include "speaker.h" // generic helpers #include "devcb.h" diff --git a/src/emu/emu.mak b/src/emu/emu.mak index 05dd170795b..937cf0572b0 100644 --- a/src/emu/emu.mak +++ b/src/emu/emu.mak @@ -94,8 +94,8 @@ EMUOBJS = \ $(EMUOBJ)/screen.o \ $(EMUOBJ)/softlist.o \ $(EMUOBJ)/sound.o \ + $(EMUOBJ)/speaker.o \ $(EMUOBJ)/state.o \ - $(EMUOBJ)/streams.o \ $(EMUOBJ)/tilemap.o \ $(EMUOBJ)/timer.o \ $(EMUOBJ)/ui.o \ diff --git a/src/emu/info.c b/src/emu/info.c index e5558944259..8d146d52775 100644 --- a/src/emu/info.c +++ b/src/emu/info.c @@ -808,7 +808,7 @@ static void print_game_display(FILE *out, const game_driver *game, const machine static void print_game_sound(FILE *out, const game_driver *game, const machine_config &config) { - int speakers = speaker_output_count(&config); + int speakers = config.m_devicelist.count(SPEAKER); /* if we have no sound, zero out the speaker count */ const device_config_sound_interface *sound = NULL; diff --git a/src/emu/machine.c b/src/emu/machine.c index f60ed8c533c..fd700bfea72 100644 --- a/src/emu/machine.c +++ b/src/emu/machine.c @@ -112,7 +112,6 @@ #include "ui.h" #include "uimenu.h" #include "uiinput.h" -#include "streams.h" #include "crsshair.h" #include "validity.h" #include "debug/debugcon.h" @@ -164,7 +163,6 @@ running_machine::running_machine(const machine_config &_config, osd_interface &o streams_data(NULL), devices_data(NULL), romload_data(NULL), - sound_data(NULL), input_data(NULL), input_port_data(NULL), ui_input_data(NULL), @@ -192,6 +190,7 @@ running_machine::running_machine(const machine_config &_config, osd_interface &o m_driver_device(NULL), m_cheat(NULL), m_render(NULL), + m_sound(NULL), m_video(NULL), m_debug_view(NULL) { @@ -302,7 +301,7 @@ void running_machine::start() ui_input_init(this); // initialize the streams engine before the sound devices start - streams_init(this); + m_sound = auto_alloc(this, sound_manager(*this)); // first load ROMs, then populate memory, and finally initialize CPUs // these operations must proceed in this order @@ -323,7 +322,6 @@ void running_machine::start() image_init(this); tilemap_init(this); crosshair_init(this); - sound_init(this); // initialize the debugger if ((debug_flags & DEBUG_FLAG_ENABLED) != 0) @@ -382,7 +380,7 @@ int running_machine::run(bool firstrun) // load the configuration settings and NVRAM bool settingsloaded = config_load_settings(this); nvram_load(this); - sound_mute(this, FALSE); + sound().ui_mute(false); // display the startup screens ui_display_startup_screens(this, firstrun, !settingsloaded); @@ -415,7 +413,7 @@ int running_machine::run(bool firstrun) m_current_phase = MACHINE_PHASE_EXIT; // save the NVRAM and configuration - sound_mute(this, true); + sound().ui_mute(true); nvram_save(this); config_save_settings(this); } diff --git a/src/emu/machine.h b/src/emu/machine.h index 21af663a7e0..78f418c5a93 100644 --- a/src/emu/machine.h +++ b/src/emu/machine.h @@ -182,6 +182,7 @@ class gfx_element; class colortable_t; class cheat_manager; class render_manager; +class sound_manager; class video_manager; class debug_view_manager; class osd_interface; @@ -196,7 +197,6 @@ typedef struct _tilemap_private tilemap_private; typedef struct _streams_private streams_private; typedef struct _devices_private devices_private; typedef struct _romload_private romload_private; -typedef struct _sound_private sound_private; typedef struct _input_private input_private; typedef struct _input_port_private input_port_private; typedef struct _ui_input_private ui_input_private; @@ -392,6 +392,7 @@ public: // managers cheat_manager &cheat() const { assert(m_cheat != NULL); return *m_cheat; } render_manager &render() const { assert(m_render != NULL); return *m_render; } + sound_manager &sound() const { assert(m_sound != NULL); return *m_sound; } video_manager &video() const { assert(m_video != NULL); return *m_video; } debug_view_manager &debug_view() const { assert(m_debug_view != NULL); return *m_debug_view; } @@ -452,7 +453,6 @@ public: streams_private * streams_data; // internal data from streams.c devices_private * devices_data; // internal data from devices.c romload_private * romload_data; // internal data from romload.c - sound_private * sound_data; // internal data from sound.c input_private * input_data; // internal data from input.c input_port_private * input_port_data; // internal data from inptport.c ui_input_private * ui_input_data; // internal data from uiinput.c @@ -533,6 +533,7 @@ private: driver_device * m_driver_device; cheat_manager * m_cheat; // internal data from cheat.c render_manager * m_render; // internal data from render.c + sound_manager * m_sound; // internal data from sound.c video_manager * m_video; // internal data from video.c debug_view_manager * m_debug_view; // internal data from debugvw.c }; diff --git a/src/emu/machine/ldcore.c b/src/emu/machine/ldcore.c index a909a7bf7d0..43e5e377e49 100644 --- a/src/emu/machine/ldcore.c +++ b/src/emu/machine/ldcore.c @@ -12,7 +12,6 @@ #include "emu.h" #include "ldcore.h" #include "avcomp.h" -#include "streams.h" #include "vbiparse.h" #include "config.h" #include "render.h" @@ -198,7 +197,7 @@ INLINE void update_audio(laserdisc_state *ld) if (ldcore->audiocustom != NULL) { sound_token *token = (sound_token *)downcast(ldcore->audiocustom)->token(); - stream_update(token->stream); + token->stream->update(); } } @@ -965,7 +964,7 @@ static void process_track_data(device_t *device) static DEVICE_START( laserdisc_sound ) { sound_token *token = (sound_token *)downcast(device)->token(); - token->stream = stream_create(device, 0, 2, 48000, token, custom_stream_callback); + token->stream = device->machine->sound().stream_alloc(*device, 0, 2, 48000, token, custom_stream_callback); token->ld = NULL; } @@ -1567,7 +1566,7 @@ static DEVICE_RESET( laserdisc ) { sound_token *token = (sound_token *)downcast(ldcore->audiocustom)->token(); token->ld = ld; - stream_set_sample_rate(token->stream, ldcore->samplerate); + token->stream->set_sample_rate(ldcore->samplerate); } /* set up the general ld */ diff --git a/src/emu/mame.c b/src/emu/mame.c index 4f7006fe37c..7e57b71b47c 100644 --- a/src/emu/mame.c +++ b/src/emu/mame.c @@ -84,7 +84,6 @@ #include "ui.h" #include "uimenu.h" #include "uiinput.h" -#include "streams.h" #include "crsshair.h" #include "validity.h" #include "debug/debugcon.h" diff --git a/src/emu/sound.c b/src/emu/sound.c index ce85a74c4e3..19a9a9443ab 100644 --- a/src/emu/sound.c +++ b/src/emu/sound.c @@ -4,24 +4,51 @@ Core sound functions and definitions. - Copyright Nicola Salmoria and the MAME Team. - Visit http://mamedev.org for licensing and usage restrictions. +**************************************************************************** + + Copyright Aaron Giles + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name 'MAME' nor the names of its contributors may be + used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. ***************************************************************************/ #include "emu.h" #include "emuopts.h" #include "osdepend.h" -#include "streams.h" #include "config.h" #include "profiler.h" #include "sound/wavwrite.h" -/*************************************************************************** - DEBUGGING -***************************************************************************/ +//************************************************************************** +// DEBUGGING +//************************************************************************** #define VERBOSE (0) @@ -29,309 +56,928 @@ -/*************************************************************************** - CONSTANTS -***************************************************************************/ - -#define MAX_MIXER_CHANNELS 100 +//************************************************************************** +// CONSTANTS +//************************************************************************** -/*************************************************************************** - DEVICE DEFINITIONS -***************************************************************************/ +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** -const device_type SPEAKER = speaker_device_config::static_alloc_device_config; +const attotime sound_manager::STREAMS_UPDATE_ATTOTIME = ATTOTIME_IN_HZ(STREAMS_UPDATE_FREQUENCY); -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ - -struct _sound_private -{ - emu_timer *update_timer; - - int totalsnd; - - UINT32 finalmix_leftover; - INT16 *finalmix; - INT32 *leftmix; - INT32 *rightmix; - - int muted; - int attenuation; - int enabled; - int nosound_mode; - - wav_file *wavfile; -}; - - - -/*************************************************************************** - FUNCTION PROTOTYPES -***************************************************************************/ - -static void sound_reset(running_machine &machine); -static void sound_exit(running_machine &machine); -static void sound_pause(running_machine &machine); -static void sound_resume(running_machine &machine); -static void sound_load(running_machine *machine, int config_type, xml_data_node *parentnode); -static void sound_save(running_machine *machine, int config_type, xml_data_node *parentnode); -static TIMER_CALLBACK( sound_update ); - - - -/*************************************************************************** - INLINE FUNCTIONS -***************************************************************************/ +//************************************************************************** +// INITIALIZATION +//************************************************************************** //------------------------------------------------- -// index_to_input - map an absolute index to -// a particular input +// sound_stream - constructor //------------------------------------------------- -INLINE speaker_device *index_to_input(running_machine *machine, int index, int &input) +sound_stream::sound_stream(device_t &device, int inputs, int outputs, int sample_rate, void *param, stream_update_func callback) + : m_device(device), + m_next(NULL), + m_sample_rate(sample_rate), + m_new_sample_rate(0), + m_attoseconds_per_sample(0), + m_max_samples_per_update(0), + m_inputs(inputs), + m_input((inputs == 0) ? NULL : auto_alloc_array_clear(device.machine, stream_input, inputs)), + m_input_array((inputs == 0) ? NULL : auto_alloc_array_clear(device.machine, stream_sample_t *, inputs)), + m_resample_bufalloc(0), + m_outputs(outputs), + m_output((outputs == 0) ? NULL : auto_alloc_array_clear(device.machine, stream_output, outputs)), + m_output_array((outputs == 0) ? NULL : auto_alloc_array_clear(device.machine, stream_sample_t *, outputs)), + m_output_bufalloc(0), + m_output_sampindex(0), + m_output_update_sampindex(0), + m_output_base_sampindex(0), + m_callback(callback), + m_param(param) { - // scan through the speakers until we find the indexed input - for (speaker_device *speaker = speaker_first(*machine); speaker != NULL; speaker = speaker_next(speaker)) + // 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"); + + // this is also the implicit parameter if we are using our internal stub + if (m_callback == &sound_stream::device_stream_update_stub) + m_param = sound; + + // create a unique tag for saving + astring state_tag; + state_tag.printf("%d", m_device.machine->sound().m_stream_list.count()); + state_save_register_item(m_device.machine, "stream", state_tag, 0, m_sample_rate); + state_save_register_postload(m_device.machine, state_postload_stub, this); + + // save the gain of each input and output + for (int inputnum = 0; inputnum < m_inputs; inputnum++) + state_save_register_item(m_device.machine, "stream", state_tag, inputnum, m_input[inputnum].m_gain); + for (int outputnum = 0; outputnum < m_outputs; outputnum++) { - if (index < speaker->inputs()) - { - input = index; - return speaker; - } - index -= speaker->inputs(); + m_output[outputnum].m_stream = this; + state_save_register_item(m_device.machine, "stream", state_tag, outputnum, m_output[outputnum].m_gain); } - // index out of range - return NULL; + // 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; +} + + +//------------------------------------------------- +// sample_time - return the emulation time of the +// next sample to be generated on the stream +//------------------------------------------------- + +attotime sound_stream::sample_time() const +{ + attotime base = m_device.machine->sound().last_update(); + base.attoseconds = 0; + return attotime_add_attoseconds(base, m_output_sampindex * m_attoseconds_per_sample); +} + + +//------------------------------------------------- +// input_gain - return the input gain on a +// given stream's input +//------------------------------------------------- + +float sound_stream::input_gain(int inputnum) const +{ + assert(inputnum >= 0 && inputnum < m_inputs); + return float(m_input[inputnum].m_gain) / 256.0f; +} + + +//------------------------------------------------- +// initial_input_gain - return the original input +// gain on a given stream's input +//------------------------------------------------- + +float sound_stream::initial_input_gain(int inputnum) const +{ + assert(inputnum >= 0 && inputnum < m_inputs); + return float(m_input[inputnum].m_initial_gain) / 256.0f; +} + + +//------------------------------------------------- +// input_name - return the original input gain +// on a given stream's input +//------------------------------------------------- + +const char *sound_stream::input_name(int inputnum, astring &string) const +{ + // start with our device name and tag + assert(inputnum >= 0 && inputnum < m_inputs); + string.printf("%s '%s': ", m_device.name(), m_device.tag()); + + // if we have a source, indicate where the sound comes from by device name and tag + if (m_input[inputnum].m_source != NULL && m_input[inputnum].m_source->m_stream != NULL) + { + device_t &source = m_input[inputnum].m_source->m_stream->device(); + string.catprintf("%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) + { + // 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)) != NULL; outputnum++) + if (outstream == m_input[inputnum].m_source->m_stream && m_input[inputnum].m_source == &outstream->m_output[streamoutputnum]) + { + string.catprintf(" Ch.%d", outputnum); + break; + } + } + } + return string; +} + + +//------------------------------------------------- +// output_gain - return the output gain on a +// given stream's output +//------------------------------------------------- + +float sound_stream::output_gain(int outputnum) const +{ + assert(outputnum >= 0 && outputnum < m_outputs); + return float(m_output[outputnum].m_gain) / 256.0f; +} + + +//------------------------------------------------- +// set_input - configure a stream's input +//------------------------------------------------- + +void sound_stream::set_input(int index, sound_stream *input_stream, int output_index, float gain) +{ + VPRINTF(("stream_set_input(%p, '%s', %d, %p, %d, %f)\n", this, m_device.tag(), index, input_stream, output_index, gain)); + + // make sure it's a valid input + if (index >= m_inputs) + fatalerror("Fatal error: stream_set_input attempted to configure non-existant input %d (%d max)", index, m_inputs); + + // make sure it's a valid output + if (input_stream != NULL && output_index >= input_stream->m_outputs) + fatalerror("Fatal error: stream_set_input attempted to use a non-existant output %d (%d max)", output_index, m_outputs); + + // if this input is already wired, update the dependent info + stream_input &input = m_input[index]; + if (input.m_source != NULL) + input.m_source->m_dependents--; + + // wire it up + input.m_source = (input_stream != NULL) ? &input_stream->m_output[output_index] : NULL; + input.m_gain = input.m_initial_gain = int(0x100 * gain); + + // update the dependent info + if (input.m_source != NULL) + input.m_source->m_dependents++; + + // update sample rates now that we know the input + recompute_sample_rate_data(); +} + + +//------------------------------------------------- +// update - force a stream to update to +// the current emulated time +//------------------------------------------------- + +void sound_stream::update() +{ + // determine the number of samples since the start of this second + attotime time = timer_get_time(m_device.machine); + INT32 update_sampindex = INT32(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) + { + assert(time.seconds == last_update.seconds + 1); + update_sampindex += m_sample_rate; + } + + // if we're behind the last update, then adjust downwards + if (time.seconds < last_update.seconds) + { + assert(time.seconds == last_update.seconds - 1); + update_sampindex -= m_sample_rate; + } + + // 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(); + + // remember this info for next time + m_output_sampindex = update_sampindex; +} + + +//------------------------------------------------- +// output_since_last_update - return a pointer to +// the output buffer and the number of samples +// since the last global update +//------------------------------------------------- + +const stream_sample_t *sound_stream::output_since_last_update(int outputnum, int &numsamples) +{ + // force an update on the stream + update(); + + // 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); +} + + +//------------------------------------------------- +// set_sample_rate - set the sample rate on a +// given stream +//------------------------------------------------- + +void sound_stream::set_sample_rate(int new_rate) +{ + // we will update this on the next global update + if (new_rate != sample_rate()) + m_new_sample_rate = new_rate; +} + + +//------------------------------------------------- +// set_input_gain - set the input gain on a +// given stream's input +//------------------------------------------------- + +void sound_stream::set_input_gain(int inputnum, float gain) +{ + update(); + assert(inputnum >= 0 && inputnum < m_inputs); + m_input[inputnum].m_gain = int(0x100 * gain); +} + + +//------------------------------------------------- +// set_output_gain - set the output gain on a +// given stream's output +//------------------------------------------------- + +void sound_stream::set_output_gain(int outputnum, float gain) +{ + update(); + assert(outputnum >= 0 && outputnum < m_outputs); + m_output[outputnum].m_gain = int(0x100 * gain); +} + + +//------------------------------------------------- +// update_with_accounting - do a regular update, +// but also do periodic accounting +//------------------------------------------------- + +void sound_stream::update_with_accounting(bool second_tick) +{ + // do the normal update + update(); + + // if we've ticked over another second, adjust all the counters that are relative to + // the current second + INT32 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; + } + + // note our current output sample + m_output_update_sampindex = m_output_sampindex; + + // 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) + { + INT32 samples_to_lose = output_bufindex - m_max_samples_per_update; + if (samples_to_lose > 0) + { + // if we have samples to move, do so for each output + if (output_bufindex > 0) + for (int outputnum = 0; outputnum < m_outputs; outputnum++) + { + stream_output &output = m_output[outputnum]; + memmove(&output.m_buffer[0], &output.m_buffer[samples_to_lose], sizeof(output.m_buffer[0]) * (output_bufindex - samples_to_lose)); + } + + // update the base position + m_output_base_sampindex += samples_to_lose; + } + } +} + + +//------------------------------------------------- +// apply_sample_rate_changes - if there is a +// pending sample rate change, apply it now +//------------------------------------------------- + +void sound_stream::apply_sample_rate_changes() +{ + // skip if nothing to do + if (m_new_sample_rate == 0) + return; + + // update to the new rate and remember the old rate + UINT32 old_rate = m_sample_rate; + m_sample_rate = m_new_sample_rate; + m_new_sample_rate = 0; + + // recompute all the data + recompute_sample_rate_data(); + + // reset our sample indexes to the current time + m_output_sampindex = (INT64)m_output_sampindex * (INT64)m_sample_rate / old_rate; + m_output_update_sampindex = (INT64)m_output_update_sampindex * (INT64)m_sample_rate / old_rate; + m_output_base_sampindex = m_output_sampindex - m_max_samples_per_update; + + // clear out the buffer + for (int outputnum = 0; outputnum < m_outputs; outputnum++) + memset(m_output[outputnum].m_buffer, 0, m_max_samples_per_update * sizeof(m_output[outputnum].m_buffer[0])); +} + + +//------------------------------------------------- +// device_stream_update_stub - stub callback for +// passing through to modern devices +//------------------------------------------------- + +STREAM_UPDATE( sound_stream::device_stream_update_stub ) +{ + device_sound_interface *sound = reinterpret_cast(param); + sound->sound_stream_update(*stream, inputs, outputs, samples); +} + + +//------------------------------------------------- +// recompute_sample_rate_data - recompute sample +// rate data, and all streams that are affected +// by this stream +//------------------------------------------------- + +void sound_stream::recompute_sample_rate_data() +{ + // recompute the timing parameters + attoseconds_t update_attoseconds = m_device.machine->sound().update_attoseconds(); + 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; + + // update resample and output buffer sizes + allocate_resample_buffers(); + allocate_output_buffers(); + + // iterate over each input + for (int inputnum = 0; inputnum < m_inputs; inputnum++) + { + // if we have a source, see if its sample rate changed + stream_input &input = m_input[inputnum]; + if (input.m_source != NULL) + { + // 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 = 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 = MAX(input.m_latency_attoseconds, latency); + assert(input.m_latency_attoseconds < update_attoseconds); + } + } +} + + +//------------------------------------------------- +// allocate_resample_buffers - recompute the +// resample buffer sizes and expand if necessary +//------------------------------------------------- + +void sound_stream::allocate_resample_buffers() +{ + // compute the target number of samples + INT32 bufsize = 2 * m_max_samples_per_update; + + // if we don't have enough room, allocate more + if (m_resample_bufalloc < bufsize) + { + // this becomes the new allocation size + int oldsize = m_resample_bufalloc; + m_resample_bufalloc = bufsize; + + // iterate over outputs and realloc their buffers + for (int inputnum = 0; inputnum < m_inputs; inputnum++) + { + stream_input &input = m_input[inputnum]; + stream_sample_t *newbuffer = auto_alloc_array(m_device.machine, stream_sample_t, m_resample_bufalloc); + memcpy(newbuffer, input.m_resample, oldsize * sizeof(stream_sample_t)); + auto_free(m_device.machine, input.m_resample); + input.m_resample = newbuffer; + } + } +} + + +//------------------------------------------------- +// allocate_output_buffers - recompute the +// output buffer sizes and expand if necessary +//------------------------------------------------- + +void sound_stream::allocate_output_buffers() +{ + // if we don't have enough room, allocate more + INT32 bufsize = OUTPUT_BUFFER_UPDATES * m_max_samples_per_update; + if (m_output_bufalloc < bufsize) + { + // this becomes the new allocation size + int oldsize = m_output_bufalloc; + m_output_bufalloc = bufsize; + + // iterate over outputs and realloc their buffers + for (int outputnum = 0; outputnum < m_outputs; outputnum++) + { + stream_output &output = m_output[outputnum]; + stream_sample_t *newbuffer = auto_alloc_array(m_device.machine, stream_sample_t, m_output_bufalloc); + memcpy(newbuffer, output.m_buffer, oldsize * sizeof(stream_sample_t)); + memset(newbuffer + oldsize, 0, (m_output_bufalloc - oldsize) * sizeof(stream_sample_t)); + auto_free(m_device.machine, output.m_buffer); + output.m_buffer = newbuffer; + } + } +} + + +//------------------------------------------------- +// postload - save/restore callback +//------------------------------------------------- + +void sound_stream::postload() +{ + // recompute the same rate information + recompute_sample_rate_data(); + + // make sure our output buffers are fully cleared + for (int outputnum = 0; outputnum < m_outputs; outputnum++) + memset(m_output[outputnum].m_buffer, 0, m_output_bufalloc * sizeof(m_output[outputnum].m_buffer[0])); + + // recompute the sample indexes to make sense + m_output_sampindex = m_device.machine->sound().last_update().attoseconds / m_attoseconds_per_sample; + m_output_update_sampindex = m_output_sampindex; + m_output_base_sampindex = m_output_sampindex - m_max_samples_per_update; +} + + +//------------------------------------------------- +// generate_samples - generate the requested +// number of samples for a stream, making sure +// all inputs have the appropriate number of +// samples generated +//------------------------------------------------- + +void sound_stream::generate_samples(int samples) +{ + // if we're already there, skip it + if (samples <= 0) + return; + + VPRINTF(("generate_samples(%p, %d)\n", this, samples)); + + // ensure all inputs are up to date and generate resampled data + for (int inputnum = 0; inputnum < m_inputs; inputnum++) + { + // update the stream to the current time + stream_input &input = m_input[inputnum]; + if (input.m_source != NULL) + input.m_source->m_stream->update(); + + // generate the resampled data + m_input_array[inputnum] = generate_resampled_data(input, samples); + } + + // loop over all outputs and compute the output pointer + for (int outputnum = 0; outputnum < m_outputs; outputnum++) + { + stream_output &output = m_output[outputnum]; + m_output_array[outputnum] = output.m_buffer + (m_output_sampindex - m_output_base_sampindex); + } + + // run the callback + VPRINTF((" callback(%p, %d)\n", this, samples)); + (*m_callback)(&m_device, this, m_param, m_input_array, m_output_array, samples); + VPRINTF((" callback done\n")); +} + + +//------------------------------------------------- +// generate_resampled_data - generate the +// resample buffer for a given input +//------------------------------------------------- + +stream_sample_t *sound_stream::generate_resampled_data(stream_input &input, UINT32 numsamples) +{ + // if we don't have an output to pull data from, generate silence + stream_sample_t *dest = input.m_resample; + if (input.m_source == NULL) + { + memset(dest, 0, numsamples * sizeof(*dest)); + return input.m_resample; + } + + // grab data from the output + stream_output &output = *input.m_source; + sound_stream &input_stream = *output.m_stream; + int gain = (input.m_gain * output.m_gain) >> 8; + + // 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; + + // now convert that time into a sample in the input stream + INT32 basesample; + if (basetime >= 0) + basesample = basetime / input_stream.m_attoseconds_per_sample; + 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); + + // determine the current fraction of a sample + UINT32 basefrac = (basetime - basesample * input_stream.m_attoseconds_per_sample) / ((input_stream.m_attoseconds_per_sample + FRAC_ONE - 1) >> FRAC_BITS); + assert(basefrac >= 0); + assert(basefrac < FRAC_ONE); + + // compute the stepping fraction + UINT32 step = ((UINT64)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) + { + while (numsamples--) + { + // compute the sample + stream_sample_t sample = *source++; + *dest++ = (sample * gain) >> 8; + } + } + + // input is undersampled: point sample except where our sample period covers a boundary + else if (step < FRAC_ONE) + { + while (numsamples != 0) + { + // fill in with point samples until we hit a boundary + int nextfrac; + while ((nextfrac = basefrac + step) < FRAC_ONE && numsamples--) + { + *dest++ = (source[0] * gain) >> 8; + basefrac = nextfrac; + } + + // if we're done, we're done + if ((INT32)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 + stream_sample_t sample = (source[0] * (0x1000 - startfrac) + source[1] * (endfrac - 0x1000)) / (endfrac - startfrac); + *dest++ = (sample * gain) >> 8; + + // advance + basefrac = nextfrac & FRAC_MASK; + source++; + } + } + + // input is oversampled: sum the energy + else + { + // use 8 bits to allow some extra headroom + int smallstep = step >> (FRAC_BITS - 8); + while (numsamples--) + { + int remainder = smallstep; + int tpos = 0; + + // compute the sample + int scale = (FRAC_ONE - basefrac) >> (FRAC_BITS - 8); + stream_sample_t sample = source[tpos++] * scale; + remainder -= scale; + while (remainder > 0x100) + { + sample += source[tpos++] * 0x100; + remainder -= 0x100; + } + sample += source[tpos] * remainder; + sample /= smallstep; + + *dest++ = (sample * gain) >> 8; + + // advance + basefrac += step; + source += basefrac >> FRAC_BITS; + basefrac &= FRAC_MASK; + } + } + + return input.m_resample; } -/*************************************************************************** - INITIALIZATION -***************************************************************************/ +//************************************************************************** +// STREAM INPUT +//************************************************************************** -/*------------------------------------------------- - sound_init - start up the sound system --------------------------------------------------*/ +//------------------------------------------------- +// stream_input - constructor +//------------------------------------------------- -void sound_init(running_machine *machine) +sound_stream::stream_input::stream_input() + : m_source(NULL), + m_resample(NULL), + m_bufsize(0), + m_bufalloc(0), + m_latency_attoseconds(0), + m_gain(0x100), + m_initial_gain(0x100) { - sound_private *global; - const char *filename; - const char *filenameavi; - - machine->sound_data = global = auto_alloc_clear(machine, sound_private); - - /* get filename for WAV file or AVI file if specified */ - filename = options_get_string(machine->options(), OPTION_WAVWRITE); - filenameavi = options_get_string(machine->options(), OPTION_AVIWRITE); - - /* handle -nosound and lower sample rate if not recording WAV or AVI*/ - global->nosound_mode = !options_get_bool(machine->options(), OPTION_SOUND); - if (global->nosound_mode && filename[0] == 0 && filenameavi[0] == 0) - machine->sample_rate = 11025; - - /* count the speakers */ - VPRINTF(("total speakers = %d\n", speaker_output_count(machine->config))); - - /* allocate memory for mix buffers */ - global->leftmix = auto_alloc_array(machine, INT32, machine->sample_rate); - global->rightmix = auto_alloc_array(machine, INT32, machine->sample_rate); - global->finalmix = auto_alloc_array(machine, INT16, machine->sample_rate); - - /* allocate a global timer for sound timing */ - global->update_timer = timer_alloc(machine, sound_update, NULL); - timer_adjust_periodic(global->update_timer, STREAMS_UPDATE_ATTOTIME, 0, STREAMS_UPDATE_ATTOTIME); - - /* open the output WAV file if specified */ - if (filename[0] != 0) - global->wavfile = wav_open(filename, machine->sample_rate, 2); - - /* enable sound by default */ - global->enabled = TRUE; - global->muted = FALSE; - sound_set_attenuation(machine, options_get_int(machine->options(), OPTION_VOLUME)); - - /* register callbacks */ - config_register(machine, "mixer", sound_load, sound_save); - machine->add_notifier(MACHINE_NOTIFY_PAUSE, sound_pause); - machine->add_notifier(MACHINE_NOTIFY_RESUME, sound_resume); - machine->add_notifier(MACHINE_NOTIFY_RESET, sound_reset); - machine->add_notifier(MACHINE_NOTIFY_EXIT, sound_exit); -} - - -/*------------------------------------------------- - sound_exit - clean up after ourselves --------------------------------------------------*/ - -static void sound_exit(running_machine &machine) -{ - sound_private *global = machine.sound_data; - - /* close any open WAV file */ - if (global->wavfile != NULL) - wav_close(global->wavfile); - global->wavfile = NULL; - - /* reset variables */ - global->totalsnd = 0; } -/*************************************************************************** - GLOBAL STATE MANAGEMENT -***************************************************************************/ +//************************************************************************** +// STREAM OUTPUT +//************************************************************************** -/*------------------------------------------------- - sound_reset - reset all sound chips --------------------------------------------------*/ +//------------------------------------------------- +// stream_output - constructor +//------------------------------------------------- -static void sound_reset(running_machine &machine) +sound_stream::stream_output::stream_output() + : m_buffer(NULL), + m_dependents(0), + m_gain(0x100) { +} + + + +//************************************************************************** +// SOUND MANAGER +//************************************************************************** + +//------------------------------------------------- +// sound_manager - constructor +//------------------------------------------------- + +sound_manager::sound_manager(running_machine &machine) + : m_machine(machine), + m_update_timer(timer_alloc(&machine, update_static, this)), + m_finalmix_leftover(0), + m_finalmix(NULL), + m_leftmix(NULL), + m_rightmix(NULL), + m_muted(0), + m_attenuation(0), + m_nosound_mode(!options_get_bool(machine.options(), OPTION_SOUND)), + m_wavfile(NULL), + m_stream_list(machine.m_respool), + m_update_attoseconds(STREAMS_UPDATE_ATTOTIME.attoseconds), + m_last_update(attotime_zero) +{ + // get filename for WAV file or AVI file if specified + const char *wavfile = options_get_string(machine.options(), OPTION_WAVWRITE); + const char *avifile = options_get_string(machine.options(), OPTION_AVIWRITE); + + // handle -nosound and lower sample rate if not recording WAV or AVI + if (m_nosound_mode && wavfile[0] == 0 && avifile[0] == 0) + machine.sample_rate = 11025; + + // count the speakers + VPRINTF(("total speakers = %d\n", machine.m_devicelist.count(SPEAKER))); + + // allocate memory for mix buffers + m_leftmix = auto_alloc_array(&machine, INT32, machine.sample_rate); + m_rightmix = auto_alloc_array(&machine, INT32, machine.sample_rate); + m_finalmix = auto_alloc_array(&machine, INT16, machine.sample_rate); + + // open the output WAV file if specified + if (wavfile[0] != 0) + m_wavfile = wav_open(wavfile, machine.sample_rate, 2); + + // register callbacks + config_register(&machine, "mixer", &sound_manager::config_load, &sound_manager::config_save); + machine.add_notifier(MACHINE_NOTIFY_PAUSE, &sound_manager::pause); + machine.add_notifier(MACHINE_NOTIFY_RESUME, &sound_manager::resume); + machine.add_notifier(MACHINE_NOTIFY_RESET, &sound_manager::reset); + + // register global states + state_save_register_global(&machine, m_last_update.seconds); + state_save_register_global(&machine, m_last_update.attoseconds); + + // set the starting attenuation + set_attenuation(options_get_int(machine.options(), OPTION_VOLUME)); + + // start the periodic update flushing timer + timer_adjust_periodic(m_update_timer, STREAMS_UPDATE_ATTOTIME, 0, STREAMS_UPDATE_ATTOTIME); +} + + +//------------------------------------------------- +// sound_manager - destructor +//------------------------------------------------- + +sound_manager::~sound_manager() +{ + // close any open WAV file + if (m_wavfile != NULL) + wav_close(m_wavfile); + m_wavfile = NULL; +} + + +//------------------------------------------------- +// stream_alloc - allocate a new stream +//------------------------------------------------- + +sound_stream *sound_manager::stream_alloc(device_t &device, int inputs, int outputs, int sample_rate, void *param, sound_stream::stream_update_func callback) +{ + if (callback != NULL) + return &m_stream_list.append(*auto_alloc(device.machine, sound_stream(device, inputs, outputs, sample_rate, param, callback))); + else + return &m_stream_list.append(*auto_alloc(device.machine, sound_stream(device, inputs, outputs, sample_rate))); +} + + +//------------------------------------------------- +// set_attenuation - set the global volume +//------------------------------------------------- + +void sound_manager::set_attenuation(int attenuation) +{ + m_attenuation = attenuation; + m_machine.osd().set_mastervolume(m_muted ? -32 : m_attenuation); +} + + +//------------------------------------------------- +// indexed_speaker_input - return the speaker +// device and input index of the global speaker +// input +//------------------------------------------------- + +bool sound_manager::indexed_speaker_input(int index, speaker_input &info) const +{ + // scan through the speakers until we find the indexed input + for (info.speaker = downcast(m_machine.m_devicelist.first(SPEAKER)); info.speaker != NULL; info.speaker = downcast(info.speaker->typenext())) + { + if (index < info.speaker->inputs()) + { + info.stream = info.speaker->input_to_stream_input(index, info.inputnum); + assert(info.stream != NULL); + return true; + } + index -= info.speaker->inputs(); + } + + // didn't locate + return false; +} + + +//------------------------------------------------- +// mute - mute sound output +//------------------------------------------------- + +void sound_manager::mute(bool mute, UINT8 reason) +{ + if (mute) + m_muted |= reason; + else + m_muted &= ~reason; + set_attenuation(m_attenuation); +} + + +//------------------------------------------------- +// reset - reset all sound chips +//------------------------------------------------- + +void sound_manager::reset(running_machine &machine) +{ + // reset all the sound chips device_sound_interface *sound = NULL; - - /* reset all the sound chips */ for (bool gotone = machine.m_devicelist.first(sound); gotone; gotone = sound->next(sound)) sound->device().reset(); } -/*------------------------------------------------- - sound_pause - pause sound output --------------------------------------------------*/ +//------------------------------------------------- +// pause - pause sound output +//------------------------------------------------- -static void sound_pause(running_machine &machine) +void sound_manager::pause(running_machine &machine) { - sound_private *global = machine.sound_data; - global->muted |= 0x02; - machine.osd().set_mastervolume(global->muted ? -32 : global->attenuation); -} - -static void sound_resume(running_machine &machine) -{ - sound_private *global = machine.sound_data; - global->muted &= ~0x02; - machine.osd().set_mastervolume(global->muted ? -32 : global->attenuation); + machine.sound().mute(true, MUTE_REASON_PAUSE); } -/*------------------------------------------------- - sound_mute - mute sound output --------------------------------------------------*/ +//------------------------------------------------- +// resume - resume sound output +//------------------------------------------------- -void sound_mute(running_machine *machine, int mute) +void sound_manager::resume(running_machine &machine) { - sound_private *global = machine->sound_data; - - if (mute) - global->muted |= 0x01; - else - global->muted &= ~0x01; - machine->osd().set_mastervolume(global->muted ? -32 : global->attenuation); + machine.sound().mute(false, MUTE_REASON_PAUSE); } -/*------------------------------------------------- - sound_set_attenuation - set the global volume --------------------------------------------------*/ +//------------------------------------------------- +// config_load - read and apply data from the +// configuration file +//------------------------------------------------- -void sound_set_attenuation(running_machine *machine, int attenuation) +void sound_manager::config_load(running_machine *machine, int config_type, xml_data_node *parentnode) { - sound_private *global = machine->sound_data; - global->attenuation = attenuation; - machine->osd().set_mastervolume(global->muted ? -32 : global->attenuation); -} - - -/*------------------------------------------------- - sound_get_attenuation - return the global - volume --------------------------------------------------*/ - -int sound_get_attenuation(running_machine *machine) -{ - sound_private *global = machine->sound_data; - return global->attenuation; -} - - -/*------------------------------------------------- - sound_global_enable - enable/disable sound - globally --------------------------------------------------*/ - -void sound_global_enable(running_machine *machine, int enable) -{ - sound_private *global = machine->sound_data; - global->enabled = enable; -} - - - -/*************************************************************************** - SOUND SAVE/LOAD -***************************************************************************/ - -/*------------------------------------------------- - sound_load - read and apply data from the - configuration file --------------------------------------------------*/ - -static void sound_load(running_machine *machine, int config_type, xml_data_node *parentnode) -{ - xml_data_node *channelnode; - int mixernum; - - /* we only care about game files */ + // we only care about game files if (config_type != CONFIG_TYPE_GAME) return; - /* might not have any data */ + // might not have any data if (parentnode == NULL) return; - /* iterate over channel nodes */ - for (channelnode = xml_get_sibling(parentnode->child, "channel"); channelnode; channelnode = xml_get_sibling(channelnode->next, "channel")) + // iterate over channel nodes + for (xml_data_node *channelnode = xml_get_sibling(parentnode->child, "channel"); channelnode != NULL; channelnode = xml_get_sibling(channelnode->next, "channel")) { - mixernum = xml_get_attribute_int(channelnode, "index", -1); - if (mixernum >= 0 && mixernum < MAX_MIXER_CHANNELS) + speaker_input info; + if (machine->sound().indexed_speaker_input(xml_get_attribute_int(channelnode, "index", -1), info)) { float defvol = xml_get_attribute_float(channelnode, "defvol", -1000.0); float newvol = xml_get_attribute_float(channelnode, "newvol", -1000.0); - if (fabs(defvol - sound_get_default_gain(machine, mixernum)) < 1e-6 && newvol != -1000.0) - sound_set_user_gain(machine, mixernum, newvol); + if (fabs(defvol - info.stream->initial_input_gain(info.inputnum)) < 1e-6 && newvol != -1000.0) + info.stream->set_input_gain(info.inputnum, newvol); } } } -/*------------------------------------------------- - sound_save - save data to the configuration - file --------------------------------------------------*/ +//------------------------------------------------- +// config_save - save data to the configuration +// file +//------------------------------------------------- -static void sound_save(running_machine *machine, int config_type, xml_data_node *parentnode) +void sound_manager::config_save(running_machine *machine, int config_type, xml_data_node *parentnode) { - int mixernum; - - /* we only care about game files */ + // we only care about game files if (config_type != CONFIG_TYPE_GAME) return; - /* iterate over mixer channels */ + // iterate over mixer channels if (parentnode != NULL) - for (mixernum = 0; mixernum < MAX_MIXER_CHANNELS; mixernum++) + for (int mixernum = 0; ; mixernum++) { - float defvol = sound_get_default_gain(machine, mixernum); - float newvol = sound_get_user_gain(machine, mixernum); + speaker_input info; + if (!machine->sound().indexed_speaker_input(mixernum, info)) + break; + float defvol = info.stream->initial_input_gain(info.inputnum); + float newvol = info.stream->input_gain(info.inputnum); if (defvol != newvol) { @@ -347,446 +993,78 @@ static void sound_save(running_machine *machine, int config_type, xml_data_node } +//------------------------------------------------- +// update - mix everything down to its final form +// and send it to the OSD layer +//------------------------------------------------- -/*************************************************************************** - MIXING STAGE -***************************************************************************/ - -/*------------------------------------------------- - sound_update - mix everything down to - its final form and send it to the OSD layer --------------------------------------------------*/ - -static TIMER_CALLBACK( sound_update ) +void sound_manager::update() { - UINT32 finalmix_step, finalmix_offset; - int samples_this_update = 0; - int sample; - sound_private *global = machine->sound_data; - INT16 *finalmix; - INT32 *leftmix, *rightmix; - VPRINTF(("sound_update\n")); g_profiler.start(PROFILER_SOUND); - leftmix = global->leftmix; - rightmix = global->rightmix; - finalmix = global->finalmix; + // force all the speaker streams to generate the proper number of samples + int samples_this_update = 0; + for (speaker_device *speaker = downcast(m_machine.m_devicelist.first(SPEAKER)); speaker != NULL; speaker = downcast(speaker->typenext())) + speaker->mix(m_leftmix, m_rightmix, samples_this_update, (m_muted & MUTE_REASON_SYSTEM)); - /* force all the speaker streams to generate the proper number of samples */ - for (speaker_device *speaker = speaker_first(*machine); speaker != NULL; speaker = speaker_next(speaker)) - speaker->mix(leftmix, rightmix, samples_this_update, !global->enabled); - - /* now downmix the final result */ - finalmix_step = machine->video().speed_factor(); - finalmix_offset = 0; - for (sample = global->finalmix_leftover; sample < samples_this_update * 100; sample += finalmix_step) + // now downmix the final result + UINT32 finalmix_step = m_machine.video().speed_factor(); + UINT32 finalmix_offset = 0; + INT16 *finalmix = m_finalmix; + int sample; + for (sample = m_finalmix_leftover; sample < samples_this_update * 100; sample += finalmix_step) { int sampindex = sample / 100; - INT32 samp; - /* clamp the left side */ - samp = leftmix[sampindex]; + // clamp the left side + INT32 samp = m_leftmix[sampindex]; if (samp < -32768) samp = -32768; else if (samp > 32767) samp = 32767; finalmix[finalmix_offset++] = samp; - /* clamp the right side */ - samp = rightmix[sampindex]; + // clamp the right side + samp = m_rightmix[sampindex]; if (samp < -32768) samp = -32768; else if (samp > 32767) samp = 32767; finalmix[finalmix_offset++] = samp; } - global->finalmix_leftover = sample - samples_this_update * 100; + m_finalmix_leftover = sample - samples_this_update * 100; - /* play the result */ + // play the result if (finalmix_offset > 0) { - if (!global->nosound_mode) - machine->osd().update_audio_stream(finalmix, finalmix_offset / 2); - machine->video().add_sound_to_recording(finalmix, finalmix_offset / 2); - if (global->wavfile != NULL) - wav_add_data_16(global->wavfile, finalmix, finalmix_offset); + if (!m_nosound_mode) + m_machine.osd().update_audio_stream(finalmix, finalmix_offset / 2); + m_machine.video().add_sound_to_recording(finalmix, finalmix_offset / 2); + if (m_wavfile != NULL) + wav_add_data_16(m_wavfile, finalmix, finalmix_offset); } - /* update the streamer */ - streams_update(machine); + // see if we ticked over to the next second + attotime curtime = timer_get_time(&m_machine); + 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 (sound_stream *stream = m_stream_list.first(); stream != NULL; stream = stream->next()) + stream->update_with_accounting(second_tick); + + // remember the update time + m_last_update = curtime; + + // update sample rates if they have changed + for (sound_stream *stream = m_stream_list.first(); stream != NULL; stream = stream->next()) + stream->apply_sample_rate_changes(); g_profiler.stop(); } - - - -//************************************************************************** -// SPEAKER DEVICE CONFIGURATION -//************************************************************************** - -//------------------------------------------------- -// speaker_device_config - constructor -//------------------------------------------------- - -speaker_device_config::speaker_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) - : device_config(mconfig, static_alloc_device_config, "Speaker", tag, owner, clock), - m_x(0.0), - m_y(0.0), - m_z(0.0) -{ -} - - -//------------------------------------------------- -// static_alloc_device_config - allocate a new -// configuration object -//------------------------------------------------- - -device_config *speaker_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) -{ - return global_alloc(speaker_device_config(mconfig, tag, owner, clock)); -} - - -//------------------------------------------------- -// alloc_device - allocate a new device object -//------------------------------------------------- - -device_t *speaker_device_config::alloc_device(running_machine &machine) const -{ - return auto_alloc(&machine, speaker_device(machine, *this)); -} - - -//------------------------------------------------- -// static_set_position - configuration helper to -// set the speaker position -//------------------------------------------------- - -void speaker_device_config::static_set_position(device_config *device, double x, double y, double z) -{ - speaker_device_config *speaker = downcast(device); - speaker->m_x = x; - speaker->m_y = y; - speaker->m_z = z; -} - - - -//************************************************************************** -// LIVE SPEAKER DEVICE -//************************************************************************** - -//------------------------------------------------- -// speaker_device - constructor -//------------------------------------------------- - -speaker_device::speaker_device(running_machine &_machine, const speaker_device_config &config) - : device_t(_machine, config), - m_config(config), - m_mixer_stream(NULL), - m_inputs(0), - m_input(NULL) -#ifdef MAME_DEBUG - , - m_max_sample(0), - m_clipped_samples(0), - m_total_samples(0) -#endif -{ -} - - -//------------------------------------------------- -// ~speaker_device - destructor -//------------------------------------------------- - -speaker_device::~speaker_device() -{ -#ifdef MAME_DEBUG - // log the maximum sample values for all speakers - if (m_max_sample > 0) - mame_printf_debug("Speaker \"%s\" - max = %d (gain *= %f) - %d%% samples clipped\n", tag(), m_max_sample, 32767.0 / (m_max_sample ? m_max_sample : 1), (int)((double)m_clipped_samples * 100.0 / m_total_samples)); -#endif /* MAME_DEBUG */ -} - - -//------------------------------------------------- -// device_start - perform device-specific -// startup -//------------------------------------------------- - -void speaker_device::device_start() -{ - // scan all the sound devices and count our inputs - int inputs = 0; - device_sound_interface *sound = NULL; - for (bool gotone = machine->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) - { - // scan each route on the device - for (const device_config_sound_interface::sound_route *route = sound->sound_config().m_route_list; route != NULL; route = route->m_next) - { - // if we are the target of this route, accumulate inputs - device_t *target_device = machine->device(route->m_target); - if (target_device == this) - { - // if the sound device is not yet started, bail however -- we need the its stream - if (!sound->device().started()) - throw device_missing_dependencies(); - - // accumulate inputs - inputs += (route->m_output == ALL_OUTPUTS) ? stream_get_device_outputs(*sound) : 1; - } - } - } - - // no inputs? that's weird - if (inputs == 0) - { - logerror("Warning: speaker \"%s\" has no inputs\n", tag()); - return; - } - - // now we know how many inputs; allocate the mixers and input data - m_mixer_stream = stream_create(this, inputs, 1, machine->sample_rate, NULL, static_mixer_update); - m_input = auto_alloc_array(machine, speaker_input, inputs); - m_inputs = 0; - - // iterate again over all the sound devices - for (bool gotone = machine->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) - { - // scan each route on the device - for (const device_config_sound_interface::sound_route *route = sound->sound_config().m_route_list; route != NULL; route = route->m_next) - { - // if we are the target of this route, hook it up - device_t *target_device = machine->device(route->m_target); - if (target_device == this) - { - // iterate over all outputs, matching any that apply - int numoutputs = stream_get_device_outputs(*sound); - for (int outputnum = 0; outputnum < numoutputs; outputnum++) - if (route->m_output == outputnum || route->m_output == ALL_OUTPUTS) - { - // fill in the input data on this speaker - m_input[m_inputs].m_gain = route->m_gain; - m_input[m_inputs].m_default_gain = route->m_gain; - m_input[m_inputs].m_name.printf("Speaker '%s': %s '%s'", tag(), sound->device().name(), sound->device().tag()); - if (numoutputs > 1) - m_input[m_inputs].m_name.catprintf(" Ch.%d", outputnum); - - // connect the output to the input - sound_stream *stream; - int streamoutput; - if (stream_device_output_to_stream_output(*sound, outputnum, &stream, &streamoutput)) - stream_set_input(m_mixer_stream, m_inputs++, stream, streamoutput, route->m_gain); - } - } - } - } -} - - -//------------------------------------------------- -// device_post_load - after we load a save state -// be sure to update the mixer stream's output -// sample rate -//------------------------------------------------- - -void speaker_device::device_post_load() -{ - stream_set_sample_rate(m_mixer_stream, machine->sample_rate); -} - - -//------------------------------------------------- -// mixer_update - mix all inputs to one output -//------------------------------------------------- - -void speaker_device::mixer_update(stream_sample_t **inputs, stream_sample_t **outputs, int samples) -{ - VPRINTF(("Mixer_update(%d)\n", samples)); - - // loop over samples - for (int pos = 0; pos < samples; pos++) - { - INT32 sample = inputs[0][pos]; - int inp; - - // add up all the inputs - for (inp = 1; inp < m_inputs; inp++) - sample += inputs[inp][pos]; - outputs[0][pos] = sample; - } -} - - -//------------------------------------------------- -// mix - mix in samples from the speaker's stream -//------------------------------------------------- - -void speaker_device::mix(INT32 *leftmix, INT32 *rightmix, int &samples_this_update, bool suppress) -{ - // skip if no stream - if (m_mixer_stream == NULL) - return; - - // update the stream, getting the start/end pointers around the operation - int numsamples; - const stream_sample_t *stream_buf = stream_get_output_since_last_update(m_mixer_stream, 0, &numsamples); - - // set or assert that all streams have the same count - if (samples_this_update == 0) - { - samples_this_update = numsamples; - - /* reset the mixing streams */ - memset(leftmix, 0, samples_this_update * sizeof(*leftmix)); - memset(rightmix, 0, samples_this_update * sizeof(*rightmix)); - } - assert(samples_this_update == numsamples); - -#ifdef MAME_DEBUG - // debug version: keep track of the maximum sample - for (int sample = 0; sample < samples_this_update; sample++) - { - if (stream_buf[sample] > m_max_sample) - m_max_sample = stream_buf[sample]; - else if (-stream_buf[sample] > m_max_sample) - m_max_sample = -stream_buf[sample]; - if (stream_buf[sample] > 32767 || stream_buf[sample] < -32768) - m_clipped_samples++; - m_total_samples++; - } -#endif - - // mix if sound is enabled - if (!suppress) - { - // if the speaker is centered, send to both left and right - if (m_config.m_x == 0) - for (int sample = 0; sample < samples_this_update; sample++) - { - leftmix[sample] += stream_buf[sample]; - rightmix[sample] += stream_buf[sample]; - } - - // if the speaker is to the left, send only to the left - else if (m_config.m_x < 0) - for (int sample = 0; sample < samples_this_update; sample++) - leftmix[sample] += stream_buf[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]; - } -} - - -//------------------------------------------------- -// set_input_gain - set the gain on a given -// input -//------------------------------------------------- - -void speaker_device::set_input_gain(int inputnum, float gain) -{ - m_input[inputnum].m_gain = gain; - stream_set_input_gain(m_mixer_stream, inputnum, gain); -} - - - -/*************************************************************************** - MISCELLANEOUS HELPERS -***************************************************************************/ - -/*------------------------------------------------- - sound_set_output_gain - set the gain of a - particular output --------------------------------------------------*/ - -void sound_set_output_gain(device_t *device, int output, float gain) -{ - sound_stream *stream; - int outputnum; - - if (stream_device_output_to_stream_output(device, output, &stream, &outputnum)) - stream_set_output_gain(stream, outputnum, gain); -} - - - -/*************************************************************************** - USER GAIN CONTROLS -***************************************************************************/ - -/*------------------------------------------------- - sound_get_user_gain_count - return the number - of user-controllable gain parameters --------------------------------------------------*/ - -int sound_get_user_gain_count(running_machine *machine) -{ - // count up the number of speaker inputs - int count = 0; - for (speaker_device *speaker = speaker_first(*machine); speaker != NULL; speaker = speaker_next(speaker)) - count += speaker->inputs(); - - return count; -} - - -/*------------------------------------------------- - sound_set_user_gain - set the nth user gain - value --------------------------------------------------*/ - -void sound_set_user_gain(running_machine *machine, int index, float gain) -{ - int inputnum; - speaker_device *speaker = index_to_input(machine, index, inputnum); - - if (speaker != NULL) - speaker->set_input_gain(inputnum, gain); -} - - -/*------------------------------------------------- - sound_get_user_gain - get the nth user gain - value --------------------------------------------------*/ - -float sound_get_user_gain(running_machine *machine, int index) -{ - int inputnum; - speaker_device *speaker = index_to_input(machine, index, inputnum); - return (speaker != NULL) ? speaker->input_gain(inputnum) : 0; -} - - -/*------------------------------------------------- - sound_get_default_gain - return the default - gain of the nth user value --------------------------------------------------*/ - -float sound_get_default_gain(running_machine *machine, int index) -{ - int inputnum; - speaker_device *speaker = index_to_input(machine, index, inputnum); - return (speaker != NULL) ? speaker->input_default_gain(inputnum) : 0; -} - - -/*------------------------------------------------- - sound_get_user_gain_name - return the name - of the nth user value --------------------------------------------------*/ - -const char *sound_get_user_gain_name(running_machine *machine, int index) -{ - int inputnum; - speaker_device *speaker = index_to_input(machine, index, inputnum); - return (speaker != NULL) ? speaker->input_name(inputnum) : 0; -} diff --git a/src/emu/sound.h b/src/emu/sound.h index 2ccee378dae..c483ce66293 100644 --- a/src/emu/sound.h +++ b/src/emu/sound.h @@ -4,8 +4,36 @@ Core sound interface functions and definitions. - Copyright Nicola Salmoria and the MAME Team. - Visit http://mamedev.org for licensing and usage restrictions. +**************************************************************************** + + Copyright Aaron Giles + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name 'MAME' nor the names of its contributors may be + used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. ***************************************************************************/ @@ -19,221 +47,229 @@ #define __SOUND_H__ -/*************************************************************************** - MACROS -***************************************************************************/ +//************************************************************************** +// MACROS +//************************************************************************** -/* these functions are macros primarily due to include file ordering */ -/* plus, they are very simple */ -#define speaker_output_count(config) (config)->m_devicelist.count(SPEAKER) -#define speaker_output_first(config) (config)->m_devicelist.first(SPEAKER) -#define speaker_output_next(previous) (previous)->typenext() +#define STREAM_UPDATE(name) void name(device_t *device, sound_stream *stream, void *param, stream_sample_t **inputs, stream_sample_t **outputs, int samples) -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** -// ======================> speaker_device_config +// forward references +class speaker_device; +typedef struct _wav_file wav_file; -class speaker_device_config : public device_config + +// structure describing an indexed speaker +struct speaker_input { - friend class speaker_device; - - // construction/destruction - speaker_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); - -public: - // allocators - static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); - virtual device_t *alloc_device(running_machine &machine) const; - - // inline configuration helpers - static void static_set_position(device_config *device, double x, double y, double z); - -protected: - // inline configuration state - double m_x; - double m_y; - double m_z; + speaker_device * speaker; // owning device + sound_stream * stream; // stream within the device + int inputnum; // input on the stream }; +// ======================> sound_stream -// ======================> speaker_device - -class speaker_device : public device_t +class sound_stream { - friend class speaker_device_config; - friend resource_pool_object::~resource_pool_object(); + friend class simple_list; + 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); - // construction/destruction - speaker_device(running_machine &_machine, const speaker_device_config &config); - virtual ~speaker_device(); - -public: - // input properties - int inputs() const { return m_inputs; } - float input_gain(int index = 0) const { return m_input[index].m_gain; } - float input_default_gain(int index = 0) const { return m_input[index].m_default_gain; } - const char *input_name(int index = 0) const { return m_input[index].m_name; } - void set_input_gain(int index, float gain); - - // internally for use by the sound system - void mix(INT32 *leftmix, INT32 *rightmix, int &samples_this_update, bool suppress); - -protected: - // device-level overrides - virtual void device_start(); - virtual void device_post_load(); - - // internal helpers - static STREAM_UPDATE( static_mixer_update ) { downcast(device)->mixer_update(inputs, outputs, samples); } - void mixer_update(stream_sample_t **inputs, stream_sample_t **outputs, int samples); - - // a single input - struct speaker_input + // stream output class + class stream_output { - float m_gain; // current gain - float m_default_gain; // default gain - astring m_name; // name of this input + public: + // construction/destruction + stream_output(); + + // internal state + sound_stream * m_stream; // owning stream + stream_sample_t * m_buffer; // output buffer + int m_dependents; // number of dependents + INT16 m_gain; // gain to apply to the output }; - // internal state - const speaker_device_config &m_config; - sound_stream * m_mixer_stream; // mixing stream - int m_inputs; // number of input streams - speaker_input * m_input; // array of input information -#ifdef MAME_DEBUG - INT32 m_max_sample; // largest sample value we've seen - INT32 m_clipped_samples; // total number of clipped samples - INT32 m_total_samples; // total number of samples -#endif + // stream input class + class stream_input + { + public: + // construction/destruction + stream_input(); + + // internal state + stream_output * m_source; // pointer to the sound_output for this source + stream_sample_t * m_resample; // buffer for resampling to the stream's sample rate + UINT32 m_bufsize; // size of output buffer, in samples + UINT32 m_bufalloc; // allocated size of output buffer, in samples + attoseconds_t m_latency_attoseconds; // latency between this stream and the input stream + INT16 m_gain; // gain to apply to this input + INT16 m_initial_gain; // initial gain supplied at creation + }; + + // constants + static const int OUTPUT_BUFFER_UPDATES = 5; + static const UINT32 FRAC_BITS = 22; + static const UINT32 FRAC_ONE = 1 << FRAC_BITS; + static const UINT32 FRAC_MASK = FRAC_ONE - 1; + + // construction/destruction + sound_stream(device_t &device, int inputs, int outputs, int sample_rate, void *param = NULL, stream_update_func callback = &sound_stream::device_stream_update_stub); + +public: + // getters + sound_stream *next() const { return m_next; } + device_t &device() const { return m_device; } + int sample_rate() const { return (m_new_sample_rate != 0) ? m_new_sample_rate : m_sample_rate; } + attotime sample_time() const; + attotime sample_period() const { return attotime_make(0, m_attoseconds_per_sample); } + int input_count() const { return m_inputs; } + int output_count() const { return m_outputs; } + float input_gain(int inputnum) const; + float initial_input_gain(int inputnum) const; + const char *input_name(int inputnum, astring &string) const; + float output_gain(int outputnum) const; + + // operations + void set_input(int inputnum, sound_stream *input_stream, int outputnum = 0, float gain = 1.0f); + void update(); + const stream_sample_t *output_since_last_update(int outputnum, int &numsamples); + + // timing + void set_sample_rate(int sample_rate); + void set_input_gain(int inputnum, float gain); + void set_output_gain(int outputnum, float gain); + +private: + // helpers called by our friends only + void update_with_accounting(bool second_tick); + void apply_sample_rate_changes(); + + // internal helpers + static STREAM_UPDATE( device_stream_update_stub ); + void recompute_sample_rate_data(); + void allocate_resample_buffers(); + void allocate_output_buffers(); + void postload(); + void generate_samples(int samples); + stream_sample_t *generate_resampled_data(stream_input &input, UINT32 numsamples); + + // linking information + device_t & m_device; // owning device + sound_stream * m_next; // next stream in the chain + + // general information + UINT32 m_sample_rate; // sample rate of this stream + UINT32 m_new_sample_rate; // newly-set sample rate for the stream + + // timing information + attoseconds_t m_attoseconds_per_sample;// number of attoseconds per sample + INT32 m_max_samples_per_update;// maximum samples per update + + // input information + int m_inputs; // number of inputs + stream_input * m_input; // list of streams we directly depend upon + stream_sample_t ** m_input_array; // array of inputs for passing to the callback + + // resample buffer information + UINT32 m_resample_bufalloc; // allocated size of each resample buffer + + // output information + int m_outputs; // number of outputs + stream_output * m_output; // list of streams which directly depend upon us + stream_sample_t ** m_output_array; // array of outputs for passing to the callback + + // output buffer information + UINT32 m_output_bufalloc; // allocated size of each output buffer + INT32 m_output_sampindex; // current position within each output buffer + INT32 m_output_update_sampindex;// position at time of last global update + INT32 m_output_base_sampindex;// sample at base of buffer, relative to the current emulated second + + // callback information + stream_update_func m_callback; // callback function + void * m_param; // callback function parameter }; -// device type definition -extern const device_type SPEAKER; +// ======================> sound_manager - - -/*************************************************************************** - SOUND DEVICE CONFIGURATION MACROS -***************************************************************************/ - -/* add/remove speakers */ -#define MCFG_SPEAKER_ADD(_tag, _x, _y, _z) \ - MCFG_DEVICE_ADD(_tag, SPEAKER, 0) \ - speaker_device_config::static_set_position(device, _x, _y, _z); \ - -#define MCFG_SPEAKER_STANDARD_MONO(_tag) \ - MCFG_SPEAKER_ADD(_tag, 0.0, 0.0, 1.0) - -#define MCFG_SPEAKER_STANDARD_STEREO(_tagl, _tagr) \ - MCFG_SPEAKER_ADD(_tagl, -0.2, 0.0, 1.0) \ - MCFG_SPEAKER_ADD(_tagr, 0.2, 0.0, 1.0) - - - -/*************************************************************************** - FUNCTION PROTOTYPES -***************************************************************************/ - -/* core interfaces */ -void sound_init(running_machine *machine); - - - -/* ----- sound device interface ----- */ - -/* global sound controls */ -void sound_mute(running_machine *machine, int mute); -void sound_set_attenuation(running_machine *machine, int attenuation); -int sound_get_attenuation(running_machine *machine); -void sound_global_enable(running_machine *machine, int enable); - -/* user gain controls on speaker inputs for mixing */ -int sound_get_user_gain_count(running_machine *machine); -void sound_set_user_gain(running_machine *machine, int index, float gain); -float sound_get_user_gain(running_machine *machine, int index); -float sound_get_default_gain(running_machine *machine, int index); -const char *sound_get_user_gain_name(running_machine *machine, int index); - - -/* driver gain controls on chip outputs */ -void sound_set_output_gain(device_t *device, int output, float gain); - - - -//************************************************************************** -// INLINE HELPERS -//************************************************************************** - -//------------------------------------------------- -// speaker_count - return the number of speaker -// devices in a machine_config -//------------------------------------------------- - -inline int speaker_count(const machine_config &config) +class sound_manager { - return config.m_devicelist.count(SPEAKER); -} + friend class sound_stream; + // reasons for muting + static const UINT8 MUTE_REASON_PAUSE = 0x01; + static const UINT8 MUTE_REASON_UI = 0x02; + static const UINT8 MUTE_REASON_DEBUGGER = 0x04; + static const UINT8 MUTE_REASON_SYSTEM = 0x08; -//------------------------------------------------- -// speaker_first - return the first speaker -// device config in a machine_config -//------------------------------------------------- + // stream updates + static const attotime STREAMS_UPDATE_ATTOTIME; -inline const speaker_device_config *speaker_first(const machine_config &config) -{ - return downcast(config.m_devicelist.first(SPEAKER)); -} +public: + static const int STREAMS_UPDATE_FREQUENCY = 50; + // construction/destruction + sound_manager(running_machine &machine); + ~sound_manager(); + + // getters + int attenuation() const { return m_attenuation; } + sound_stream *first_stream() const { return m_stream_list.first(); } + attotime last_update() const { return m_last_update; } + attoseconds_t update_attoseconds() const { return m_update_attoseconds; } + + // stream creation + sound_stream *stream_alloc(device_t &device, int inputs, int outputs, int sample_rate, void *param = NULL, sound_stream::stream_update_func callback = NULL); + + // global controls + void set_attenuation(int attenuation); + 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 + bool indexed_speaker_input(int index, speaker_input &info) const; + +private: + // internal helpers + void mute(bool mute, UINT8 reason); + static void reset(running_machine &machine); + static void pause(running_machine &machine); + static void resume(running_machine &machine); + static void config_load(running_machine *machine, int config_type, xml_data_node *parentnode); + static void config_save(running_machine *machine, int config_type, xml_data_node *parentnode); -//------------------------------------------------- -// speaker_next - return the next speaker -// device config in a machine_config -//------------------------------------------------- + static TIMER_CALLBACK( update_static ) { reinterpret_cast(ptr)->update(); } + void update(); -inline const speaker_device_config *speaker_next(const speaker_device_config *previous) -{ - return downcast(previous->typenext()); -} + // internal state + running_machine & m_machine; // reference to our machine + emu_timer * m_update_timer; // timer to drive periodic updates + UINT32 m_finalmix_leftover; + INT16 * m_finalmix; + INT32 * m_leftmix; + INT32 * m_rightmix; -//------------------------------------------------- -// speaker_count - return the number of speaker -// devices in a machine -//------------------------------------------------- + UINT8 m_muted; + int m_attenuation; + int m_nosound_mode; -inline int speaker_count(running_machine &machine) -{ - return machine.m_devicelist.count(SPEAKER); -} - - -//------------------------------------------------- -// speaker_first - return the first speaker -// device in a machine -//------------------------------------------------- - -inline speaker_device *speaker_first(running_machine &machine) -{ - return downcast(machine.m_devicelist.first(SPEAKER)); -} - - -//------------------------------------------------- -// speaker_next - return the next speaker -// device in a machine -//------------------------------------------------- - -inline speaker_device *speaker_next(speaker_device *previous) -{ - return downcast(previous->typenext()); -} + wav_file * m_wavfile; + + // streams data + simple_list m_stream_list; // list of streams + attoseconds_t m_update_attoseconds; // attoseconds between global updates + attotime m_last_update; // last update time +}; #endif /* __SOUND_H__ */ diff --git a/src/emu/sound/2151intf.c b/src/emu/sound/2151intf.c index bf3e5d95686..12d713caf4e 100644 --- a/src/emu/sound/2151intf.c +++ b/src/emu/sound/2151intf.c @@ -7,7 +7,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "fm.h" #include "2151intf.h" #include "ym2151.h" @@ -57,7 +56,7 @@ static DEVICE_START( ym2151 ) rate = device->clock()/64; /* stream setup */ - info->stream = stream_create(device,0,2,rate,info,ym2151_update); + info->stream = device->machine->sound().stream_alloc(*device,0,2,rate,info,ym2151_update); info->chip = ym2151_init(device,device->clock(),rate); assert_always(info->chip != NULL, "Error creating YM2151 chip"); @@ -88,7 +87,7 @@ READ8_DEVICE_HANDLER( ym2151_r ) if (offset & 1) { - stream_update(token->stream); + token->stream->update(); return ym2151_read_status(token->chip); } else @@ -101,7 +100,7 @@ WRITE8_DEVICE_HANDLER( ym2151_w ) if (offset & 1) { - stream_update(token->stream); + token->stream->update(); ym2151_write_reg(token->chip, token->lastreg, data); } else diff --git a/src/emu/sound/2203intf.c b/src/emu/sound/2203intf.c index 85aa3d37cc9..70b99c5050d 100644 --- a/src/emu/sound/2203intf.c +++ b/src/emu/sound/2203intf.c @@ -1,5 +1,4 @@ #include "emu.h" -#include "streams.h" #include "2203intf.h" #include "fm.h" @@ -81,7 +80,7 @@ static TIMER_CALLBACK( timer_callback_2203_1 ) void ym2203_update_request(void *param) { ym2203_state *info = (ym2203_state *)param; - stream_update(info->stream); + info->stream->update(); } @@ -139,7 +138,7 @@ static DEVICE_START( ym2203 ) info->timer[1] = timer_alloc(device->machine, timer_callback_2203_1, info); /* stream system initialize */ - info->stream = stream_create(device,0,1,rate,info,ym2203_stream_update); + info->stream = device->machine->sound().stream_alloc(*device,0,1,rate,info,ym2203_stream_update); /* Initialize FM emurator */ info->chip = ym2203_init(info,device,device->clock(),rate,timer_handler,IRQHandler,&psgintf); diff --git a/src/emu/sound/2413intf.c b/src/emu/sound/2413intf.c index 9118561bc3e..fc37220eb23 100644 --- a/src/emu/sound/2413intf.c +++ b/src/emu/sound/2413intf.c @@ -5,7 +5,6 @@ ****************************************************************/ #include "emu.h" -#include "streams.h" #include "ym2413.h" #include "2413intf.h" @@ -50,7 +49,7 @@ static STREAM_UPDATE( ym2413_stream_update ) static void _stream_update(void *param, int interval) { ym2413_state *info = (ym2413_state *)param; - stream_update(info->stream); + info->stream->update(); } static DEVICE_START( ym2413 ) @@ -63,7 +62,7 @@ static DEVICE_START( ym2413 ) assert_always(info->chip != NULL, "Error creating YM2413 chip"); /* stream system initialize */ - info->stream = stream_create(device,0,2,rate,info,ym2413_stream_update); + info->stream = device->machine->sound().stream_alloc(*device,0,2,rate,info,ym2413_stream_update); ym2413_set_update_handler(info->chip, _stream_update, info); @@ -84,7 +83,7 @@ static DEVICE_START( ym2413 ) { ym2413_reset (i); - ym2413[i].DAC_stream = stream_create(device, 0, 1, device->clock()/72, i, YM2413DAC_update); + ym2413[i].DAC_stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock()/72, i, YM2413DAC_update); if (ym2413[i].DAC_stream == -1) return 1; diff --git a/src/emu/sound/2608intf.c b/src/emu/sound/2608intf.c index 42f410b2ada..6048fcf2d79 100644 --- a/src/emu/sound/2608intf.c +++ b/src/emu/sound/2608intf.c @@ -12,7 +12,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "ay8910.h" #include "2608intf.h" #include "fm.h" @@ -110,7 +109,7 @@ static void timer_handler(void *param,int c,int count,int clock) void ym2608_update_request(void *param) { ym2608_state *info = (ym2608_state *)param; - stream_update(info->stream); + info->stream->update(); } static STREAM_UPDATE( ym2608_stream_update ) @@ -157,7 +156,7 @@ static DEVICE_START( ym2608 ) info->timer[1] = timer_alloc(device->machine, timer_callback_2608_1, info); /* stream system initialize */ - info->stream = stream_create(device,0,2,rate,info,ym2608_stream_update); + info->stream = device->machine->sound().stream_alloc(*device,0,2,rate,info,ym2608_stream_update); /* setup adpcm buffers */ pcmbufa = *device->region(); pcmsizea = device->region()->bytes(); diff --git a/src/emu/sound/2610intf.c b/src/emu/sound/2610intf.c index f20fc7e574e..345dadaafc4 100644 --- a/src/emu/sound/2610intf.c +++ b/src/emu/sound/2610intf.c @@ -12,7 +12,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "ay8910.h" #include "2610intf.h" #include "fm.h" @@ -110,7 +109,7 @@ static void timer_handler(void *param,int c,int count,int clock) void ym2610_update_request(void *param) { ym2610_state *info = (ym2610_state *)param; - stream_update(info->stream); + info->stream->update(); } @@ -161,7 +160,7 @@ static DEVICE_START( ym2610 ) info->timer[1] = timer_alloc(device->machine, timer_callback_1, info); /* stream system initialize */ - info->stream = stream_create(device,0,2,rate,info,(type == YM2610) ? ym2610_stream_update : ym2610b_stream_update); + info->stream = device->machine->sound().stream_alloc(*device,0,2,rate,info,(type == YM2610) ? ym2610_stream_update : ym2610b_stream_update); /* setup adpcm buffers */ pcmbufa = *device->region(); pcmsizea = device->region()->bytes(); diff --git a/src/emu/sound/2612intf.c b/src/emu/sound/2612intf.c index e1a86406a5e..c2895103298 100644 --- a/src/emu/sound/2612intf.c +++ b/src/emu/sound/2612intf.c @@ -12,7 +12,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "sound/fm.h" #include "sound/2612intf.h" @@ -77,7 +76,7 @@ static void timer_handler(void *param,int c,int count,int clock) void ym2612_update_request(void *param) { ym2612_state *info = (ym2612_state *)param; - stream_update(info->stream); + info->stream->update(); } /***********************************************************/ @@ -113,7 +112,7 @@ static DEVICE_START( ym2612 ) info->timer[1] = timer_alloc(device->machine, timer_callback_2612_1, info); /* stream system initialize */ - info->stream = stream_create(device,0,2,rate,info,ym2612_stream_update); + info->stream = device->machine->sound().stream_alloc(*device,0,2,rate,info,ym2612_stream_update); /**** initialize YM2612 ****/ info->chip = ym2612_init(info,device,device->clock(),rate,timer_handler,IRQHandler); diff --git a/src/emu/sound/262intf.c b/src/emu/sound/262intf.c index c6a85147363..8770258437c 100644 --- a/src/emu/sound/262intf.c +++ b/src/emu/sound/262intf.c @@ -6,7 +6,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "262intf.h" #include "ymf262.h" @@ -72,7 +71,7 @@ static STREAM_UPDATE( ymf262_stream_update ) static void _stream_update(void *param, int interval) { ymf262_state *info = (ymf262_state *)param; - stream_update(info->stream); + info->stream->update(); } @@ -89,7 +88,7 @@ static DEVICE_START( ymf262 ) info->chip = ymf262_init(device,device->clock(),rate); assert_always(info->chip != NULL, "Error creating YMF262 chip"); - info->stream = stream_create(device,0,4,rate,info,ymf262_stream_update); + info->stream = device->machine->sound().stream_alloc(*device,0,4,rate,info,ymf262_stream_update); /* YMF262 setup */ ymf262_set_timer_handler (info->chip, timer_handler_262, info); diff --git a/src/emu/sound/3526intf.c b/src/emu/sound/3526intf.c index c9d58b41bf6..7f9ecf70ed0 100644 --- a/src/emu/sound/3526intf.c +++ b/src/emu/sound/3526intf.c @@ -17,7 +17,6 @@ * ******************************************************************************/ #include "emu.h" -#include "streams.h" #include "3526intf.h" #include "fm.h" #include "sound/fmopl.h" @@ -83,7 +82,7 @@ static STREAM_UPDATE( ym3526_stream_update ) static void _stream_update(void *param, int interval) { ym3526_state *info = (ym3526_state *)param; - stream_update(info->stream); + info->stream->update(); } @@ -100,7 +99,7 @@ static DEVICE_START( ym3526 ) info->chip = ym3526_init(device,device->clock(),rate); assert_always(info->chip != NULL, "Error creating YM3526 chip"); - info->stream = stream_create(device,0,1,rate,info,ym3526_stream_update); + info->stream = device->machine->sound().stream_alloc(*device,0,1,rate,info,ym3526_stream_update); /* YM3526 setup */ ym3526_set_timer_handler (info->chip, TimerHandler, info); ym3526_set_irq_handler (info->chip, IRQHandler, info); diff --git a/src/emu/sound/3812intf.c b/src/emu/sound/3812intf.c index ebedd8a4c4f..6e69421f300 100644 --- a/src/emu/sound/3812intf.c +++ b/src/emu/sound/3812intf.c @@ -17,7 +17,6 @@ * ******************************************************************************/ #include "emu.h" -#include "streams.h" #include "3812intf.h" #include "fm.h" #include "sound/fmopl.h" @@ -83,7 +82,7 @@ static STREAM_UPDATE( ym3812_stream_update ) static void _stream_update(void * param, int interval) { ym3812_state *info = (ym3812_state *)param; - stream_update(info->stream); + info->stream->update(); } @@ -100,7 +99,7 @@ static DEVICE_START( ym3812 ) info->chip = ym3812_init(device,device->clock(),rate); assert_always(info->chip != NULL, "Error creating YM3812 chip"); - info->stream = stream_create(device,0,1,rate,info,ym3812_stream_update); + info->stream = device->machine->sound().stream_alloc(*device,0,1,rate,info,ym3812_stream_update); /* YM3812 setup */ ym3812_set_timer_handler (info->chip, TimerHandler, info); diff --git a/src/emu/sound/8950intf.c b/src/emu/sound/8950intf.c index e89d4989e07..ce6709581d8 100644 --- a/src/emu/sound/8950intf.c +++ b/src/emu/sound/8950intf.c @@ -17,7 +17,6 @@ * ******************************************************************************/ #include "emu.h" -#include "streams.h" #include "8950intf.h" #include "fm.h" #include "sound/fmopl.h" @@ -110,7 +109,7 @@ static STREAM_UPDATE( y8950_stream_update ) static void _stream_update(void *param, int interval) { y8950_state *info = (y8950_state *)param; - stream_update(info->stream); + info->stream->update(); } @@ -130,8 +129,7 @@ static DEVICE_START( y8950 ) /* ADPCM ROM data */ y8950_set_delta_t_memory(info->chip, *device->region(), device->region()->bytes()); - info->stream = stream_create(device,0,1,rate,info,y8950_stream_update); - + info->stream = device->machine->sound().stream_alloc(*device,0,1,rate,info,y8950_stream_update); /* port and keyboard handler */ y8950_set_port_handler(info->chip, Y8950PortHandler_w, Y8950PortHandler_r, info); y8950_set_keyboard_handler(info->chip, Y8950KeyboardHandler_w, Y8950KeyboardHandler_r, info); diff --git a/src/emu/sound/aica.c b/src/emu/sound/aica.c index 967dcb3db38..b8fd907b58e 100644 --- a/src/emu/sound/aica.c +++ b/src/emu/sound/aica.c @@ -9,7 +9,6 @@ */ #include "emu.h" -#include "streams.h" #include "aica.h" #include "aicadsp.h" @@ -1255,7 +1254,7 @@ static DEVICE_START( aica ) { AICA->IntARMCB = intf->irq_callback; - AICA->stream = stream_create(device, 0, 2, 44100, AICA, AICA_Update); + AICA->stream = device->machine->sound().stream_alloc(*device, 0, 2, 44100, AICA, AICA_Update); } } diff --git a/src/emu/sound/asc.c b/src/emu/sound/asc.c index 5ce20abd0f9..e3e0290d7e7 100644 --- a/src/emu/sound/asc.c +++ b/src/emu/sound/asc.c @@ -30,7 +30,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "asc.h" //************************************************************************** @@ -106,7 +105,7 @@ static TIMER_CALLBACK( sync_timer_cb ) { asc_device *pDevice = (asc_device *)ptr; - stream_update(pDevice->m_stream); + pDevice->m_stream->update(); } //------------------------------------------------- @@ -130,7 +129,7 @@ asc_device::asc_device(running_machine &_machine, const asc_device_config &confi void asc_device::device_start() { // create the stream - m_stream = stream_create(this, 0, 2, 22257, this, static_stream_generate); + m_stream = m_machine.sound().stream_alloc(*this, 0, 2, 22257, this, static_stream_generate); memset(m_regs, 0, sizeof(m_regs)); @@ -156,7 +155,7 @@ void asc_device::device_start() void asc_device::device_reset() { - stream_update(m_stream); + m_stream->update(); memset(m_regs, 0, sizeof(m_regs)); memset(m_fifo_a, 0, sizeof(m_fifo_a)); @@ -333,7 +332,7 @@ READ8_MEMBER( asc_device::read ) } else { - stream_update(m_stream); + m_stream->update(); switch (offset) { case R_VERSION: @@ -498,7 +497,7 @@ WRITE8_MEMBER( asc_device::write ) { // printf("ASC: %02x to %x (was %x)\n", data, offset, m_regs[offset-0x800]); - stream_update(m_stream); + m_stream->update(); switch (offset) { case R_MODE: diff --git a/src/emu/sound/asc.h b/src/emu/sound/asc.h index 8050093ff6c..4266774adeb 100644 --- a/src/emu/sound/asc.h +++ b/src/emu/sound/asc.h @@ -12,7 +12,6 @@ #ifndef __ASC_H__ #define __ASC_H__ -#include "streams.h" diff --git a/src/emu/sound/astrocde.c b/src/emu/sound/astrocde.c index 7e5edab5bc5..f1ae66edf94 100644 --- a/src/emu/sound/astrocde.c +++ b/src/emu/sound/astrocde.c @@ -40,7 +40,6 @@ ***********************************************************/ #include "emu.h" -#include "streams.h" #include "astrocde.h" @@ -272,7 +271,7 @@ static DEVICE_START( astrocade ) chip->bitswap[i] = BITSWAP8(i, 0,1,2,3,4,5,6,7); /* allocate a stream for output */ - chip->stream = stream_create(device, 0, 1, device->clock(), chip, astrocade_update); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock(), chip, astrocade_update); /* reset state */ DEVICE_RESET_CALL(astrocade); @@ -297,7 +296,7 @@ WRITE8_DEVICE_HANDLER( astrocade_sound_w ) offset &= 7; /* update */ - stream_update(chip->stream); + chip->stream->update(); /* stash the new register value */ chip->reg[offset & 7] = data; diff --git a/src/emu/sound/ay8910.c b/src/emu/sound/ay8910.c index 519c8395ea4..5fab115687a 100644 --- a/src/emu/sound/ay8910.c +++ b/src/emu/sound/ay8910.c @@ -105,7 +105,6 @@ has twice the steps, happening twice as fast. ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "ay8910.h" /************************************* @@ -776,7 +775,7 @@ void *ay8910_start_ym(void *infoptr, device_type chip_type, device_t *device, in /* 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 divider of 8 here. */ - info->channel = stream_create(device, 0, info->streams, device->clock() / 8, info, ay8910_update); + info->channel = device->machine->sound().stream_alloc(*device, 0, info->streams, device->clock() / 8, info, ay8910_update); ay8910_set_clock_ym(info,device->clock()); ay8910_statesave(info, device); @@ -833,13 +832,13 @@ void ay8910_set_volume(device_t *device,int channel,int volume) for (ch = 0; ch < psg->streams; ch++) if (channel == ch || psg->streams == 1 || channel == ALL_8910_CHANNELS) - stream_set_output_gain(psg->channel, ch, volume / 100.0); + psg->channel->set_output_gain(ch, volume / 100.0); } void ay8910_set_clock_ym(void *chip, int clock) { ay8910_context *psg = (ay8910_context *)chip; - stream_set_sample_rate(psg->channel, clock / 8 ); + psg->channel->set_sample_rate( clock / 8 ); } void ay8910_write_ym(void *chip, int addr, int data) @@ -854,7 +853,7 @@ void ay8910_write_ym(void *chip, int addr, int data) if (r == AY_ESHAPE || psg->regs[r] != data) { /* update the output buffer before changing the register */ - stream_update(psg->channel); + psg->channel->update(); } ay8910_write_reg(psg,r,data); @@ -874,7 +873,7 @@ int ay8910_read_ym(void *chip) if (r > 15) return 0; /* There are no state dependent register in the AY8910! */ - /* stream_update(psg->channel); */ + /* psg->channel->update(); */ switch (r) { diff --git a/src/emu/sound/beep.c b/src/emu/sound/beep.c index e9e1b951d4c..0c0fe947f9e 100644 --- a/src/emu/sound/beep.c +++ b/src/emu/sound/beep.c @@ -12,7 +12,6 @@ ****************************************************************************/ #include "emu.h" -#include "streams.h" #include "sound/beep.h" @@ -93,7 +92,7 @@ static DEVICE_START( beep ) { beep_state *pBeep = get_safe_token(device); - pBeep->stream = stream_create(device, 0, 1, BEEP_RATE, pBeep, beep_sound_update ); + pBeep->stream = device->machine->sound().stream_alloc(*device, 0, 1, BEEP_RATE, pBeep, beep_sound_update ); pBeep->enable = 0; pBeep->frequency = 3250; pBeep->incr = 0; @@ -116,7 +115,7 @@ void beep_set_state(device_t *device, int on) if (info->enable == on) return; - stream_update(info->stream); + info->stream->update(); info->enable = on; /* restart wave from beginning */ @@ -139,7 +138,7 @@ void beep_set_frequency(device_t *device,int frequency) if (info->frequency == frequency) return; - stream_update(info->stream); + info->stream->update(); info->frequency = frequency; info->signal = 0x07fff; info->incr = 0; @@ -157,11 +156,11 @@ void beep_set_volume(device_t *device, int volume) { beep_state *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); volume = 100 * volume / 7; - sound_set_output_gain(device, 0, volume); + downcast(device)->set_output_gain(0, volume); } diff --git a/src/emu/sound/bsmt2000.c b/src/emu/sound/bsmt2000.c index cf0c776ae50..e72a5857522 100644 --- a/src/emu/sound/bsmt2000.c +++ b/src/emu/sound/bsmt2000.c @@ -43,7 +43,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "bsmt2000.h" @@ -227,7 +226,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_create(*this, 0, 2, clock() / 128); + m_stream = m_machine.sound().stream_alloc(*this, 0, 2, clock() / 128); // register for save states state_save_register_device_item(this, 0, m_register_select); @@ -261,7 +260,7 @@ void bsmt2000_device::device_timer(emu_timer &timer, device_timer_id id, int par { // deferred reset case TIMER_ID_RESET: - stream_update(m_stream); + m_stream->update(); m_cpu->reset(); break; @@ -281,8 +280,8 @@ void bsmt2000_device::device_timer(emu_timer &timer, device_timer_id id, int par //------------------------------------------------- -// stream_generate - handle update requests for -// our sound stream +// sound_stream_update - 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) @@ -398,7 +397,7 @@ WRITE16_MEMBER( bsmt2000_device::tms_rom_bank_w ) WRITE16_MEMBER( bsmt2000_device::tms_left_w ) { - stream_update(m_stream); + m_stream->update(); m_left_data = data; } @@ -410,7 +409,7 @@ WRITE16_MEMBER( bsmt2000_device::tms_left_w ) WRITE16_MEMBER( bsmt2000_device::tms_right_w ) { - stream_update(m_stream); + m_stream->update(); m_right_data = data; } diff --git a/src/emu/sound/c140.c b/src/emu/sound/c140.c index 30a939d5b82..f87c8d22b8c 100644 --- a/src/emu/sound/c140.c +++ b/src/emu/sound/c140.c @@ -44,7 +44,6 @@ Unmapped registers: #include "emu.h" -#include "streams.h" #include "c140.h" #define MAX_VOICE 24 @@ -195,7 +194,7 @@ static long find_sample(c140_state *info, long adrs, long bank, int voice) WRITE8_DEVICE_HANDLER( c140_w ) { c140_state *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); offset&=0x1ff; @@ -471,7 +470,7 @@ static DEVICE_START( c140 ) info->banking_type = intf->banking_type; - info->stream = stream_create(device,0,2,info->sample_rate,info,update_stereo); + info->stream = device->machine->sound().stream_alloc(*device,0,2,info->sample_rate,info,update_stereo); info->pRom=*device->region(); diff --git a/src/emu/sound/c352.c b/src/emu/sound/c352.c index bbfd1a2d224..90a3c1e6fc0 100644 --- a/src/emu/sound/c352.c +++ b/src/emu/sound/c352.c @@ -14,7 +14,6 @@ */ #include "emu.h" -#include "streams.h" #include "c352.h" #define VERBOSE (0) @@ -365,7 +364,7 @@ static unsigned short c352_read_reg16(c352_state *info, unsigned long address) unsigned long chan; unsigned short val; - stream_update(info->stream); + info->stream->update(); chan = (address >> 4) & 0xfff; if (chan > 31) @@ -391,7 +390,7 @@ static void c352_write_reg16(c352_state *info, unsigned long address, unsigned s unsigned long chan; int i; - stream_update(info->stream); + info->stream->update(); chan = (address >> 4) & 0xfff; @@ -546,7 +545,7 @@ static DEVICE_START( c352 ) info->sample_rate_base = device->clock() / 192; - info->stream = stream_create(device, 0, 4, info->sample_rate_base, info, c352_update); + info->stream = device->machine->sound().stream_alloc(*device, 0, 4, info->sample_rate_base, info, c352_update); c352_init(info, device); } diff --git a/src/emu/sound/c6280.c b/src/emu/sound/c6280.c index 519264f6cf2..0412d014dab 100644 --- a/src/emu/sound/c6280.c +++ b/src/emu/sound/c6280.c @@ -54,7 +54,6 @@ */ #include "emu.h" -#include "streams.h" #include "c6280.h" typedef struct { @@ -143,7 +142,7 @@ static void c6280_write(c6280_t *p, int offset, int data) t_channel *q = &p->channel[p->select]; /* Update stream */ - stream_update(p->stream); + p->stream->update(); switch(offset & 0x0F) { @@ -329,7 +328,7 @@ static DEVICE_START( c6280 ) c6280_init(device, info, device->clock(), rate); /* Create stereo stream */ - info->stream = stream_create(device, 0, 2, rate, info, c6280_update); + info->stream = device->machine->sound().stream_alloc(*device, 0, 2, rate, info, c6280_update); } READ8_DEVICE_HANDLER( c6280_r ) diff --git a/src/emu/sound/cdda.c b/src/emu/sound/cdda.c index 946a7248c23..4087ce6888e 100644 --- a/src/emu/sound/cdda.c +++ b/src/emu/sound/cdda.c @@ -4,7 +4,6 @@ */ #include "emu.h" -#include "streams.h" #include "cdrom.h" #include "cdda.h" @@ -59,7 +58,7 @@ static DEVICE_START( cdda ) //intf = (const struct CDDAinterface *)device->baseconfig().static_config(); - info->stream = stream_create(device, 0, 2, 44100, info, cdda_update); + info->stream = device->machine->sound().stream_alloc(*device, 0, 2, 44100, info, cdda_update); state_save_register_device_item( device, 0, info->audio_playing ); state_save_register_device_item( device, 0, info->audio_pause ); @@ -114,7 +113,7 @@ void cdda_start_audio(device_t *device, UINT32 startlba, UINT32 numblocks) { cdda_info *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); info->audio_playing = TRUE; info->audio_pause = FALSE; info->audio_ended_normally = FALSE; @@ -132,7 +131,7 @@ void cdda_stop_audio(device_t *device) { cdda_info *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); info->audio_playing = FALSE; info->audio_ended_normally = TRUE; } @@ -147,7 +146,7 @@ void cdda_pause_audio(device_t *device, int pause) { cdda_info *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); info->audio_pause = pause; } @@ -161,7 +160,7 @@ UINT32 cdda_get_audio_lba(device_t *device) { cdda_info *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); return info->audio_lba; } @@ -175,7 +174,7 @@ int cdda_audio_active(device_t *device) { cdda_info *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); return info->audio_playing; } @@ -299,8 +298,8 @@ void cdda_set_volume(device_t *device,int volume) { cdda_info *cdda = get_safe_token(device); - stream_set_output_gain(cdda->stream,0,volume / 100.0); - stream_set_output_gain(cdda->stream,1,volume / 100.0); + cdda->stream->set_output_gain(0,volume / 100.0); + cdda->stream->set_output_gain(1,volume / 100.0); } /*------------------------------------------------- @@ -313,9 +312,9 @@ void cdda_set_channel_volume(device_t *device, int channel, int volume) cdda_info *cdda = get_safe_token(device); if(channel == 0) - stream_set_output_gain(cdda->stream,0,volume / 100.0); + cdda->stream->set_output_gain(0,volume / 100.0); if(channel == 1) - stream_set_output_gain(cdda->stream,1,volume / 100.0); + cdda->stream->set_output_gain(1,volume / 100.0); } /************************************************************************** diff --git a/src/emu/sound/cdp1863.c b/src/emu/sound/cdp1863.c index 2cce4fcbc93..0f174342ba2 100644 --- a/src/emu/sound/cdp1863.c +++ b/src/emu/sound/cdp1863.c @@ -16,7 +16,6 @@ */ #include "emu.h" -#include "streams.h" #include "cdp1863.h" /*************************************************************************** @@ -176,7 +175,7 @@ static DEVICE_START( cdp1863 ) const cdp1863_config *config = get_safe_config(device); /* set initial values */ - cdp1863->stream = stream_create(device, 0, 1, device->machine->sample_rate, cdp1863, cdp1863_stream_update); + cdp1863->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->machine->sample_rate, cdp1863, cdp1863_stream_update); cdp1863->clock1 = device->clock(); cdp1863->clock2 = config->clock2; cdp1863->oe = 1; diff --git a/src/emu/sound/cdp1864.c b/src/emu/sound/cdp1864.c index 23b2dcd8cac..bf71f8b81e5 100644 --- a/src/emu/sound/cdp1864.c +++ b/src/emu/sound/cdp1864.c @@ -23,7 +23,6 @@ */ #include "emu.h" -#include "streams.h" #include "cdp1864.h" /*************************************************************************** @@ -447,7 +446,7 @@ static DEVICE_START( cdp1864 ) cdp1864_init_palette(device, intf); /* create sound stream */ - cdp1864->stream = stream_create(device, 0, 1, device->machine->sample_rate, cdp1864, cdp1864_stream_update); + cdp1864->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->machine->sample_rate, cdp1864, cdp1864_stream_update); /* create the timers */ cdp1864->int_timer = timer_alloc(device->machine, cdp1864_int_tick, (void *)device); diff --git a/src/emu/sound/cdp1869.c b/src/emu/sound/cdp1869.c index c9a716e1fff..d05b55b9f6a 100644 --- a/src/emu/sound/cdp1869.c +++ b/src/emu/sound/cdp1869.c @@ -434,7 +434,7 @@ void cdp1869_device::device_start() initialize_palette(); // create sound stream - m_stream = stream_create(this, 0, 1, m_machine.sample_rate, this, static_stream_generate); + m_stream = m_machine.sound().stream_alloc(*this, 0, 1, m_machine.sample_rate); // register for state saving state_save_register_device_item(this, 0, m_prd); @@ -512,16 +512,11 @@ void cdp1869_device::initialize_palette() //------------------------------------------------- -// stream_generate - handle update requests for +// sound_stream_update - handle update requests for // our sound stream //------------------------------------------------- -STREAM_UPDATE( cdp1869_device::static_stream_generate ) -{ - reinterpret_cast(param)->stream_generate(inputs, outputs, samples); -} - -void cdp1869_device::stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void cdp1869_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) { // reset the output stream memset(outputs[0], 0, samples * sizeof(*outputs[0])); @@ -713,7 +708,7 @@ WRITE8_MEMBER( cdp1869_device::out4_w ) m_toneoff = BIT(offset, 7); m_tonediv = (offset & 0x7f00) >> 8; - stream_update(m_stream); + m_stream->update(); } @@ -753,7 +748,7 @@ WRITE8_MEMBER( cdp1869_device::out5_w ) m_wnfreq = (offset & 0x7000) >> 12; m_wnoff = BIT(offset, 15); - stream_update(m_stream); + m_stream->update(); if (m_cmem) { diff --git a/src/emu/sound/cdp1869.h b/src/emu/sound/cdp1869.h index 71e66061850..f2c218e24f0 100644 --- a/src/emu/sound/cdp1869.h +++ b/src/emu/sound/cdp1869.h @@ -271,8 +271,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); // internal callbacks - static STREAM_UPDATE( static_stream_generate ); - virtual void stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples); + virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); inline bool is_ntsc(); inline UINT8 read_page_ram_byte(offs_t address); diff --git a/src/emu/sound/cem3394.c b/src/emu/sound/cem3394.c index cc4baa04f43..3becc97bf8c 100644 --- a/src/emu/sound/cem3394.c +++ b/src/emu/sound/cem3394.c @@ -12,7 +12,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "cem3394.h" @@ -335,7 +334,7 @@ static DEVICE_START( cem3394 ) chip->inv_sample_rate = 1.0 / (double)chip->sample_rate; /* allocate stream channels, 1 per chip */ - chip->stream = stream_create(device, 0, 1, chip->sample_rate, chip, cem3394_update); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 1, chip->sample_rate, chip, cem3394_update); chip->external = intf->external; chip->vco_zero_freq = intf->vco_zero_freq; chip->filter_zero_freq = intf->filter_zero_freq; @@ -426,7 +425,7 @@ void cem3394_set_voltage(device_t *device, int input, double voltage) chip->values[input] = voltage; /* update the stream first */ - stream_update(chip->stream); + chip->stream->update(); /* switch off the input */ switch (input) diff --git a/src/emu/sound/dac.c b/src/emu/sound/dac.c index 10590b9b1c9..33a35580f80 100644 --- a/src/emu/sound/dac.c +++ b/src/emu/sound/dac.c @@ -1,5 +1,4 @@ #include "emu.h" -#include "streams.h" #include "dac.h" @@ -43,7 +42,7 @@ void dac_data_w(device_t *device, UINT8 data) if (info->output != out) { /* update the output buffer before changing the registers */ - stream_update(info->channel); + info->channel->update(); info->output = out; } } @@ -57,7 +56,7 @@ void dac_signed_data_w(device_t *device, UINT8 data) if (info->output != out) { /* update the output buffer before changing the registers */ - stream_update(info->channel); + info->channel->update(); info->output = out; } } @@ -71,7 +70,7 @@ void dac_data_16_w(device_t *device, UINT16 data) if (info->output != out) { /* update the output buffer before changing the registers */ - stream_update(info->channel); + info->channel->update(); info->output = out; } } @@ -86,7 +85,7 @@ void dac_signed_data_16_w(device_t *device, UINT16 data) if (info->output != out) { /* update the output buffer before changing the registers */ - stream_update(info->channel); + info->channel->update(); info->output = out; } } @@ -111,7 +110,7 @@ static DEVICE_START( dac ) DAC_build_voltable(info); - info->channel = stream_create(device,0,1,device->clock() ? device->clock() : DEFAULT_SAMPLE_RATE,info,DAC_update); + info->channel = device->machine->sound().stream_alloc(*device,0,1,device->clock() ? device->clock() : DEFAULT_SAMPLE_RATE,info,DAC_update); info->output = 0; state_save_register_device_item(device, 0, info->output); diff --git a/src/emu/sound/digitalk.c b/src/emu/sound/digitalk.c index c3d67b1bf41..6d212db71b2 100644 --- a/src/emu/sound/digitalk.c +++ b/src/emu/sound/digitalk.c @@ -1,5 +1,4 @@ #include "emu.h" -#include "streams.h" #include "digitalk.h" /* @@ -650,7 +649,7 @@ static DEVICE_START(digitalker) digitalker *dg = get_safe_token(device); dg->device = device; dg->rom = device->machine->region(device->tag())->base(); - dg->stream = stream_create(device, 0, 1, device->clock()/4, dg, digitalker_update); + dg->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock()/4, dg, digitalker_update); dg->dac_index = 128; dg->data = 0xff; dg->cs = dg->cms = dg->wr = 1; diff --git a/src/emu/sound/disc_inp.c b/src/emu/sound/disc_inp.c index 054d2d485eb..53331138932 100644 --- a/src/emu/sound/disc_inp.c +++ b/src/emu/sound/disc_inp.c @@ -295,7 +295,7 @@ void DISCRETE_CLASS_FUNC(dss_input_stream, input_write)(int sub_node, UINT8 data if (m_is_buffered) { /* Bring the system up to now */ - stream_update(m_buffer_stream); + m_buffer_stream->update(); m_data = new_data; } @@ -334,9 +334,8 @@ 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 = stream_create(snd_device, 0, 1, this->sample_rate(), this, static_stream_generate); + m_buffer_stream = m_device->machine->sound().stream_alloc(*snd_device, 0, 1, this->sample_rate(), this, static_stream_generate); - stream_set_input(snd_device->get_stream(), m_stream_in_number, - m_buffer_stream, 0, 1.0); + snd_device->get_stream()->set_input(m_stream_in_number, m_buffer_stream); } } diff --git a/src/emu/sound/discrete.c b/src/emu/sound/discrete.c index fa6140d4538..723be279454 100644 --- a/src/emu/sound/discrete.c +++ b/src/emu/sound/discrete.c @@ -34,7 +34,6 @@ ************************************************************************/ #include "emu.h" -#include "streams.h" #include "wavwrite.h" #include "discrete.h" @@ -316,7 +315,7 @@ void discrete_task::check(discrete_task *dest_task) output_buffer buf; buf.node_buf = auto_alloc_array(m_device.machine, double, - ((task_node->sample_rate() + STREAMS_UPDATE_FREQUENCY) / STREAMS_UPDATE_FREQUENCY)); + ((task_node->sample_rate() + sound_manager::STREAMS_UPDATE_FREQUENCY) / sound_manager::STREAMS_UPDATE_FREQUENCY)); buf.ptr = buf.node_buf; buf.source = dest_node->m_input[inputnum]; buf.node_num = inputnode_num; @@ -657,7 +656,7 @@ void discrete_device::display_profiling(void) printf("Task(%d): %8.2f %15.2f\n", (*task)->task_group, tt / (double) total * 100.0, tt / (double) m_total_samples); } - printf("Average samples/stream_update: %8.2f\n", (double) m_total_samples / (double) m_total_stream_updates); + printf("Average samples/double->update: %8.2f\n", (double) m_total_samples / (double) m_total_stream_updates); } @@ -919,7 +918,7 @@ discrete_device::~discrete_device(void) void discrete_device::device_start() { // create the stream - //m_stream = stream_create(this, 0, 2, 22257, this, static_stream_generate); + //m_stream = m_machine.sound().stream_alloc(*this, 0, 2, 22257); const discrete_block *intf_start = (m_config.m_intf != NULL) ? m_config.m_intf : (discrete_block *) baseconfig().static_config(); char name[32]; @@ -1019,7 +1018,7 @@ void discrete_sound_device::device_start() fatalerror("init_nodes() - Couldn't find an output node"); /* initialize the stream(s) */ - m_stream = stream_create(*this,m_input_stream_list.count(), m_output_list.count(), m_sample_rate); + m_stream = m_machine.sound().stream_alloc(*this,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) diff --git a/src/emu/sound/discrete.h b/src/emu/sound/discrete.h index 102205926a6..9174c9753a9 100644 --- a/src/emu/sound/discrete.h +++ b/src/emu/sound/discrete.h @@ -3465,7 +3465,6 @@ * ************************************************************************/ -#include "streams.h" #include "wavwrite.h" /************************************* @@ -4440,7 +4439,7 @@ public: /* --------------------------------- */ - virtual void update_to_current_time(void) const { stream_update(m_stream); } + virtual void update_to_current_time(void) const { m_stream->update(); } sound_stream *get_stream(void) { return m_stream; } protected: diff --git a/src/emu/sound/dmadac.c b/src/emu/sound/dmadac.c index f98fc25a4e1..3972cd6d0f6 100644 --- a/src/emu/sound/dmadac.c +++ b/src/emu/sound/dmadac.c @@ -6,7 +6,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "dmadac.h" @@ -113,7 +112,7 @@ static DEVICE_START( dmadac ) info->volume = 0x100; /* allocate a stream channel */ - info->channel = stream_create(device, 0, 1, DEFAULT_SAMPLE_RATE, info, dmadac_update); + info->channel = device->machine->sound().stream_alloc(*device, 0, 1, DEFAULT_SAMPLE_RATE, info, dmadac_update); /* register with the save state system */ state_save_register_device_item(device, 0, info->bufin); @@ -140,7 +139,7 @@ void dmadac_transfer(dmadac_sound_device **devlist, UINT8 num_channels, offs_t c for (i = 0; i < num_channels; i++) { dmadac_state *info = get_safe_token(devlist[i]); - stream_update(info->channel); + info->channel->update(); } /* loop over all channels and accumulate the data */ @@ -187,7 +186,7 @@ void dmadac_enable(dmadac_sound_device **devlist, UINT8 num_channels, UINT8 enab for (i = 0; i < num_channels; i++) { dmadac_state *info = get_safe_token(devlist[i]); - stream_update(info->channel); + info->channel->update(); info->enabled = enable; if (!enable) info->bufin = info->bufout = 0; @@ -210,7 +209,7 @@ void dmadac_set_frequency(dmadac_sound_device **devlist, UINT8 num_channels, dou for (i = 0; i < num_channels; i++) { dmadac_state *info = get_safe_token(devlist[i]); - stream_set_sample_rate(info->channel, frequency); + info->channel->set_sample_rate(frequency); } } @@ -230,7 +229,7 @@ void dmadac_set_volume(dmadac_sound_device **devlist, UINT8 num_channels, UINT16 for (i = 0; i < num_channels; i++) { dmadac_state *info = get_safe_token(devlist[i]); - stream_update(info->channel); + info->channel->update(); info->volume = volume; } } diff --git a/src/emu/sound/es5503.c b/src/emu/sound/es5503.c index 38280e74edb..cc2c8f55c98 100644 --- a/src/emu/sound/es5503.c +++ b/src/emu/sound/es5503.c @@ -34,7 +34,6 @@ */ #include "emu.h" -#include "streams.h" #include "es5503.h" typedef struct @@ -141,7 +140,7 @@ static TIMER_CALLBACK( es5503_timer_cb ) ES5503Osc *osc = (ES5503Osc *)ptr; ES5503Chip *chip = (ES5503Chip *)osc->chip; - stream_update(chip->stream); + chip->stream->update(); } static STREAM_UPDATE( es5503_pcm_update ) @@ -267,7 +266,7 @@ static DEVICE_START( es5503 ) chip->oscsenabled = 1; chip->output_rate = (device->clock()/8)/34; // (input clock / 8) / # of oscs. enabled + 2 - chip->stream = stream_create(device, 0, 2, chip->output_rate, chip, es5503_pcm_update); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 2, chip->output_rate, chip, es5503_pcm_update); } READ8_DEVICE_HANDLER( es5503_r ) @@ -276,7 +275,7 @@ READ8_DEVICE_HANDLER( es5503_r ) int i; ES5503Chip *chip = get_safe_token(device); - stream_update(chip->stream); + chip->stream->update(); if (offset < 0xe0) { @@ -376,7 +375,7 @@ WRITE8_DEVICE_HANDLER( es5503_w ) { ES5503Chip *chip = get_safe_token(device); - stream_update(chip->stream); + chip->stream->update(); if (offset < 0xe0) { @@ -486,7 +485,7 @@ WRITE8_DEVICE_HANDLER( es5503_w ) chip->oscsenabled = (data>>1); chip->output_rate = (chip->clock/8)/(2+chip->oscsenabled); - stream_set_sample_rate(chip->stream, chip->output_rate); + chip->stream->set_sample_rate(chip->output_rate); break; case 0xe2: // A/D converter diff --git a/src/emu/sound/es5506.c b/src/emu/sound/es5506.c index c36a4f4af4e..3da4ad0ca02 100644 --- a/src/emu/sound/es5506.c +++ b/src/emu/sound/es5506.c @@ -81,7 +81,6 @@ Ensoniq OTIS - ES5505 Ensoniq OTTO - ***********************************************************************************************/ #include "emu.h" -#include "streams.h" #include "es5506.h" @@ -911,7 +910,7 @@ static void es5506_start_common(device_t *device, const void *config, device_typ eslog = fopen("es.log", "w"); /* create the stream */ - chip->stream = stream_create(device, 0, 2, device->clock() / (16*32), chip, es5506_update); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 2, device->clock() / (16*32), chip, es5506_update); /* initialize the regions */ chip->region_base[0] = intf->region0 ? (UINT16 *)device->machine->region(intf->region0)->base() : NULL; @@ -1111,7 +1110,7 @@ INLINE void es5506_reg_write_low(es5506_state *chip, es5506_voice *voice, offs_t { chip->active_voices = data & 0x1f; chip->sample_rate = chip->master_clock / (16 * (chip->active_voices + 1)); - stream_set_sample_rate(chip->stream, chip->sample_rate); + chip->stream->set_sample_rate(chip->sample_rate); if (LOG_COMMANDS && eslog) fprintf(eslog, "active voices=%d, sample_rate=%d\n", chip->active_voices, chip->sample_rate); @@ -1312,7 +1311,7 @@ WRITE8_DEVICE_HANDLER( es5506_w ) return; /* force an update */ - stream_update(chip->stream); + chip->stream->update(); /* switch off the page and register */ if (chip->current_page < 0x20) @@ -1521,7 +1520,7 @@ READ8_DEVICE_HANDLER( es5506_r ) fprintf(eslog, "read from %02x/%02x -> ", chip->current_page, offset / 4 * 8); /* force an update */ - stream_update(chip->stream); + chip->stream->update(); /* switch off the page and register */ if (chip->current_page < 0x20) @@ -1732,7 +1731,7 @@ INLINE void es5505_reg_write_low(es5506_state *chip, es5506_voice *voice, offs_t { chip->active_voices = data & 0x1f; chip->sample_rate = chip->master_clock / (16 * (chip->active_voices + 1)); - stream_set_sample_rate(chip->stream, chip->sample_rate); + chip->stream->set_sample_rate(chip->sample_rate); if (LOG_COMMANDS && eslog) fprintf(eslog, "active voices=%d, sample_rate=%d\n", chip->active_voices, chip->sample_rate); @@ -1840,7 +1839,7 @@ INLINE void es5505_reg_write_high(es5506_state *chip, es5506_voice *voice, offs_ { chip->active_voices = data & 0x1f; chip->sample_rate = chip->master_clock / (16 * (chip->active_voices + 1)); - stream_set_sample_rate(chip->stream, chip->sample_rate); + chip->stream->set_sample_rate(chip->sample_rate); if (LOG_COMMANDS && eslog) fprintf(eslog, "active voices=%d, sample_rate=%d\n", chip->active_voices, chip->sample_rate); @@ -1884,7 +1883,7 @@ INLINE void es5505_reg_write_test(es5506_state *chip, es5506_voice *voice, offs_ { chip->active_voices = data & 0x1f; chip->sample_rate = chip->master_clock / (16 * (chip->active_voices + 1)); - stream_set_sample_rate(chip->stream, chip->sample_rate); + chip->stream->set_sample_rate(chip->sample_rate); if (LOG_COMMANDS && eslog) fprintf(eslog, "active voices=%d, sample_rate=%d\n", chip->active_voices, chip->sample_rate); @@ -1910,7 +1909,7 @@ WRITE16_DEVICE_HANDLER( es5505_w ) // logerror("%s:ES5505 write %02x/%02x = %04x & %04x\n", cpuexec_describe_context(machine), chip->current_page, offset, data, mem_mask); /* force an update */ - stream_update(chip->stream); + chip->stream->update(); /* switch off the page and register */ if (chip->current_page < 0x20) @@ -2123,7 +2122,7 @@ READ16_DEVICE_HANDLER( es5505_r ) fprintf(eslog, "read from %02x/%02x -> ", chip->current_page, offset); /* force an update */ - stream_update(chip->stream); + chip->stream->update(); /* switch off the page and register */ if (chip->current_page < 0x20) diff --git a/src/emu/sound/es8712.c b/src/emu/sound/es8712.c index 59ad2d5708b..e99a4abcac2 100644 --- a/src/emu/sound/es8712.c +++ b/src/emu/sound/es8712.c @@ -13,7 +13,6 @@ #include "emu.h" -#include "streams.h" #include "es8712.h" #define MAX_SAMPLE_CHUNK 10000 @@ -228,7 +227,7 @@ static DEVICE_START( es8712 ) chip->region_base = *device->region(); /* generate the name and create the stream */ - chip->stream = stream_create(device, 0, 1, device->clock(), chip, es8712_update); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock(), chip, es8712_update); /* initialize the rest of the structure */ chip->signal = -2; @@ -251,7 +250,7 @@ static DEVICE_RESET( es8712 ) if (chip->playing) { /* update the stream, then turn it off */ - stream_update(chip->stream); + chip->stream->update(); chip->playing = 0; chip->repeat = 0; } @@ -267,7 +266,7 @@ static DEVICE_RESET( es8712 ) void es8712_set_bank_base(device_t *device, int base) { es8712_state *chip = get_safe_token(device); - stream_update(chip->stream); + chip->stream->update(); chip->bank_offset = base; } @@ -283,8 +282,8 @@ void es8712_set_frequency(device_t *device, int frequency) es8712_state *chip = get_safe_token(device); /* update the stream and set the new base */ - stream_update(chip->stream); - stream_set_sample_rate(chip->stream, frequency); + chip->stream->update(); + chip->stream->set_sample_rate(frequency); } @@ -323,7 +322,7 @@ void es8712_play(device_t *device) if (chip->playing) { /* update the stream */ - stream_update(chip->stream); + chip->stream->update(); chip->playing = 0; } } diff --git a/src/emu/sound/flt_rc.c b/src/emu/sound/flt_rc.c index 9369631c946..f0af134e6ce 100644 --- a/src/emu/sound/flt_rc.c +++ b/src/emu/sound/flt_rc.c @@ -1,5 +1,4 @@ #include "emu.h" -#include "streams.h" #include "flt_rc.h" typedef struct _filter_rc_state filter_rc_state; @@ -94,7 +93,7 @@ static DEVICE_START( filter_rc ) const flt_rc_config *conf = (const flt_rc_config *)device->baseconfig().static_config(); info->device = device; - info->stream = stream_create(device, 1, 1, device->machine->sample_rate, info, filter_rc_update); + info->stream = device->machine->sound().stream_alloc(*device, 1, 1, device->machine->sample_rate, info, filter_rc_update); if (conf) set_RC_info(info, conf->type, conf->R1, conf->R2, conf->R3, conf->C); else @@ -106,7 +105,7 @@ void filter_rc_set_RC(device_t *device, int type, double R1, double R2, double R { filter_rc_state *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); set_RC_info(info, type, R1, R2, R3, C); diff --git a/src/emu/sound/flt_vol.c b/src/emu/sound/flt_vol.c index 9f183f9dff4..0f2c14a0a6b 100644 --- a/src/emu/sound/flt_vol.c +++ b/src/emu/sound/flt_vol.c @@ -1,5 +1,4 @@ #include "emu.h" -#include "streams.h" #include "flt_vol.h" @@ -35,7 +34,7 @@ static DEVICE_START( filter_volume ) filter_volume_state *info = get_safe_token(device); info->gain = 0x100; - info->stream = stream_create(device, 1, 1, device->machine->sample_rate, info, filter_volume_update); + info->stream = device->machine->sound().stream_alloc(*device, 1, 1, device->machine->sample_rate, info, filter_volume_update); } diff --git a/src/emu/sound/gaelco.c b/src/emu/sound/gaelco.c index 2f37da528d7..959047a6d89 100644 --- a/src/emu/sound/gaelco.c +++ b/src/emu/sound/gaelco.c @@ -34,7 +34,6 @@ Registers per channel: ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "gaelco.h" #include "wavwrite.h" @@ -213,7 +212,7 @@ WRITE16_DEVICE_HANDLER( gaelcosnd_w ) LOG_READ_WRITES(("%s: (GAE1): write %04x to %04x\n", cpuexec_describe_context(device->machine), data, offset)); /* first update the stream to this point in time */ - stream_update(info->stream); + info->stream->update(); COMBINE_DATA(&info->sndregs[offset]); @@ -260,7 +259,7 @@ static DEVICE_START( gaelco ) for (j = 0; j < 4; j++){ info->banks[j] = intf->banks[j]; } - info->stream = stream_create(device, 0, 2, 8000, info, gaelco_update); + info->stream = device->machine->sound().stream_alloc(*device, 0, 2, 8000, info, gaelco_update); info->snd_data = (UINT8 *)device->machine->region(intf->gfxregion)->base(); if (info->snd_data == NULL) info->snd_data = *device->region(); diff --git a/src/emu/sound/hc55516.c b/src/emu/sound/hc55516.c index 2de7532f09d..23c0cfd3c09 100644 --- a/src/emu/sound/hc55516.c +++ b/src/emu/sound/hc55516.c @@ -7,7 +7,6 @@ *****************************************************************************/ #include "emu.h" -#include "streams.h" #include "hc55516.h" @@ -77,7 +76,7 @@ static void start_common(device_t *device, UINT8 _shiftreg_mask, int _active_clo chip->last_clock_state = 0; /* create the stream */ - chip->channel = stream_create(device, 0, 1, SAMPLE_RATE, chip, hc55516_update); + chip->channel = device->machine->sound().stream_alloc(*device, 0, 1, SAMPLE_RATE, chip, hc55516_update); state_save_register_device_item(device, 0, chip->last_clock_state); state_save_register_device_item(device, 0, chip->digit); @@ -255,7 +254,7 @@ void hc55516_clock_w(device_t *device, int state) if (is_active_clock_transition(chip, clock_state)) { /* update the output buffer before changing the registers */ - stream_update(chip->channel); + chip->channel->update(); /* clear the update count */ chip->update_count = 0; @@ -274,7 +273,7 @@ void hc55516_digit_w(device_t *device, int digit) if (is_external_osciallator(chip)) { - stream_update(chip->channel); + chip->channel->update(); chip->new_digit = digit & 1; } else @@ -289,7 +288,7 @@ int hc55516_clock_state_r(device_t *device) /* only makes sense for setups with an external oscillator */ assert(is_external_osciallator(chip)); - stream_update(chip->channel); + chip->channel->update(); return current_clock_state(chip); } diff --git a/src/emu/sound/ics2115.c b/src/emu/sound/ics2115.c index 8e21e9a5e67..0e11e35251c 100644 --- a/src/emu/sound/ics2115.c +++ b/src/emu/sound/ics2115.c @@ -49,7 +49,7 @@ void ics2115_device::device_start() m_rom = *region(); m_timer[0].timer = timer_alloc(machine, timer_cb_0, this); m_timer[1].timer = timer_alloc(machine, timer_cb_1, this); - m_stream = stream_create(this, 0, 2, 33075, this, static_stream_generate); + m_stream = m_machine.sound().stream_alloc(*this, 0, 2, 33075); //Exact formula as per patent 5809466 //This seems to give the ok fit but it is not good enough. @@ -148,11 +148,6 @@ void ics2115_device::device_reset() } } -STREAM_UPDATE( ics2115_device::static_stream_generate ) -{ - reinterpret_cast(param)->stream_generate(inputs, outputs, samples); -} - //TODO: improve using next-state logic from column 126 of patent 5809466 int ics2115_voice::update_volume_envelope() { @@ -363,7 +358,7 @@ int ics2115_device::fill_output(ics2115_voice& voice, stream_sample_t *outputs[2 return irq_invalid; } -void ics2115_device::stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void ics2115_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **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/emu/sound/ics2115.h b/src/emu/sound/ics2115.h index 79cd3fabf7f..047f0009007 100644 --- a/src/emu/sound/ics2115.h +++ b/src/emu/sound/ics2115.h @@ -3,7 +3,6 @@ #ifndef __ICS2115_H__ #define __ICS2115_H__ -#include "streams.h" //************************************************************************** // INTERFACE CONFIGURATION MACROS @@ -138,8 +137,7 @@ protected: virtual void device_reset(); // internal callbacks - static STREAM_UPDATE( static_stream_generate ); - virtual void stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples); + void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); // internal state const ics2115_device_config &m_config; diff --git a/src/emu/sound/iremga20.c b/src/emu/sound/iremga20.c index a9b3c01b75e..d1956cbbed0 100644 --- a/src/emu/sound/iremga20.c +++ b/src/emu/sound/iremga20.c @@ -27,7 +27,6 @@ Revisions: *********************************************************/ #include "emu.h" -#include "streams.h" #include "iremga20.h" #define MAX_VOL 256 @@ -148,7 +147,7 @@ WRITE8_DEVICE_HANDLER( irem_ga20_w ) //logerror("GA20: Offset %02x, data %04x\n",offset,data); - stream_update(chip->stream); + chip->stream->update(); channel = offset >> 3; @@ -193,7 +192,7 @@ READ8_DEVICE_HANDLER( irem_ga20_r ) ga20_state *chip = get_safe_token(device); int channel; - stream_update(chip->stream); + chip->stream->update(); channel = offset >> 3; @@ -248,7 +247,7 @@ static DEVICE_START( iremga20 ) for ( i = 0; i < 0x40; i++ ) chip->regs[i] = 0; - chip->stream = stream_create( device, 0, 2, device->clock()/4, chip, IremGA20_update ); + chip->stream = device->machine->sound().stream_alloc( *device, 0, 2, device->clock()/4, chip, IremGA20_update ); state_save_register_device_item_array(device, 0, chip->regs); for (i = 0; i < 4; i++) diff --git a/src/emu/sound/k005289.c b/src/emu/sound/k005289.c index d6b41054f00..a33ce5c7e98 100644 --- a/src/emu/sound/k005289.c +++ b/src/emu/sound/k005289.c @@ -26,7 +26,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "k005289.h" #define FREQBASEBITS 16 @@ -165,7 +164,7 @@ static DEVICE_START( k005289 ) /* get stream channels */ info->rate = device->clock()/16; - info->stream = stream_create(device, 0, 1, info->rate, info, K005289_update); + info->stream = device->machine->sound().stream_alloc(*device, 0, 1, info->rate, info, K005289_update); info->mclock = device->clock(); /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */ @@ -194,7 +193,7 @@ static void k005289_recompute(k005289_state *info) { k005289_sound_channel *voice = info->channel_list; - stream_update(info->stream); /* update the streams */ + info->stream->update(); /* update the streams */ voice[0].frequency = info->k005289_A_frequency; voice[1].frequency = info->k005289_B_frequency; diff --git a/src/emu/sound/k007232.c b/src/emu/sound/k007232.c index 491a712a27d..f763342dabd 100644 --- a/src/emu/sound/k007232.c +++ b/src/emu/sound/k007232.c @@ -24,7 +24,6 @@ added external port callback, and functions to set the volume of the channels #include "emu.h" -#include "streams.h" #include "k007232.h" @@ -329,7 +328,7 @@ static DEVICE_START( k007232 ) for( i = 0; i < 0x10; i++ ) info->wreg[i] = 0; - info->stream = stream_create(device,0,2,device->clock()/128,info,KDAC_A_update); + info->stream = device->machine->sound().stream_alloc(*device,0,2,device->clock()/128,info,KDAC_A_update); KDAC_A_make_fncode(info); } @@ -343,7 +342,7 @@ WRITE8_DEVICE_HANDLER( k007232_w ) int r = offset; int v = data; - stream_update(info->stream); + info->stream->update(); info->wreg[r] = v; /* stock write data */ diff --git a/src/emu/sound/k051649.c b/src/emu/sound/k051649.c index 9c2e85c8a6f..9a9d60cd71c 100644 --- a/src/emu/sound/k051649.c +++ b/src/emu/sound/k051649.c @@ -23,7 +23,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "k051649.h" #define FREQBASEBITS 16 @@ -139,7 +138,7 @@ static DEVICE_START( k051649 ) /* get stream channels */ info->rate = device->clock()/16; - info->stream = stream_create(device, 0, 1, info->rate, info, k051649_update); + info->stream = device->machine->sound().stream_alloc(*device, 0, 1, info->rate, info, k051649_update); info->mclock = device->clock(); /* allocate a buffer to mix into - 1 second's worth should be more than enough */ @@ -168,7 +167,7 @@ static DEVICE_RESET( k051649 ) WRITE8_DEVICE_HANDLER( k051649_waveform_w ) { k051649_state *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); info->channel_list[offset>>5].waveform[offset&0x1f]=data; /* SY 20001114: Channel 5 shares the waveform with channel 4 */ if (offset >= 0x60) @@ -185,14 +184,14 @@ READ8_DEVICE_HANDLER ( k051649_waveform_r ) WRITE8_DEVICE_HANDLER( k052539_waveform_w ) { k051649_state *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); info->channel_list[offset>>5].waveform[offset&0x1f]=data; } WRITE8_DEVICE_HANDLER( k051649_volume_w ) { k051649_state *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); info->channel_list[offset&0x7].volume=data&0xf; } @@ -201,14 +200,14 @@ WRITE8_DEVICE_HANDLER( k051649_frequency_w ) k051649_state *info = get_safe_token(device); info->f[offset]=data; - stream_update(info->stream); + info->stream->update(); info->channel_list[offset>>1].frequency=(info->f[offset&0xe] + (info->f[offset|1]<<8))&0xfff; } WRITE8_DEVICE_HANDLER( k051649_keyonoff_w ) { k051649_state *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); info->channel_list[0].key=data&1; info->channel_list[1].key=data&2; info->channel_list[2].key=data&4; diff --git a/src/emu/sound/k053260.c b/src/emu/sound/k053260.c index f25c2f47105..37a25745db4 100644 --- a/src/emu/sound/k053260.c +++ b/src/emu/sound/k053260.c @@ -5,7 +5,6 @@ *********************************************************/ #include "emu.h" -#include "streams.h" #include "k053260.h" /* 2004-02-28: Fixed PPCM decoding. Games sound much better now.*/ @@ -234,7 +233,7 @@ static DEVICE_START( k053260 ) ic->delta_table = auto_alloc_array( device->machine, UINT32, 0x1000 ); - ic->channel = stream_create( device, 0, 2, rate, ic, k053260_update ); + ic->channel = device->machine->sound().stream_alloc( *device, 0, 2, rate, ic, k053260_update ); InitDeltaTable( ic, rate, device->clock() ); @@ -297,7 +296,7 @@ WRITE8_DEVICE_HANDLER( k053260_w ) return; } - stream_update( ic->channel); + ic->channel->update(); /* before we update the regs, we need to check for a latched reg */ if ( r == 0x28 ) { diff --git a/src/emu/sound/k054539.c b/src/emu/sound/k054539.c index 9b4ab78e513..55e753c86bf 100644 --- a/src/emu/sound/k054539.c +++ b/src/emu/sound/k054539.c @@ -18,7 +18,6 @@ CHANNEL_DEBUG enables the following keys: *********************************************************/ #include "emu.h" -#include "streams.h" #include "k054539.h" #define CHANNEL_DEBUG 0 @@ -473,7 +472,7 @@ static void k054539_init_chip(device_t *device, k054539_state *info) // 480 hz is TRUSTED by gokuparo disco stage - the looping sample doesn't line up otherwise timer_pulse(device->machine, ATTOTIME_IN_HZ(480), info, 0, k054539_irq); - info->stream = stream_create(device, 0, 2, device->clock(), info, k054539_update); + info->stream = device->machine->sound().stream_alloc(*device, 0, 2, device->clock(), info, k054539_update); state_save_register_device_item_array(device, 0, info->regs); state_save_register_device_item_pointer(device, 0, info->ram, 0x4000); diff --git a/src/emu/sound/mos6560.c b/src/emu/sound/mos6560.c index f4246227077..ae6afa7fc0f 100644 --- a/src/emu/sound/mos6560.c +++ b/src/emu/sound/mos6560.c @@ -57,7 +57,6 @@ #include "emu.h" -#include "streams.h" #include "sound/mos6560.h" /*************************************************************************** @@ -579,7 +578,7 @@ static void mos6560_soundport_w( device_t *device, int offset, int data ) { mos6560_state *mos6560 = get_safe_token(device); int old = mos6560->reg[offset]; - stream_update(mos6560->channel); + mos6560->channel->update(); switch (offset) { @@ -740,7 +739,7 @@ static void mos6560_sound_start( device_t *device ) mos6560_state *mos6560 = get_safe_token(device); int i; - mos6560->channel = stream_create(device, 0, 1, device->machine->sample_rate, 0, mos6560_update); + mos6560->channel = device->machine->sound().stream_alloc(*device, 0, 1, device->machine->sample_rate, 0, mos6560_update); /* buffer for fastest played sample for 5 second so we have enough data for min 5 second */ mos6560->noisesize = NOISE_FREQUENCY_MAX * NOISE_BUFFER_SIZE_SEC; diff --git a/src/emu/sound/msm5205.c b/src/emu/sound/msm5205.c index 2032df1d535..6a607edd238 100644 --- a/src/emu/sound/msm5205.c +++ b/src/emu/sound/msm5205.c @@ -15,7 +15,6 @@ */ #include "emu.h" -#include "streams.h" #include "msm5205.h" /* @@ -148,7 +147,7 @@ static TIMER_CALLBACK( MSM5205_vclk_callback ) /* update when signal changed */ if( voice->signal != new_signal) { - stream_update(voice->stream); + voice->stream->update(); voice->signal = new_signal; } } @@ -188,7 +187,7 @@ static DEVICE_START( msm5205 ) ComputeTables (voice); /* stream system initialize */ - voice->stream = stream_create(device,0,1,device->clock(),voice,MSM5205_update); + voice->stream = device->machine->sound().stream_alloc(*device,0,1,device->clock(),voice,MSM5205_update); voice->timer = timer_alloc(device->machine, MSM5205_vclk_callback, voice); /* initialize */ @@ -269,7 +268,7 @@ static void msm5205_playmode(msm5205_state *voice,int select) if( voice->prescaler != prescaler ) { - stream_update(voice->stream); + voice->stream->update(); voice->prescaler = prescaler; /* timer set */ @@ -284,7 +283,7 @@ static void msm5205_playmode(msm5205_state *voice,int select) if( voice->bitwidth != bitwidth ) { - stream_update(voice->stream); + voice->stream->update(); voice->bitwidth = bitwidth; } @@ -295,7 +294,7 @@ void msm5205_set_volume(device_t *device,int volume) { msm5205_state *voice = get_safe_token(device); - stream_set_output_gain(voice->stream,0,volume / 100.0); + voice->stream->set_output_gain(0,volume / 100.0); } void msm5205_change_clock_w(device_t *device, INT32 clock) diff --git a/src/emu/sound/msm5232.c b/src/emu/sound/msm5232.c index 11b8410dd7b..3f89f65060f 100644 --- a/src/emu/sound/msm5232.c +++ b/src/emu/sound/msm5232.c @@ -1,5 +1,4 @@ #include "emu.h" -#include "streams.h" #include "msm5232.h" @@ -345,7 +344,7 @@ WRITE8_DEVICE_HANDLER( msm5232_w ) if (offset > 0x0d) return; - stream_update (chip->stream); + chip->stream->update (); if (offset < 0x08) /* pitch */ { @@ -797,7 +796,7 @@ static DEVICE_START( msm5232 ) msm5232_init(chip, intf, device->clock(), rate); - chip->stream = stream_create(device, 0, 11, rate, chip, MSM5232_update_one); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 11, rate, chip, MSM5232_update_one); /* register with the save state system */ state_save_register_postload(device->machine, msm5232_postload, chip); @@ -844,11 +843,11 @@ void msm5232_set_clock(device_t *device, int clock) if (chip->clock != clock) { - stream_update (chip->stream); + chip->stream->update (); chip->clock = clock; chip->rate = clock/CLOCK_RATE_DIVIDER; msm5232_init_tables( chip ); - stream_set_sample_rate(chip->stream, chip->rate); + chip->stream->set_sample_rate(chip->rate); } } diff --git a/src/emu/sound/multipcm.c b/src/emu/sound/multipcm.c index 6a1011e47b6..a810f58a4cf 100644 --- a/src/emu/sound/multipcm.c +++ b/src/emu/sound/multipcm.c @@ -32,7 +32,6 @@ */ #include "emu.h" -#include "streams.h" #include "multipcm.h" //???? @@ -503,7 +502,7 @@ static DEVICE_START( multipcm ) ptChip->ROM=*device->region(); ptChip->Rate=(float) device->clock() / MULTIPCM_CLOCKDIV; - ptChip->stream = stream_create(device, 0, 2, ptChip->Rate, ptChip, MultiPCM_update); + ptChip->stream = device->machine->sound().stream_alloc(*device, 0, 2, ptChip->Rate, ptChip, MultiPCM_update); //Volume+pan table for(i=0;i<0x800;++i) diff --git a/src/emu/sound/n63701x.c b/src/emu/sound/n63701x.c index f8ab537159e..9c33e396ee2 100644 --- a/src/emu/sound/n63701x.c +++ b/src/emu/sound/n63701x.c @@ -14,7 +14,6 @@ silence compression: '00 nn' must be replaced by nn+1 times '80'. ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "n63701x.h" @@ -115,7 +114,7 @@ static DEVICE_START( namco_63701x ) chip->rom = *device->region(); - chip->stream = stream_create(device, 0, 2, device->clock()/1000, chip, namco_63701x_update); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 2, device->clock()/1000, chip, namco_63701x_update); } @@ -140,7 +139,7 @@ WRITE8_DEVICE_HANDLER( namco_63701x_w ) int rom_offs; /* update the streams */ - stream_update(chip->stream); + chip->stream->update(); chip->voices[ch].playing = 1; chip->voices[ch].base_addr = 0x10000 * ((chip->voices[ch].select & 0xe0) >> 5); diff --git a/src/emu/sound/namco.c b/src/emu/sound/namco.c index 00ef7e53b34..5a0821ec09c 100644 --- a/src/emu/sound/namco.c +++ b/src/emu/sound/namco.c @@ -12,7 +12,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "namco.h" @@ -389,9 +388,9 @@ static DEVICE_START( namco ) /* get stream channels */ if (intf->stereo) - chip->stream = stream_create(device, 0, 2, chip->sample_rate, chip, namco_update_stereo); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 2, chip->sample_rate, chip, namco_update_stereo); else - chip->stream = stream_create(device, 0, 1, chip->sample_rate, chip, namco_update_mono); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 1, chip->sample_rate, chip, namco_update_mono); /* start with sound enabled, many games don't have a sound enable register */ chip->sound_enable = 1; @@ -471,7 +470,7 @@ WRITE8_DEVICE_HANDLER( pacman_sound_w ) return; /* update the streams */ - stream_update(chip->stream); + chip->stream->update(); /* set the register */ chip->soundregs[offset] = data; @@ -567,7 +566,7 @@ WRITE8_DEVICE_HANDLER( polepos_sound_w ) return; /* update the streams */ - stream_update(chip->stream); + chip->stream->update(); /* set the register */ chip->soundregs[offset] = data; @@ -645,7 +644,7 @@ static WRITE8_DEVICE_HANDLER( namco_15xx_w ) return; /* update the streams */ - stream_update(chip->stream); + chip->stream->update(); /* set the register */ chip->soundregs[offset] = data; @@ -722,7 +721,7 @@ static WRITE8_DEVICE_HANDLER( namcos1_sound_w ) return; /* update the streams */ - stream_update(chip->stream); + chip->stream->update(); /* set the register */ chip->soundregs[offset] = data; @@ -769,7 +768,7 @@ WRITE8_DEVICE_HANDLER( namcos1_cus30_w ) if (chip->wavedata[offset] != data) { /* update the streams */ - stream_update(chip->stream); + chip->stream->update(); chip->wavedata[offset] = data; diff --git a/src/emu/sound/nes_apu.c b/src/emu/sound/nes_apu.c index 88139c3de48..a0bd3f224a8 100644 --- a/src/emu/sound/nes_apu.c +++ b/src/emu/sound/nes_apu.c @@ -45,7 +45,6 @@ *****************************************************************************/ #include "emu.h" -#include "streams.h" #include "nes_apu.h" #include "cpu/m6502/m6502.h" @@ -664,7 +663,7 @@ INLINE uint8 apu_read(nesapu_state *info,int address) INLINE void apu_write(nesapu_state *info,int address, uint8 value) { info->APU.regs[address]=value; - stream_update(info->stream); + info->stream->update(); apu_regwrite(info,address,value); } @@ -707,7 +706,7 @@ static DEVICE_START( nesapu ) /* Initialize individual chips */ (info->APU.dpcm).memory = cputag_get_address_space(device->machine, intf->cpu_tag, ADDRESS_SPACE_PROGRAM); - info->stream = stream_create(device, 0, 1, rate, info, nes_psg_update_sound); + info->stream = device->machine->sound().stream_alloc(*device, 0, 1, rate, info, nes_psg_update_sound); /* register for save */ for (i = 0; i < 2; i++) diff --git a/src/emu/sound/nile.c b/src/emu/sound/nile.c index 98c4edacfe2..54132196ebc 100644 --- a/src/emu/sound/nile.c +++ b/src/emu/sound/nile.c @@ -25,7 +25,6 @@ ************************************/ #include "emu.h" -#include "streams.h" #include "nile.h" #define NILE_VOICES 8 @@ -75,7 +74,7 @@ WRITE16_DEVICE_HANDLER( nile_sndctrl_w ) nile_state *info = get_safe_token(device); UINT16 ctrl=info->ctrl; - stream_update(info->stream); + info->stream->update(); COMBINE_DATA(&info->ctrl); @@ -88,7 +87,7 @@ READ16_DEVICE_HANDLER( nile_sndctrl_r ) { nile_state *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); return info->ctrl; } @@ -98,7 +97,7 @@ READ16_DEVICE_HANDLER( nile_snd_r ) nile_state *info = get_safe_token(device); int reg=offset&0xf; - stream_update(info->stream); + info->stream->update(); if(reg==2 || reg==3) { @@ -122,7 +121,7 @@ WRITE16_DEVICE_HANDLER( nile_snd_w ) nile_state *info = get_safe_token(device); int v, r; - stream_update(info->stream); + info->stream->update(); COMBINE_DATA(&info->sound_regs[offset]); @@ -228,7 +227,7 @@ static DEVICE_START( nile ) info->sound_ram = *device->region(); - info->stream = stream_create(device, 0, 2, 44100, info, nile_update); + info->stream = device->machine->sound().stream_alloc(*device, 0, 2, 44100, info, nile_update); } diff --git a/src/emu/sound/okim6258.c b/src/emu/sound/okim6258.c index 5924bcbd0a9..0921fd9d4ca 100644 --- a/src/emu/sound/okim6258.c +++ b/src/emu/sound/okim6258.c @@ -10,7 +10,6 @@ #include "emu.h" -#include "streams.h" #include "okim6258.h" #define COMMAND_STOP (1 << 0) @@ -202,7 +201,7 @@ static DEVICE_START( okim6258 ) info->output_bits = intf->output_12bits ? 12 : 10; info->divider = dividers[intf->divider]; - info->stream = stream_create(device, 0, 1, device->clock()/info->divider, info, okim6258_update); + info->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock()/info->divider, info, okim6258_update); info->signal = -2; info->step = 0; @@ -221,7 +220,7 @@ static DEVICE_RESET( okim6258 ) { okim6258_state *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); info->signal = -2; info->step = 0; @@ -241,7 +240,7 @@ void okim6258_set_divider(device_t *device, int val) int divider = dividers[val]; info->divider = dividers[val]; - stream_set_sample_rate(info->stream, info->master_clock / divider); + info->stream->set_sample_rate(info->master_clock / divider); } @@ -256,7 +255,7 @@ void okim6258_set_clock(device_t *device, int val) okim6258_state *info = get_safe_token(device); info->master_clock = val; - stream_set_sample_rate(info->stream, info->master_clock / info->divider); + info->stream->set_sample_rate(info->master_clock / info->divider); } @@ -284,7 +283,7 @@ READ8_DEVICE_HANDLER( okim6258_status_r ) { okim6258_state *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); return (info->status & STATUS_PLAYING) ? 0x00 : 0x80; } @@ -300,7 +299,7 @@ WRITE8_DEVICE_HANDLER( okim6258_data_w ) okim6258_state *info = get_safe_token(device); /* update the stream */ - stream_update(info->stream); + info->stream->update(); info->data_in = data; info->nibble_shift = 0; @@ -317,7 +316,7 @@ WRITE8_DEVICE_HANDLER( okim6258_ctrl_w ) { okim6258_state *info = get_safe_token(device); - stream_update(info->stream); + info->stream->update(); if (data & COMMAND_STOP) { diff --git a/src/emu/sound/okim6295.c b/src/emu/sound/okim6295.c index 08a11f9cf31..2462426644c 100644 --- a/src/emu/sound/okim6295.c +++ b/src/emu/sound/okim6295.c @@ -36,7 +36,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "okim6295.h" @@ -178,7 +177,7 @@ void okim6295_device::device_start() // create the stream int divisor = m_config.m_pin7 ? 132 : 165; - m_stream = stream_create(*this, 0, 1, clock() / divisor); + m_stream = m_machine.sound().stream_alloc(*this, 0, 1, clock() / divisor); state_save_register_device_item(this, 0, m_command); state_save_register_device_item(this, 0, m_bank_offs); @@ -201,7 +200,7 @@ void okim6295_device::device_start() void okim6295_device::device_reset() { - stream_update(m_stream); + m_stream->update(); for (int voicenum = 0; voicenum < OKIM6295_VOICES; voicenum++) m_voice[voicenum].m_playing = false; } @@ -225,7 +224,7 @@ void okim6295_device::device_post_load() void okim6295_device::device_clock_changed() { int divisor = m_pin7_state ? 132 : 165; - stream_set_sample_rate(m_stream, clock() / divisor); + m_stream->set_sample_rate(clock() / divisor); } @@ -253,7 +252,7 @@ void okim6295_device::sound_stream_update(sound_stream &stream, stream_sample_t void okim6295_device::set_bank_base(offs_t base) { // flush out anything pending - stream_update(m_stream); + m_stream->update(); // if we are setting a non-zero base, and we have no bank, allocate one if (!m_bank_installed && base != 0) @@ -293,7 +292,7 @@ UINT8 okim6295_device::read_status() UINT8 result = 0xf0; // naname expects bits 4-7 to be 1 // set the bit to 1 if something is playing on a given channel - stream_update(m_stream); + m_stream->update(); for (int voicenum = 0; voicenum < OKIM6295_VOICES; voicenum++) if (m_voice[voicenum].m_playing) result |= 1 << voicenum; @@ -327,7 +326,7 @@ void okim6295_device::write_command(UINT8 command) // popmessage("OKI6295 start %x contact MAMEDEV", voicemask); // update the stream - stream_update(m_stream); + m_stream->update(); // determine which voice(s) (voice is set by a 1 bit in the upper 4 bits of the second byte) for (int voicenum = 0; voicenum < OKIM6295_VOICES; voicenum++, voicemask >>= 1) @@ -386,7 +385,7 @@ void okim6295_device::write_command(UINT8 command) else { // update the stream, then turn it off - stream_update(m_stream); + m_stream->update(); // determine which voice(s) (voice is set by a 1 bit in bits 3-6 of the command int voicemask = command >> 3; diff --git a/src/emu/sound/okim6295.h b/src/emu/sound/okim6295.h index f545995a4ef..cb3b3fde7b9 100644 --- a/src/emu/sound/okim6295.h +++ b/src/emu/sound/okim6295.h @@ -11,7 +11,6 @@ #ifndef __OKIM6295_H__ #define __OKIM6295_H__ -#include "streams.h" diff --git a/src/emu/sound/okim6376.c b/src/emu/sound/okim6376.c index c16f70259c1..20384770c69 100644 --- a/src/emu/sound/okim6376.c +++ b/src/emu/sound/okim6376.c @@ -11,7 +11,6 @@ #include "emu.h" -#include "streams.h" #include "okim6376.h" #define MAX_SAMPLE_CHUNK 10000 @@ -307,7 +306,7 @@ static DEVICE_START( okim6376 ) info->master_clock = device->clock(); /* generate the name and create the stream */ - info->stream = stream_create(device, 0, 1, device->clock()/divisor, info, okim6376_update); + info->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock()/divisor, info, okim6376_update); /* initialize the voices */ for (voice = 0; voice < OKIM6376_VOICES; voice++) @@ -333,7 +332,7 @@ static DEVICE_RESET( okim6376 ) okim6376_state *info = get_safe_token(device); int i; - stream_update(info->stream); + info->stream->update(); for (i = 0; i < OKIM6376_VOICES; i++) info->voice[i].playing = 0; } @@ -355,7 +354,7 @@ READ8_DEVICE_HANDLER( okim6376_r ) result = 0xff; /* set the bit to 1 if something is playing on a given channel */ - stream_update(info->stream); + info->stream->update(); for (i = 0; i < OKIM6376_VOICES; i++) { struct ADPCMVoice *voice = &info->voice[i]; @@ -392,7 +391,7 @@ WRITE8_DEVICE_HANDLER( okim6376_w ) popmessage("OKI6376 start %x contact MAMEDEV", temp); /* update the stream */ - stream_update(info->stream); + info->stream->update(); /* determine which voice(s) (voice is set by a 1 bit in the upper 4 bits of the second byte) */ for (i = 0; i < OKIM6376_VOICES; i++, temp >>= 1) @@ -451,7 +450,7 @@ WRITE8_DEVICE_HANDLER( okim6376_w ) int temp = data >> 3, i; /* update the stream, then turn it off */ - stream_update(info->stream); + info->stream->update(); /* determine which voice(s) (voice is set by a 1 bit in bits 3-6 of the command */ for (i = 0; i < OKIM6376_VOICES; i++, temp >>= 1) diff --git a/src/emu/sound/pokey.c b/src/emu/sound/pokey.c index 09e9999cd6e..8d2bb878d81 100644 --- a/src/emu/sound/pokey.c +++ b/src/emu/sound/pokey.c @@ -50,7 +50,6 @@ *****************************************************************************/ #include "emu.h" -#include "streams.h" #include "pokey.h" /* @@ -668,7 +667,7 @@ static DEVICE_START( pokey ) devcb_resolve_write8(&chip->serout_w, &chip->intf.serout_w, device); chip->interrupt_cb = chip->intf.interrupt_cb; - chip->channel = stream_create(device, 0, 1, sample_rate, chip, pokey_update); + chip->channel = device->machine->sound().stream_alloc(*device, 0, 1, sample_rate, chip, pokey_update); register_for_save(chip, device); } @@ -956,7 +955,7 @@ WRITE8_DEVICE_HANDLER( pokey_w ) pokey_state *p = get_safe_token(device); int ch_mask = 0, new_val; - stream_update(p->channel); + p->channel->update(); /* determine which address was changed */ switch (offset & 15) diff --git a/src/emu/sound/psx.c b/src/emu/sound/psx.c index eee9a9fc424..e99c64ee065 100644 --- a/src/emu/sound/psx.c +++ b/src/emu/sound/psx.c @@ -9,7 +9,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "psx.h" #define VERBOSE_LEVEL ( 0 ) @@ -370,7 +369,7 @@ static DEVICE_START( psxspu ) chip->installHack = 0; - chip->stream = stream_create( device, 0, 2, 44100, chip, PSXSPU_update ); + chip->stream = device->machine->sound().stream_alloc( *device, 0, 2, 44100, chip, PSXSPU_update ); } diff --git a/src/emu/sound/qsound.c b/src/emu/sound/qsound.c index 0965cc86a66..f257a598ad1 100644 --- a/src/emu/sound/qsound.c +++ b/src/emu/sound/qsound.c @@ -32,7 +32,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "qsound.h" /* @@ -124,8 +123,8 @@ static DEVICE_START( qsound ) { /* Allocate stream */ - chip->stream = stream_create( - device, 0, 2, + chip->stream = device->machine->sound().stream_alloc( + *device, 0, 2, device->clock() / QSOUND_CLOCKDIV, chip, qsound_update ); diff --git a/src/emu/sound/rf5c400.c b/src/emu/sound/rf5c400.c index 50915b5d0f1..13c745988e2 100644 --- a/src/emu/sound/rf5c400.c +++ b/src/emu/sound/rf5c400.c @@ -16,7 +16,6 @@ */ #include "emu.h" -#include "streams.h" #include "rf5c400.h" typedef struct _rf5c400_channel rf5c400_channel; @@ -346,7 +345,7 @@ static void rf5c400_init_chip(device_t *device, rf5c400_state *info) state_save_register_device_item(device, i, info->channels[i].env_scale); } - info->stream = stream_create(device, 0, 2, device->clock()/384, info, rf5c400_update); + info->stream = device->machine->sound().stream_alloc(*device, 0, 2, device->clock()/384, info, rf5c400_update); } diff --git a/src/emu/sound/rf5c68.c b/src/emu/sound/rf5c68.c index 5425bc4ac85..43dbd764646 100644 --- a/src/emu/sound/rf5c68.c +++ b/src/emu/sound/rf5c68.c @@ -3,7 +3,6 @@ /*********************************************************/ #include "emu.h" -#include "streams.h" #include "rf5c68.h" @@ -146,7 +145,7 @@ static DEVICE_START( rf5c68 ) rf5c68_state *chip = get_safe_token(device); /* allocate the stream */ - chip->stream = stream_create(device, 0, 2, device->clock() / 384, chip, rf5c68_update); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 2, device->clock() / 384, chip, rf5c68_update); chip->device = device; @@ -169,7 +168,7 @@ WRITE8_DEVICE_HANDLER( rf5c68_w ) int i; /* force the stream to update first */ - stream_update(chip->stream); + chip->stream->update(); /* switch off the address */ switch (offset) diff --git a/src/emu/sound/s14001a.c b/src/emu/sound/s14001a.c index a2caa40dbc2..0c4c96b0e75 100644 --- a/src/emu/sound/s14001a.c +++ b/src/emu/sound/s14001a.c @@ -235,7 +235,6 @@ and off as it normally does during speech). Once START has gone low-high-low, th #undef ACCURATE_SQUEAL #include "emu.h" -#include "streams.h" #include "s14001a.h" typedef struct @@ -593,13 +592,13 @@ static DEVICE_START( s14001a ) chip->SpeechRom = *device->region(); - chip->stream = stream_create(device, 0, 1, device->clock() ? device->clock() : device->machine->sample_rate, chip, s14001a_pcm_update); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock() ? device->clock() : device->machine->sample_rate, chip, s14001a_pcm_update); } int s14001a_bsy_r(device_t *device) { S14001AChip *chip = get_safe_token(device); - stream_update(chip->stream); + chip->stream->update(); #ifdef DEBUGSTATE fprintf(stderr,"busy state checked: %d\n",(chip->machineState != 0) ); #endif @@ -609,14 +608,14 @@ int s14001a_bsy_r(device_t *device) void s14001a_reg_w(device_t *device, int data) { S14001AChip *chip = get_safe_token(device); - stream_update(chip->stream); + chip->stream->update(); chip->WordInput = data; } void s14001a_rst_w(device_t *device, int data) { S14001AChip *chip = get_safe_token(device); - stream_update(chip->stream); + chip->stream->update(); chip->LatchedWord = chip->WordInput; chip->resetState = (data==1); chip->machineState = chip->resetState ? 1 : chip->machineState; @@ -625,13 +624,13 @@ void s14001a_rst_w(device_t *device, int data) void s14001a_set_clock(device_t *device, int clock) { S14001AChip *chip = get_safe_token(device); - stream_set_sample_rate(chip->stream, clock); + chip->stream->set_sample_rate(clock); } void s14001a_set_volume(device_t *device, int volume) { S14001AChip *chip = get_safe_token(device); - stream_update(chip->stream); + chip->stream->update(); chip->VSU1000_amp = volume; } diff --git a/src/emu/sound/s2636.c b/src/emu/sound/s2636.c index d62fa32e627..6da13b9744e 100644 --- a/src/emu/sound/s2636.c +++ b/src/emu/sound/s2636.c @@ -5,7 +5,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "sound/s2636.h" @@ -31,7 +30,7 @@ void s2636_soundport_w (device_t *device, int offset, int data) { s2636_sound *token = get_token(device); - stream_update(token->channel); + token->channel->update(); token->reg[offset] = data; switch (offset) { @@ -80,7 +79,7 @@ static DEVICE_START(s2636_sound) { s2636_sound *token = get_token(device); memset(token, 0, sizeof(*token)); - token->channel = stream_create(device, 0, 1, device->machine->sample_rate, 0, s2636_update); + token->channel = device->machine->sound().stream_alloc(*device, 0, 1, device->machine->sample_rate, 0, s2636_update); } diff --git a/src/emu/sound/saa1099.c b/src/emu/sound/saa1099.c index 4e68bf6c8ae..8906890c944 100644 --- a/src/emu/sound/saa1099.c +++ b/src/emu/sound/saa1099.c @@ -64,7 +64,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "saa1099.h" @@ -328,7 +327,7 @@ static DEVICE_START( saa1099 ) saa->sample_rate = device->clock() / 256; /* for each chip allocate one stream */ - saa->stream = stream_create(device, 0, 2, saa->sample_rate, saa, saa1099_update); + saa->stream = device->machine->sound().stream_alloc(*device, 0, 2, saa->sample_rate, saa, saa1099_update); } WRITE8_DEVICE_HANDLER( saa1099_control_w ) @@ -360,7 +359,7 @@ WRITE8_DEVICE_HANDLER( saa1099_data_w ) int ch; /* first update the stream to this point in time */ - stream_update(saa->stream); + saa->stream->update(); switch (reg) { diff --git a/src/emu/sound/samples.c b/src/emu/sound/samples.c index 2ed29bc6427..2efb1501e3f 100644 --- a/src/emu/sound/samples.c +++ b/src/emu/sound/samples.c @@ -1,6 +1,5 @@ #include "emu.h" #include "emuopts.h" -#include "streams.h" #include "samples.h" @@ -250,7 +249,7 @@ void sample_start(device_t *device,int channel,int samplenum,int loop) chan = &info->channel[channel]; /* force an update before we start */ - stream_update(chan->stream); + chan->stream->update(); /* update the parameters */ sample = &info->samples->sample[samplenum]; @@ -275,7 +274,7 @@ void sample_start_raw(device_t *device,int channel,const INT16 *sampledata,int s chan = &info->channel[channel]; /* force an update before we start */ - stream_update(chan->stream); + chan->stream->update(); /* update the parameters */ chan->source = sampledata; @@ -299,7 +298,7 @@ void sample_set_freq(device_t *device,int channel,int freq) chan = &info->channel[channel]; /* force an update before we start */ - stream_update(chan->stream); + chan->stream->update(); chan->step = ((INT64)freq << FRAC_BITS) / info->device->machine->sample_rate; } @@ -314,7 +313,7 @@ void sample_set_volume(device_t *device,int channel,float volume) chan = &info->channel[channel]; - stream_set_output_gain(chan->stream, 0, volume); + chan->stream->set_output_gain(0, volume); } @@ -328,7 +327,7 @@ void sample_set_pause(device_t *device,int channel,int pause) chan = &info->channel[channel]; /* force an update before we start */ - stream_update(chan->stream); + chan->stream->update(); chan->paused = pause; } @@ -344,7 +343,7 @@ void sample_stop(device_t *device,int channel) chan = &info->channel[channel]; /* force an update before we start */ - stream_update(chan->stream); + chan->stream->update(); chan->source = NULL; chan->source_num = -1; } @@ -360,7 +359,7 @@ int sample_get_base_freq(device_t *device,int channel) chan = &info->channel[channel]; /* force an update before we start */ - stream_update(chan->stream); + chan->stream->update(); return chan->basefreq; } @@ -375,7 +374,7 @@ int sample_playing(device_t *device,int channel) chan = &info->channel[channel]; /* force an update before we start */ - stream_update(chan->stream); + chan->stream->update(); return (chan->source != NULL); } @@ -485,7 +484,7 @@ static DEVICE_START( samples ) info->channel = auto_alloc_array(device->machine, sample_channel, info->numchannels); for (i = 0; i < info->numchannels; i++) { - info->channel[i].stream = stream_create(device, 0, 1, device->machine->sample_rate, &info->channel[i], sample_update_sound); + info->channel[i].stream = device->machine->sound().stream_alloc(*device, 0, 1, device->machine->sample_rate, &info->channel[i], sample_update_sound); info->channel[i].source = NULL; info->channel[i].source_num = -1; diff --git a/src/emu/sound/scsp.c b/src/emu/sound/scsp.c index 96900fdbe61..c5f68bc33ee 100644 --- a/src/emu/sound/scsp.c +++ b/src/emu/sound/scsp.c @@ -27,7 +27,6 @@ */ #include "emu.h" -#include "streams.h" #include "scsp.h" #include "scspdsp.h" @@ -1250,7 +1249,7 @@ static DEVICE_START( scsp ) { scsp->Int68kCB = intf->irq_callback; - scsp->stream = stream_create(device, 0, 2, 44100, scsp, SCSP_Update); + scsp->stream = device->machine->sound().stream_alloc(*device, 0, 2, 44100, scsp, SCSP_Update); } } @@ -1272,7 +1271,7 @@ READ16_DEVICE_HANDLER( scsp_r ) { scsp_state *scsp = get_safe_token(device); - stream_update(scsp->stream); + scsp->stream->update(); return SCSP_r16(scsp, offset*2); } @@ -1284,7 +1283,7 @@ WRITE16_DEVICE_HANDLER( scsp_w ) scsp_state *scsp = get_safe_token(device); UINT16 tmp, *scsp_regs; - stream_update(scsp->stream); + scsp->stream->update(); tmp = SCSP_r16(scsp, offset*2); COMBINE_DATA(&tmp); diff --git a/src/emu/sound/segapcm.c b/src/emu/sound/segapcm.c index 377f151eae7..15fd74eaf29 100644 --- a/src/emu/sound/segapcm.c +++ b/src/emu/sound/segapcm.c @@ -3,7 +3,6 @@ /*********************************************************/ #include "emu.h" -#include "streams.h" #include "segapcm.h" typedef struct _segapcm_state segapcm_state; @@ -128,7 +127,7 @@ static DEVICE_START( segapcm ) spcm->bankmask = mask & (rom_mask >> spcm->bankshift); - spcm->stream = stream_create(device, 0, 2, device->clock() / 128, spcm, SEGAPCM_update); + spcm->stream = device->machine->sound().stream_alloc(*device, 0, 2, device->clock() / 128, spcm, SEGAPCM_update); state_save_register_device_item_array(device, 0, spcm->low); state_save_register_device_item_pointer(device, 0, spcm->ram, 0x800); @@ -138,14 +137,14 @@ static DEVICE_START( segapcm ) WRITE8_DEVICE_HANDLER( sega_pcm_w ) { segapcm_state *spcm = get_safe_token(device); - stream_update(spcm->stream); + spcm->stream->update(); spcm->ram[offset & 0x07ff] = data; } READ8_DEVICE_HANDLER( sega_pcm_r ) { segapcm_state *spcm = get_safe_token(device); - stream_update(spcm->stream); + spcm->stream->update(); return spcm->ram[offset & 0x07ff]; } diff --git a/src/emu/sound/sid.c b/src/emu/sound/sid.c index f16900c5aa7..f6afaa983b9 100644 --- a/src/emu/sound/sid.c +++ b/src/emu/sound/sid.c @@ -258,7 +258,7 @@ void sid6581_port_w (_SID6581 *This, int offset, int data) break; case 0x15: case 0x16: case 0x17: case 0x18: - stream_update(This->mixer_channel); + This->mixer_channel->update(); This->reg[offset] = data; This->masterVolume = ( This->reg[0x18] & 15 ); This->masterVolumeAmplIndex = This->masterVolume << 8; @@ -300,7 +300,7 @@ void sid6581_port_w (_SID6581 *This, int offset, int data) break; default: - stream_update(This->mixer_channel); + This->mixer_channel->update(); This->reg[offset] = data; if (offset<7) { @@ -348,11 +348,11 @@ int sid6581_port_r (running_machine *machine, _SID6581 *This, int offset) data=0; break; case 0x1b: - stream_update(This->mixer_channel); + This->mixer_channel->update(); data = This->optr3.output; break; case 0x1c: - stream_update(This->mixer_channel); + This->mixer_channel->update(); data = This->optr3.enveVol; break; default: diff --git a/src/emu/sound/sid.h b/src/emu/sound/sid.h index b6cd462ccf5..df512edda13 100644 --- a/src/emu/sound/sid.h +++ b/src/emu/sound/sid.h @@ -10,7 +10,6 @@ #include "sound/sid6581.h" #include "sidvoice.h" -#include "streams.h" /* private area */ typedef struct __SID6581 diff --git a/src/emu/sound/sid6581.c b/src/emu/sound/sid6581.c index 06484f43d87..4960442b1fc 100644 --- a/src/emu/sound/sid6581.c +++ b/src/emu/sound/sid6581.c @@ -35,7 +35,7 @@ static void sid_start(device_t *device, SIDTYPE sidtype) const sid6581_interface *iface = (const sid6581_interface*) device->baseconfig().static_config(); sid->device = device; - sid->mixer_channel = stream_create (device, 0, 1, device->machine->sample_rate, (void *) sid, sid_update); + sid->mixer_channel = device->machine->sound().stream_alloc(*device, 0, 1, device->machine->sample_rate, (void *) sid, sid_update); sid->PCMfreq = device->machine->sample_rate; sid->clock = device->clock(); sid->ad_read = iface ? iface->ad_read : NULL; diff --git a/src/emu/sound/sn76477.c b/src/emu/sound/sn76477.c index d881c83f7d7..4c6ab6fa96c 100644 --- a/src/emu/sound/sn76477.c +++ b/src/emu/sound/sn76477.c @@ -28,7 +28,6 @@ *****************************************************************************/ #include "emu.h" -#include "streams.h" #include "wavwrite.h" #include "sn76477.h" @@ -991,7 +990,7 @@ static void SN76477_test_enable_w(sn76477_state *sn, UINT32 data) { if (data != sn->enable) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_enable_w(sn, data); @@ -1034,7 +1033,7 @@ void sn76477_mixer_a_w(device_t *device, UINT32 data) if (data != ((sn->mixer_mode >> 0) & 0x01)) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_mixer_a_w(sn, data); @@ -1059,7 +1058,7 @@ void sn76477_mixer_b_w(device_t *device, UINT32 data) if (data != ((sn->mixer_mode >> 1) & 0x01)) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_mixer_b_w(sn, data); @@ -1084,7 +1083,7 @@ void sn76477_mixer_c_w(device_t *device, UINT32 data) if (data != ((sn->mixer_mode >> 2) & 0x01)) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_mixer_c_w(sn, data); @@ -1116,7 +1115,7 @@ void sn76477_envelope_1_w(device_t *device, UINT32 data) if (data != ((sn->envelope_mode >> 0) & 0x01)) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_envelope_1_w(sn, data); @@ -1141,7 +1140,7 @@ void sn76477_envelope_2_w(device_t *device, UINT32 data) if (data != ((sn->envelope_mode >> 1) & 0x01)) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_envelope_2_w(sn, data); @@ -1173,7 +1172,7 @@ void sn76477_vco_w(device_t *device, UINT32 data) if (data != sn->vco_mode) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_vco_w(sn, data); @@ -1205,7 +1204,7 @@ void sn76477_one_shot_res_w(device_t *device, double data) if (data != sn->one_shot_res) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_one_shot_res_w(sn, data); @@ -1237,7 +1236,7 @@ void sn76477_one_shot_cap_w(device_t *device, double data) if (data != sn->one_shot_cap) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_one_shot_cap_w(sn, data); @@ -1266,7 +1265,7 @@ void sn76477_one_shot_cap_voltage_w(device_t *device, double data) /* switch to internal, if not already */ if (sn->one_shot_cap_voltage_ext) { - stream_update(sn->channel); + sn->channel->update(); sn->one_shot_cap_voltage_ext = 0; @@ -1278,7 +1277,7 @@ void sn76477_one_shot_cap_voltage_w(device_t *device, double data) /* set the voltage on the cap */ if (!sn->one_shot_cap_voltage_ext || (data != sn->one_shot_cap_voltage)) { - stream_update(sn->channel); + sn->channel->update(); sn->one_shot_cap_voltage_ext = 1; sn->one_shot_cap_voltage = data; @@ -1312,7 +1311,7 @@ void sn76477_slf_res_w(device_t *device, double data) if (data != sn->slf_res) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_slf_res_w(sn, data); @@ -1344,7 +1343,7 @@ void sn76477_slf_cap_w(device_t *device, double data) if (data != sn->slf_cap) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_slf_cap_w(sn, data); @@ -1375,7 +1374,7 @@ void sn76477_slf_cap_voltage_w(device_t *device, double data) /* switch to internal, if not already */ if (sn->slf_cap_voltage_ext) { - stream_update(sn->channel); + sn->channel->update(); sn->slf_cap_voltage_ext = 0; @@ -1387,7 +1386,7 @@ void sn76477_slf_cap_voltage_w(device_t *device, double data) /* set the voltage on the cap */ if (!sn->slf_cap_voltage_ext || (data != sn->slf_cap_voltage)) { - stream_update(sn->channel); + sn->channel->update(); sn->slf_cap_voltage_ext = 1; sn->slf_cap_voltage = data; @@ -1421,7 +1420,7 @@ void sn76477_vco_res_w(device_t *device, double data) if (data != sn->vco_res) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_vco_res_w(sn, data); @@ -1453,7 +1452,7 @@ void sn76477_vco_cap_w(device_t *device, double data) if (data != sn->vco_cap) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_vco_cap_w(sn, data); @@ -1482,7 +1481,7 @@ void sn76477_vco_cap_voltage_w(device_t *device, double data) /* switch to internal, if not already */ if (sn->vco_cap_voltage_ext) { - stream_update(sn->channel); + sn->channel->update(); sn->vco_cap_voltage_ext = 0; @@ -1494,7 +1493,7 @@ void sn76477_vco_cap_voltage_w(device_t *device, double data) /* set the voltage on the cap */ if (!sn->vco_cap_voltage_ext || (data != sn->vco_cap_voltage)) { - stream_update(sn->channel); + sn->channel->update(); sn->vco_cap_voltage_ext = 1; sn->vco_cap_voltage = data; @@ -1528,7 +1527,7 @@ void sn76477_vco_voltage_w(device_t *device, double data) if (data != sn->vco_voltage) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_vco_voltage_w(sn, data); @@ -1561,7 +1560,7 @@ void sn76477_pitch_voltage_w(device_t *device, double data) if (data != sn->pitch_voltage) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_pitch_voltage_w(sn, data); @@ -1594,7 +1593,7 @@ void sn76477_noise_clock_w(device_t *device, UINT32 data) if external control is enabled */ if (sn->noise_clock && sn->noise_clock_ext) { - stream_update(sn->channel); + sn->channel->update(); sn->real_noise_bit_ff = generate_next_real_noise_bit(sn); } @@ -1635,7 +1634,7 @@ void sn76477_noise_clock_res_w(device_t *device, double data) if (((data == 0) && !sn->noise_clock_ext) || ((data != 0) && (data != sn->noise_clock_res))) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_noise_clock_res_w(sn, data); @@ -1667,7 +1666,7 @@ void sn76477_noise_filter_res_w(device_t *device, double data) if (data != sn->noise_filter_res) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_noise_filter_res_w(sn, data); @@ -1699,7 +1698,7 @@ void sn76477_noise_filter_cap_w(device_t *device, double data) if (data != sn->noise_filter_cap) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_noise_filter_cap_w(sn, data); @@ -1728,7 +1727,7 @@ void sn76477_noise_filter_cap_voltage_w(device_t *device, double data) /* switch to internal, if not already */ if (sn->noise_filter_cap_voltage_ext) { - stream_update(sn->channel); + sn->channel->update(); sn->noise_filter_cap_voltage_ext = 0; @@ -1740,7 +1739,7 @@ void sn76477_noise_filter_cap_voltage_w(device_t *device, double data) /* set the voltage on the cap */ if (!sn->noise_filter_cap_voltage_ext || (data != sn->noise_filter_cap_voltage)) { - stream_update(sn->channel); + sn->channel->update(); sn->noise_filter_cap_voltage_ext = 1; sn->noise_filter_cap_voltage = data; @@ -1774,7 +1773,7 @@ void sn76477_attack_res_w(device_t *device, double data) if (data != sn->attack_res) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_attack_res_w(sn, data); @@ -1806,7 +1805,7 @@ void sn76477_decay_res_w(device_t *device, double data) if (data != sn->decay_res) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_decay_res_w(sn, data); @@ -1838,7 +1837,7 @@ void sn76477_attack_decay_cap_w(device_t *device, double data) if (data != sn->attack_decay_cap) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_attack_decay_cap_w(sn, data); @@ -1868,7 +1867,7 @@ void sn76477_attack_decay_cap_voltage_w(device_t *device, double data) /* switch to internal, if not already */ if (sn->attack_decay_cap_voltage_ext) { - stream_update(sn->channel); + sn->channel->update(); sn->attack_decay_cap_voltage_ext = 0; @@ -1881,7 +1880,7 @@ void sn76477_attack_decay_cap_voltage_w(device_t *device, double data) /* set the voltage on the cap */ if (!sn->attack_decay_cap_voltage_ext || (data != sn->attack_decay_cap_voltage)) { - stream_update(sn->channel); + sn->channel->update(); sn->attack_decay_cap_voltage_ext = 1; sn->attack_decay_cap_voltage = data; @@ -1916,7 +1915,7 @@ void sn76477_amplitude_res_w(device_t *device, double data) if (data != sn->amplitude_res) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_amplitude_res_w(sn, data); @@ -1948,7 +1947,7 @@ void sn76477_feedback_res_w(device_t *device, double data) if (data != sn->feedback_res) { - stream_update(sn->channel); + sn->channel->update(); _SN76477_feedback_res_w(sn, data); @@ -1989,13 +1988,13 @@ static STREAM_UPDATE( SN76477_update ) #if TEST_MODE - static int recursing = 0; /* we need to prevent recursion since enable_w calls stream_update */ + static int recursing = 0; /* we need to prevent recursion since enable_w calls input_code_pressed_once(device->machine, KEYCODE_SPACE->update */ - if (input_code_pressed_once(device->machine, KEYCODE_SPACE) && !recursing) + if () && !recursing) { recursing = 1; - sound_global_enable(device->machine, 1); + device->machine->sound().system_enable(); SN76477_test_enable_w(sn, !sn->enable); } @@ -2407,7 +2406,7 @@ static DEVICE_START( sn76477 ) sn->device = device; - sn->channel = stream_create(device, 0, 1, device->machine->sample_rate, sn, SN76477_update); + sn->channel = device->machine->sound().stream_alloc(*device, 0, 1, device->machine->sample_rate, sn, SN76477_update); if (device->clock() > 0) { diff --git a/src/emu/sound/sn76496.c b/src/emu/sound/sn76496.c index 673325325e4..0f44e928352 100644 --- a/src/emu/sound/sn76496.c +++ b/src/emu/sound/sn76496.c @@ -103,7 +103,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "sn76496.h" @@ -152,14 +151,14 @@ INLINE sn76496_state *get_safe_token(device_t *device) READ_LINE_DEVICE_HANDLER( sn76496_ready_r ) { sn76496_state *R = get_safe_token(device); - stream_update(R->Channel); + R->Channel->update(); return (R->CyclestoREADY? 0 : 1); } WRITE8_DEVICE_HANDLER( sn76496_stereo_w ) { sn76496_state *R = get_safe_token(device); - stream_update(R->Channel); + R->Channel->update(); if (R->Stereo) R->StereoMask = data; else fatalerror("Call to stereo write with mono chip!\n"); } @@ -171,7 +170,7 @@ WRITE8_DEVICE_HANDLER( sn76496_w ) /* update the output buffer before changing the registers */ - stream_update(R->Channel); + R->Channel->update(); /* set number of cycles until READY is active; this is always one 'sample', i.e. it equals the clock divider exactly; until the @@ -347,7 +346,7 @@ static int SN76496_init(device_t *device, sn76496_state *R, int stereo) int sample_rate = device->clock()/2; int i; - R->Channel = stream_create(device,0,(stereo?2:1),sample_rate,R,SN76496Update); + R->Channel = device->machine->sound().stream_alloc(*device,0,(stereo?2:1),sample_rate,R,SN76496Update); for (i = 0;i < 4;i++) R->Volume[i] = 0; diff --git a/src/emu/sound/snkwave.c b/src/emu/sound/snkwave.c index b2e07206cfa..1cc18df3743 100644 --- a/src/emu/sound/snkwave.c +++ b/src/emu/sound/snkwave.c @@ -7,7 +7,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "snkwave.h" @@ -120,7 +119,7 @@ static DEVICE_START( snkwave ) chip->sample_rate = chip->external_clock >> CLOCK_SHIFT; /* get stream channels */ - chip->stream = stream_create(device, 0, 1, chip->sample_rate, chip, snkwave_update); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 1, chip->sample_rate, chip, snkwave_update); /* reset all the voices */ chip->frequency = 0; @@ -147,7 +146,7 @@ WRITE8_DEVICE_HANDLER( snkwave_w ) { snkwave_state *chip = get_safe_token(device); - stream_update(chip->stream); + chip->stream->update(); // all registers are 6-bit data &= 0x3f; diff --git a/src/emu/sound/sp0250.c b/src/emu/sound/sp0250.c index 53f2b6387e4..91340b2a411 100644 --- a/src/emu/sound/sp0250.c +++ b/src/emu/sound/sp0250.c @@ -17,7 +17,6 @@ */ #include "emu.h" -#include "streams.h" #include "sp0250.h" /* @@ -128,7 +127,7 @@ static void sp0250_load_values(sp0250_state *sp) static TIMER_CALLBACK( sp0250_timer_tick ) { sp0250_state *sp = (sp0250_state *)ptr; - stream_update(sp->stream); + sp->stream->update(); } static STREAM_UPDATE( sp0250_update ) @@ -212,14 +211,14 @@ static DEVICE_START( sp0250 ) timer_pulse(device->machine, attotime_mul(ATTOTIME_IN_HZ(device->clock()), CLOCK_DIVIDER), sp, 0, sp0250_timer_tick); } - sp->stream = stream_create(device, 0, 1, device->clock() / CLOCK_DIVIDER, sp, sp0250_update); + sp->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock() / CLOCK_DIVIDER, sp, sp0250_update); } WRITE8_DEVICE_HANDLER( sp0250_w ) { sp0250_state *sp = get_safe_token(device); - stream_update(sp->stream); + sp->stream->update(); if (sp->fifo_pos != 15) { sp->fifo[sp->fifo_pos++] = data; @@ -234,7 +233,7 @@ WRITE8_DEVICE_HANDLER( sp0250_w ) UINT8 sp0250_drq_r(device_t *device) { sp0250_state *sp = get_safe_token(device); - stream_update(sp->stream); + sp->stream->update(); return (sp->fifo_pos == 15) ? CLEAR_LINE : ASSERT_LINE; } diff --git a/src/emu/sound/sp0256.c b/src/emu/sound/sp0256.c index 4f083fc0e04..7481c9d48e9 100644 --- a/src/emu/sound/sp0256.c +++ b/src/emu/sound/sp0256.c @@ -32,7 +32,6 @@ */ #include "emu.h" -#include "streams.h" #include "sp0256.h" #define CLOCK_DIVIDER (7*6*8) @@ -1187,7 +1186,7 @@ static DEVICE_START( sp0256 ) devcb_call_write_line(&sp->drq, 1); devcb_call_write_line(&sp->sby, 1); - sp->stream = stream_create(device, 0, 1, device->clock() / CLOCK_DIVIDER, sp, sp0256_update); + sp->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock() / CLOCK_DIVIDER, sp, sp0256_update); /* -------------------------------------------------------------------- */ /* Configure our internal variables. */ diff --git a/src/emu/sound/speaker.c b/src/emu/sound/speaker.c index 59757bf252f..5d6112d2c06 100644 --- a/src/emu/sound/speaker.c +++ b/src/emu/sound/speaker.c @@ -71,7 +71,6 @@ */ #include "emu.h" -#include "streams.h" #include "speaker.h" static const INT16 default_levels[2] = {0, 32767}; @@ -141,7 +140,7 @@ static DEVICE_START( speaker ) int i; double x; - sp->channel = stream_create(device, 0, 1, device->machine->sample_rate, sp, speaker_sound_update); + sp->channel = device->machine->sound().stream_alloc(*device, 0, 1, device->machine->sample_rate, sp, speaker_sound_update); if (intf != NULL) { @@ -165,7 +164,7 @@ static DEVICE_START( speaker ) sp->channel_sample_period_secfrac = ATTOSECONDS_TO_DOUBLE(sp->channel_sample_period); sp->interm_sample_period = sp->channel_sample_period / RATE_MULTIPLIER; sp->interm_sample_period_secfrac = ATTOSECONDS_TO_DOUBLE(sp->interm_sample_period); - sp->channel_last_sample_time = stream_get_time(sp->channel); + sp->channel_last_sample_time = sp->channel->sample_time(); sp->channel_next_sample_time = attotime_add_attoseconds(sp->channel_last_sample_time, sp->channel_sample_period); sp->next_interm_sample_time = attotime_add_attoseconds(sp->channel_last_sample_time, sp->interm_sample_period); sp->interm_sample_index = 0; @@ -211,7 +210,7 @@ static DEVICE_START( speaker ) } -/* Called via stream_update(stream). +/* Called via stream->update(). * This can be triggered by the core (based on emulated time) or via speaker_level_w(). */ static STREAM_UPDATE( speaker_sound_update ) @@ -230,7 +229,7 @@ static STREAM_UPDATE( speaker_sound_update ) sampled_time = attotime_mul(sampled_time, samples); /* Note: since the stream is in the process of being updated, - * stream_get_time() will return the time before the update! (MAME 0.130) + * stream->sample_time() will return the time before the update! (MAME 0.130) * Avoid using it here in order to avoid a subtle dependence on the stream implementation. */ } @@ -293,12 +292,12 @@ void speaker_level_w(device_t *device, int new_level) */ /* Force streams.c to update sound until this point in time now */ - stream_update(sp->channel); + sp->channel->update(); /* This is redundant because time update has to be done within speaker_sound_update() anyway, * however this ensures synchronization between the speaker and stream timing: */ - sp->channel_last_sample_time = stream_get_time(sp->channel); + sp->channel_last_sample_time = sp->channel->sample_time(); sp->channel_next_sample_time = attotime_add_attoseconds(sp->channel_last_sample_time, sp->channel_sample_period); sp->next_interm_sample_time = attotime_add_attoseconds(sp->channel_last_sample_time, sp->interm_sample_period); sp->last_update_time = sp->channel_last_sample_time; diff --git a/src/emu/sound/speaker.h b/src/emu/sound/speaker.h index 89a98108b28..342a5eb2cfc 100644 --- a/src/emu/sound/speaker.h +++ b/src/emu/sound/speaker.h @@ -8,8 +8,8 @@ #pragma once -#ifndef __SPEAKER_H__ -#define __SPEAKER_H__ +#ifndef __SOUND_SPEAKER_H__ +#define __SOUND_SPEAKER_H__ #include "devlegcy.h" diff --git a/src/emu/sound/st0016.c b/src/emu/sound/st0016.c index 3e942106a40..c4473995127 100644 --- a/src/emu/sound/st0016.c +++ b/src/emu/sound/st0016.c @@ -4,7 +4,6 @@ ************************************/ #include "emu.h" -#include "streams.h" #include "st0016.h" #define VERBOSE (0) @@ -143,7 +142,7 @@ static DEVICE_START( st0016 ) info->sound_ram = intf->p_soundram; - info->stream = stream_create(device, 0, 2, 44100, info, st0016_update); + info->stream = device->machine->sound().stream_alloc(*device, 0, 2, 44100, info, st0016_update); } diff --git a/src/emu/sound/t6w28.c b/src/emu/sound/t6w28.c index aa023e9204d..e678b50ea25 100644 --- a/src/emu/sound/t6w28.c +++ b/src/emu/sound/t6w28.c @@ -30,7 +30,6 @@ Offset 0: ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "t6w28.h" @@ -73,7 +72,7 @@ WRITE8_DEVICE_HANDLER( t6w28_w ) /* update the output buffer before changing the registers */ - stream_update(R->Channel); + R->Channel->update(); offset &= 1; @@ -310,7 +309,7 @@ static int t6w28_init(device_t *device, t6w28_state *R) int sample_rate = device->clock()/16; int i; - R->Channel = stream_create(device,0,2,sample_rate,R,t6w28_update); + R->Channel = device->machine->sound().stream_alloc(*device,0,2,sample_rate,R,t6w28_update); R->SampleRate = sample_rate; diff --git a/src/emu/sound/tiaintf.c b/src/emu/sound/tiaintf.c index 6f485396777..cd3091ef3d7 100644 --- a/src/emu/sound/tiaintf.c +++ b/src/emu/sound/tiaintf.c @@ -1,5 +1,4 @@ #include "emu.h" -#include "streams.h" #include "tiaintf.h" #include "tiasound.h" @@ -29,7 +28,7 @@ static DEVICE_START( tia ) { tia_state *info = get_safe_token(device); - info->channel = stream_create(device, 0, 1, device->clock(), info, tia_update); + info->channel = device->machine->sound().stream_alloc(*device, 0, 1, device->clock(), info, tia_update); info->chip = tia_sound_init(device->clock(), device->clock(), 16); assert_always(info->chip != NULL, "Error creating TIA chip"); @@ -44,7 +43,7 @@ static DEVICE_STOP( tia ) WRITE8_DEVICE_HANDLER( tia_sound_w ) { tia_state *info = get_safe_token(device); - stream_update(info->channel); + info->channel->update(); tia_write(info->chip, offset, data); } diff --git a/src/emu/sound/tiasound.c b/src/emu/sound/tiasound.c index 43587416208..47e1e6c72bf 100644 --- a/src/emu/sound/tiasound.c +++ b/src/emu/sound/tiasound.c @@ -40,7 +40,6 @@ /*****************************************************************************/ #include "emu.h" -#include "streams.h" #include "tiaintf.h" #include "tiasound.h" diff --git a/src/emu/sound/tms3615.c b/src/emu/sound/tms3615.c index afae523c58b..d8d8ceb92d5 100644 --- a/src/emu/sound/tms3615.c +++ b/src/emu/sound/tms3615.c @@ -1,5 +1,4 @@ #include "emu.h" -#include "streams.h" #include "tms3615.h" #define VMIN 0x0000 @@ -90,7 +89,7 @@ static DEVICE_START( tms3615 ) { tms_state *tms = get_safe_token(device); - tms->channel = stream_create(device, 0, 2, device->clock()/8, tms, tms3615_sound_update); + tms->channel = device->machine->sound().stream_alloc(*device, 0, 2, device->clock()/8, tms, tms3615_sound_update); tms->samplerate = device->clock()/8; tms->basefreq = device->clock(); } diff --git a/src/emu/sound/tms36xx.c b/src/emu/sound/tms36xx.c index c77a0f14747..6d1e4635f73 100644 --- a/src/emu/sound/tms36xx.c +++ b/src/emu/sound/tms36xx.c @@ -1,5 +1,4 @@ #include "emu.h" -#include "streams.h" #include "tms36xx.h" #define VERBOSE 1 @@ -421,7 +420,7 @@ void mm6221aa_tune_w(device_t *device, int tune) LOG(("%s tune:%X\n", tms->subtype, tune)); /* update the stream before changing the tune */ - stream_update(tms->channel); + tms->channel->update(); tms->tune_num = tune; tms->tune_ofs = 0; @@ -441,7 +440,7 @@ void tms36xx_note_w(device_t *device, int octave, int note) LOG(("%s octave:%X note:%X\n", tms->subtype, octave, note)); /* update the stream before changing the tune */ - stream_update(tms->channel); + tms->channel->update(); /* play a single note from 'tune 4', a list of the 13 tones */ tms36xx_reset_counters(tms); @@ -461,7 +460,7 @@ static void tms3617_enable(tms_state *tms, int enable) return; /* update the stream before changing the tune */ - stream_update(tms->channel); + tms->channel->update(); LOG(("%s enable voices", tms->subtype)); for (i = 0; i < 6; i++) @@ -501,7 +500,7 @@ static DEVICE_START( tms36xx ) tms->intf = (const tms36xx_interface *)device->baseconfig().static_config(); - tms->channel = stream_create(device, 0, 1, device->clock() * 64, tms, tms36xx_sound_update); + tms->channel = device->machine->sound().stream_alloc(*device, 0, 1, device->clock() * 64, tms, tms36xx_sound_update); tms->samplerate = device->clock() * 64; tms->basefreq = device->clock(); enable = 0; diff --git a/src/emu/sound/tms5110.c b/src/emu/sound/tms5110.c index e05c226e2ba..3067c8ab351 100644 --- a/src/emu/sound/tms5110.c +++ b/src/emu/sound/tms5110.c @@ -61,7 +61,6 @@ ***********************************************************************************************/ #include "emu.h" -#include "streams.h" #include "tms5110.h" #define MAX_SAMPLE_CHUNK 512 @@ -1032,7 +1031,7 @@ static DEVICE_START( tms5110 ) devcb_resolve_read_line(&tms->data_func, &tms->intf->data_func, device); /* initialize a stream */ - tms->stream = stream_create(device, 0, 1, device->clock() / 80, tms, tms5110_update); + tms->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock() / 80, tms, tms5110_update); if (tms->table == NULL) { @@ -1153,7 +1152,7 @@ WRITE8_DEVICE_HANDLER( tms5110_ctl_w ) tms5110_state *tms = get_safe_token(device); /* bring up to date first */ - stream_update(tms->stream); + tms->stream->update(); tms->CTL_pins = data & 0xf; } @@ -1169,7 +1168,7 @@ WRITE_LINE_DEVICE_HANDLER( tms5110_pdc_w ) tms5110_state *tms = get_safe_token(device); /* bring up to date first */ - stream_update(tms->stream); + tms->stream->update(); tms5110_PDC_set(tms, state); } @@ -1195,7 +1194,7 @@ READ8_DEVICE_HANDLER( tms5110_ctl_r ) tms5110_state *tms = get_safe_token(device); /* bring up to date first */ - stream_update(tms->stream); + tms->stream->update(); if (tms->state == CTL_STATE_OUTPUT) { //if (DEBUG_5110) logerror("Status read (status=%2d)\n", tms->talk_status); @@ -1213,7 +1212,7 @@ READ8_DEVICE_HANDLER( m58817_status_r ) tms5110_state *tms = get_safe_token(device); /* bring up to date first */ - stream_update(tms->stream); + tms->stream->update(); return (tms->talk_status << 0); /*CTL1 = still talking ? */ } @@ -1234,7 +1233,7 @@ READ8_DEVICE_HANDLER( tms5110_romclk_hack_r ) tms5110_state *tms = get_safe_token(device); /* bring up to date first */ - stream_update(tms->stream); + tms->stream->update(); /* create and start timer if necessary */ if (!tms->romclk_hack_timer_started) @@ -1258,7 +1257,7 @@ int tms5110_ready_r(device_t *device) tms5110_state *tms = get_safe_token(device); /* bring up to date first */ - stream_update(tms->stream); + tms->stream->update(); return (tms->fifo_count < FIFO_SIZE-1); } @@ -1303,7 +1302,7 @@ static STREAM_UPDATE( tms5110_update ) void tms5110_set_frequency(device_t *device, int frequency) { tms5110_state *tms = get_safe_token(device); - stream_set_sample_rate(tms->stream, frequency / 80); + tms->stream->set_sample_rate(frequency / 80); } diff --git a/src/emu/sound/tms5220.c b/src/emu/sound/tms5220.c index 931843d9c2e..ddd55dd6cad 100644 --- a/src/emu/sound/tms5220.c +++ b/src/emu/sound/tms5220.c @@ -247,7 +247,6 @@ device), PES Speech adapter (serial port connection) ***********************************************************************************************/ #include "emu.h" -#include "streams.h" #include "tms5220.h" /* *****optional defines***** */ @@ -1519,7 +1518,7 @@ static DEVICE_START( tms5220 ) devcb_resolve_write_line(&tms->readyq_func, &tms->intf->readyq_func, device); /* initialize a stream */ - tms->stream = stream_create(device, 0, 1, device->clock() / 80, tms, tms5220_update); + tms->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock() / 80, tms, tms5220_update); /*if (tms->table == NULL) { @@ -1629,13 +1628,13 @@ static TIMER_CALLBACK( io_ready_cb ) logerror("Serviced write: %02x\n", tms->write_latch); //fprintf(stderr, "Processed write data: %02X\n", tms->write_latch); #endif - stream_update(tms->stream); + tms->stream->update(); tms5220_data_write(tms, tms->write_latch); break; case 0x01: /* Read */ /* bring up to date first */ - stream_update(tms->stream); + tms->stream->update(); tms->read_latch = tms5220_status_read(tms); break; case 0x03: @@ -1780,7 +1779,7 @@ WRITE8_DEVICE_HANDLER( tms5220_data_w ) if (!tms->true_timing) { /* bring up to date first */ - stream_update(tms->stream); + tms->stream->update(); tms5220_data_write(tms, data); } else @@ -1808,7 +1807,7 @@ READ8_DEVICE_HANDLER( tms5220_status_r ) if (!tms->true_timing) { /* bring up to date first */ - stream_update(tms->stream); + tms->stream->update(); return tms5220_status_read(tms); } else @@ -1836,7 +1835,7 @@ READ_LINE_DEVICE_HANDLER( tms5220_readyq_r ) { tms5220_state *tms = get_safe_token(device); /* bring up to date first */ - stream_update(tms->stream); + tms->stream->update(); return !tms5220_ready_read(tms); } @@ -1854,7 +1853,7 @@ double tms5220_time_to_ready(device_t *device) double cycles; /* bring up to date first */ - stream_update(tms->stream); + tms->stream->update(); cycles = tms5220_cycles_to_ready(tms); return cycles * 80.0 / tms->clock; } @@ -1871,7 +1870,7 @@ READ_LINE_DEVICE_HANDLER( tms5220_intq_r ) { tms5220_state *tms = get_safe_token(device); /* bring up to date first */ - stream_update(tms->stream); + tms->stream->update(); return !tms5220_int_read(tms); } @@ -1916,7 +1915,7 @@ static STREAM_UPDATE( tms5220_update ) void tms5220_set_frequency(device_t *device, int frequency) { tms5220_state *tms = get_safe_token(device); - stream_set_sample_rate(tms->stream, frequency / 80); + tms->stream->set_sample_rate(frequency / 80); tms->clock = frequency; } diff --git a/src/emu/sound/upd7759.c b/src/emu/sound/upd7759.c index 4bdc4ac1e60..3349b3a98f6 100644 --- a/src/emu/sound/upd7759.c +++ b/src/emu/sound/upd7759.c @@ -98,7 +98,6 @@ *************************************************************/ #include "emu.h" -#include "streams.h" #include "upd7759.h" @@ -536,7 +535,7 @@ static TIMER_CALLBACK( upd7759_slave_update ) UINT8 olddrq = chip->drq; /* update the stream */ - stream_update(chip->channel); + chip->channel->update(); /* advance the state */ advance_state(chip); @@ -642,7 +641,7 @@ static DEVICE_START( upd7759 ) chip->device = device; /* allocate a stream channel */ - chip->channel = stream_create(device, 0, 1, device->clock()/4, chip, upd7759_update); + chip->channel = device->machine->sound().stream_alloc(*device, 0, 1, device->clock()/4, chip, upd7759_update); /* compute the stepping rate based on the chip's clock speed */ chip->step = 4 * FRAC_ONE; @@ -687,7 +686,7 @@ void upd7759_reset_w(device_t *device, UINT8 data) chip->reset = (data != 0); /* update the stream first */ - stream_update(chip->channel); + chip->channel->update(); /* on the falling edge, reset everything */ if (oldreset && !chip->reset) @@ -704,7 +703,7 @@ void upd7759_start_w(device_t *device, UINT8 data) logerror("upd7759_start_w: %d->%d\n", oldstart, chip->start); /* update the stream first */ - stream_update(chip->channel); + chip->channel->update(); /* on the rising edge, if we're idle, start going, but not if we're held in reset */ if (chip->state == STATE_IDLE && !oldstart && chip->start && chip->reset) diff --git a/src/emu/sound/vlm5030.c b/src/emu/sound/vlm5030.c index 03fe3965788..543d9b9915d 100644 --- a/src/emu/sound/vlm5030.c +++ b/src/emu/sound/vlm5030.c @@ -108,7 +108,6 @@ chirp 12-..: vokume 0 : silent */ #include "emu.h" -#include "streams.h" #include "vlm5030.h" /* interpolator per frame */ @@ -488,7 +487,7 @@ phase_stop: /* realtime update */ static void vlm5030_update(vlm5030_state *chip) { - stream_update(chip->channel); + chip->channel->update(); } /* setup parameteroption when RST=H */ @@ -704,7 +703,7 @@ static DEVICE_START( vlm5030 ) else chip->address_mask = chip->intf->memory_size-1; - chip->channel = stream_create(device, 0, 1, emulation_rate,chip,vlm5030_update_callback); + chip->channel = device->machine->sound().stream_alloc(*device, 0, 1, emulation_rate,chip,vlm5030_update_callback); /* don't restore "UINT8 *chip->rom" when use vlm5030_set_rom() */ diff --git a/src/emu/sound/votrax.c b/src/emu/sound/votrax.c index f62e4b4ca49..d8a202147ab 100644 --- a/src/emu/sound/votrax.c +++ b/src/emu/sound/votrax.c @@ -16,7 +16,6 @@ the variable VotraxBaseFrequency, this is defaulted to 8000 **************************************************************************/ #include "emu.h" -#include "streams.h" #include "samples.h" #include "votrax.h" @@ -118,7 +117,7 @@ static DEVICE_START( votrax ) votrax->frequency = 8000; votrax->volume = 230; - votrax->channel = stream_create(device, 0, 1, device->machine->sample_rate, votrax, votrax_update_sound); + votrax->channel = device->machine->sound().stream_alloc(*device, 0, 1, device->machine->sample_rate, votrax, votrax_update_sound); votrax->sample = NULL; votrax->step = 0; @@ -130,7 +129,7 @@ WRITE8_DEVICE_HANDLER( votrax_w ) votrax_state *info = get_safe_token(device); int Phoneme,Intonation; - stream_update(info->channel); + info->channel->update(); Phoneme = data & 0x3F; Intonation = data >> 6; @@ -146,14 +145,14 @@ WRITE8_DEVICE_HANDLER( votrax_w ) info->pos = 0; info->frac = 0; info->step = ((INT64)(info->sample->frequency + (256*Intonation)) << FRAC_BITS) / info->device->machine->sample_rate; - stream_set_output_gain(info->channel, 0, (info->volume + (8*Intonation)*100/255) / 100.0); + info->channel->set_output_gain(0, (info->volume + (8*Intonation)*100/255) / 100.0); } } int votrax_status_r(device_t *device) { votrax_state *info = get_safe_token(device); - stream_update(info->channel); + info->channel->update(); return (info->sample != NULL); } diff --git a/src/emu/sound/vrender0.c b/src/emu/sound/vrender0.c index 7a5642780b3..94c1e7129fe 100644 --- a/src/emu/sound/vrender0.c +++ b/src/emu/sound/vrender0.c @@ -1,5 +1,4 @@ #include "emu.h" -#include "streams.h" #include "vrender0.h" /*********************************** @@ -111,7 +110,7 @@ static DEVICE_START( vrender0 ) memcpy(&(VR0->Intf),intf,sizeof(vr0_interface)); memset(VR0->SOUNDREGS,0,sizeof(VR0->SOUNDREGS)); - VR0->stream = stream_create(device, 0, 2, 44100, VR0, VR0_Update); + VR0->stream = device->machine->sound().stream_alloc(*device, 0, 2, 44100, VR0, VR0_Update); state_save_register_device_item_array(device, 0, VR0->SOUNDREGS); } diff --git a/src/emu/sound/wave.c b/src/emu/sound/wave.c index 8b854b7a30c..24535e7efc0 100644 --- a/src/emu/sound/wave.c +++ b/src/emu/sound/wave.c @@ -14,7 +14,6 @@ ****************************************************************************/ #include "emu.h" -#include "streams.h" #include "imagedev/cassette.h" #include "wave.h" @@ -23,7 +22,7 @@ static STREAM_UPDATE( wave_sound_update ) { device_image_interface *image = (device_image_interface *)param; - int speakers = speaker_output_count(image->device().machine->config); + int speakers = image->device().machine->m_devicelist.count(SPEAKER); cassette_image *cassette; cassette_state state; double time_index; @@ -69,12 +68,12 @@ static DEVICE_START( wave ) assert( device != NULL ); assert( device->baseconfig().static_config() != NULL ); - int speakers = speaker_output_count(device->machine->config); + int speakers = device->machine->config->m_devicelist.count(SPEAKER); image = dynamic_cast(device->machine->device( (const char *)device->baseconfig().static_config())); if (speakers > 1) - stream_create(device, 0, 2, device->machine->sample_rate, (void *)image, wave_sound_update); + device->machine->sound().stream_alloc(*device, 0, 2, device->machine->sample_rate, (void *)image, wave_sound_update); else - stream_create(device, 0, 1, device->machine->sample_rate, (void *)image, wave_sound_update); + device->machine->sound().stream_alloc(*device, 0, 1, device->machine->sample_rate, (void *)image, wave_sound_update); } diff --git a/src/emu/sound/x1_010.c b/src/emu/sound/x1_010.c index 9803cf1aa30..abf887cb4e5 100644 --- a/src/emu/sound/x1_010.c +++ b/src/emu/sound/x1_010.c @@ -49,7 +49,6 @@ Registers: ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "x1_010.h" @@ -217,7 +216,7 @@ static DEVICE_START( x1_010 ) LOG_SOUND(("masterclock = %d rate = %d\n", device->clock(), info->rate )); /* get stream channels */ - info->stream = stream_create(device,0,2,info->rate,info,seta_update); + info->stream = device->machine->sound().stream_alloc(*device,0,2,info->rate,info,seta_update); } diff --git a/src/emu/sound/ym2151.c b/src/emu/sound/ym2151.c index 79d96dac131..767743b6215 100644 --- a/src/emu/sound/ym2151.c +++ b/src/emu/sound/ym2151.c @@ -5,7 +5,6 @@ ******************************************************************************/ #include "emu.h" -#include "streams.h" #include "ym2151.h" diff --git a/src/emu/sound/ymf271.c b/src/emu/sound/ymf271.c index 75f93579d22..f60ed3a7ea3 100644 --- a/src/emu/sound/ymf271.c +++ b/src/emu/sound/ymf271.c @@ -13,7 +13,6 @@ */ #include "emu.h" -#include "streams.h" #include "ymf271.h" #define VERBOSE (1) @@ -1779,7 +1778,7 @@ static DEVICE_START( ymf271 ) intf = (device->baseconfig().static_config() != NULL) ? (const ymf271_interface *)device->baseconfig().static_config() : &defintrf; ymf271_init(device, chip, *device->region(), intf->irq_callback, &intf->ext_read, &intf->ext_write); - chip->stream = stream_create(device, 0, 2, device->clock()/384, chip, ymf271_update); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 2, device->clock()/384, chip, ymf271_update); for (i = 0; i < 256; i++) { diff --git a/src/emu/sound/ymf278b.c b/src/emu/sound/ymf278b.c index 1947235d4d8..8cc602cf0a9 100644 --- a/src/emu/sound/ymf278b.c +++ b/src/emu/sound/ymf278b.c @@ -58,7 +58,6 @@ */ #include "emu.h" -#include "streams.h" #include "ymf278b.h" #define VERBOSE 0 @@ -742,7 +741,7 @@ static DEVICE_START( ymf278b ) intf = (device->baseconfig().static_config() != NULL) ? (const ymf278b_interface *)device->baseconfig().static_config() : &defintrf; ymf278b_init(device, chip, intf->irq_callback); - chip->stream = stream_create(device, 0, 2, device->clock()/768, chip, ymf278b_pcm_update); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 2, device->clock()/768, chip, ymf278b_pcm_update); // Volume table, 1 = -0.375dB, 8 = -3dB, 256 = -96dB for(i = 0; i < 256; i++) diff --git a/src/emu/sound/ymz280b.c b/src/emu/sound/ymz280b.c index 959f8dab7b1..86703776642 100644 --- a/src/emu/sound/ymz280b.c +++ b/src/emu/sound/ymz280b.c @@ -22,7 +22,6 @@ #include "emu.h" -#include "streams.h" #include "ymz280b.h" @@ -652,7 +651,7 @@ static DEVICE_START( ymz280b ) chip->irq_callback = intf->irq_callback; /* create the stream */ - chip->stream = stream_create(device, 0, 2, INTERNAL_SAMPLE_RATE, chip, ymz280b_update); + chip->stream = device->machine->sound().stream_alloc(*device, 0, 2, INTERNAL_SAMPLE_RATE, chip, ymz280b_update); /* allocate memory */ chip->scratch = auto_alloc_array(device->machine, INT16, MAX_SAMPLE_CHUNK); @@ -716,7 +715,7 @@ static void write_to_register(ymz280b_state *chip, int data) int i; /* force an update */ - stream_update(chip->stream); + chip->stream->update(); /* lower registers follow a pattern */ if (chip->current_register < 0x80) @@ -903,7 +902,7 @@ static int compute_status(ymz280b_state *chip) } /* force an update */ - stream_update(chip->stream); + chip->stream->update(); result = chip->status_register; diff --git a/src/emu/sound/zsg2.c b/src/emu/sound/zsg2.c index f658b9ff235..7f5f99a3a04 100644 --- a/src/emu/sound/zsg2.c +++ b/src/emu/sound/zsg2.c @@ -44,7 +44,6 @@ */ #include "emu.h" -#include "streams.h" #include "zsg2.h" // 16 registers per channel, 48 channels @@ -181,7 +180,7 @@ WRITE16_DEVICE_HANDLER( zsg2_w ) assert(mem_mask == 0xffff); // we only support full 16-bit accesses - stream_update(info->stream); + info->stream->update(); if (adr < 0x600) { @@ -227,7 +226,7 @@ static DEVICE_START( zsg2 ) memset(&info->zc, 0, sizeof(info->zc)); memset(&info->act, 0, sizeof(info->act)); - info->stream = stream_create(device, 0, 2, info->sample_rate, info, update_stereo); + info->stream = device->machine->sound().stream_alloc(*device, 0, 2, info->sample_rate, info, update_stereo); info->bank_samples = device->machine->region(intf->samplergn)->base(); } diff --git a/src/emu/streams.c b/src/emu/streams.c deleted file mode 100644 index e6ded4a3990..00000000000 --- a/src/emu/streams.c +++ /dev/null @@ -1,1025 +0,0 @@ -/*************************************************************************** - - streams.c - - Handle general purpose audio streams - - Copyright Nicola Salmoria and the MAME Team. - Visit http://mamedev.org for licensing and usage restrictions. - -**************************************************************************** - - Streaming works as follows: - - Each stream can have 'n' inputs and 'm' outputs. The inputs for a - stream are the outputs from another stream. Note that for tracking - purposes, each stream tracks its input streams directly, but does - not explicitly track its output streams. Instead, each output simply - tracks the number of dependent input streams. - - Each stream has a sample rate. This rate controls the sample rate - of the outputs. All outputs on a stream output at the same sample - rate. - - Each stream also has a callback function. This function is called - with an array of input sample streams, and an array of output - sample streams. The input sample streams are automatically resampled - by the streaming engine to match the stream's current sample rate. - The output sample streams are expected to be generated at the - stream's current sample rate. - - Before the callback can be invoked, all the inputs that flow into it - must be updated as well. However, each stream can have an independent - sample rate, so this isn't as easy as it sounds. - - To update a stream, the engine must iterate over all the inputs. For - each input, it requests that input to update to the current time. - Then it resamples the input data into a local resample buffer at the - stream's sample rate. Once all inputs are up-to-date, it calls the - callback with the array of resampled input sample buffers. The - callback is expected to fill in the array of output sample buffers. - These sample buffers can then be further resampled and passed to - other streams, or output as desired. - -***************************************************************************/ - -#include "emu.h" -#include "streams.h" -#include "profiler.h" - - - -/*************************************************************************** - DEBUGGING -***************************************************************************/ - -#define VERBOSE (0) - -#define VPRINTF(x) do { if (VERBOSE) mame_printf_debug x; } while (0) - - - -/*************************************************************************** - CONSTANTS -***************************************************************************/ - -#define OUTPUT_BUFFER_UPDATES (5) - -#define FRAC_BITS 22 -#define FRAC_ONE (1 << FRAC_BITS) -#define FRAC_MASK (FRAC_ONE - 1) - - - -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ - -typedef struct _stream_input stream_input; -typedef struct _stream_output stream_output; - -struct _stream_input -{ - /* linking information */ - sound_stream * owner; /* pointer to the owning stream */ - stream_output * source; /* pointer to the sound_output for this source */ - - /* resample buffer */ - stream_sample_t * resample; /* buffer for resampling to the stream's sample rate */ - UINT32 bufsize; /* size of output buffer, in samples */ - UINT32 bufalloc; /* allocated size of output buffer, in samples */ - - /* resampling information */ - attoseconds_t latency_attoseconds; /* latency between this stream and the input stream */ - INT16 gain; /* gain to apply to this input */ -}; - - -struct _stream_output -{ - /* linking information */ - sound_stream * owner; /* pointer to the owning stream */ - - /* output buffer */ - stream_sample_t * buffer; /* output buffer */ - - /* output buffer position */ - int dependents; /* number of dependents */ - INT16 gain; /* gain to apply to the output */ -}; - - -class sound_stream -{ -public: - /* linking information */ - device_t * device; /* owning device */ - sound_stream * next; /* next stream in the chain */ - int index; /* index for save states */ - - /* general information */ - UINT32 sample_rate; /* sample rate of this stream */ - UINT32 new_sample_rate; /* newly-set sample rate for the stream */ - - /* timing information */ - attoseconds_t attoseconds_per_sample; /* number of attoseconds per sample */ - INT32 max_samples_per_update; /* maximum samples per update */ - - /* input information */ - int inputs; /* number of inputs */ - stream_input * input; /* list of streams we directly depend upon */ - stream_sample_t ** input_array; /* array of inputs for passing to the callback */ - - /* resample buffer information */ - UINT32 resample_bufalloc; /* allocated size of each resample buffer */ - - /* output information */ - int outputs; /* number of outputs */ - stream_output * output; /* list of streams which directly depend upon us */ - stream_sample_t ** output_array; /* array of outputs for passing to the callback */ - - /* output buffer information */ - UINT32 output_bufalloc; /* allocated size of each output buffer */ - INT32 output_sampindex; /* current position within each output buffer */ - INT32 output_update_sampindex;/* position at time of last global update */ - INT32 output_base_sampindex; /* sample at base of buffer, relative to the current emulated second */ - - /* callback information */ - stream_update_func callback; /* callback function */ - void * param; /* callback function parameter */ -}; - - -struct _streams_private -{ - sound_stream * stream_head; /* pointer to first stream */ - sound_stream ** stream_tailptr; /* pointer to pointer to last stream */ - int stream_index; /* index of the current stream */ - attoseconds_t update_attoseconds; /* attoseconds between global updates */ - attotime last_update; /* last update time */ -}; - - - -/*************************************************************************** - FUNCTION PROTOTYPES -***************************************************************************/ - -static STATE_POSTLOAD( stream_postload ); -static void allocate_resample_buffers(running_machine *machine, sound_stream *stream); -static void allocate_output_buffers(running_machine *machine, sound_stream *stream); -static void recompute_sample_rate_data(running_machine *machine, sound_stream *stream); -static void generate_samples(sound_stream *stream, int samples); -static stream_sample_t *generate_resampled_data(stream_input *input, UINT32 numsamples); - - - -/*************************************************************************** - INLINE FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - time_to_sampindex - convert an absolute - time to a sample index in a given stream --------------------------------------------------*/ - -INLINE INT32 time_to_sampindex(const streams_private *strdata, const sound_stream *stream, attotime time) -{ - /* determine the number of samples since the start of this second */ - INT32 sample = (INT32)(time.attoseconds / stream->attoseconds_per_sample); - - /* if we're ahead of the last update, then adjust upwards */ - if (time.seconds > strdata->last_update.seconds) - { - assert(time.seconds == strdata->last_update.seconds + 1); - sample += stream->sample_rate; - } - - /* if we're behind the last update, then adjust downwards */ - if (time.seconds < strdata->last_update.seconds) - { - assert(time.seconds == strdata->last_update.seconds - 1); - sample -= stream->sample_rate; - } - return sample; -} - - - -/*************************************************************************** - SYSTEM-LEVEL MANAGEMENT -***************************************************************************/ - -/*------------------------------------------------- - streams_init - initialize the streams engine --------------------------------------------------*/ - -void streams_init(running_machine *machine) -{ - streams_private *strdata; - - /* allocate memory for our private data */ - strdata = auto_alloc_clear(machine, streams_private); - - /* reset globals */ - strdata->stream_tailptr = &strdata->stream_head; - strdata->update_attoseconds = STREAMS_UPDATE_ATTOTIME.attoseconds; - - /* set the global pointer */ - machine->streams_data = strdata; - - /* register global states */ - state_save_register_global(machine, strdata->last_update.seconds); - state_save_register_global(machine, strdata->last_update.attoseconds); - state_save_register_postload(machine, stream_postload, strdata); -} - - -/*------------------------------------------------- - streams_update - update all the streams - periodically --------------------------------------------------*/ - -void streams_update(running_machine *machine) -{ - streams_private *strdata = machine->streams_data; - attotime curtime = timer_get_time(machine); - int second_tick = FALSE; - sound_stream *stream; - - VPRINTF(("streams_update\n")); - - /* see if we ticked over to the next second */ - if (curtime.seconds != strdata->last_update.seconds) - { - assert(curtime.seconds == strdata->last_update.seconds + 1); - second_tick = TRUE; - } - - /* iterate over all the streams */ - for (stream = strdata->stream_head; stream != NULL; stream = stream->next) - { - INT32 output_bufindex = stream->output_sampindex - stream->output_base_sampindex; - int outputnum; - - /* make sure this stream is up-to-date */ - stream_update(stream); - - /* if we've ticked over another second, adjust all the counters that are relative to - the current second */ - if (second_tick) - { - stream->output_sampindex -= stream->sample_rate; - stream->output_base_sampindex -= stream->sample_rate; - } - - /* note our current output sample */ - stream->output_update_sampindex = stream->output_sampindex; - - /* if we don't have enough output buffer space to hold two updates' worth of samples, - we need to shuffle things down */ - if (stream->output_bufalloc - output_bufindex < 2 * stream->max_samples_per_update) - { - INT32 samples_to_lose = output_bufindex - stream->max_samples_per_update; - if (samples_to_lose > 0) - { - /* if we have samples to move, do so for each output */ - if (output_bufindex > 0) - for (outputnum = 0; outputnum < stream->outputs; outputnum++) - { - stream_output *output = &stream->output[outputnum]; - memmove(&output->buffer[0], &output->buffer[samples_to_lose], sizeof(output->buffer[0]) * (output_bufindex - samples_to_lose)); - } - - /* update the base position */ - stream->output_base_sampindex += samples_to_lose; - } - } - } - - /* remember the update time */ - strdata->last_update = curtime; - - /* update sample rates if they have changed */ - for (stream = strdata->stream_head; stream != NULL; stream = stream->next) - if (stream->new_sample_rate != 0) - { - UINT32 old_rate = stream->sample_rate; - int outputnum; - - /* update to the new rate and remember the old rate */ - stream->sample_rate = stream->new_sample_rate; - stream->new_sample_rate = 0; - - /* recompute all the data */ - recompute_sample_rate_data(machine, stream); - - /* reset our sample indexes to the current time */ - stream->output_sampindex = (INT64)stream->output_sampindex * (INT64)stream->sample_rate / old_rate; - stream->output_update_sampindex = (INT64)stream->output_update_sampindex * (INT64)stream->sample_rate / old_rate; - stream->output_base_sampindex = stream->output_sampindex - stream->max_samples_per_update; - - /* clear out the buffer */ - for (outputnum = 0; outputnum < stream->outputs; outputnum++) - memset(stream->output[outputnum].buffer, 0, stream->max_samples_per_update * sizeof(stream->output[outputnum].buffer[0])); - } -} - - - -/*************************************************************************** - STREAM CONFIGURATION AND SETUP -***************************************************************************/ - -/*------------------------------------------------- - stream_create - create a new stream --------------------------------------------------*/ - -/* create a new stream */ -static STREAM_UPDATE( device_stream_update_stub ) -{ - device_sound_interface *sound = reinterpret_cast(param); - sound->sound_stream_update(*stream, inputs, outputs, samples); -} - -sound_stream *stream_create(device_t &device, int inputs, int outputs, int sample_rate) -{ - device_sound_interface *sound; - if (device.interface(sound)) - return stream_create(&device, inputs, outputs, sample_rate, sound, device_stream_update_stub); - fatalerror("Modern stream_create() called for device with no sound interface"); -} - -sound_stream *stream_create(device_t *device, int inputs, int outputs, int sample_rate, void *param, stream_update_func callback) -{ - running_machine *machine = device->machine; - streams_private *strdata = machine->streams_data; - int inputnum, outputnum; - sound_stream *stream; - char statetag[30]; - - /* allocate memory */ - stream = auto_alloc_clear(device->machine, sound_stream); - - VPRINTF(("stream_create(%d, %d, %d) => %p\n", inputs, outputs, sample_rate, stream)); - - /* fill in the data */ - stream->device = device; - stream->index = strdata->stream_index++; - stream->sample_rate = sample_rate; - stream->inputs = inputs; - stream->outputs = outputs; - stream->callback = callback; - stream->param = param; - - /* create a unique tag for saving */ - sprintf(statetag, "%d", stream->index); - state_save_register_item(machine, "stream", statetag, 0, stream->sample_rate); - - /* allocate space for the inputs */ - if (inputs > 0) - { - stream->input = auto_alloc_array_clear(device->machine, stream_input, inputs); - stream->input_array = auto_alloc_array_clear(device->machine, stream_sample_t *, inputs); - } - - /* initialize the state of each input */ - for (inputnum = 0; inputnum < inputs; inputnum++) - { - stream->input[inputnum].owner = stream; - stream->input[inputnum].gain = 0x100; - state_save_register_item(machine, "stream", statetag, inputnum, stream->input[inputnum].gain); - } - - /* allocate space for the outputs */ - if (outputs > 0) - { - stream->output = auto_alloc_array_clear(device->machine, stream_output, outputs); - stream->output_array = auto_alloc_array_clear(device->machine, stream_sample_t *, outputs); - } - - /* initialize the state of each output */ - for (outputnum = 0; outputnum < outputs; outputnum++) - { - stream->output[outputnum].owner = stream; - stream->output[outputnum].gain = 0x100; - state_save_register_item(machine, "stream", statetag, outputnum, stream->output[outputnum].gain); - } - - /* hook us into the master stream list */ - *strdata->stream_tailptr = stream; - strdata->stream_tailptr = &stream->next; - - /* 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(device->machine, stream); - - /* set up the initial output buffer positions now that we have data */ - stream->output_base_sampindex = -stream->max_samples_per_update; - - return stream; -} - - -/*------------------------------------------------- - stream_device_output_to_stream_output - - convert a device/output pair to a stream/ - output pair --------------------------------------------------*/ - -int stream_device_output_to_stream_output(device_t *device, int outputnum, sound_stream **streamptr, int *streamoutputptr) -{ - streams_private *strdata = device->machine->streams_data; - sound_stream *stream; - - /* scan the list looking for the nth stream that matches the tag */ - for (stream = strdata->stream_head; stream != NULL; stream = stream->next) - if (stream->device == device) - { - if (outputnum < stream->outputs) - { - *streamptr = stream; - *streamoutputptr = outputnum; - return TRUE; - } - outputnum -= stream->outputs; - } - return FALSE; -} - - -/*------------------------------------------------- - stream_device_input_to_stream_input - - convert a device/input pair to a stream/ - input pair --------------------------------------------------*/ - -int stream_device_input_to_stream_input(device_t *device, int inputnum, sound_stream **streamptr, int *streaminputptr) -{ - streams_private *strdata = device->machine->streams_data; - sound_stream *stream; - - /* scan the list looking for the nth stream that matches the tag */ - for (stream = strdata->stream_head; stream != NULL; stream = stream->next) - if (stream->device == device) - { - if (inputnum < stream->inputs) - { - *streamptr = stream; - *streaminputptr = inputnum; - return TRUE; - } - inputnum -= stream->inputs; - } - return FALSE; -} - - -/*------------------------------------------------- - stream_set_input - configure a stream's input --------------------------------------------------*/ - -void stream_set_input(sound_stream *stream, int index, sound_stream *input_stream, int output_index, float gain) -{ - stream_input *input; - - VPRINTF(("stream_set_input(%p, %d, %p, %d, %f)\n", stream, index, input_stream, output_index, gain)); - - /* make sure it's a valid input */ - if (index >= stream->inputs) - fatalerror("Fatal error: stream_set_input attempted to configure non-existant input %d (%d max)", index, stream->inputs); - - /* make sure it's a valid output */ - if (input_stream != NULL && output_index >= input_stream->outputs) - fatalerror("Fatal error: stream_set_input attempted to use a non-existant output %d (%d max)", output_index, input_stream->outputs); - - /* if this input is already wired, update the dependent info */ - input = &stream->input[index]; - if (input->source != NULL) - input->source->dependents--; - - /* wire it up */ - input->source = (input_stream != NULL) ? &input_stream->output[output_index] : NULL; - input->gain = (int)(0x100 * gain); - - /* update the dependent info */ - if (input->source != NULL) - input->source->dependents++; - - /* update sample rates now that we know the input */ - recompute_sample_rate_data(stream->device->machine, stream); -} - - -/*------------------------------------------------- - stream_update - force a stream to update to - the current emulated time --------------------------------------------------*/ - -void stream_update(sound_stream *stream) -{ - running_machine *machine = stream->device->machine; - streams_private *strdata = machine->streams_data; - INT32 update_sampindex = time_to_sampindex(strdata, stream, timer_get_time(machine)); - - /* generate samples to get us up to the appropriate time */ - g_profiler.start(PROFILER_SOUND); - assert(stream->output_sampindex - stream->output_base_sampindex >= 0); - assert(update_sampindex - stream->output_base_sampindex <= stream->output_bufalloc); - generate_samples(stream, update_sampindex - stream->output_sampindex); - g_profiler.stop(); - - /* remember this info for next time */ - stream->output_sampindex = update_sampindex; -} - - -/*------------------------------------------------- - stream_get_output_since_last_update - return a - pointer to the output buffer and the number of - samples since the last global update --------------------------------------------------*/ - -const stream_sample_t *stream_get_output_since_last_update(sound_stream *stream, int outputnum, int *numsamples) -{ - stream_output *output = &stream->output[outputnum]; - - /* force an update on the stream */ - stream_update(stream); - - /* compute the number of samples and a pointer to the output buffer */ - *numsamples = stream->output_sampindex - stream->output_update_sampindex; - return output->buffer + (stream->output_update_sampindex - stream->output_base_sampindex); -} - - - -/*************************************************************************** - STREAM TIMING -***************************************************************************/ - -/*------------------------------------------------- - stream_get_sample_rate - return the currently - set sample rate on a given stream --------------------------------------------------*/ - -int stream_get_sample_rate(sound_stream *stream) -{ - /* take into account any pending sample rate changes */ - return (stream->new_sample_rate != 0) ? stream->new_sample_rate : stream->sample_rate; -} - - -/*------------------------------------------------- - stream_set_sample_rate - set the sample rate - on a given stream --------------------------------------------------*/ - -void stream_set_sample_rate(sound_stream *stream, int sample_rate) -{ - /* we will update this on the next global update */ - if (sample_rate != stream_get_sample_rate(stream)) - stream->new_sample_rate = sample_rate; -} - - -/*------------------------------------------------- - stream_get_time - return the emulation time - of the next sample to be generated on the - stream --------------------------------------------------*/ - -attotime stream_get_time(sound_stream *stream) -{ - streams_private *strdata = stream->device->machine->streams_data; - attotime base = attotime_make(strdata->last_update.seconds, 0); - return attotime_add_attoseconds(base, stream->output_sampindex * stream->attoseconds_per_sample); -} - - -/*------------------------------------------------- - stream_get_sample_period - return the duration - of a single sample for a stream --------------------------------------------------*/ - -attotime stream_get_sample_period(sound_stream *stream) -{ - return attotime_make(0, stream->attoseconds_per_sample); -} - - - -/*************************************************************************** - STREAM INFORMATION AND CONTROL -***************************************************************************/ - -/*------------------------------------------------- - stream_get_device_outputs - return the total - number of outputs for the given device --------------------------------------------------*/ - -int stream_get_device_outputs(device_t *device) -{ - streams_private *strdata = device->machine->streams_data; - sound_stream *stream; - int outputs = 0; - - /* scan the list looking for the nth stream that matches the tag */ - for (stream = strdata->stream_head; stream != NULL; stream = stream->next) - if (stream->device == device) - outputs += stream->outputs; - return outputs; -} - - -/*------------------------------------------------- - stream_find_by_device - find a stream using a - device and index --------------------------------------------------*/ - -sound_stream *stream_find_by_device(device_t *device, int streamindex) -{ - streams_private *strdata = device->machine->streams_data; - sound_stream *stream; - - /* scan the list looking for the nth stream that matches the tag */ - for (stream = strdata->stream_head; stream != NULL; stream = stream->next) - if (stream->device == device && streamindex-- == 0) - return stream; - return NULL; -} - - -/*------------------------------------------------- - stream_get_inputs - return the number of - inputs for a given stream --------------------------------------------------*/ - -int stream_get_inputs(sound_stream *stream) -{ - return stream->inputs; -} - - -/*------------------------------------------------- - stream_get_outputs - return the number of - outputs for a given stream --------------------------------------------------*/ - -int stream_get_outputs(sound_stream *stream) -{ - return stream->outputs; -} - - -/*------------------------------------------------- - stream_set_input_gain - set the input gain on - a given stream --------------------------------------------------*/ - -void stream_set_input_gain(sound_stream *stream, int input, float gain) -{ - stream_update(stream); - stream->input[input].gain = (int)(0x100 * gain); -} - - -/*------------------------------------------------- - stream_set_output_gain - set the output gain on - a given stream --------------------------------------------------*/ - -void stream_set_output_gain(sound_stream *stream, int output, float gain) -{ - stream_update(stream); - stream->output[output].gain = (int)(0x100 * gain); -} - - - -/*************************************************************************** - STREAM BUFFER MAINTENANCE -***************************************************************************/ - -/*------------------------------------------------- - stream_postload - save/restore callback --------------------------------------------------*/ - -static STATE_POSTLOAD( stream_postload ) -{ - streams_private *strdata = reinterpret_cast(param); - for (sound_stream *stream = strdata->stream_head; stream != NULL; stream = stream->next) - { - /* recompute the same rate information */ - recompute_sample_rate_data(machine, stream); - - /* make sure our output buffers are fully cleared */ - for (int outputnum = 0; outputnum < stream->outputs; outputnum++) - memset(stream->output[outputnum].buffer, 0, stream->output_bufalloc * sizeof(stream->output[outputnum].buffer[0])); - - /* recompute the sample indexes to make sense */ - stream->output_sampindex = strdata->last_update.attoseconds / stream->attoseconds_per_sample; - stream->output_update_sampindex = stream->output_sampindex; - stream->output_base_sampindex = stream->output_sampindex - stream->max_samples_per_update; - } -} - - -/*------------------------------------------------- - allocate_resample_buffers - recompute the - resample buffer sizes and expand if necessary --------------------------------------------------*/ - -static void allocate_resample_buffers(running_machine *machine, sound_stream *stream) -{ - /* compute the target number of samples */ - INT32 bufsize = 2 * stream->max_samples_per_update; - - /* if we don't have enough room, allocate more */ - if (stream->resample_bufalloc < bufsize) - { - int inputnum; - int oldsize; - - /* this becomes the new allocation size */ - oldsize = stream->resample_bufalloc; - stream->resample_bufalloc = bufsize; - - /* iterate over outputs and realloc their buffers */ - for (inputnum = 0; inputnum < stream->inputs; inputnum++) - { - stream_input *input = &stream->input[inputnum]; - stream_sample_t *newbuffer = auto_alloc_array(machine, stream_sample_t, stream->resample_bufalloc); - memcpy(newbuffer, input->resample, oldsize * sizeof(stream_sample_t)); - auto_free(machine, input->resample); - input->resample = newbuffer; - } - } -} - - -/*------------------------------------------------- - allocate_output_buffers - recompute the - output buffer sizes and expand if necessary --------------------------------------------------*/ - -static void allocate_output_buffers(running_machine *machine, sound_stream *stream) -{ - /* compute the target number of samples */ - INT32 bufsize = OUTPUT_BUFFER_UPDATES * stream->max_samples_per_update; - - /* if we don't have enough room, allocate more */ - if (stream->output_bufalloc < bufsize) - { - int outputnum; - int oldsize; - - /* this becomes the new allocation size */ - oldsize = stream->output_bufalloc; - stream->output_bufalloc = bufsize; - - /* iterate over outputs and realloc their buffers */ - for (outputnum = 0; outputnum < stream->outputs; outputnum++) - { - stream_output *output = &stream->output[outputnum]; - stream_sample_t *newbuffer = auto_alloc_array(machine, stream_sample_t, stream->output_bufalloc); - memcpy(newbuffer, output->buffer, oldsize * sizeof(stream_sample_t)); - auto_free(machine, output->buffer); - output->buffer = newbuffer; - } - } -} - - -/*------------------------------------------------- - recompute_sample_rate_data - recompute sample - rate data, and all streams that are affected - by this stream --------------------------------------------------*/ - -static void recompute_sample_rate_data(running_machine *machine, sound_stream *stream) -{ - streams_private *strdata = machine->streams_data; - int inputnum; - - /* recompute the timing parameters */ - stream->attoseconds_per_sample = ATTOSECONDS_PER_SECOND / stream->sample_rate; - stream->max_samples_per_update = (strdata->update_attoseconds + stream->attoseconds_per_sample - 1) / stream->attoseconds_per_sample; - - /* update resample and output buffer sizes */ - allocate_resample_buffers(machine, stream); - allocate_output_buffers(machine, stream); - - /* iterate over each input */ - for (inputnum = 0; inputnum < stream->inputs; inputnum++) - { - stream_input *input = &stream->input[inputnum]; - - /* if we have a source, see if its sample rate changed */ - if (input->source != NULL) - { - sound_stream *input_stream = input->source->owner; - attoseconds_t new_attosecs_per_sample = ATTOSECONDS_PER_SECOND / input_stream->sample_rate; - attoseconds_t latency; - - /* okay, we have a new sample rate; recompute the latency to be the maximum - sample period between us and our input */ - latency = MAX(new_attosecs_per_sample, stream->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_stream->sample_rate < stream->sample_rate) - latency += new_attosecs_per_sample; - - /* if our sample rates match exactly, we don't need any latency */ - else if (input_stream->sample_rate == stream->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->latency_attoseconds = MAX(input->latency_attoseconds, latency); - assert(input->latency_attoseconds < strdata->update_attoseconds); - } - } -} - - - -/*************************************************************************** - SOUND GENERATION -***************************************************************************/ - -/*------------------------------------------------- - generate_samples - generate the requested - number of samples for a stream, making sure - all inputs have the appropriate number of - samples generated --------------------------------------------------*/ - -static void generate_samples(sound_stream *stream, int samples) -{ - int inputnum, outputnum; - - /* if we're already there, skip it */ - if (samples <= 0) - return; - - VPRINTF(("generate_samples(%p, %d)\n", stream, samples)); - - /* ensure all inputs are up to date and generate resampled data */ - for (inputnum = 0; inputnum < stream->inputs; inputnum++) - { - stream_input *input = &stream->input[inputnum]; - - /* update the stream to the current time */ - if (input->source != NULL) - stream_update(input->source->owner); - - /* generate the resampled data */ - stream->input_array[inputnum] = generate_resampled_data(input, samples); - } - - /* loop over all outputs and compute the output pointer */ - for (outputnum = 0; outputnum < stream->outputs; outputnum++) - { - stream_output *output = &stream->output[outputnum]; - stream->output_array[outputnum] = output->buffer + (stream->output_sampindex - stream->output_base_sampindex); - } - - /* run the callback */ - VPRINTF((" callback(%p, %d)\n", stream, samples)); - (*stream->callback)(stream->device, stream, stream->param, stream->input_array, stream->output_array, samples); - VPRINTF((" callback done\n")); -} - - -/*------------------------------------------------- - generate_resampled_data - generate the - resample buffer for a given input --------------------------------------------------*/ - -static stream_sample_t *generate_resampled_data(stream_input *input, UINT32 numsamples) -{ - stream_sample_t *dest = input->resample; - stream_output *output = input->source; - sound_stream *stream = input->owner; - sound_stream *input_stream; - stream_sample_t *source; - stream_sample_t sample; - attoseconds_t basetime; - INT32 basesample; - UINT32 basefrac; - UINT32 step; - int gain; - - /* if we don't have an output to pull data from, generate silence */ - if (output == NULL) - { - memset(dest, 0, numsamples * sizeof(*dest)); - return input->resample; - } - - /* grab data from the output */ - input_stream = output->owner; - gain = (input->gain * output->gain) >> 8; - - /* determine the time at which the current sample begins, accounting for the - latency we calculated between the input and output streams */ - basetime = stream->output_sampindex * stream->attoseconds_per_sample - input->latency_attoseconds; - - /* now convert that time into a sample in the input stream */ - if (basetime >= 0) - basesample = basetime / input_stream->attoseconds_per_sample; - else - basesample = -(-basetime / input_stream->attoseconds_per_sample) - 1; - - /* compute a source pointer to the first sample */ - assert(basesample >= input_stream->output_base_sampindex); - source = output->buffer + (basesample - input_stream->output_base_sampindex); - - /* determine the current fraction of a sample */ - basefrac = (basetime - basesample * input_stream->attoseconds_per_sample) / ((input_stream->attoseconds_per_sample + FRAC_ONE - 1) >> FRAC_BITS); - assert(basefrac >= 0); - assert(basefrac < FRAC_ONE); - - /* compute the stepping fraction */ - step = ((UINT64)input_stream->sample_rate << FRAC_BITS) / stream->sample_rate; - - /* if we have equal sample rates, we just need to copy */ - if (step == FRAC_ONE) - { - while (numsamples--) - { - /* compute the sample */ - sample = *source++; - *dest++ = (sample * gain) >> 8; - } - } - - /* input is undersampled: point sample except where our sample period covers a boundary */ - else if (step < FRAC_ONE) - { - while (numsamples != 0) - { - int nextfrac, startfrac, endfrac; - - /* fill in with point samples until we hit a boundary */ - while ((nextfrac = basefrac + step) < FRAC_ONE && numsamples--) - { - *dest++ = (source[0] * gain) >> 8; - basefrac = nextfrac; - } - - /* if we're done, we're done */ - if ((INT32)numsamples-- < 0) - break; - - /* compute starting and ending fractional positions */ - startfrac = basefrac >> (FRAC_BITS - 12); - endfrac = nextfrac >> (FRAC_BITS - 12); - - /* blend between the two samples accordingly */ - sample = (source[0] * (0x1000 - startfrac) + source[1] * (endfrac - 0x1000)) / (endfrac - startfrac); - *dest++ = (sample * gain) >> 8; - - /* advance */ - basefrac = nextfrac & FRAC_MASK; - source++; - } - } - - /* input is oversampled: sum the energy */ - else - { - /* use 8 bits to allow some extra headroom */ - int smallstep = step >> (FRAC_BITS - 8); - - while (numsamples--) - { - int remainder = smallstep; - int tpos = 0; - int scale; - - /* compute the sample */ - scale = (FRAC_ONE - basefrac) >> (FRAC_BITS - 8); - sample = source[tpos++] * scale; - remainder -= scale; - while (remainder > 0x100) - { - sample += source[tpos++] * 0x100; - remainder -= 0x100; - } - sample += source[tpos] * remainder; - sample /= smallstep; - - *dest++ = (sample * gain) >> 8; - - /* advance */ - basefrac += step; - source += basefrac >> FRAC_BITS; - basefrac &= FRAC_MASK; - } - } - - return input->resample; -} diff --git a/src/emu/streams.h b/src/emu/streams.h deleted file mode 100644 index 9eb78a3ba24..00000000000 --- a/src/emu/streams.h +++ /dev/null @@ -1,115 +0,0 @@ -/*************************************************************************** - - streams.h - - Handle general purpose audio streams - - Copyright Nicola Salmoria and the MAME Team. - Visit http://mamedev.org for licensing and usage restrictions. - -***************************************************************************/ - -#ifndef STREAMS_H -#define STREAMS_H - - - -/*************************************************************************** - CONSTANTS -***************************************************************************/ - -#define STREAMS_UPDATE_FREQUENCY (50) -#define STREAMS_UPDATE_ATTOTIME ATTOTIME_IN_HZ(STREAMS_UPDATE_FREQUENCY) - - - -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ - -class sound_stream; - -typedef void (*stream_update_func)(device_t *device, sound_stream *stream, void *param, stream_sample_t **inputs, stream_sample_t **outputs, int samples); - -#define STREAM_UPDATE(name) void name(device_t *device, sound_stream *stream, void *param, stream_sample_t **inputs, stream_sample_t **outputs, int samples) - - - -/*************************************************************************** - FUNCTION PROTOTYPES -***************************************************************************/ - - -/* ----- system-level management ----- */ - -/* initialize the streams engine */ -void streams_init(running_machine *machine); - -/* update all the streams periodically */ -void streams_update(running_machine *machine); - - - -/* ----- stream configuration and setup ----- */ - -/* create a new stream */ -sound_stream *stream_create(device_t &device, int inputs, int outputs, int sample_rate); - -/* create a new stream */ -sound_stream *stream_create(device_t *device, int inputs, int outputs, int sample_rate, void *param, stream_update_func callback); - -/* convert a device/output pair to a stream/output pair */ -int stream_device_output_to_stream_output(device_t *device, int outputnum, sound_stream **streamptr, int *streamoutputptr); - -/* convert a device/input pair to a stream/input pair */ -int stream_device_input_to_stream_input(device_t *device, int inputnum, sound_stream **streamptr, int *streaminputptr); - -/* configure a stream's input */ -void stream_set_input(sound_stream *stream, int index, sound_stream *input_stream, int output_index, float gain); - -/* force a stream to update to the current emulated time */ -void stream_update(sound_stream *stream); - -/* return a pointer to the output buffer and the number of samples since the last global update */ -const stream_sample_t *stream_get_output_since_last_update(sound_stream *stream, int outputnum, int *numsamples); - - - -/* ----- stream timing ----- */ - -/* return the currently set sample rate on a given stream */ -int stream_get_sample_rate(sound_stream *stream); - -/* set the sample rate on a given stream */ -void stream_set_sample_rate(sound_stream *stream, int sample_rate); - -/* return the emulation time of the next sample to be generated on the stream */ -attotime stream_get_time(sound_stream *stream); - -/* return the duration of a single sample for a stream */ -attotime stream_get_sample_period(sound_stream *stream); - - - -/* ----- stream information and control ----- */ - -/* return the total number of outputs for the given device */ -int stream_get_device_outputs(device_t *device); - -/* find a stream using a device and index */ -sound_stream *stream_find_by_device(device_t *device, int streamindex); - -/* return the number of inputs for a given stream */ -int stream_get_inputs(sound_stream *stream); - -/* return the number of outputs for a given stream */ -int stream_get_outputs(sound_stream *stream); - -/* set the input gain on a given stream */ -void stream_set_input_gain(sound_stream *stream, int input, float gain); - -/* set the output gain on a given stream */ -void stream_set_output_gain(sound_stream *stream, int output, float gain); - - -#endif diff --git a/src/emu/ui.c b/src/emu/ui.c index b03a4ae3ebc..cf6b1be3087 100644 --- a/src/emu/ui.c +++ b/src/emu/ui.c @@ -1603,23 +1603,24 @@ static slider_state *slider_init(running_machine *machine) slider_state *listhead = NULL; slider_state **tailptr = &listhead; astring string; - int numitems, item; + int item; /* add overall volume */ *tailptr = slider_alloc(machine, "Master Volume", -32, 0, 0, 1, slider_volume, NULL); tailptr = &(*tailptr)->next; /* add per-channel volume */ - numitems = sound_get_user_gain_count(machine); - for (item = 0; item < numitems; item++) + speaker_input info; + for (item = 0; machine->sound().indexed_speaker_input(item, info); item++) { INT32 maxval = 2000; - INT32 defval = sound_get_default_gain(machine, item) * 1000.0f + 0.5f; + INT32 defval = info.stream->initial_input_gain(info.inputnum) * 1000.0f + 0.5f; if (defval > 1000) maxval = 2 * defval; - string.printf("%s Volume", sound_get_user_gain_name(machine, item)); + info.stream->input_name(info.inputnum, string); + string.cat(" Volume"); *tailptr = slider_alloc(machine, string, 0, defval, maxval, 20, slider_mixervol, (void *)(FPTR)item); tailptr = &(*tailptr)->next; } @@ -1755,10 +1756,10 @@ static slider_state *slider_init(running_machine *machine) static INT32 slider_volume(running_machine *machine, void *arg, astring *string, INT32 newval) { if (newval != SLIDER_NOCHANGE) - sound_set_attenuation(machine, newval); + machine->sound().set_attenuation(newval); if (string != NULL) - string->printf("%3ddB", sound_get_attenuation(machine)); - return sound_get_attenuation(machine); + string->printf("%3ddB", machine->sound().attenuation()); + return machine->sound().attenuation(); } @@ -1769,12 +1770,14 @@ static INT32 slider_volume(running_machine *machine, void *arg, astring *string, static INT32 slider_mixervol(running_machine *machine, void *arg, astring *string, INT32 newval) { - int which = (FPTR)arg; + speaker_input info; + if (!machine->sound().indexed_speaker_input((FPTR)arg, info)) + return 0; if (newval != SLIDER_NOCHANGE) - sound_set_user_gain(machine, which, (float)newval * 0.001f); + info.stream->set_input_gain(info.inputnum, (float)newval * 0.001f); if (string != NULL) - string->printf("%4.2f", sound_get_user_gain(machine, which)); - return floor(sound_get_user_gain(machine, which) * 1000.0f + 0.5f); + string->printf("%4.2f", info.stream->input_gain(info.inputnum)); + return floor(info.stream->input_gain(info.inputnum) * 1000.0f + 0.5f); } diff --git a/src/mame/audio/8080bw.c b/src/mame/audio/8080bw.c index a88df65833c..df4cbaab833 100644 --- a/src/mame/audio/8080bw.c +++ b/src/mame/audio/8080bw.c @@ -43,7 +43,7 @@ WRITE8_HANDLER( invadpt2_sh_port_1_w ) state->screen_red = data & 0x04; - sound_global_enable(space->machine, data & 0x20); + space->machine->sound().system_enable(data & 0x20); state->port_1_last_extra = data; @@ -134,7 +134,7 @@ WRITE8_HANDLER( lrescue_sh_port_1_w ) if (rising_bits & 0x08) sample_start(state->samples, 1, 0, 0); /* Alien Hit */ if (rising_bits & 0x10) sample_start(state->samples, 2, 5, 0); /* Bonus Ship (not confirmed) */ - sound_global_enable(space->machine, data & 0x20); + space->machine->sound().system_enable(data & 0x20); state->screen_red = data & 0x04; @@ -192,7 +192,7 @@ WRITE8_HANDLER( ballbomb_sh_port_1_w ) if (rising_bits & 0x08) sample_start(state->samples, 1, 7, 0); /* Hit a Bomb */ if (rising_bits & 0x10) sample_start(state->samples, 3, 8, 0); /* Bonus Base at 1500 points */ - sound_global_enable(space->machine, data & 0x20); + space->machine->sound().system_enable(data & 0x20); state->screen_red = data & 0x04; @@ -268,7 +268,7 @@ WRITE8_HANDLER( indianbt_sh_port_1_w ) if (rising_bits & 0x04) sample_start(state->samples, 2, 3, 0); /* Move */ if (rising_bits & 0x08) sample_start(state->samples, 3, 2, 0); /* Hit */ - sound_global_enable(space->machine, data & 0x20); + space->machine->sound().system_enable(data & 0x20); state->screen_red = data & 0x01; @@ -867,7 +867,7 @@ WRITE8_HANDLER( schaser_sh_port_2_w ) discrete_sound_w(state->discrete, SCHASER_MUSIC_BIT, data & 0x01); discrete_sound_w(state->discrete, SCHASER_SND_EN, data & 0x02); - sound_global_enable(space->machine, data & 0x02); + space->machine->sound().system_enable(data & 0x02); coin_lockout_global_w(space->machine, data & 0x04); @@ -1079,7 +1079,7 @@ WRITE8_HANDLER( schasercv_sh_port_2_w ) speaker_level_w(state->speaker, (data & 0x01) ? 1 : 0); /* End-of-Level */ - sound_global_enable(space->machine, data & 0x10); + space->machine->sound().system_enable(data & 0x10); state->c8080bw_flip_screen = data & 0x20; } @@ -1101,7 +1101,7 @@ WRITE8_HANDLER( yosakdon_sh_port_1_w ) if (rising_bits & 0x08) sample_start(state->samples, 1, 2, 0); /* Man dead */ if (rising_bits & 0x10) sample_start(state->samples, 5, 8, 0); /* Bonus Man? */ - sound_global_enable(space->machine, data & 0x20); + space->machine->sound().system_enable(data & 0x20); state->port_1_last_extra = data; } diff --git a/src/mame/audio/amiga.c b/src/mame/audio/amiga.c index ec0bd6b3136..19c761bc0bc 100644 --- a/src/mame/audio/amiga.c +++ b/src/mame/audio/amiga.c @@ -9,7 +9,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "includes/amiga.h" #include "cpu/m68000/m68000.h" @@ -118,7 +117,7 @@ void amiga_audio_update(device_t *device) { amiga_audio *audio_state = get_safe_token(device); - stream_update(audio_state->stream); + audio_state->stream->update(); } @@ -275,7 +274,7 @@ static DEVICE_START( amiga_sound ) } /* create the stream */ - audio_state->stream = stream_create(device, 0, 4, device->clock() / CLOCK_DIVIDER, audio_state, amiga_stream_update); + audio_state->stream = device->machine->sound().stream_alloc(*device, 0, 4, device->clock() / CLOCK_DIVIDER, audio_state, amiga_stream_update); } diff --git a/src/mame/audio/astrof.c b/src/mame/audio/astrof.c index 7a76fa0ea6d..24a2ab782c7 100644 --- a/src/mame/audio/astrof.c +++ b/src/mame/audio/astrof.c @@ -72,7 +72,7 @@ WRITE8_HANDLER( astrof_audio_1_w ) /* D6 - don't know. Probably something to do with the explosion sounds */ /* D7 - sound enable bit */ - sound_global_enable(space->machine, data & 0x80); + space->machine->sound().system_enable(data & 0x80); state->port_1_last = data; } @@ -202,7 +202,7 @@ WRITE8_HANDLER( tomahawk_audio_w ) /* D6 - explosion */ /* D7 - sound enable bit */ - sound_global_enable(space->machine, data & 0x80); + space->machine->sound().system_enable(data & 0x80); } diff --git a/src/mame/audio/beezer.c b/src/mame/audio/beezer.c index e5682b1025a..3e85ba847a7 100644 --- a/src/mame/audio/beezer.c +++ b/src/mame/audio/beezer.c @@ -51,7 +51,6 @@ #include "emu.h" #include "machine/rescap.h" -#include "streams.h" #include "cpu/m6809/m6809.h" #include "includes/beezer.h" @@ -397,7 +396,7 @@ static DEVICE_START( common_sh_start ) state->sh6840_clocks_per_sample = (int)(((double)SH6840_CLOCK / (double)sample_rate) * (double)(1 << 24)); /* allocate the stream */ - state->stream = stream_create(device, 0, 1, sample_rate, NULL, beezer_stream_update); + state->stream = device->machine->sound().stream_alloc(*device, 0, 1, sample_rate, NULL, beezer_stream_update); state->maincpu = device->machine->device("maincpu"); sh6840_register_state_globals(device); @@ -477,7 +476,7 @@ READ8_DEVICE_HANDLER( beezer_sh6840_r ) beezer_sound_state *state = get_safe_token(device); /* force an update of the stream */ - stream_update(state->stream); + state->stream->update(); switch (offset) { @@ -503,7 +502,7 @@ WRITE8_DEVICE_HANDLER( beezer_timer1_w ) beezer_sound_state *state = get_safe_token(device); /* force an update of the stream */ - stream_update(state->stream); + state->stream->update(); state->sh6840_latchwriteold = state->sh6840_latchwrite; state->sh6840_latchwrite = data&0x80; if ((!state->sh6840_latchwriteold) && (state->sh6840_latchwrite)) // rising edge @@ -518,7 +517,7 @@ WRITE8_DEVICE_HANDLER( beezer_sh6840_w ) struct sh6840_timer_channel *sh6840_timer = state->sh6840_timer; /* force an update of the stream */ - stream_update(state->stream); + state->stream->update(); switch (offset) { @@ -578,7 +577,7 @@ WRITE8_DEVICE_HANDLER( beezer_sh6840_w ) WRITE8_DEVICE_HANDLER( beezer_sfxctrl_w ) { beezer_sound_state *state = get_safe_token(device); - stream_update(state->stream); + state->stream->update(); state->sh6840_volume[offset] = data; } diff --git a/src/mame/audio/bzone.c b/src/mame/audio/bzone.c index 6b4c2e74c33..de88a21048e 100644 --- a/src/mame/audio/bzone.c +++ b/src/mame/audio/bzone.c @@ -18,7 +18,6 @@ D0 explosion enable gates a noise generator */ #include "emu.h" -#include "streams.h" #include "includes/bzone.h" #include "sound/discrete.h" @@ -393,7 +392,7 @@ WRITE8_DEVICE_HANDLER( bzone_sounds_w ) discrete_sound_w(device, BZ_INPUT, data); output_set_value("startled", (data >> 6) & 1); - sound_global_enable(device->machine, data & 0x20); + device->machine->sound().system_enable(data & 0x20); } diff --git a/src/mame/audio/cchasm.c b/src/mame/audio/cchasm.c index 95bc020fb7f..2d39370ba10 100644 --- a/src/mame/audio/cchasm.c +++ b/src/mame/audio/cchasm.c @@ -5,7 +5,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "cpu/z80/z80.h" #include "machine/z80ctc.h" #include "includes/cchasm.h" diff --git a/src/mame/audio/cinemat.c b/src/mame/audio/cinemat.c index 47ddc89190b..961ae50815e 100644 --- a/src/mame/audio/cinemat.c +++ b/src/mame/audio/cinemat.c @@ -1500,7 +1500,7 @@ static WRITE8_DEVICE_HANDLER( sound_portb_w ) /* bit 2 controls the global mute */ if ((data & 4) != (last_portb_write & 4)) - sound_global_enable(device->machine, !(data & 4)); + device->machine->sound().system_mute(data & 4); /* remember the last value written */ last_portb_write = data; diff --git a/src/mame/audio/circus.c b/src/mame/audio/circus.c index afe44f94d77..7e7d6261dc5 100644 --- a/src/mame/audio/circus.c +++ b/src/mame/audio/circus.c @@ -275,5 +275,5 @@ WRITE8_HANDLER( circus_clown_z_w ) } /* Bit 7 enables amplifier (0 = on) */ - sound_global_enable(space->machine, ~data & 0x80); + space->machine->sound().system_mute(data & 0x80); } diff --git a/src/mame/audio/copsnrob.c b/src/mame/audio/copsnrob.c index 0dbc8de9def..7fcaa492730 100644 --- a/src/mame/audio/copsnrob.c +++ b/src/mame/audio/copsnrob.c @@ -735,7 +735,7 @@ WRITE8_HANDLER( copsnrob_misc_w ) case 0x07: discrete_sound_w(device, COPSNROB_AUDIO_ENABLE, special_data); - //sound_global_enable(space->machine, !special_data); + //space->machine->sound().system_mute(special_data); break; } diff --git a/src/mame/audio/cps3.c b/src/mame/audio/cps3.c index 87c6186466d..a5ebecafa22 100644 --- a/src/mame/audio/cps3.c +++ b/src/mame/audio/cps3.c @@ -4,7 +4,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "includes/cps3.h" #define CPS3_VOICES 16 @@ -115,7 +114,7 @@ static DEVICE_START( cps3_sound ) cps3_sound_state *state = get_safe_token(device); /* Allocate the stream */ - state->stream = stream_create(device, 0, 2, device->clock() / 384, NULL, cps3_stream_update); + state->stream = device->machine->sound().stream_alloc(*device, 0, 2, device->clock() / 384, NULL, cps3_stream_update); } DEVICE_GET_INFO( cps3_sound ) @@ -139,7 +138,7 @@ WRITE32_DEVICE_HANDLER( cps3_sound_w ) { cps3_sound_state *state = get_safe_token(device); - stream_update(state->stream); + state->stream->update(); if (offset < 0x80) { @@ -170,7 +169,7 @@ WRITE32_DEVICE_HANDLER( cps3_sound_w ) READ32_DEVICE_HANDLER( cps3_sound_r ) { cps3_sound_state *state = get_safe_token(device); - stream_update(state->stream); + state->stream->update(); if (offset < 0x80) { diff --git a/src/mame/audio/exidy.c b/src/mame/audio/exidy.c index b80e8c3224c..7746ddfa88a 100644 --- a/src/mame/audio/exidy.c +++ b/src/mame/audio/exidy.c @@ -7,7 +7,6 @@ #include "emu.h" #include "cpu/z80/z80.h" #include "machine/rescap.h" -#include "streams.h" #include "cpu/m6502/m6502.h" #include "machine/6821pia.h" #include "machine/6532riot.h" @@ -402,7 +401,7 @@ static DEVICE_START( common_sh_start ) state->sh6840_clocks_per_sample = (int)((double)SH6840_CLOCK / (double)sample_rate * (double)(1 << 24)); /* allocate the stream */ - state->stream = stream_create(device, 0, 1, sample_rate, NULL, exidy_stream_update); + state->stream = device->machine->sound().stream_alloc(*device, 0, 1, sample_rate, NULL, exidy_stream_update); state->maincpu = device->machine->device("maincpu"); sh6840_register_state_globals(device); @@ -588,7 +587,7 @@ static WRITE8_DEVICE_HANDLER( exidy_sh8253_w ) exidy_sound_state *state = get_safe_token(device); int chan; - stream_update(state->stream); + state->stream->update(); switch (offset) { @@ -640,7 +639,7 @@ READ8_DEVICE_HANDLER( exidy_sh6840_r ) exidy_sound_state *state = get_safe_token(device); /* force an update of the stream */ - stream_update(state->stream); + state->stream->update(); switch (offset) { @@ -668,7 +667,7 @@ WRITE8_DEVICE_HANDLER( exidy_sh6840_w ) struct sh6840_timer_channel *sh6840_timer = state->sh6840_timer; /* force an update of the stream */ - stream_update(state->stream); + state->stream->update(); switch (offset) { @@ -729,7 +728,7 @@ WRITE8_DEVICE_HANDLER( exidy_sfxctrl_w ) { exidy_sound_state *state = get_safe_token(device); - stream_update(state->stream); + state->stream->update(); switch (offset) { diff --git a/src/mame/audio/exidy440.c b/src/mame/audio/exidy440.c index e984d38582f..b7d4bc0eda5 100644 --- a/src/mame/audio/exidy440.c +++ b/src/mame/audio/exidy440.c @@ -9,7 +9,6 @@ #include "emu.h" #include "cpu/m6809/m6809.h" -#include "streams.h" #include "includes/exidy440.h" @@ -162,7 +161,7 @@ static DEVICE_START( exidy440_sound ) channel_frequency[3] = device->clock()/2; /* get stream channels */ - stream = stream_create(device, 0, 2, device->clock(), NULL, channel_update); + stream = device->machine->sound().stream_alloc(*device, 0, 2, device->clock(), NULL, channel_update); /* allocate the sample cache */ length = machine->region("cvsd")->bytes() * 16 + MAX_CACHE_ENTRIES * sizeof(sound_cache_entry); @@ -359,7 +358,7 @@ static WRITE8_HANDLER( sound_volume_w ) fprintf(debuglog, "Volume %02X=%02X\n", offset, data); /* update the stream */ - stream_update(stream); + stream->update(); /* set the new volume */ sound_volume[offset] = ~data; @@ -389,7 +388,7 @@ static WRITE8_HANDLER( sound_interrupt_clear_w ) static void m6844_update(void) { /* update the stream */ - stream_update(stream); + stream->update(); } @@ -714,7 +713,7 @@ static void stop_cvsd(int ch) { /* the DMA channel is marked inactive; that will kill the audio */ sound_channel[ch].remaining = 0; - stream_update(stream); + stream->update(); if (SOUND_LOG && debuglog) fprintf(debuglog, "Channel %d stop\n", ch); diff --git a/src/mame/audio/flower.c b/src/mame/audio/flower.c index f973f44d8a7..d75ae7e1194 100644 --- a/src/mame/audio/flower.c +++ b/src/mame/audio/flower.c @@ -5,7 +5,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "includes/flower.h" @@ -172,7 +171,7 @@ static DEVICE_START( flower_sound ) int i; /* get stream channels */ - state->stream = stream_create(device, 0, 1, samplerate, 0, flower_update_mono); + state->stream = device->machine->sound().stream_alloc(*device, 0, 1, samplerate, 0, flower_update_mono); /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */ state->mixer_buffer = auto_alloc_array(device->machine, short, 2 * samplerate); @@ -241,7 +240,7 @@ WRITE8_DEVICE_HANDLER( flower_sound1_w ) int base; /* update the streams */ - stream_update(state->stream); + state->stream->update(); /* set the register */ state->soundregs1[offset] = data; @@ -291,7 +290,7 @@ popmessage("%02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x% */ /* update the streams */ - stream_update(state->stream); + state->stream->update(); /* set the register */ state->soundregs2[offset] = data; diff --git a/src/mame/audio/galaxian.c b/src/mame/audio/galaxian.c index add7a17c7ee..015c25dc4b2 100644 --- a/src/mame/audio/galaxian.c +++ b/src/mame/audio/galaxian.c @@ -21,7 +21,6 @@ TODO: ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "includes/galaxian.h" /************************************* diff --git a/src/mame/audio/geebee.c b/src/mame/audio/geebee.c index 29b62671de6..298a6a530c3 100644 --- a/src/mame/audio/geebee.c +++ b/src/mame/audio/geebee.c @@ -8,7 +8,6 @@ ****************************************************************************/ #include "emu.h" -#include "streams.h" #include "includes/warpwarp.h" @@ -44,7 +43,7 @@ WRITE8_DEVICE_HANDLER( geebee_sound_w ) { geebee_sound_state *state = get_safe_token(device); - stream_update(state->channel); + state->channel->update(); state->sound_latch = data; state->volume = 0x7fff; /* set volume */ state->noise = 0x0000; /* reset noise shifter */ @@ -139,7 +138,7 @@ static DEVICE_START( geebee_sound ) state->decay[0x7fff-i] = (INT16) (0x7fff/exp(1.0*i/4096)); /* 1V = HSYNC = 18.432MHz / 3 / 2 / 384 = 8000Hz */ - state->channel = stream_create(device, 0, 1, 18432000 / 3 / 2 / 384, NULL, geebee_sound_update); + state->channel = device->machine->sound().stream_alloc(*device, 0, 1, 18432000 / 3 / 2 / 384, NULL, geebee_sound_update); state->vcount = 0; state->volume_timer = timer_alloc(machine, volume_decay, state); diff --git a/src/mame/audio/gomoku.c b/src/mame/audio/gomoku.c index 9576a67a6a3..e72a239150a 100644 --- a/src/mame/audio/gomoku.c +++ b/src/mame/audio/gomoku.c @@ -7,7 +7,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "includes/gomoku.h" @@ -180,7 +179,7 @@ static DEVICE_START( gomoku_sound ) int ch; /* get stream channels */ - state->stream = stream_create(device, 0, 1, samplerate, NULL, gomoku_update_mono); + state->stream = device->machine->sound().stream_alloc(*device, 0, 1, samplerate, NULL, gomoku_update_mono); /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */ state->mixer_buffer = auto_alloc_array(machine, short, 2 * samplerate); @@ -237,7 +236,7 @@ WRITE8_DEVICE_HANDLER( gomoku_sound1_w ) int ch; /* update the streams */ - stream_update(state->stream); + state->stream->update(); /* set the register */ state->soundregs1[offset] = data; @@ -260,7 +259,7 @@ WRITE8_DEVICE_HANDLER( gomoku_sound2_w ) int ch; /* update the streams */ - stream_update(state->stream); + state->stream->update(); /* set the register */ state->soundregs2[offset] = data; diff --git a/src/mame/audio/gridlee.c b/src/mame/audio/gridlee.c index 25a0dc66907..a0b1a9d9807 100644 --- a/src/mame/audio/gridlee.c +++ b/src/mame/audio/gridlee.c @@ -5,7 +5,6 @@ *************************************************************************/ #include "emu.h" -#include "streams.h" #include "includes/gridlee.h" #include "sound/samples.h" @@ -72,7 +71,7 @@ static DEVICE_START( gridlee_sound ) running_machine *machine = device->machine; /* allocate the stream */ - state->stream = stream_create(device, 0, 1, machine->sample_rate, NULL, gridlee_stream_update); + state->stream = device->machine->sound().stream_alloc(*device, 0, 1, machine->sample_rate, NULL, gridlee_stream_update); state->samples = device->machine->device("samples"); @@ -104,7 +103,7 @@ WRITE8_DEVICE_HANDLER( gridlee_sound_w ) static UINT8 sound_data[24]; device_t *samples = state->samples; - stream_update(state->stream); + state->stream->update(); switch (offset) { diff --git a/src/mame/audio/leland.c b/src/mame/audio/leland.c index 4271c3c616b..6d382db47cb 100644 --- a/src/mame/audio/leland.c +++ b/src/mame/audio/leland.c @@ -78,7 +78,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "cpu/i86/i86.h" #include "cpu/z80/z80.h" #include "includes/leland.h" @@ -272,7 +271,7 @@ static DEVICE_START( leland_sound ) state->dac_bufout[0] = state->dac_bufout[1] = 0; /* allocate the stream */ - state->dac_stream = stream_create(device, 0, 1, 256*60, NULL, leland_update); + state->dac_stream = device->machine->sound().stream_alloc(*device, 0, 1, 256*60, NULL, leland_update); /* allocate memory */ state->dac_buffer[0] = auto_alloc_array(device->machine, UINT8, DAC_BUFFER_SIZE); @@ -546,14 +545,14 @@ static DEVICE_START( common_sh_start ) state->has_ym2151 = (device->machine->device("ymsnd") != NULL); /* allocate separate streams for the DMA and non-DMA DACs */ - state->dma_stream = stream_create(device, 0, 1, OUTPUT_RATE, (void *)dmaspace, leland_80186_dma_update); - state->nondma_stream = stream_create(device, 0, 1, OUTPUT_RATE, NULL, leland_80186_dac_update); + state->dma_stream = device->machine->sound().stream_alloc(*device, 0, 1, OUTPUT_RATE, (void *)dmaspace, leland_80186_dma_update); + state->nondma_stream = device->machine->sound().stream_alloc(*device, 0, 1, OUTPUT_RATE, NULL, leland_80186_dac_update); /* if we have a 2151, install an externally driven DAC stream */ if (state->has_ym2151) { state->ext_base = machine->region("dac")->base(); - state->extern_stream = stream_create(device, 0, 1, OUTPUT_RATE, NULL, leland_80186_extern_update); + state->extern_stream = device->machine->sound().stream_alloc(*device, 0, 1, OUTPUT_RATE, NULL, leland_80186_extern_update); } /* create timers here so they stick around */ @@ -1087,7 +1086,7 @@ static TIMER_CALLBACK( dma_timer_callback ) struct dma_state *d = &state->i80186.dma[which]; /* force an update and see if we're really done */ - stream_update(state->dma_stream); + state->dma_stream->update(); /* complete the status update */ d->control &= ~0x0002; @@ -1302,42 +1301,42 @@ static READ16_DEVICE_HANDLER( i80186_internal_port_r ) case 0xd0/2: if (LOG_PORTS) logerror("%05X:read 80186 DMA%d lower source address\n", cpu_get_pc(state->i80186.cpu), (offset - 0xc0/2) / 8); which = (offset - 0xc0/2) / 8; - stream_update(state->dma_stream); + state->dma_stream->update(); return state->i80186.dma[which].source; case 0xc2/2: case 0xd2/2: if (LOG_PORTS) logerror("%05X:read 80186 DMA%d upper source address\n", cpu_get_pc(state->i80186.cpu), (offset - 0xc0/2) / 8); which = (offset - 0xc0/2) / 8; - stream_update(state->dma_stream); + state->dma_stream->update(); return state->i80186.dma[which].source >> 16; case 0xc4/2: case 0xd4/2: if (LOG_PORTS) logerror("%05X:read 80186 DMA%d lower dest address\n", cpu_get_pc(state->i80186.cpu), (offset - 0xc0/2) / 8); which = (offset - 0xc0/2) / 8; - stream_update(state->dma_stream); + state->dma_stream->update(); return state->i80186.dma[which].dest; case 0xc6/2: case 0xd6/2: if (LOG_PORTS) logerror("%05X:read 80186 DMA%d upper dest address\n", cpu_get_pc(state->i80186.cpu), (offset - 0xc0/2) / 8); which = (offset - 0xc0/2) / 8; - stream_update(state->dma_stream); + state->dma_stream->update(); return state->i80186.dma[which].dest >> 16; case 0xc8/2: case 0xd8/2: if (LOG_PORTS) logerror("%05X:read 80186 DMA%d transfer count\n", cpu_get_pc(state->i80186.cpu), (offset - 0xc0/2) / 8); which = (offset - 0xc0/2) / 8; - stream_update(state->dma_stream); + state->dma_stream->update(); return state->i80186.dma[which].count; case 0xca/2: case 0xda/2: if (LOG_PORTS) logerror("%05X:read 80186 DMA%d control\n", cpu_get_pc(state->i80186.cpu), (offset - 0xc0/2) / 8); which = (offset - 0xc0/2) / 8; - stream_update(state->dma_stream); + state->dma_stream->update(); return state->i80186.dma[which].control; default: @@ -1530,7 +1529,7 @@ static WRITE16_DEVICE_HANDLER( i80186_internal_port_w ) case 0xd0/2: if (LOG_PORTS) logerror("%05X:80186 DMA%d lower source address = %04X & %04X\n", cpu_get_pc(state->i80186.cpu), (offset - 0xc0/2) / 8, data, mem_mask); which = (offset - 0xc0/2) / 8; - stream_update(state->dma_stream); + state->dma_stream->update(); state->i80186.dma[which].source = (state->i80186.dma[which].source & ~0x0ffff) | (data & 0x0ffff); break; @@ -1538,7 +1537,7 @@ static WRITE16_DEVICE_HANDLER( i80186_internal_port_w ) case 0xd2/2: if (LOG_PORTS) logerror("%05X:80186 DMA%d upper source address = %04X & %04X\n", cpu_get_pc(state->i80186.cpu), (offset - 0xc0/2) / 8, data, mem_mask); which = (offset - 0xc0/2) / 8; - stream_update(state->dma_stream); + state->dma_stream->update(); state->i80186.dma[which].source = (state->i80186.dma[which].source & ~0xf0000) | ((data << 16) & 0xf0000); break; @@ -1546,7 +1545,7 @@ static WRITE16_DEVICE_HANDLER( i80186_internal_port_w ) case 0xd4/2: if (LOG_PORTS) logerror("%05X:80186 DMA%d lower dest address = %04X & %04X\n", cpu_get_pc(state->i80186.cpu), (offset - 0xc0/2) / 8, data, mem_mask); which = (offset - 0xc0/2) / 8; - stream_update(state->dma_stream); + state->dma_stream->update(); state->i80186.dma[which].dest = (state->i80186.dma[which].dest & ~0x0ffff) | (data & 0x0ffff); break; @@ -1554,7 +1553,7 @@ static WRITE16_DEVICE_HANDLER( i80186_internal_port_w ) case 0xd6/2: if (LOG_PORTS) logerror("%05X:80186 DMA%d upper dest address = %04X & %04X\n", cpu_get_pc(state->i80186.cpu), (offset - 0xc0/2) / 8, data, mem_mask); which = (offset - 0xc0/2) / 8; - stream_update(state->dma_stream); + state->dma_stream->update(); state->i80186.dma[which].dest = (state->i80186.dma[which].dest & ~0xf0000) | ((data << 16) & 0xf0000); break; @@ -1562,7 +1561,7 @@ static WRITE16_DEVICE_HANDLER( i80186_internal_port_w ) case 0xd8/2: if (LOG_PORTS) logerror("%05X:80186 DMA%d transfer count = %04X & %04X\n", cpu_get_pc(state->i80186.cpu), (offset - 0xc0/2) / 8, data, mem_mask); which = (offset - 0xc0/2) / 8; - stream_update(state->dma_stream); + state->dma_stream->update(); state->i80186.dma[which].count = data; break; @@ -1570,7 +1569,7 @@ static WRITE16_DEVICE_HANDLER( i80186_internal_port_w ) case 0xda/2: if (LOG_PORTS) logerror("%05X:80186 DMA%d control = %04X & %04X\n", cpu_get_pc(state->i80186.cpu), (offset - 0xc0/2) / 8, data, mem_mask); which = (offset - 0xc0/2) / 8; - stream_update(state->dma_stream); + state->dma_stream->update(); update_dma_control(state, which, data); break; @@ -1942,7 +1941,7 @@ static WRITE16_DEVICE_HANDLER( dac_w ) { /* if this is the first byte, sync the stream */ if (count == 0) - stream_update(state->nondma_stream); + state->nondma_stream->update(); /* prescale by the volume */ d->buffer[d->bufin] = d->value * d->volume; @@ -1978,7 +1977,7 @@ static WRITE16_DEVICE_HANDLER( redline_dac_w ) { /* if this is the first byte, sync the stream */ if (count == 0) - stream_update(state->nondma_stream); + state->nondma_stream->update(); /* prescale by the volume */ d->buffer[d->bufin] = d->value * d->volume; @@ -2015,7 +2014,7 @@ static WRITE16_DEVICE_HANDLER( dac_10bit_w ) { /* if this is the first byte, sync the stream */ if (count == 0) - stream_update(state->nondma_stream); + state->nondma_stream->update(); /* prescale by the volume */ d->buffer[d->bufin] = d->value * (0xff / DAC_VOLUME_SCALE / 2); @@ -2052,7 +2051,7 @@ static WRITE16_DEVICE_HANDLER( ataxx_dac_control ) /* if we have a YM2151 (and an external DAC), handle those offsets */ if (state->has_ym2151) { - stream_update(state->extern_stream); + state->extern_stream->update(); switch (offset) { case 0x04: diff --git a/src/mame/audio/micro3d.c b/src/mame/audio/micro3d.c index 20b8c75b88b..ec30ae74b2c 100644 --- a/src/mame/audio/micro3d.c +++ b/src/mame/audio/micro3d.c @@ -7,7 +7,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "sound/upd7759.h" #include "includes/micro3d.h" @@ -193,7 +192,7 @@ void micro3d_noise_sh_w(running_machine *machine, UINT8 data) double q; double fc; - stream_update(nstate->stream); + nstate->stream->update(); nstate->dac[data & 3] = state->dac_data; @@ -315,7 +314,7 @@ static DEVICE_START( micro3d_sound ) noise_state *state = get_safe_token(device); /* Allocate the stream */ - state->stream = stream_create(device, 0, 2, machine->sample_rate, state, micro3d_stream_update); + state->stream = device->machine->sound().stream_alloc(*device, 0, 2, machine->sample_rate, state, micro3d_stream_update); filter_init(machine, &state->filter, machine->sample_rate); configure_filter(&state->noise_filters[0], 2.7e3 + 2.7e3, 1.0e-6); diff --git a/src/mame/audio/mw8080bw.c b/src/mame/audio/mw8080bw.c index 83a3b07b221..21f7feb2632 100644 --- a/src/mame/audio/mw8080bw.c +++ b/src/mame/audio/mw8080bw.c @@ -1061,7 +1061,7 @@ WRITE8_DEVICE_HANDLER( checkmat_audio_w ) coin_counter_w(device->machine, 0, (data >> 2) & 0x01); - sound_global_enable(device->machine, (data >> 3) & 0x01); + device->machine->sound().system_enable((data >> 3) & 0x01); discrete_sound_w(device, CHECKMAT_TONE_DATA_45, (data >> 4) & 0x03); discrete_sound_w(device, CHECKMAT_TONE_DATA_67, (data >> 6) & 0x03); @@ -1600,7 +1600,7 @@ WRITE8_HANDLER( gmissile_audio_1_w ) coin_counter_w(space->machine, 0, (data >> 2) & 0x01); - sound_global_enable(space->machine, (data >> 3) & 0x01); + space->machine->sound().system_enable((data >> 3) & 0x01); /* if (data & 0x10) enable RIGHT MISSILE sound (goes to right speaker) */ if (rising_bits & 0x10) sample_start(state->samples2, 0, 0, 0); @@ -1695,7 +1695,7 @@ WRITE8_HANDLER( m4_audio_1_w ) coin_counter_w(space->machine, 0, (data >> 2) & 0x01); - sound_global_enable(space->machine, (data >> 3) & 0x01); + space->machine->sound().system_enable((data >> 3) & 0x01); /* if (data & 0x10) enable LEFT PLAYER SHOT sound (goes to left speaker) */ if (rising_bits & 0x10) sample_start(state->samples1, 0, 0, 0); @@ -1970,7 +1970,7 @@ WRITE8_DEVICE_HANDLER( clowns_audio_2_w ) discrete_sound_w(device, CLOWNS_POP_TOP_EN, (data >> 2) & 0x01); - sound_global_enable(device->machine, (data >> 3) & 0x01); + device->machine->sound().system_enable((data >> 3) & 0x01); discrete_sound_w(device, CLOWNS_SPRINGBOARD_HIT_EN, (data >> 4) & 0x01); @@ -2323,7 +2323,7 @@ WRITE8_DEVICE_HANDLER( spacwalk_audio_1_w ) state->clowns_controller_select = (data >> 1) & 0x01; - sound_global_enable(device->machine, (data >> 2) & 0x01); + device->machine->sound().system_enable((data >> 2) & 0x01); discrete_sound_w(device, SPACWALK_SPACE_SHIP_EN, (data >> 3) & 0x01); } @@ -2553,7 +2553,7 @@ WRITE8_DEVICE_HANDLER( shuffle_audio_1_w ) discrete_sound_w(device, SHUFFLE_ROLLOVER_EN, (data >> 1) & 0x01); - sound_global_enable(device->machine, (data >> 2) & 0x01); + device->machine->sound().system_enable((data >> 2) & 0x01); discrete_sound_w(device, NODE_29, (data >> 3) & 0x07); @@ -2617,7 +2617,7 @@ WRITE8_HANDLER( dogpatch_audio_w ) coin_counter_w(space->machine, 0, (data >> 2) & 0x01); - sound_global_enable(space->machine, (data >> 3) & 0x01); + space->machine->sound().system_enable((data >> 3) & 0x01); /* if (data & 0x10) enable LEFT SHOOT sound */ @@ -3152,7 +3152,7 @@ MACHINE_CONFIG_END WRITE8_DEVICE_HANDLER( spcenctr_audio_1_w ) { - sound_global_enable(device->machine, (data >> 0) & 0x01); + device->machine->sound().system_enable((data >> 0) & 0x01); /* D1 is marked as 'OPTIONAL SWITCH VIDEO FOR COCKTAIL', but it is never set by the software */ @@ -3242,7 +3242,8 @@ WRITE8_HANDLER( phantom2_audio_1_w ) /* if (data & 0x02) enable ENEMY SHOT sound */ - sound_global_enable(space->machine, (data >> 2) & 0x01); + space->machine->sound().system_mute(!(data & 0x20)); + space->machine->sound().system_enable((data >> 2) & 0x01); coin_counter_w(space->machine, 0, (data >> 3) & 0x01); @@ -3367,7 +3368,7 @@ WRITE8_DEVICE_HANDLER( bowler_audio_1_w ) coin_counter_w(device->machine, 0, (data >> 1) & 0x01); - sound_global_enable(device->machine, (data >> 2) & 0x01); + device->machine->sound().system_enable((data >> 2) & 0x01); discrete_sound_w(device, BOWLER_FOWL_EN, (data >> 3) & 0x01); @@ -4096,7 +4097,7 @@ WRITE8_DEVICE_HANDLER( invaders_audio_1_w ) discrete_sound_w(device, INVADERS_NODE(INVADERS_INVADER_HIT_EN, 1), data & 0x08); discrete_sound_w(device, INVADERS_NODE(INVADERS_BONUS_MISSLE_BASE_EN, 1), data & 0x10); - sound_global_enable(device->machine, data & 0x20); + device->machine->sound().system_enable(data & 0x20); /* D6 and D7 are not connected */ } @@ -4729,7 +4730,7 @@ WRITE8_DEVICE_HANDLER( invad2ct_audio_1_w ) discrete_sound_w(device, INVADERS_NODE(INVADERS_INVADER_HIT_EN, 1), data & 0x08); discrete_sound_w(device, INVADERS_NODE(INVADERS_BONUS_MISSLE_BASE_EN, 1), data & 0x10); - sound_global_enable(device->machine, data & 0x20); + device->machine->sound().system_enable(data & 0x20); /* D6 and D7 are not connected */ } diff --git a/src/mame/audio/phoenix.c b/src/mame/audio/phoenix.c index 15d049a948a..48f3290efc7 100644 --- a/src/mame/audio/phoenix.c +++ b/src/mame/audio/phoenix.c @@ -9,7 +9,6 @@ #include "emu.h" -#include "streams.h" #include "sound/tms36xx.h" #include "includes/phoenix.h" @@ -503,7 +502,7 @@ WRITE8_DEVICE_HANDLER( phoenix_sound_control_a_w ) discrete_sound_w(state->discrete, PHOENIX_EFFECT_3_EN , data & 0x40); discrete_sound_w(state->discrete, PHOENIX_EFFECT_4_EN , data & 0x80); #endif - stream_update(state->channel); + state->channel->update(); state->sound_latch_a = data; } @@ -567,7 +566,7 @@ static DEVICE_START( phoenix_sound ) state->poly18[i] = bits; } - state->channel = stream_create(device, 0, 1, device->machine->sample_rate, 0, phoenix_sound_update); + state->channel = device->machine->sound().stream_alloc(*device, 0, 1, device->machine->sample_rate, 0, phoenix_sound_update); register_state(device); } diff --git a/src/mame/audio/pleiads.c b/src/mame/audio/pleiads.c index a00d2a0bc47..8088b797457 100644 --- a/src/mame/audio/pleiads.c +++ b/src/mame/audio/pleiads.c @@ -7,7 +7,6 @@ * ****************************************************************************/ #include "emu.h" -#include "streams.h" #include "sound/tms36xx.h" #include "audio/pleiads.h" @@ -429,7 +428,7 @@ WRITE8_DEVICE_HANDLER( pleiads_sound_control_a_w ) logerror("pleiads_sound_control_b_w $%02x\n", data); - stream_update(state->channel); + state->channel->update(); state->sound_latch_a = data; } @@ -455,7 +454,7 @@ WRITE8_DEVICE_HANDLER( pleiads_sound_control_b_w ) tms36xx_note_w(state->tms, pitch, note); - stream_update(state->channel); + state->channel->update(); state->sound_latch_b = data; } @@ -468,7 +467,7 @@ WRITE8_DEVICE_HANDLER( pleiads_sound_control_c_w ) return; logerror("pleiads_sound_control_c_w $%02x\n", data); - stream_update(state->channel); + state->channel->update(); state->sound_latch_c = data; } @@ -497,7 +496,7 @@ static DEVICE_START( common_sh_start ) state->poly18[i] = bits; } - state->channel = stream_create(device, 0, 1, device->machine->sample_rate, NULL, pleiads_sound_update); + state->channel = device->machine->sound().stream_alloc(*device, 0, 1, device->machine->sample_rate, NULL, pleiads_sound_update); } static DEVICE_START( pleiads_sound ) diff --git a/src/mame/audio/polepos.c b/src/mame/audio/polepos.c index 51e1d70d39d..0cbc8e41a55 100644 --- a/src/mame/audio/polepos.c +++ b/src/mame/audio/polepos.c @@ -3,7 +3,6 @@ Sound handler ****************************************************************************/ #include "emu.h" -#include "streams.h" #include "sound/filter.h" #include "machine/rescap.h" #include "namco52.h" @@ -114,7 +113,7 @@ static STREAM_UPDATE( engine_sound_update ) static DEVICE_START( polepos_sound ) { polepos_sound_state *state = get_safe_token(device); - state->stream = stream_create(device, 0, 1, OUTPUT_RATE, NULL, engine_sound_update); + state->stream = device->machine->sound().stream_alloc(*device, 0, 1, OUTPUT_RATE, NULL, engine_sound_update); state->sample_msb = state->sample_lsb = 0; state->sample_enable = 0; @@ -165,7 +164,7 @@ WRITE8_DEVICE_HANDLER( polepos_engine_sound_lsb_w ) { polepos_sound_state *state = get_safe_token(device); /* Update stream first so all samples at old frequency are updated. */ - stream_update(state->stream); + state->stream->update(); state->sample_lsb = data & 62; state->sample_enable = data & 1; } @@ -176,7 +175,7 @@ WRITE8_DEVICE_HANDLER( polepos_engine_sound_lsb_w ) WRITE8_DEVICE_HANDLER( polepos_engine_sound_msb_w ) { polepos_sound_state *state = get_safe_token(device); - stream_update(state->stream); + state->stream->update(); state->sample_msb = data & 63; } diff --git a/src/mame/audio/redbaron.c b/src/mame/audio/redbaron.c index b44dc06ca91..6f1dd670731 100644 --- a/src/mame/audio/redbaron.c +++ b/src/mame/audio/redbaron.c @@ -15,7 +15,6 @@ */ #include "emu.h" -#include "streams.h" #include "includes/bzone.h" #include "sound/pokey.h" @@ -63,7 +62,7 @@ WRITE8_DEVICE_HANDLER( redbaron_sounds_w ) if( data == state->latch ) return; - stream_update(state->channel); + state->channel->update(); state->latch = data; } @@ -224,7 +223,7 @@ static DEVICE_START( redbaron_sound ) state->vol_crash[i] = 32767 * r0 / (r0 + r1); } - state->channel = stream_create(device, 0, 1, OUTPUT_RATE, 0, redbaron_sound_update); + state->channel = device->machine->sound().stream_alloc(*device, 0, 1, OUTPUT_RATE, 0, redbaron_sound_update); } diff --git a/src/mame/audio/scramble.c b/src/mame/audio/scramble.c index e355f45fad6..e668c5e7590 100644 --- a/src/mame/audio/scramble.c +++ b/src/mame/audio/scramble.c @@ -85,7 +85,7 @@ WRITE8_DEVICE_HANDLER( scramble_sh_irqtrigger_w ) ttl7474_clock_w(target, (~data & 0x08) >> 3); /* bit 4 is sound disable */ - sound_global_enable(device->machine, (~data & 0x10) >> 4); + device->machine->sound().system_mute((data & 0x10) >> 4); } WRITE8_DEVICE_HANDLER( mrkougar_sh_irqtrigger_w ) diff --git a/src/mame/audio/segag80r.c b/src/mame/audio/segag80r.c index 2d885a1b393..1e090543764 100644 --- a/src/mame/audio/segag80r.c +++ b/src/mame/audio/segag80r.c @@ -8,7 +8,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "cpu/mcs48/mcs48.h" #include "includes/segag80r.h" #include "machine/8255ppi.h" @@ -276,7 +275,7 @@ WRITE8_HANDLER( astrob_sound_w ) if ((data & 0x10) && sample_playing(samples, 4)) sample_stop(samples, 4); /* MUTE */ - sound_global_enable(space->machine, !(data & 0x20)); + space->machine->sound().system_mute(data & 0x20); /* REFILL: channel 5 */ if (!(data & 0x40) && !sample_playing(samples, 5)) sample_start(samples, 5, 9, FALSE); @@ -547,7 +546,7 @@ static WRITE8_DEVICE_HANDLER( sega005_sound_b_w ) //mame_printf_debug("sound[%d] = %02X\n", 1, data); /* force a stream update */ - stream_update(sega005_stream); + sega005_stream->update(); /* ROM address */ sound_addr = ((data & 0x0f) << 7) | (sound_addr & 0x7f); @@ -580,7 +579,7 @@ static DEVICE_START( sega005_sound ) running_machine *machine = device->machine; /* create the stream */ - sega005_stream = stream_create(device, 0, 1, SEGA005_COUNTER_FREQ, NULL, sega005_stream_update); + sega005_stream = device->machine->sound().stream_alloc(*device, 0, 1, SEGA005_COUNTER_FREQ, NULL, sega005_stream_update); /* create a timer for the 555 */ sega005_sound_timer = timer_alloc(machine, sega005_auto_timer, NULL); @@ -630,7 +629,7 @@ static STREAM_UPDATE( sega005_stream_update ) static TIMER_CALLBACK( sega005_auto_timer ) { /* force an update then clock the sound address if not held in reset */ - stream_update(sega005_stream); + sega005_stream->update(); if ((sound_state[1] & 0x20) && !(sound_state[1] & 0x10)) { sound_addr = (sound_addr & 0x780) | ((sound_addr + 1) & 0x07f); diff --git a/src/mame/audio/segasnd.c b/src/mame/audio/segasnd.c index ae2c6308c73..6fff0dfabe7 100644 --- a/src/mame/audio/segasnd.c +++ b/src/mame/audio/segasnd.c @@ -10,7 +10,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "cpu/mcs48/mcs48.h" #include "sound/sp0250.h" #include "segasnd.h" @@ -651,7 +650,7 @@ static DEVICE_START( usb_sound ) usb.work_ram = auto_alloc_array(machine, UINT8, 0x400); /* create a sound stream */ - usb.stream = stream_create(device, 0, 1, SAMPLE_RATE, NULL, usb_stream_update); + usb.stream = device->machine->sound().stream_alloc(*device, 0, 1, SAMPLE_RATE, NULL, usb_stream_update); /* initialize state */ usb.noise_shift = 0x15555; @@ -758,7 +757,7 @@ static void timer_w(int which, UINT8 offset, UINT8 data) timer8253_channel *ch; int was_holding; - stream_update(usb.stream); + usb.stream->update(); /* switch off the offset */ switch (offset) @@ -825,7 +824,7 @@ static void env_w(int which, UINT8 offset, UINT8 data) { timer8253 *g = &usb.timer_group[which]; - stream_update(usb.stream); + usb.stream->update(); if (offset < 3) g->env[offset] = (double)data; diff --git a/src/mame/audio/seibu.c b/src/mame/audio/seibu.c index b57811749e0..cb082b0cf93 100644 --- a/src/mame/audio/seibu.c +++ b/src/mame/audio/seibu.c @@ -33,7 +33,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "audio/seibu.h" #include "sound/3812intf.h" #include "sound/2151intf.h" @@ -175,7 +174,7 @@ static DEVICE_START( seibu_adpcm ) seibu_adpcm_state *state = (seibu_adpcm_state *)downcast(device)->token(); state->playing = 0; - state->stream = stream_create(device, 0, 1, device->clock(), state, seibu_adpcm_callback); + state->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock(), state, seibu_adpcm_callback); state->base = machine->region("adpcm")->base(); state->adpcm.reset(); } @@ -218,7 +217,7 @@ WRITE8_DEVICE_HANDLER( seibu_adpcm_adr_w ) seibu_adpcm_state *state = (seibu_adpcm_state *)downcast(device)->token(); if (state->stream) - stream_update(state->stream); + state->stream->update(); if (offset) { state->end = data<<8; @@ -236,7 +235,7 @@ WRITE8_DEVICE_HANDLER( seibu_adpcm_ctl_w ) // sequence is 00 02 01 each time. if (state->stream) - stream_update(state->stream); + state->stream->update(); switch (data) { case 0: diff --git a/src/mame/audio/snes_snd.c b/src/mame/audio/snes_snd.c index 12d539cdc3a..8a60074342f 100644 --- a/src/mame/audio/snes_snd.c +++ b/src/mame/audio/snes_snd.c @@ -26,7 +26,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "audio/snes_snd.h" /*************************************************************************** @@ -1059,7 +1058,7 @@ static READ8_DEVICE_HANDLER( snes_dsp_io_r ) { snes_sound_state *spc700 = get_safe_token(device); - stream_update(spc700->channel); + spc700->channel->update(); #ifdef NO_ENVX if (8 == (spc700->ram[0xf2] & 0x0f)) @@ -1074,7 +1073,7 @@ static WRITE8_DEVICE_HANDLER( snes_dsp_io_w ) { snes_sound_state *spc700 = get_safe_token(device); - stream_update(spc700->channel); + spc700->channel->update(); if (offset == 0x7c) { @@ -1310,7 +1309,7 @@ static DEVICE_START( snes_sound ) snes_sound_state *spc700 = get_safe_token(device); running_machine *machine = device->machine; - spc700->channel = stream_create(device, 0, 2, 32000, 0, snes_sh_update); + spc700->channel = device->machine->sound().stream_alloc(*device, 0, 2, 32000, 0, snes_sh_update); spc700->ram = auto_alloc_array_clear(device->machine, UINT8, SNES_SPCRAM_SIZE); diff --git a/src/mame/audio/snk6502.c b/src/mame/audio/snk6502.c index 65247b2f81b..01669f4d1fb 100644 --- a/src/mame/audio/snk6502.c +++ b/src/mame/audio/snk6502.c @@ -11,7 +11,6 @@ #include "emu.h" -#include "streams.h" #include "sound/sn76477.h" #include "sound/samples.h" #include "includes/snk6502.h" @@ -663,7 +662,7 @@ static DEVICE_START( snk6502_sound ) // 38.99 Hz update (according to schematic) snk6502_set_music_clock(device->machine, M_LN2 * (RES_K(18) * 2 + RES_K(1)) * CAP_U(1)); - state->tone_stream = stream_create(device, 0, 1, SAMPLE_RATE, NULL, snk6502_tone_update); + state->tone_stream = device->machine->sound().stream_alloc(*device, 0, 1, SAMPLE_RATE, NULL, snk6502_tone_update); } DEVICE_GET_INFO( snk6502_sound ) diff --git a/src/mame/audio/tiamc1.c b/src/mame/audio/tiamc1.c index 86d1138a468..fbd87ec8740 100644 --- a/src/mame/audio/tiamc1.c +++ b/src/mame/audio/tiamc1.c @@ -32,7 +32,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "includes/tiamc1.h" #define CLOCK_DIVIDER 16 @@ -307,7 +306,7 @@ static DEVICE_START( tiamc1_sound ) timer8253_reset(&state->timer0); timer8253_reset(&state->timer1); - state->channel = stream_create(device, 0, 1, device->clock() / CLOCK_DIVIDER, 0, tiamc1_sound_update); + state->channel = device->machine->sound().stream_alloc(*device, 0, 1, device->clock() / CLOCK_DIVIDER, 0, tiamc1_sound_update); state->timer1_divider = 0; diff --git a/src/mame/audio/turbo.c b/src/mame/audio/turbo.c index daaded7f1f8..dfdef156ca6 100644 --- a/src/mame/audio/turbo.c +++ b/src/mame/audio/turbo.c @@ -415,7 +415,7 @@ WRITE8_DEVICE_HANDLER( subroc3d_sound_c_w ) sample_set_volume(samples, 11, (data & 0x40) ? 0 : 1.0); /* /GAME START */ - sound_global_enable(device->machine, !(data & 0x80)); + device->machine->sound().system_mute(data & 0x80); } @@ -570,7 +570,7 @@ WRITE8_DEVICE_HANDLER( buckrog_sound_b_w ) if ((diff & 0x40) && !(data & 0x40) && sample_playing(samples, 5)) sample_stop(samples, 5); /* GAME ON */ - sound_global_enable(device->machine, data & 0x80); + device->machine->sound().system_enable(data & 0x80); } diff --git a/src/mame/audio/tx1.c b/src/mame/audio/tx1.c index 2f45e3de352..d101dd03743 100644 --- a/src/mame/audio/tx1.c +++ b/src/mame/audio/tx1.c @@ -5,7 +5,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "sound/ay8910.h" #include "video/resnet.h" #include "includes/tx1.h" @@ -77,7 +76,7 @@ INLINE tx1_sound_state *get_safe_token(device_t *device) WRITE8_DEVICE_HANDLER( tx1_pit8253_w ) { tx1_sound_state *state = get_safe_token(device); - stream_update(state->stream); + state->stream->update(); if (offset < 3) { @@ -172,7 +171,7 @@ static const double tx1_engine_gains[16] = WRITE8_DEVICE_HANDLER( tx1_ay8910_a_w ) { tx1_sound_state *state = get_safe_token(device); - stream_update(state->stream); + state->stream->update(); /* All outputs inverted */ state->ay_outputa = ~data; @@ -183,15 +182,17 @@ WRITE8_DEVICE_HANDLER( tx1_ay8910_b_w ) tx1_sound_state *state = get_safe_token(device); double gain; - stream_update(state->stream); + state->stream->update(); /* Only B3-0 are inverted */ state->ay_outputb = data ^ 0xf; /* It'll do until we get quadrophonic speaker support! */ gain = BIT(state->ay_outputb, 4) ? 1.5 : 2.0; - sound_set_output_gain(device, 0, gain); - sound_set_output_gain(device, 1, gain); - sound_set_output_gain(device, 2, gain); + device_sound_interface *sound; + device->interface(sound); + sound->set_output_gain(0, gain); + sound->set_output_gain(1, gain); + sound->set_output_gain(2, gain); } /*************************************************************************** @@ -300,7 +301,7 @@ static DEVICE_START( tx1_sound ) /* Allocate the stream */ - state->stream = stream_create(device, 0, 2, machine->sample_rate, NULL, tx1_stream_update); + state->stream = device->machine->sound().stream_alloc(*device, 0, 2, machine->sample_rate, NULL, tx1_stream_update); state->freq_to_step = (double)(1 << TX1_FRAC) / (double)machine->sample_rate; /* Compute the engine resistor weights */ @@ -418,7 +419,7 @@ WRITE8_DEVICE_HANDLER( bb_ym1_a_w ) { tx1_sound_state *state = get_safe_token(device); - stream_update(state->stream); + state->stream->update(); state->ym1_outputa = data ^ 0xff; } @@ -426,7 +427,7 @@ WRITE8_DEVICE_HANDLER( bb_ym2_a_w ) { tx1_sound_state *state = get_safe_token(device); - stream_update(state->stream); + state->stream->update(); state->ym2_outputa = data ^ 0xff; } @@ -437,7 +438,7 @@ WRITE8_DEVICE_HANDLER( bb_ym2_b_w ) device_t *ym2 = device->machine->device("ym2"); double gain; - stream_update(state->stream); + state->stream->update(); state->ym2_outputb = data ^ 0xff; @@ -454,16 +455,19 @@ WRITE8_DEVICE_HANDLER( bb_ym2_b_w ) */ /* Rear left speaker */ + device_sound_interface *sound; + ym1->interface(sound); gain = data & 0x80 ? 1.0 : 2.0; - sound_set_output_gain(ym1, 0, gain); - sound_set_output_gain(ym1, 1, gain); - sound_set_output_gain(ym1, 2, gain); + sound->set_output_gain(0, gain); + sound->set_output_gain(1, gain); + sound->set_output_gain(2, gain); /* Rear right speaker */ + ym2->interface(sound); gain = data & 0x40 ? 1.0 : 2.0; - sound_set_output_gain(ym2, 0, gain); - sound_set_output_gain(ym2, 1, gain); - sound_set_output_gain(ym2, 2, gain); + sound->set_output_gain(0, gain); + sound->set_output_gain(1, gain); + sound->set_output_gain(2, gain); } /* This is admittedly a bit of a hack job... */ @@ -568,7 +572,7 @@ static DEVICE_START( buggyboy_sound ) state->eng_voltages[i] = combine_4_weights(aweights, BIT(tmp[i], 0), BIT(tmp[i], 1), BIT(tmp[i], 2), BIT(tmp[i], 3)); /* Allocate the stream */ - state->stream = stream_create(device, 0, 2, machine->sample_rate, NULL, buggyboy_stream_update); + state->stream = device->machine->sound().stream_alloc(*device, 0, 2, machine->sample_rate, NULL, buggyboy_stream_update); state->freq_to_step = (double)(1 << 24) / (double)machine->sample_rate; } diff --git a/src/mame/audio/warpwarp.c b/src/mame/audio/warpwarp.c index 976b24d4814..9fe6ec91862 100644 --- a/src/mame/audio/warpwarp.c +++ b/src/mame/audio/warpwarp.c @@ -8,7 +8,6 @@ ****************************************************************************/ #include "emu.h" -#include "streams.h" #include "includes/warpwarp.h" #define CLOCK_16H (18432000/3/2/16) @@ -56,7 +55,7 @@ WRITE8_DEVICE_HANDLER( warpwarp_sound_w ) { warpwarp_sound_state *state = get_safe_token(device); - stream_update(state->channel); + state->channel->update(); state->sound_latch = data & 0x0f; state->sound_volume = 0x7fff; /* set sound_volume */ state->noise = 0x0000; /* reset noise shifter */ @@ -95,7 +94,7 @@ WRITE8_DEVICE_HANDLER( warpwarp_music1_w ) { warpwarp_sound_state *state = get_safe_token(device); - stream_update(state->channel); + state->channel->update(); state->music1_latch = data & 0x3f; } @@ -109,7 +108,7 @@ static TIMER_CALLBACK( music_volume_decay ) WRITE8_DEVICE_HANDLER( warpwarp_music2_w ) { warpwarp_sound_state *state = get_safe_token(device); - stream_update(state->channel); + state->channel->update(); state->music2_latch = data & 0x3f; state->music_volume = 0x7fff; /* fast decay enabled? */ @@ -235,7 +234,7 @@ static DEVICE_START( warpwarp_sound ) for( i = 0; i < 0x8000; i++ ) state->decay[0x7fff-i] = (INT16) (0x7fff/exp(1.0*i/4096)); - state->channel = stream_create(device, 0, 1, CLOCK_16H, NULL, warpwarp_sound_update); + state->channel = device->machine->sound().stream_alloc(*device, 0, 1, CLOCK_16H, NULL, warpwarp_sound_update); state->sound_volume_timer = timer_alloc(machine, sound_volume_decay, state); state->music_volume_timer = timer_alloc(machine, music_volume_decay, state); diff --git a/src/mame/audio/wiping.c b/src/mame/audio/wiping.c index 2e02e30541d..8c843442861 100644 --- a/src/mame/audio/wiping.c +++ b/src/mame/audio/wiping.c @@ -7,7 +7,6 @@ ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "includes/wiping.h" @@ -180,7 +179,7 @@ static DEVICE_START( wiping_sound ) sound_channel *voice; /* get stream channels */ - state->stream = stream_create(device, 0, 1, samplerate, NULL, wiping_update_mono); + state->stream = device->machine->sound().stream_alloc(*device, 0, 1, samplerate, NULL, wiping_update_mono); /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */ state->mixer_buffer = auto_alloc_array(machine, short, 2 * samplerate); @@ -237,7 +236,7 @@ WRITE8_DEVICE_HANDLER( wiping_sound_w ) int base; /* update the streams */ - stream_update(state->stream); + state->stream->update(); /* set the register */ state->soundregs[offset] = data; diff --git a/src/mame/drivers/40love.c b/src/mame/drivers/40love.c index 3dd90957b69..6cb81eefb18 100644 --- a/src/mame/drivers/40love.c +++ b/src/mame/drivers/40love.c @@ -713,10 +713,12 @@ static WRITE8_DEVICE_HANDLER( sound_control_0_w ) // popmessage("SND0 0=%02x 1=%02x 2=%02x 3=%02x", state->snd_ctrl0, state->snd_ctrl1, state->snd_ctrl2, state->snd_ctrl3); /* this definitely controls main melody voice on 2'-1 and 4'-1 outputs */ - sound_set_output_gain(device, 0, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ - sound_set_output_gain(device, 1, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ - sound_set_output_gain(device, 2, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ - sound_set_output_gain(device, 3, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ + device_sound_interface *sound; + device->interface(sound); + sound->set_output_gain(0, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ + sound->set_output_gain(1, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ + sound->set_output_gain(2, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ + sound->set_output_gain(3, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ } static WRITE8_DEVICE_HANDLER( sound_control_1_w ) @@ -724,10 +726,12 @@ static WRITE8_DEVICE_HANDLER( sound_control_1_w ) fortyl_state *state = device->machine->driver_data(); state->snd_ctrl1 = data & 0xff; // popmessage("SND1 0=%02x 1=%02x 2=%02x 3=%02x", state->snd_ctrl0, state->snd_ctrl1, state->snd_ctrl2, state->snd_ctrl3); - sound_set_output_gain(device, 4, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ - sound_set_output_gain(device, 5, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ - sound_set_output_gain(device, 6, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ - sound_set_output_gain(device, 7, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ + device_sound_interface *sound; + device->interface(sound); + sound->set_output_gain(4, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ + sound->set_output_gain(5, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ + sound->set_output_gain(6, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ + sound->set_output_gain(7, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ } static WRITE8_DEVICE_HANDLER( sound_control_2_w ) @@ -737,8 +741,10 @@ static WRITE8_DEVICE_HANDLER( sound_control_2_w ) state->snd_ctrl2 = data & 0xff; // popmessage("SND2 0=%02x 1=%02x 2=%02x 3=%02x", state->snd_ctrl0, state->snd_ctrl1, state->snd_ctrl2, state->snd_ctrl3); + device_sound_interface *sound; + device->interface(sound); for (i = 0; i < 3; i++) - sound_set_output_gain(device, i, state->vol_ctrl[(state->snd_ctrl2 >> 4) & 15] / 100.0); /* ym2149f all */ + sound->set_output_gain(i, state->vol_ctrl[(state->snd_ctrl2 >> 4) & 15] / 100.0); /* ym2149f all */ } static WRITE8_DEVICE_HANDLER( sound_control_3_w ) /* unknown */ diff --git a/src/mame/drivers/aleck64.c b/src/mame/drivers/aleck64.c index 5c9b72193fd..dc69c36279c 100644 --- a/src/mame/drivers/aleck64.c +++ b/src/mame/drivers/aleck64.c @@ -166,7 +166,6 @@ Notes: */ #include "emu.h" -#include "streams.h" #include "cpu/rsp/rsp.h" #include "cpu/mips/mips3.h" #include "sound/dmadac.h" diff --git a/src/mame/drivers/astinvad.c b/src/mame/drivers/astinvad.c index 40ffbf04e72..731b95fe2cc 100644 --- a/src/mame/drivers/astinvad.c +++ b/src/mame/drivers/astinvad.c @@ -333,7 +333,7 @@ static WRITE8_DEVICE_HANDLER( astinvad_sound1_w ) if (bits_gone_hi & 0x04) sample_start(state->samples, 2, SND_BASEHIT, 0); if (bits_gone_hi & 0x08) sample_start(state->samples, 3, SND_INVADERHIT, 0); - sound_global_enable(device->machine, data & 0x20); + device->machine->sound().system_enable(data & 0x20); state->screen_red = data & 0x04; } @@ -379,7 +379,7 @@ static WRITE8_HANDLER( spaceint_sound2_w ) int bits_gone_hi = data & ~state->sound_state[1]; state->sound_state[1] = data; - sound_global_enable(space->machine, data & 0x02); + space->machine->sound().system_enable(data & 0x02); if (bits_gone_hi & 0x04) sample_start(state->samples, 3, SND_INVADERHIT, 0); diff --git a/src/mame/drivers/astrocde.c b/src/mame/drivers/astrocde.c index ad54a94968a..95d7628804d 100644 --- a/src/mame/drivers/astrocde.c +++ b/src/mame/drivers/astrocde.c @@ -338,8 +338,8 @@ static READ8_HANDLER( gorf_io_1_r ) case 4: astrocade_sparkle[2] = data; break; case 5: astrocade_sparkle[3] = data; break; case 6: - sound_set_output_gain(space->machine->device("astrocade1"), 0, data ? 0.0 : 1.0); - sound_set_output_gain(space->machine->device("samples"), 0, data ? 1.0 : 0.0); + space->machine->device("astrocade1")->set_output_gain(0, data ? 0.0 : 1.0); + space->machine->device("samples")->set_output_gain(0, data ? 1.0 : 0.0); break; case 7: mame_printf_debug("io_1:%d\n", data); break; } diff --git a/src/mame/drivers/bfm_sc2.c b/src/mame/drivers/bfm_sc2.c index 8cdf0a31fab..b24e11678a7 100644 --- a/src/mame/drivers/bfm_sc2.c +++ b/src/mame/drivers/bfm_sc2.c @@ -681,13 +681,13 @@ static WRITE8_HANDLER( volume_override_w ) if ( old != volume_override ) { - device_t *ym = space->machine->device("ymsnd"); - device_t *upd = space->machine->device("upd"); + ym2413_device *ym = space->machine->device("ymsnd"); + upd7759_device *upd = space->machine->device("upd"); float percent = volume_override? 1.0f : (32-global_volume)/32.0f; - sound_set_output_gain(ym, 0, percent); - sound_set_output_gain(ym, 1, percent); - sound_set_output_gain(upd, 0, percent); + ym->set_output_gain(0, percent); + ym->set_output_gain(1, percent); + upd->set_output_gain(0, percent); } } @@ -778,13 +778,13 @@ static WRITE8_HANDLER( expansion_latch_w ) } { - device_t *ym = space->machine->device("ymsnd"); - device_t *upd = space->machine->device("upd"); + ym2413_device *ym = space->machine->device("ymsnd"); + upd7759_device *upd = space->machine->device("upd"); float percent = volume_override ? 1.0f : (32-global_volume)/32.0f; - sound_set_output_gain(ym, 0, percent); - sound_set_output_gain(ym, 1, percent); - sound_set_output_gain(upd, 0, percent); + ym->set_output_gain(0, percent); + ym->set_output_gain(1, percent); + upd->set_output_gain(0, percent); } } } diff --git a/src/mame/drivers/buggychl.c b/src/mame/drivers/buggychl.c index 687180c62b9..465d55779ec 100644 --- a/src/mame/drivers/buggychl.c +++ b/src/mame/drivers/buggychl.c @@ -127,7 +127,7 @@ static WRITE8_HANDLER( nmi_enable_w ) static WRITE8_HANDLER( sound_enable_w ) { - sound_global_enable(space->machine, data & 1); + space->machine->sound().system_enable(data & 1); } diff --git a/src/mame/drivers/crbaloon.c b/src/mame/drivers/crbaloon.c index 2bde17cd649..1d51eda76c5 100644 --- a/src/mame/drivers/crbaloon.c +++ b/src/mame/drivers/crbaloon.c @@ -167,7 +167,7 @@ static WRITE8_HANDLER( port_sound_w ) crbaloon_set_clear_collision_address((data & 0x01) ? TRUE : FALSE); /* D1 - SOUND STOP */ - sound_global_enable(space->machine, (data & 0x02) ? TRUE : FALSE); + space->machine->sound().system_enable((data & 0x02) ? TRUE : FALSE); /* D2 - unlabeled - music enable */ crbaloon_audio_set_music_enable(discrete, 0, (data & 0x04) ? TRUE : FALSE); diff --git a/src/mame/drivers/cubeqst.c b/src/mame/drivers/cubeqst.c index 293ac727081..1f06d671e2d 100644 --- a/src/mame/drivers/cubeqst.c +++ b/src/mame/drivers/cubeqst.c @@ -21,7 +21,6 @@ #include "cpu/m68000/m68000.h" #include "cpu/cubeqcpu/cubeqcpu.h" #include "sound/dac.h" -#include "streams.h" #include "machine/laserdsc.h" #include "machine/nvram.h" diff --git a/src/mame/drivers/cubocd32.c b/src/mame/drivers/cubocd32.c index 03e6723fbbb..a2e5a7b5afb 100644 --- a/src/mame/drivers/cubocd32.c +++ b/src/mame/drivers/cubocd32.c @@ -376,7 +376,7 @@ static WRITE32_HANDLER( aga_overlay_w ) static WRITE8_DEVICE_HANDLER( cd32_cia_0_porta_w ) { /* bit 1 = cd audio mute */ - sound_set_output_gain(device->machine->device("cdda"), 0, ( data & 1 ) ? 0.0 : 1.0 ); + device->machine->device("cdda")->set_output_gain( 0, ( data & 1 ) ? 0.0 : 1.0 ); /* bit 2 = Power Led on Amiga */ set_led_status(device->machine, 0, (data & 2) ? 0 : 1); diff --git a/src/mame/drivers/dai3wksi.c b/src/mame/drivers/dai3wksi.c index d009edefc43..e98b09d1678 100644 --- a/src/mame/drivers/dai3wksi.c +++ b/src/mame/drivers/dai3wksi.c @@ -286,7 +286,7 @@ static WRITE8_HANDLER( dai3wksi_audio_1_w ) { device_t *ic79 = space->machine->device("ic79"); - sound_global_enable(space->machine, data & 0x80); + space->machine->sound().system_enable(data & 0x80); sn76477_enable_w(ic79, (~data >> 5) & 0x01); /* invader movement enable */ sn76477_envelope_1_w(ic79, (~data >> 2) & 0x01); /* invader movement envelope control*/ diff --git a/src/mame/drivers/darius.c b/src/mame/drivers/darius.c index 5f6bbbbd421..c3806c912c4 100644 --- a/src/mame/drivers/darius.c +++ b/src/mame/drivers/darius.c @@ -914,7 +914,7 @@ static MACHINE_RESET( darius ) state->adpcm_command = 0; state->nmi_enable = 0; - sound_global_enable(machine, 1); /* mixer enabled */ + machine->sound().system_enable(true); /* mixer enabled */ for (i = 0; i < DARIUS_VOL_MAX; i++) state->vol[i] = 0x00; /* min volume */ diff --git a/src/mame/drivers/equites.c b/src/mame/drivers/equites.c index 2d8fba4ad50..9d455e9c85a 100644 --- a/src/mame/drivers/equites.c +++ b/src/mame/drivers/equites.c @@ -408,7 +408,7 @@ static TIMER_CALLBACK( equites_frq_adjuster_callback ) state->cymvol *= 0.94f; state->hihatvol *= 0.94f; - sound_set_output_gain(state->msm, 10, state->hihatvol + state->cymvol * (state->ay_port_b & 3) * 0.33); /* NO from msm5232 */ + state->msm->set_output_gain(10, state->hihatvol + state->cymvol * (state->ay_port_b & 3) * 0.33); /* NO from msm5232 */ } static SOUND_START(equites) @@ -596,25 +596,25 @@ static WRITE8_HANDLER(equites_8155_w) break; case 1: //logerror( "8155 I/O Port A write %x\n", data ); state->eq8155_port_a = data; - sound_set_output_gain(state->msm, 0, (data >> 4) / 15.0); /* group1 from msm5232 */ - sound_set_output_gain(state->msm, 1, (data >> 4) / 15.0); /* group1 from msm5232 */ - sound_set_output_gain(state->msm, 2, (data >> 4) / 15.0); /* group1 from msm5232 */ - sound_set_output_gain(state->msm, 3, (data >> 4) / 15.0); /* group1 from msm5232 */ - sound_set_output_gain(state->msm, 4, (data & 0x0f) / 15.0); /* group2 from msm5232 */ - sound_set_output_gain(state->msm, 5, (data & 0x0f) / 15.0); /* group2 from msm5232 */ - sound_set_output_gain(state->msm, 6, (data & 0x0f) / 15.0); /* group2 from msm5232 */ - sound_set_output_gain(state->msm, 7, (data & 0x0f) / 15.0); /* group2 from msm5232 */ + state->msm->set_output_gain(0, (data >> 4) / 15.0); /* group1 from msm5232 */ + state->msm->set_output_gain(1, (data >> 4) / 15.0); /* group1 from msm5232 */ + state->msm->set_output_gain(2, (data >> 4) / 15.0); /* group1 from msm5232 */ + state->msm->set_output_gain(3, (data >> 4) / 15.0); /* group1 from msm5232 */ + state->msm->set_output_gain(4, (data & 0x0f) / 15.0); /* group2 from msm5232 */ + state->msm->set_output_gain(5, (data & 0x0f) / 15.0); /* group2 from msm5232 */ + state->msm->set_output_gain(6, (data & 0x0f) / 15.0); /* group2 from msm5232 */ + state->msm->set_output_gain(7, (data & 0x0f) / 15.0); /* group2 from msm5232 */ break; case 2: //logerror( "8155 I/O Port B write %x\n", data ); equites_8155_portb_w(space, 0, data); break; case 3: //logerror( "8155 I/O Port C (or control) write %x\n", data ); state->eq8155_port_c = data; - sound_set_output_gain(state->msm, 8, (data & 0x0f) / 15.0); /* SOLO 8' from msm5232 */ + state->msm->set_output_gain(8, (data & 0x0f) / 15.0); /* SOLO 8' from msm5232 */ if (data & 0x20) - sound_set_output_gain(state->msm, 9, (data & 0x0f) / 15.0); /* SOLO 16' from msm5232 */ + state->msm->set_output_gain(9, (data & 0x0f) / 15.0); /* SOLO 16' from msm5232 */ else - sound_set_output_gain(state->msm, 9, 0); /* SOLO 16' from msm5232 */ + state->msm->set_output_gain(9, 0); /* SOLO 16' from msm5232 */ break; case 4: //logerror( "8155 Timer low 8 bits write %x\n", data ); @@ -1188,7 +1188,7 @@ static MACHINE_START( equites ) state->mcu = machine->device("mcu"); state->audio_cpu = machine->device("audiocpu"); - state->msm = machine->device("msm"); + state->msm = machine->device("msm"); state->dac_1 = machine->device("dac1"); state->dac_2 = machine->device("dac2"); diff --git a/src/mame/drivers/fcrash.c b/src/mame/drivers/fcrash.c index 2f266f0ceb3..271d9d0f6a6 100644 --- a/src/mame/drivers/fcrash.c +++ b/src/mame/drivers/fcrash.c @@ -55,8 +55,8 @@ static WRITE8_HANDLER( fcrash_snd_bankswitch_w ) { cps_state *state = space->machine->driver_data(); - sound_set_output_gain(state->msm_1, 0, (data & 0x08) ? 0.0 : 1.0); - sound_set_output_gain(state->msm_2, 0, (data & 0x10) ? 0.0 : 1.0); + state->msm_1->set_output_gain(0, (data & 0x08) ? 0.0 : 1.0); + state->msm_2->set_output_gain(0, (data & 0x10) ? 0.0 : 1.0); memory_set_bank(space->machine, "bank1", data & 0x07); } @@ -698,8 +698,8 @@ static MACHINE_START( fcrash ) state->maincpu = machine->device("maincpu"); state->audiocpu = machine->device("soundcpu"); - state->msm_1 = machine->device("msm1"); - state->msm_2 = machine->device("msm2"); + state->msm_1 = machine->device("msm1"); + state->msm_2 = machine->device("msm2"); state_save_register_global(machine, state->sample_buffer1); state_save_register_global(machine, state->sample_buffer2); diff --git a/src/mame/drivers/firefox.c b/src/mame/drivers/firefox.c index f9fbdda5044..15fbce71c11 100644 --- a/src/mame/drivers/firefox.c +++ b/src/mame/drivers/firefox.c @@ -100,7 +100,7 @@ static WRITE8_HANDLER( firefox_disc_lock_w ) static WRITE8_HANDLER( audio_enable_w ) { - sound_set_output_gain(space->machine->device("ldsound"), ~offset & 1, (data & 0x80) ? 1.0 : 0.0); + space->machine->device("ldsound")->set_output_gain(~offset & 1, (data & 0x80) ? 1.0 : 0.0); } static WRITE8_HANDLER( firefox_disc_reset_w ) diff --git a/src/mame/drivers/flstory.c b/src/mame/drivers/flstory.c index ee5ce9de6c9..4dab9d6e132 100644 --- a/src/mame/drivers/flstory.c +++ b/src/mame/drivers/flstory.c @@ -402,10 +402,12 @@ static WRITE8_DEVICE_HANDLER( sound_control_0_w ) // popmessage("SND0 0=%02x 1=%02x 2=%02x 3=%02x", state->snd_ctrl0, state->snd_ctrl1, state->snd_ctrl2, state->snd_ctrl3); /* this definitely controls main melody voice on 2'-1 and 4'-1 outputs */ - sound_set_output_gain(device, 0, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ - sound_set_output_gain(device, 1, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ - sound_set_output_gain(device, 2, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ - sound_set_output_gain(device, 3, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ + device_sound_interface *sound; + device->interface(sound); + sound->set_output_gain(0, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ + sound->set_output_gain(1, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ + sound->set_output_gain(2, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ + sound->set_output_gain(3, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group1 from msm5232 */ } static WRITE8_DEVICE_HANDLER( sound_control_1_w ) @@ -414,10 +416,12 @@ static WRITE8_DEVICE_HANDLER( sound_control_1_w ) state->snd_ctrl1 = data & 0xff; // popmessage("SND1 0=%02x 1=%02x 2=%02x 3=%02x", state->snd_ctrl0, state->snd_ctrl1, state->snd_ctrl2, state->snd_ctrl3); - sound_set_output_gain(device, 4, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ - sound_set_output_gain(device, 5, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ - sound_set_output_gain(device, 6, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ - sound_set_output_gain(device, 7, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ + device_sound_interface *sound; + device->interface(sound); + sound->set_output_gain(4, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ + sound->set_output_gain(5, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ + sound->set_output_gain(6, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ + sound->set_output_gain(7, state->vol_ctrl[(state->snd_ctrl1 >> 4) & 15] / 100.0); /* group2 from msm5232 */ } static WRITE8_DEVICE_HANDLER( sound_control_2_w ) @@ -428,8 +432,10 @@ static WRITE8_DEVICE_HANDLER( sound_control_2_w ) state->snd_ctrl2 = data & 0xff; // popmessage("SND2 0=%02x 1=%02x 2=%02x 3=%02x", state->snd_ctrl0, state->snd_ctrl1, state->snd_ctrl2, state->snd_ctrl3); + device_sound_interface *sound; + device->interface(sound); for (i = 0; i < 3; i++) - sound_set_output_gain(device, i, state->vol_ctrl[(state->snd_ctrl2 >> 4) & 15] / 100.0); /* ym2149f all */ + sound->set_output_gain(i, state->vol_ctrl[(state->snd_ctrl2 >> 4) & 15] / 100.0); /* ym2149f all */ } static WRITE8_DEVICE_HANDLER( sound_control_3_w ) /* unknown */ diff --git a/src/mame/drivers/galaxian.c b/src/mame/drivers/galaxian.c index c6de6d844a6..7e895269453 100644 --- a/src/mame/drivers/galaxian.c +++ b/src/mame/drivers/galaxian.c @@ -570,7 +570,7 @@ static WRITE8_DEVICE_HANDLER( konami_sound_control_w ) cputag_set_input_line(device->machine, "audiocpu", 0, HOLD_LINE); /* bit 4 is sound disable */ - sound_global_enable(device->machine, ~data & 0x10); + device->machine->sound().system_mute(data & 0x10); } diff --git a/src/mame/drivers/gottlieb.c b/src/mame/drivers/gottlieb.c index cabc4cfc1ec..cbaecf5dca5 100644 --- a/src/mame/drivers/gottlieb.c +++ b/src/mame/drivers/gottlieb.c @@ -202,7 +202,6 @@ VBlank duration: 1/VSYNC * (16/256) = 1017.6 us #include "sound/samples.h" #include "sound/sp0250.h" #include "machine/nvram.h" -#include "streams.h" #include "includes/gottlieb.h" diff --git a/src/mame/drivers/looping.c b/src/mame/drivers/looping.c index 9fbbd4a6b84..51e4354cffe 100644 --- a/src/mame/drivers/looping.c +++ b/src/mame/drivers/looping.c @@ -385,14 +385,18 @@ static WRITE8_DEVICE_HANDLER( ay_enable_w ) { int output; + device_sound_interface *sound; + device->interface(sound); for (output = 0; output < 3; output++) - sound_set_output_gain(device, output, (data & 1) ? 1.0 : 0.0); + sound->set_output_gain(output, (data & 1) ? 1.0 : 0.0); } static WRITE8_DEVICE_HANDLER( speech_enable_w ) { - sound_set_output_gain(device, 0, (data & 1) ? 1.0 : 0.0); + device_sound_interface *sound; + device->interface(sound); + sound->set_output_gain(0, (data & 1) ? 1.0 : 0.0); } diff --git a/src/mame/drivers/m10.c b/src/mame/drivers/m10.c index 7a199ff46d8..b93809132f1 100644 --- a/src/mame/drivers/m10.c +++ b/src/mame/drivers/m10.c @@ -256,7 +256,7 @@ static WRITE8_HANDLER( m10_ctrl_w ) state->flip = ~data & 0x10; if (!(input_port_read(space->machine, "CAB") & 0x02)) - sound_global_enable(space->machine, ~data & 0x80); + space->machine->sound().system_mute(data & 0x80); /* sound command in lower 4 bytes */ switch (data & 0x07) @@ -332,7 +332,7 @@ static WRITE8_HANDLER( m11_ctrl_w ) state->flip = ~data & 0x10; if (!(input_port_read(space->machine, "CAB") & 0x02)) - sound_global_enable(space->machine, ~data & 0x80); + space->machine->sound().system_mute(data & 0x80); } /* @@ -361,7 +361,7 @@ static WRITE8_HANDLER( m15_ctrl_w ) if (input_port_read(space->machine, "CAB") & 0x01) state->flip = ~data & 0x04; if (!(input_port_read(space->machine, "CAB") & 0x02)) - sound_global_enable(space->machine, ~data & 0x08); + space->machine->sound().system_mute(data & 0x08); } diff --git a/src/mame/drivers/magmax.c b/src/mame/drivers/magmax.c index 8dbe7409a73..ce2a8d492ab 100644 --- a/src/mame/drivers/magmax.c +++ b/src/mame/drivers/magmax.c @@ -109,9 +109,9 @@ static MACHINE_RESET( magmax ) static WRITE8_DEVICE_HANDLER( ay8910_portA_0_w ) { -device_t *ay1 = device->machine->device("ay1"); -device_t *ay2 = device->machine->device("ay2"); -device_t *ay3 = device->machine->device("ay3"); +ay8910_device *ay1 = device->machine->device("ay1"); +ay8910_device *ay2 = device->machine->device("ay2"); +ay8910_device *ay3 = device->machine->device("ay3"); float percent; /*There are three AY8910 chips and four(!) separate amplifiers on the board @@ -166,26 +166,26 @@ bit3 - SOUND Chan#8 name=AY-3-8910 #2 Ch C /*popmessage("gain_ctrl = %2x",data&0x0f);*/ percent = (gain_control & 1) ? 1.0 : 0.50; - sound_set_output_gain(ay1, 0, percent); + ay1->set_output_gain(0, percent); //fixme: set_RC_filter(0,10000,100000000,0,10000); /* 10K, 10000pF = 0.010uF */ percent = (gain_control & 2) ? 0.45 : 0.23; - sound_set_output_gain(ay1, 1, percent); - sound_set_output_gain(ay1, 2, percent); - sound_set_output_gain(ay2, 0, percent); - sound_set_output_gain(ay2, 1, percent); + ay1->set_output_gain(1, percent); + ay1->set_output_gain(2, percent); + ay2->set_output_gain(0, percent); + ay2->set_output_gain(1, percent); //fixme: set_RC_filter(1,4700,100000000,0,4700); /* 4.7K, 4700pF = 0.0047uF */ //fixme: set_RC_filter(2,4700,100000000,0,4700); /* 4.7K, 4700pF = 0.0047uF */ //fixme: set_RC_filter(3,4700,100000000,0,4700); /* 4.7K, 4700pF = 0.0047uF */ //fixme: set_RC_filter(4,4700,100000000,0,4700); /* 4.7K, 4700pF = 0.0047uF */ percent = (gain_control & 4) ? 0.45 : 0.23; - sound_set_output_gain(ay2, 2, percent); - sound_set_output_gain(ay3, 0, percent); + ay2->set_output_gain(2, percent); + ay3->set_output_gain(0, percent); percent = (gain_control & 8) ? 0.45 : 0.23; - sound_set_output_gain(ay3, 1, percent); - sound_set_output_gain(ay3, 2, percent); + ay3->set_output_gain(1, percent); + ay3->set_output_gain(2, percent); } static WRITE16_HANDLER( magmax_vreg_w ) diff --git a/src/mame/drivers/maxaflex.c b/src/mame/drivers/maxaflex.c index fed10179283..a7cddadd2c5 100644 --- a/src/mame/drivers/maxaflex.c +++ b/src/mame/drivers/maxaflex.c @@ -80,7 +80,7 @@ static WRITE8_HANDLER( mcu_portB_w ) cputag_set_input_line(space->machine, "mcu", M6805_IRQ_LINE, CLEAR_LINE ); /* AUDMUTE */ - sound_global_enable(space->machine, (data >> 5) & 1); + space->machine->sound().system_enable((data >> 5) & 1); /* RES600 */ if (diff & 0x10) diff --git a/src/mame/drivers/mjkjidai.c b/src/mame/drivers/mjkjidai.c index 2fba1abad2d..d1278217280 100644 --- a/src/mame/drivers/mjkjidai.c +++ b/src/mame/drivers/mjkjidai.c @@ -22,7 +22,6 @@ TODO: ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "cpu/z80/z80.h" #include "sound/sn76496.h" #include "sound/okim6295.h" @@ -73,7 +72,7 @@ static DEVICE_START( mjkjidai_adpcm ) mjkjidai_adpcm_state *state = (mjkjidai_adpcm_state *)downcast(device)->token(); state->playing = 0; - state->stream = stream_create(device, 0, 1, device->clock(), state, mjkjidai_adpcm_callback); + state->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock(), state, mjkjidai_adpcm_callback); state->base = machine->region("adpcm")->base(); state->adpcm.reset(); } diff --git a/src/mame/drivers/msisaac.c b/src/mame/drivers/msisaac.c index 3196c0be837..7d3eb612678 100644 --- a/src/mame/drivers/msisaac.c +++ b/src/mame/drivers/msisaac.c @@ -246,14 +246,16 @@ static WRITE8_DEVICE_HANDLER( sound_control_0_w ) state->snd_ctrl0 = data & 0xff; //popmessage("SND0 0=%2x 1=%2x", state->snd_ctrl0, state->snd_ctrl1); - sound_set_output_gain(device, 0, state->vol_ctrl[state->snd_ctrl0 & 15] / 100.0); /* group1 from msm5232 */ - sound_set_output_gain(device, 1, state->vol_ctrl[state->snd_ctrl0 & 15] / 100.0); /* group1 from msm5232 */ - sound_set_output_gain(device, 2, state->vol_ctrl[state->snd_ctrl0 & 15] / 100.0); /* group1 from msm5232 */ - sound_set_output_gain(device, 3, state->vol_ctrl[state->snd_ctrl0 & 15] / 100.0); /* group1 from msm5232 */ - sound_set_output_gain(device, 4, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group2 from msm5232 */ - sound_set_output_gain(device, 5, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group2 from msm5232 */ - sound_set_output_gain(device, 6, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group2 from msm5232 */ - sound_set_output_gain(device, 7, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group2 from msm5232 */ + device_sound_interface *sound; + device->interface(sound); + sound->set_output_gain(0, state->vol_ctrl[state->snd_ctrl0 & 15] / 100.0); /* group1 from msm5232 */ + sound->set_output_gain(1, state->vol_ctrl[state->snd_ctrl0 & 15] / 100.0); /* group1 from msm5232 */ + sound->set_output_gain(2, state->vol_ctrl[state->snd_ctrl0 & 15] / 100.0); /* group1 from msm5232 */ + sound->set_output_gain(3, state->vol_ctrl[state->snd_ctrl0 & 15] / 100.0); /* group1 from msm5232 */ + sound->set_output_gain(4, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group2 from msm5232 */ + sound->set_output_gain(5, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group2 from msm5232 */ + sound->set_output_gain(6, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group2 from msm5232 */ + sound->set_output_gain(7, state->vol_ctrl[(state->snd_ctrl0 >> 4) & 15] / 100.0); /* group2 from msm5232 */ } static WRITE8_HANDLER( sound_control_1_w ) { diff --git a/src/mame/drivers/ninjaw.c b/src/mame/drivers/ninjaw.c index adfed83c49b..70d7bf444c3 100644 --- a/src/mame/drivers/ninjaw.c +++ b/src/mame/drivers/ninjaw.c @@ -794,7 +794,7 @@ static MACHINE_RESET( ninjaw ) memset(state->pandata, 0, sizeof(state->pandata)); /**** mixer control enable ****/ - sound_global_enable(machine, 1); /* mixer enabled */ + machine->sound().system_enable(true); /* mixer enabled */ } static MACHINE_CONFIG_START( ninjaw, ninjaw_state ) diff --git a/src/mame/drivers/renegade.c b/src/mame/drivers/renegade.c index 16bc1867437..981bc3cfb18 100644 --- a/src/mame/drivers/renegade.c +++ b/src/mame/drivers/renegade.c @@ -101,7 +101,6 @@ $8000 - $ffff ROM ***************************************************************************/ #include "emu.h" -#include "streams.h" #include "deprecat.h" #include "cpu/m6502/m6502.h" #include "cpu/m6809/m6809.h" @@ -174,7 +173,7 @@ static DEVICE_START( renegade_adpcm ) running_machine *machine = device->machine; struct renegade_adpcm_state *state = &renegade_adpcm; state->playing = 0; - state->stream = stream_create(device, 0, 1, device->clock(), state, renegade_adpcm_callback); + state->stream = device->machine->sound().stream_alloc(*device, 0, 1, device->clock(), state, renegade_adpcm_callback); state->base = machine->region("adpcm")->base(); state->adpcm.reset(); } diff --git a/src/mame/drivers/segahang.c b/src/mame/drivers/segahang.c index f56a8254f92..a6bb33bbbd5 100644 --- a/src/mame/drivers/segahang.c +++ b/src/mame/drivers/segahang.c @@ -327,7 +327,7 @@ static WRITE8_DEVICE_HANDLER( tilemap_sound_w ) cpu_set_input_line(state->soundcpu, INPUT_LINE_NMI, (data & 0x80) ? CLEAR_LINE : ASSERT_LINE); segaic16_tilemap_set_colscroll(device->machine, 0, ~data & 0x04); segaic16_tilemap_set_rowscroll(device->machine, 0, ~data & 0x02); - sound_global_enable(device->machine, data & 0x01); + device->machine->sound().system_enable(data & 0x01); } diff --git a/src/mame/drivers/segaorun.c b/src/mame/drivers/segaorun.c index ace01671ba0..cf35776dc18 100644 --- a/src/mame/drivers/segaorun.c +++ b/src/mame/drivers/segaorun.c @@ -699,7 +699,7 @@ static WRITE16_HANDLER( outrun_custom_io_w ) D7: /MUTE D6-D0: unknown */ - sound_global_enable(space->machine, data & 0x80); + space->machine->sound().system_enable(data & 0x80); } return; diff --git a/src/mame/drivers/segaxbd.c b/src/mame/drivers/segaxbd.c index 2596886a14c..117a98a1db4 100644 --- a/src/mame/drivers/segaxbd.c +++ b/src/mame/drivers/segaxbd.c @@ -571,7 +571,7 @@ static WRITE16_HANDLER( iochip_0_w ) D7: Amplifier mute control (1= sounding, 0= muted) D6-D0: CN D pin A17-A23 (output level 1= high, 0= low) */ - sound_global_enable(space->machine, data & 0x80); + space->machine->sound().system_enable(data & 0x80); return; } @@ -661,7 +661,7 @@ static WRITE16_HANDLER( aburner2_iochip_0_D_w ) coin_counter_w(space->machine, 0, (data >> 4) & 0x01); output_set_lamp_value(0, (data >> 5) & 0x01); /* lock on lamp */ output_set_lamp_value(1, (data >> 6) & 0x01); /* danger lamp */ - sound_global_enable(space->machine, (data >> 7) & 0x01); + space->machine->sound().system_enable((data >> 7) & 0x01); } diff --git a/src/mame/drivers/segaybd.c b/src/mame/drivers/segaybd.c index 6cd5c09a3c1..febd9dae1e0 100644 --- a/src/mame/drivers/segaybd.c +++ b/src/mame/drivers/segaybd.c @@ -368,7 +368,7 @@ static WRITE16_HANDLER( io_chip_w ) /* D7 = /MUTE */ /* D6-D0 = FLT31-25 */ - sound_global_enable(space->machine, data & 0x80); + space->machine->sound().system_enable(data & 0x80); break; /* CNT register */ diff --git a/src/mame/drivers/system1.c b/src/mame/drivers/system1.c index a79582a597a..15d7b9958c7 100644 --- a/src/mame/drivers/system1.c +++ b/src/mame/drivers/system1.c @@ -471,7 +471,7 @@ static void dakkochn_custom_w(running_machine *machine, UINT8 data, UINT8 prevda static WRITE8_DEVICE_HANDLER( sound_control_w ) { /* bit 0 = MUTE (inverted sense on System 2) */ - sound_global_enable(device->machine, ~(data ^ mute_xor) & 1); + device->machine->sound().system_mute((data ^ mute_xor) & 1); /* bit 6 = feedback from sound board that read occurrred */ diff --git a/src/mame/drivers/taito_b.c b/src/mame/drivers/taito_b.c index b512c3ea250..f74220ff8b9 100644 --- a/src/mame/drivers/taito_b.c +++ b/src/mame/drivers/taito_b.c @@ -2130,9 +2130,11 @@ static void mb87078_gain_changed( running_machine *machine, int channel, int per if (channel == 1) { - sound_set_output_gain(state->ym, 0, percent / 100.0); - sound_set_output_gain(state->ym, 1, percent / 100.0); - sound_set_output_gain(state->ym, 2, percent / 100.0); + device_sound_interface *sound; + state->ym->interface(sound); + sound->set_output_gain(0, percent / 100.0); + sound->set_output_gain(1, percent / 100.0); + sound->set_output_gain(2, percent / 100.0); //popmessage("MB87078 gain ch#%i percent=%i", channel, percent); } } diff --git a/src/mame/drivers/taito_l.c b/src/mame/drivers/taito_l.c index 0def398ddec..5c52273b644 100644 --- a/src/mame/drivers/taito_l.c +++ b/src/mame/drivers/taito_l.c @@ -658,7 +658,9 @@ static WRITE8_DEVICE_HANDLER( champwr_msm5205_stop_w ) static WRITE8_DEVICE_HANDLER( champwr_msm5205_volume_w ) { - sound_set_output_gain(device, 0, data / 255.0); + device_sound_interface *sound; + device->interface(sound); + sound->set_output_gain(0, data / 255.0); } static READ8_HANDLER( horshoes_tracky_reset_r ) diff --git a/src/mame/drivers/thepit.c b/src/mame/drivers/thepit.c index fe13cf63fce..e8ba296fae8 100644 --- a/src/mame/drivers/thepit.c +++ b/src/mame/drivers/thepit.c @@ -142,7 +142,7 @@ static READ8_HANDLER( thepit_colorram_r ) static WRITE8_HANDLER( thepit_sound_enable_w ) { - sound_global_enable(space->machine, data); + space->machine->sound().system_enable(data); } diff --git a/src/mame/drivers/tutankhm.c b/src/mame/drivers/tutankhm.c index 0b5ff975f59..5220a1ba564 100644 --- a/src/mame/drivers/tutankhm.c +++ b/src/mame/drivers/tutankhm.c @@ -102,7 +102,7 @@ static WRITE8_HANDLER( tutankhm_bankselect_w ) static WRITE8_HANDLER( sound_mute_w ) { - sound_global_enable(space->machine, ~data & 1); + space->machine->sound().system_mute(data & 1); } diff --git a/src/mame/drivers/uapce.c b/src/mame/drivers/uapce.c index 05dc81fee88..2a1acb78eda 100644 --- a/src/mame/drivers/uapce.c +++ b/src/mame/drivers/uapce.c @@ -38,7 +38,7 @@ static WRITE8_HANDLER( jamma_if_control_latch_w ) UINT8 diff = data ^ jamma_if_control_latch; jamma_if_control_latch = data; - sound_global_enable( space->machine, (data >> 7) & 1 ); + space->machine->sound().system_enable( (data >> 7) & 1 ); if ( diff & 0x40 ) { diff --git a/src/mame/drivers/warriorb.c b/src/mame/drivers/warriorb.c index 7ae94bc3ee1..02723248521 100644 --- a/src/mame/drivers/warriorb.c +++ b/src/mame/drivers/warriorb.c @@ -568,7 +568,7 @@ static MACHINE_RESET( taito_dualscreen ) state->banknum = 0; /**** mixer control enable ****/ - sound_global_enable(machine, 1); /* mixer enabled */ + machine->sound().system_enable(true); /* mixer enabled */ } static MACHINE_CONFIG_START( darius2d, warriorb_state ) diff --git a/src/mame/includes/cps1.h b/src/mame/includes/cps1.h index 5fae066a9d5..a459e8659c4 100644 --- a/src/mame/includes/cps1.h +++ b/src/mame/includes/cps1.h @@ -1,6 +1,8 @@ #ifndef _CPS1_H_ #define _CPS1_H_ +#include "sound/msm5205.h" + struct gfx_range { // start and end are as passed by the game (shift adjusted to be all @@ -129,8 +131,8 @@ public: /* devices */ device_t *maincpu; device_t *audiocpu; - device_t *msm_1; // fcrash - device_t *msm_2; // fcrash + msm5205_device *msm_1; // fcrash + msm5205_device *msm_2; // fcrash }; /*----------- defined in drivers/cps1.c -----------*/ diff --git a/src/mame/includes/equites.h b/src/mame/includes/equites.h index e3e08f5fd87..8196364eb57 100644 --- a/src/mame/includes/equites.h +++ b/src/mame/includes/equites.h @@ -1,4 +1,6 @@ +#include "sound/msm5232.h" + #define POPDRUMKIT 0 @@ -39,7 +41,7 @@ public: /* devices */ device_t *mcu; device_t *audio_cpu; - device_t *msm; + msm5232_device *msm; device_t *dac_1; device_t *dac_2; }; diff --git a/src/mame/includes/snes.h b/src/mame/includes/snes.h index d42eaa0ce96..1f67028a1ed 100644 --- a/src/mame/includes/snes.h +++ b/src/mame/includes/snes.h @@ -3,7 +3,6 @@ #include "devlegcy.h" #include "devcb.h" -#include "streams.h" #include "cpu/spc700/spc700.h" #include "cpu/g65816/g65816.h" #include "cpu/upd7725/upd7725.h" diff --git a/src/mame/machine/atarigen.c b/src/mame/machine/atarigen.c index eab0181dadb..4322959fc14 100644 --- a/src/mame/machine/atarigen.c +++ b/src/mame/machine/atarigen.c @@ -840,7 +840,7 @@ void atarigen_set_vol(running_machine *machine, int volume, device_type type) device_sound_interface *sound = NULL; for (bool gotone = machine->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) if (sound->device().type() == type) - sound_set_output_gain(*sound, ALL_OUTPUTS, volume / 100.0); + sound->set_output_gain(ALL_OUTPUTS, volume / 100.0); } diff --git a/src/mame/machine/balsente.c b/src/mame/machine/balsente.c index ea1fe7184af..81853e917c4 100644 --- a/src/mame/machine/balsente.c +++ b/src/mame/machine/balsente.c @@ -974,7 +974,7 @@ WRITE8_HANDLER( balsente_counter_control_w ) { int ch; for (ch = 0; ch < 6; ch++) - sound_set_output_gain(state->cem_device[ch], 0, (data & 0x01) ? 1.0 : 0); + state->cem_device[ch]->set_output_gain(0, (data & 0x01) ? 1.0 : 0); } /* bit D1 is hooked to counter 0's gate */ diff --git a/src/mame/machine/n64.c b/src/mame/machine/n64.c index cbb0ac1ae65..847164325e7 100644 --- a/src/mame/machine/n64.c +++ b/src/mame/machine/n64.c @@ -3,7 +3,6 @@ #include "emu.h" #include "cpu/mips/mips3.h" #include "cpu/mips/mips3com.h" -#include "streams.h" #include "includes/n64.h" #include "sound/dmadac.h" #include "profiler.h" diff --git a/src/mame/video/bking.c b/src/mame/video/bking.c index 99d0746b5ad..e78cb3c3010 100644 --- a/src/mame/video/bking.c +++ b/src/mame/video/bking.c @@ -172,7 +172,7 @@ WRITE8_HANDLER( bking_cont3_w ) state->palette_bank = (data >> 1) & 0x03; - sound_global_enable(space->machine, ~data & 0x08); + space->machine->sound().system_mute(data & 0x08); } diff --git a/src/mame/video/dday.c b/src/mame/video/dday.c index 9b4c895e062..e4a119fcb20 100644 --- a/src/mame/video/dday.c +++ b/src/mame/video/dday.c @@ -301,7 +301,7 @@ WRITE8_HANDLER( dday_control_w ) if (!(data & 0x10) && (state->control & 0x10)) state->ay1->reset(); - sound_global_enable(space->machine, data & 0x10); + space->machine->sound().system_enable(data & 0x10); /* bit 6 is search light enable */ state->sl_enable = data & 0x40;