summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/sound/flt_rc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/sound/flt_rc.c')
-rw-r--r--src/emu/sound/flt_rc.c145
1 files changed, 59 insertions, 86 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");
-}