nes_apu.cpp: Correct noise algorithm

This commit is contained in:
cam900 2020-05-30 23:28:04 +09:00
parent cddd9181b0
commit 9310d2cac8
3 changed files with 6 additions and 40 deletions

View File

@ -22,7 +22,7 @@
*****************************************************************************
NES_APU.C
NES_APU.CPP
Actual NES APU interface.
@ -81,23 +81,6 @@ void nesapu_device::create_syncs(unsigned long sps)
}
}
/* INITIALIZE NOISE LOOKUP TABLE */
static void create_noise(u8 *buf, const int bits, int size)
{
int m = 0x0011;
int xor_val, i;
for (i = 0; i < size; i++)
{
xor_val = m & 1;
m >>= 1;
xor_val ^= (m & 1);
m |= xor_val << (bits - 1);
buf[i] = m;
}
}
DEFINE_DEVICE_TYPE(NES_APU, nesapu_device, "nesapu", "N2A03 APU")
nesapu_device::nesapu_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
@ -109,11 +92,6 @@ nesapu_device::nesapu_device(const machine_config &mconfig, const char *tag, dev
, m_irq_handler(*this)
, m_mem_read_cb(*this)
{
for (auto & elem : m_noise_lut)
{
elem = 0;
}
for (auto & elem : m_vbl_times)
{
elem = 0;
@ -169,8 +147,6 @@ void nesapu_device::device_start()
m_irq_handler.resolve_safe();
m_mem_read_cb.resolve_safe(0x00);
create_noise(m_noise_lut, 13, apu_t::NOISE_LONG);
calculate_rates();
/* register for save */
@ -199,7 +175,7 @@ void nesapu_device::device_start()
save_item(NAME(m_APU.tri.enabled));
save_item(NAME(m_APU.noi.regs));
save_item(NAME(m_APU.noi.cur_pos));
save_item(NAME(m_APU.noi.seed));
save_item(NAME(m_APU.noi.vbl_length));
save_item(NAME(m_APU.noi.phaseacc));
save_item(NAME(m_APU.noi.output_vol));
@ -409,12 +385,7 @@ s8 nesapu_device::apu_noise(apu_t::noise_t *chan)
while (chan->phaseacc < 0)
{
chan->phaseacc += freq;
chan->cur_pos++;
if (apu_t::NOISE_SHORT == chan->cur_pos && (chan->regs[2] & 0x80))
chan->cur_pos = 0;
else if (apu_t::NOISE_LONG == chan->cur_pos)
chan->cur_pos = 0;
chan->seed = (chan->seed >> 1) | ((BIT(chan->seed, 0) ^ BIT(chan->seed, (chan->regs[2] & 0x80) ? 6 : 1)) << 14);
}
if (chan->regs[0] & 0x10) /* fixed volume */
@ -422,11 +393,11 @@ s8 nesapu_device::apu_noise(apu_t::noise_t *chan)
else
outvol = 0x0F - chan->env_vol;
output = m_noise_lut[chan->cur_pos];
output = chan->seed & 0xff;
if (output > outvol)
output = outvol;
if (m_noise_lut[chan->cur_pos] & 0x80) /* make it negative */
if (chan->seed & 0x80) /* make it negative */
output = -output;
return (s8) output;

View File

@ -71,7 +71,6 @@ private:
apu_t m_APU; /* Actual APUs */
u32 m_samps_per_sync; /* Number of samples per vsync */
u32 m_buffer_size; /* Actual buffer size in bytes */
u8 m_noise_lut[apu_t::NOISE_LONG]; /* Noise sample lookup table */
u32 m_vbl_times[0x20]; /* VBL durations in samples */
u32 m_sync_times1[SYNCS_MAX1]; /* Samples per sync table */
u32 m_sync_times2[SYNCS_MAX2]; /* Samples per sync table */

View File

@ -94,7 +94,7 @@ struct apu_t
}
uint8 regs[4]; /* regs[1] unused */
int cur_pos = 0;
u32 seed = 1;
int vbl_length = 0;
float phaseacc = 0.0;
float output_vol = 0.0;
@ -147,10 +147,6 @@ struct apu_t
static constexpr unsigned SMASK = 0x15;
static constexpr unsigned IRQCTRL = 0x17;
static constexpr unsigned NOISE_LONG = 0x4000;
static constexpr unsigned NOISE_SHORT = 93;
apu_t()
{
memset(regs, 0, sizeof(regs));