mame/src/emu/sound/flt_vol.c
Aaron Giles 2ad5072023 BIG update.
Remove redundant machine items from address_space and device_t.
Neither machine nor m_machine are directly accessible anymore.
Instead a new getter machine() is available which returns a
machine reference. So:

  space->machine->xxx   ==>  space->machine().xxx
  device->machine->yyy  ==>  device->machine().yyy

Globally changed all running_machine pointers to running_machine
references. Any function/method that takes a running_machine takes
it as a required parameter (1 or 2 exceptions). Being consistent
here gets rid of a lot of odd &machine or *machine, but it does
mean a very large bulk change across the project.

Structs which have a running_machine * now have that variable
renamed to m_machine, and now have a shiny new machine() method
that works like the space and device methods above. Since most of
these are things that should eventually be devices anyway, consider
this a step in that direction.

98% of the update was done with regex searches. The changes are
architected such that the compiler will catch the remaining
errors:

// find things that use an embedded machine directly and replace
// with a machine() getter call
S: ->machine->
R: ->machine\(\)\.

// do the same if via a reference
S: \.machine->
R: \.machine\(\)\.

// convert function parameters to running_machine &
S: running_machine \*machine([^;])
R: running_machine \&machine\1

// replace machine-> with machine.
S: machine->
R: machine\.

// replace &machine() with machine()
S: \&([()->a-z0-9_]+machine\(\))
R: \1

// sanity check: look for this used as a cast
(running_machine &)
// and change to this:
*(running_machine *)
2011-03-29 15:50:04 +00:00

76 lines
2.2 KiB
C

#include "emu.h"
#include "flt_vol.h"
typedef struct _filter_volume_state filter_volume_state;
struct _filter_volume_state
{
sound_stream * stream;
int gain;
};
INLINE filter_volume_state *get_safe_token(device_t *device)
{
assert(device != NULL);
assert(device->type() == FILTER_VOLUME);
return (filter_volume_state *)downcast<legacy_device_base *>(device)->token();
}
static STREAM_UPDATE( filter_volume_update )
{
stream_sample_t *src = inputs[0];
stream_sample_t *dst = outputs[0];
filter_volume_state *info = (filter_volume_state *)param;
while (samples--)
*dst++ = (*src++ * info->gain) >> 8;
}
static DEVICE_START( filter_volume )
{
filter_volume_state *info = get_safe_token(device);
info->gain = 0x100;
info->stream = device->machine().sound().stream_alloc(*device, 1, 1, device->machine().sample_rate(), info, filter_volume_update);
}
void flt_volume_set_volume(device_t *device, float volume)
{
filter_volume_state *info = get_safe_token(device);
info->gain = (int)(volume * 256);
}
/**************************************************************************
* Generic get_info
**************************************************************************/
DEVICE_GET_INFO( filter_volume )
{
switch (state)
{
/* --- the following bits of info are returned as 64-bit signed integers --- */
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(filter_volume_state); break;
/* --- the following bits of info are returned as pointers to data or functions --- */
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( filter_volume ); break;
case DEVINFO_FCT_STOP: /* Nothing */ break;
case DEVINFO_FCT_RESET: /* Nothing */ break;
/* --- the following bits of info are returned as NULL-terminated strings --- */
case DEVINFO_STR_NAME: strcpy(info->s, "Volume Filter"); break;
case DEVINFO_STR_FAMILY: strcpy(info->s, "Filters"); break;
case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break;
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;
}
}
DEFINE_LEGACY_SOUND_DEVICE(FILTER_VOLUME, filter_volume);