Update Pole Position sound to use new Namco sound cores and add filtering support

This commit is contained in:
arcadez2003 2024-08-17 19:28:19 +01:00 committed by GitHub
parent 1e1aee8b01
commit e8f7ade377
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,6 +3,7 @@
Sound handler
****************************************************************************/
#include "driver.h"
#include "../sound/filter.h"
static int sample_msb = 0;
static int sample_lsb = 0;
@ -10,13 +11,30 @@ static int sample_enable = 0;
static int sound_stream;
#define AMP(r) (r*128/10100)
static int volume_table[8] =
#define POLEPOS_R166 1000.0
#define POLEPOS_R167 2200.0
#define POLEPOS_R168 4700.0
/* resistor values when shorted by 4066 running at 5V */
#define POLEPOS_R166_SHUNT 1.0/(1.0/POLEPOS_R166 + 1.0/250)
#define POLEPOS_R167_SHUNT 1.0/(1.0/POLEPOS_R166 + 1.0/250)
#define POLEPOS_R168_SHUNT 1.0/(1.0/POLEPOS_R166 + 1.0/250)
static double volume_table[8] =
{
AMP(2200), AMP(3200), AMP(4400), AMP(5400),
AMP(6900), AMP(7900), AMP(9100), AMP(10100)
(POLEPOS_R168_SHUNT + POLEPOS_R167_SHUNT + POLEPOS_R166_SHUNT + 2200) / 10000,
(POLEPOS_R168_SHUNT + POLEPOS_R167_SHUNT + POLEPOS_R166 + 2200) / 10000,
(POLEPOS_R168_SHUNT + POLEPOS_R167 + POLEPOS_R166_SHUNT + 2200) / 10000,
(POLEPOS_R168_SHUNT + POLEPOS_R167 + POLEPOS_R166 + 2200) / 10000,
(POLEPOS_R168 + POLEPOS_R167_SHUNT + POLEPOS_R166_SHUNT + 2200) / 10000,
(POLEPOS_R168 + POLEPOS_R167_SHUNT + POLEPOS_R166 + 2200) / 10000,
(POLEPOS_R168 + POLEPOS_R167 + POLEPOS_R166_SHUNT + 2200) / 10000,
(POLEPOS_R168 + POLEPOS_R167 + POLEPOS_R166 + 2200) / 10000
};
static struct filter2_context filter_engine[3];
static double r_filt_out[3] = {RES_K(4.7), RES_K(7.5), RES_K(10)};
static double r_filt_total = 1.0 / (1.0/RES_K(4.7) + 1.0/RES_K(7.5) + 1.0/RES_K(10));
/************************************/
/* Stream updater */
@ -24,9 +42,10 @@ static int volume_table[8] =
static void engine_sound_update(int num, INT16 *buffer, int length)
{
static UINT32 current_position;
UINT32 step, clock, slot, volume;
UINT32 step, clock, slot;
UINT8 *base;
double volume, i_total;
int loop;
/* if we're not enabled, just fill with 0 */
if (!sample_enable || Machine->sample_rate == 0)
@ -47,7 +66,24 @@ static void engine_sound_update(int num, INT16 *buffer, int length)
/* fill in the sample */
while (length--)
{
*buffer++ = (base[(current_position >> 12) & 0x7ff] * volume);
filter_engine[0].x0 = (3.4 / 255 * base[(current_position >> 12) & 0x7ff] - 2) * volume;
filter_engine[1].x0 = filter_engine[0].x0;
filter_engine[2].x0 = filter_engine[0].x0;
i_total = 0;
for (loop = 0; loop < 3; loop++)
{
filter2_step(&filter_engine[loop]);
/* The op-amp powered @ 5V will clip to 0V & 3.5V.
* Adjusted to vRef of 2V, we will clip as follows: */
if (filter_engine[loop].y0 > 1.5) filter_engine[loop].y0 = 1.5;
if (filter_engine[loop].y0 < -2) filter_engine[loop].y0 = -2;
i_total += filter_engine[loop].y0 / r_filt_out[loop];
}
i_total *= r_filt_total * 32000/2; /* now contains voltage adjusted by final gain */
*buffer++ = (int)i_total;
current_position += step;
}
}
@ -57,10 +93,30 @@ static void engine_sound_update(int num, INT16 *buffer, int length)
/************************************/
int polepos_sh_start(const struct MachineSound *msound)
{
sound_stream = stream_init("Engine Sound", 25, Machine->sample_rate, 0, engine_sound_update);
sound_stream = stream_init("Engine Sound", 77, Machine->sample_rate, 0, engine_sound_update);
sample_msb = sample_lsb = 0;
sample_enable = 0;
return 0;
/* setup the filters */
filter_opamp_m_bandpass_setup(RES_K(220), RES_K(33), RES_K(390), CAP_U(.01), CAP_U(.01),
&filter_engine[0]);
filter_opamp_m_bandpass_setup(RES_K(150), RES_K(22), RES_K(330), CAP_U(.0047), CAP_U(.0047),
&filter_engine[1]);
/* Filter 3 is a little different. Because of the input capacitor, it is
* a high pass filter. */
filter2_setup(FILTER_HIGHPASS, 950, Q_TO_DAMP(.707), 1,
&filter_engine[2]);
return 0;
}
/************************************/
/* Sound handler reset */
/************************************/
void polepos_sh_reset(void)
{
int loop;
for (loop = 0; loop < 3; loop++) filter2_reset(&filter_engine[loop]);
}
/************************************/
@ -75,6 +131,7 @@ void polepos_sh_stop(void)
/************************************/
WRITE_HANDLER( polepos_engine_sound_lsb_w )
{
/* Update stream first so all samples at old frequency are updated. */
stream_update(sound_stream, 0);
sample_lsb = data & 62;
sample_enable = data & 1;