summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/sound
diff options
context:
space:
mode:
author Andrew Gardner <andrew-gardner@users.noreply.github.com>2013-01-31 15:46:45 +0000
committer Andrew Gardner <andrew-gardner@users.noreply.github.com>2013-01-31 15:46:45 +0000
commit0068d9316da7da20b4dbe168e4986c3dc765600e (patch)
treee3ca101ee56c309c396f642b1b3afddca8251740 /src/emu/sound
parentdaea35e7d56d3236188e36d4112ee1a8bf4b0cb3 (diff)
Modernize the Volume and RC filter sound devices. [Andrew Gardner]
Diffstat (limited to 'src/emu/sound')
-rw-r--r--src/emu/sound/flt_rc.c145
-rw-r--r--src/emu/sound/flt_rc.h47
-rw-r--r--src/emu/sound/flt_vol.c79
-rw-r--r--src/emu/sound/flt_vol.h31
4 files changed, 138 insertions, 164 deletions
diff --git a/src/emu/sound/flt_rc.c b/src/emu/sound/flt_rc.c
index f4c059b9811..7d026a65253 100644
--- a/src/emu/sound/flt_rc.c
+++ b/src/emu/sound/flt_rc.c
@@ -1,38 +1,65 @@
#include "emu.h"
#include "flt_rc.h"
-struct filter_rc_state
+
+const flt_rc_config flt_rc_ac_default = {FLT_RC_AC, 10000, 0, 0, CAP_U(1)};
+
+
+// device type definition
+const device_type FILTER_RC = &device_creator<filter_rc_device>;
+
+
+//**************************************************************************
+// LIVE DEVICE
+//**************************************************************************
+
+//-------------------------------------------------
+// qsound_device - constructor
+//-------------------------------------------------
+
+filter_rc_device::filter_rc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
+ : device_t(mconfig, FILTER_RC, "RC Filter", tag, owner, clock),
+ device_sound_interface(mconfig, *this),
+ m_stream(NULL),
+ m_k(0),
+ m_memory(0),
+ m_type(0)
{
- device_t *device;
- sound_stream * stream;
- int k;
- int memory;
- int type;
-};
-
-INLINE filter_rc_state *get_safe_token(device_t *device)
+}
+
+
+//-------------------------------------------------
+// device_start - device-specific startup
+//-------------------------------------------------
+
+void filter_rc_device::device_start()
{
- assert(device != NULL);
- assert(device->type() == FILTER_RC);
- return (filter_rc_state *)downcast<filter_rc_device *>(device)->token();
+ const flt_rc_config *conf = (const flt_rc_config *)static_config();
+
+ m_stream = stream_alloc(1, 1, machine().sample_rate());
+ if (conf)
+ set_RC_info(conf->type, conf->R1, conf->R2, conf->R3, conf->C);
+ else
+ set_RC_info(FLT_RC_LOWPASS, 1, 1, 1, 0);
}
-const flt_rc_config flt_rc_ac_default = {FLT_RC_AC, 10000, 0, 0, CAP_U(1)};
+//-------------------------------------------------
+// sound_stream_update - handle a stream update
+//-------------------------------------------------
-static STREAM_UPDATE( filter_rc_update )
+void filter_rc_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
stream_sample_t *src = inputs[0];
stream_sample_t *dst = outputs[0];
- filter_rc_state *info = (filter_rc_state *)param;
- int memory = info->memory;
+ int memory = m_memory;
- switch (info->type)
+ switch (m_type)
{
case FLT_RC_LOWPASS:
while (samples--)
{
- memory += ((*src++ - memory) * info->k) / 0x10000;
+ memory += ((*src++ - memory) * m_k) / 0x10000;
*dst++ = memory;
}
break;
@@ -41,26 +68,27 @@ static STREAM_UPDATE( filter_rc_update )
while (samples--)
{
*dst++ = *src - memory;
- memory += ((*src++ - memory) * info->k) / 0x10000;
+ memory += ((*src++ - memory) * m_k) / 0x10000;
}
break;
}
- info->memory = memory;
+ m_memory = memory;
}
-static void set_RC_info(filter_rc_state *info, int type, double R1, double R2, double R3, double C)
+
+void filter_rc_device::set_RC_info(int type, double R1, double R2, double R3, double C)
{
double Req;
- info->type = type;
+ m_type = type;
- switch (info->type)
+ switch (m_type)
{
case FLT_RC_LOWPASS:
if (C == 0.0)
{
/* filter disabled */
- info->k = 0x10000;
+ m_k = 0x10000;
return;
}
Req = (R1 * (R2 + R3)) / (R1 + R2 + R3);
@@ -70,80 +98,25 @@ static void set_RC_info(filter_rc_state *info, int type, double R1, double R2, d
if (C == 0.0)
{
/* filter disabled */
- info->k = 0x0;
- info->memory = 0x0;
+ m_k = 0x0;
+ m_memory = 0x0;
return;
}
Req = R1;
break;
default:
- fatalerror("filter_rc_setRC: Wrong filter type %d\n", info->type);
+ fatalerror("filter_rc_setRC: Wrong filter type %d\n", m_type);
}
/* Cut Frequency = 1/(2*Pi*Req*C) */
/* k = (1-(EXP(-TIMEDELTA/RC))) */
- info->k = 0x10000 - 0x10000 * (exp(-1 / (Req * C) / info->device->machine().sample_rate()));
-}
-
-
-static DEVICE_START( filter_rc )
-{
- filter_rc_state *info = get_safe_token(device);
- const flt_rc_config *conf = (const flt_rc_config *)device->static_config();
-
- info->device = device;
- 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
- set_RC_info(info, FLT_RC_LOWPASS, 1, 1, 1, 0);
-}
-
-
-void filter_rc_set_RC(device_t *device, int type, double R1, double R2, double R3, double C)
-{
- filter_rc_state *info = get_safe_token(device);
-
- info->stream->update();
-
- set_RC_info(info, type, R1, R2, R3, C);
-
-}
-
-const device_type FILTER_RC = &device_creator<filter_rc_device>;
-
-filter_rc_device::filter_rc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
- : device_t(mconfig, FILTER_RC, "RC Filter", tag, owner, clock),
- device_sound_interface(mconfig, *this)
-{
- m_token = global_alloc_clear(filter_rc_state);
+ m_k = 0x10000 - 0x10000 * (exp(-1 / (Req * C) / machine().sample_rate()));
}
-//-------------------------------------------------
-// device_config_complete - perform any
-// operations now that the configuration is
-// complete
-//-------------------------------------------------
-void filter_rc_device::device_config_complete()
+void filter_rc_device::filter_rc_set_RC(int type, double R1, double R2, double R3, double C)
{
+ m_stream->update();
+ set_RC_info(type, R1, R2, R3, C);
}
-//-------------------------------------------------
-// device_start - device-specific startup
-//-------------------------------------------------
-
-void filter_rc_device::device_start()
-{
- DEVICE_START_NAME( filter_rc )(this);
-}
-
-//-------------------------------------------------
-// sound_stream_update - handle a stream update
-//-------------------------------------------------
-
-void filter_rc_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
-{
- // should never get here
- fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
-}
diff --git a/src/emu/sound/flt_rc.h b/src/emu/sound/flt_rc.h
index 7e321d3fd61..aeb18716632 100644
--- a/src/emu/sound/flt_rc.h
+++ b/src/emu/sound/flt_rc.h
@@ -1,14 +1,9 @@
#pragma once
#ifndef __FLT_RC_H__
-#define FLT_RC_H
+#define __FLT_RC_H__
#include "machine/rescap.h"
-#include "devlegcy.h"
-
-#define FLT_RC_LOWPASS 0
-#define FLT_RC_HIGHPASS 1
-#define FLT_RC_AC 2
/*
* FLT_RC_LOWPASS:
@@ -45,6 +40,24 @@
*
*/
+//**************************************************************************
+// INTERFACE CONFIGURATION MACROS
+//**************************************************************************
+
+#define MCFG_FILTER_RC_ADD(_tag, _clock) \
+ MCFG_DEVICE_ADD(_tag, FILTER_RC, _clock)
+#define MCFG_FILTER_RC_REPLACE(_tag, _clock) \
+ MCFG_DEVICE_REPLACE(_tag, FILTER_RC, _clock)
+
+
+//**************************************************************************
+// TYPE DEFINITIONS
+//**************************************************************************
+
+#define FLT_RC_LOWPASS 0
+#define FLT_RC_HIGHPASS 1
+#define FLT_RC_AC 2
+
struct flt_rc_config
{
int type;
@@ -56,27 +69,33 @@ struct flt_rc_config
extern const flt_rc_config flt_rc_ac_default;
-void filter_rc_set_RC(device_t *device, int type, double R1, double R2, double R3, double C);
+
+// ======================> filter_rc_device
class filter_rc_device : public device_t,
- public device_sound_interface
+ public device_sound_interface
{
public:
filter_rc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
- ~filter_rc_device() { global_free(m_token); }
+ ~filter_rc_device() { }
+
+ void filter_rc_set_RC(int type, double R1, double R2, double R3, double C);
- // access to legacy token
- void *token() const { assert(m_token != NULL); return m_token; }
protected:
// device-level overrides
- virtual void device_config_complete();
virtual void device_start();
// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
+
+private:
+ void set_RC_info(int type, double R1, double R2, double R3, double C);
+
private:
- // internal state
- void *m_token;
+ sound_stream* m_stream;
+ int m_k;
+ int m_memory;
+ int m_type;
};
extern const device_type FILTER_RC;
diff --git a/src/emu/sound/flt_vol.c b/src/emu/sound/flt_vol.c
index 66a5ee55c30..2532371ecb9 100644
--- a/src/emu/sound/flt_vol.c
+++ b/src/emu/sound/flt_vol.c
@@ -2,81 +2,50 @@
#include "flt_vol.h"
-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<filter_volume_device *>(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);
-}
-
+// device type definition
const device_type FILTER_VOLUME = &device_creator<filter_volume_device>;
-filter_volume_device::filter_volume_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
- : device_t(mconfig, FILTER_VOLUME, "Volume Filter", tag, owner, clock),
- device_sound_interface(mconfig, *this)
-{
- m_token = global_alloc_clear(filter_volume_state);
-}
-
//-------------------------------------------------
-// device_config_complete - perform any
-// operations now that the configuration is
-// complete
+// qsound_device - constructor
//-------------------------------------------------
-void filter_volume_device::device_config_complete()
+filter_volume_device::filter_volume_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
+ : device_t(mconfig, FILTER_VOLUME, "Volume Filter", tag, owner, clock),
+ device_sound_interface(mconfig, *this),
+ m_stream(NULL),
+ m_gain(0)
{
}
+
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void filter_volume_device::device_start()
{
- DEVICE_START_NAME( filter_volume )(this);
+ m_gain = 0x100;
+ m_stream = stream_alloc(1, 1, machine().sample_rate());
}
+
//-------------------------------------------------
// sound_stream_update - handle a stream update
//-------------------------------------------------
void filter_volume_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
- // should never get here
- fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
+ stream_sample_t *src = inputs[0];
+ stream_sample_t *dst = outputs[0];
+
+ while (samples--)
+ *dst++ = (*src++ * m_gain) >> 8;
+}
+
+
+
+void filter_volume_device::flt_volume_set_volume(float volume)
+{
+ m_gain = (int)(volume * 256);
}
+
diff --git a/src/emu/sound/flt_vol.h b/src/emu/sound/flt_vol.h
index 9c7047acf64..7836930247c 100644
--- a/src/emu/sound/flt_vol.h
+++ b/src/emu/sound/flt_vol.h
@@ -3,30 +3,43 @@
#ifndef __FLT_VOL_H__
#define __FLT_VOL_H__
-#include "devlegcy.h"
-void flt_volume_set_volume(device_t *device, float volume);
+//**************************************************************************
+// INTERFACE CONFIGURATION MACROS
+//**************************************************************************
+
+#define MCFG_FILTER_VOLUME_ADD(_tag, _clock) \
+ MCFG_DEVICE_ADD(_tag, FILTER_VOLUME, _clock)
+#define MCFG_FILTER_VOLUME_REPLACE(_tag, _clock) \
+ MCFG_DEVICE_REPLACE(_tag, FILTER_VOLUME, _clock)
+
+
+//**************************************************************************
+// TYPE DEFINITIONS
+//**************************************************************************
+
+// ======================> filter_volume_device
class filter_volume_device : public device_t,
- public device_sound_interface
+ public device_sound_interface
{
public:
filter_volume_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
- ~filter_volume_device() { global_free(m_token); }
+ ~filter_volume_device() { }
+
+ void flt_volume_set_volume(float volume);
- // access to legacy token
- void *token() const { assert(m_token != NULL); return m_token; }
protected:
// device-level overrides
- virtual void device_config_complete();
virtual void device_start();
// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
+
private:
- // internal state
- void *m_token;
+ sound_stream* m_stream;
+ int m_gain;
};
extern const device_type FILTER_VOLUME;