From c11c22b3e83bdf7ac8d48f0a8e3be48ba31786f8 Mon Sep 17 00:00:00 2001 From: Lord-Nightmare Date: Wed, 25 Jan 2017 05:45:25 -0500 Subject: [PATCH] saa1099.cpp: Use the correct LFSR polynomial for the SAA1099 noise generation, and add some notes about an unemulated undocumented feature of the noise clock. [Jepael, Lord Nightmare] --- src/devices/sound/saa1099.cpp | 8 +++++--- src/devices/sound/saa1099.h | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/devices/sound/saa1099.cpp b/src/devices/sound/saa1099.cpp index 4ea28c6adcf..b43103ca73c 100644 --- a/src/devices/sound/saa1099.cpp +++ b/src/devices/sound/saa1099.cpp @@ -221,7 +221,7 @@ void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t * case 0: m_noise[ch].freq = m_master_clock/256.0 * 2; break; case 1: m_noise[ch].freq = m_master_clock/512.0 * 2; break; case 2: m_noise[ch].freq = m_master_clock/1024.0 * 2; break; - case 3: m_noise[ch].freq = m_channels[ch * 3].freq; break; + case 3: m_noise[ch].freq = m_channels[ch * 3].freq; break; // todo: this case will be m_master_clock/[ch*3's octave divisor, 0 is = 256*2, higher numbers are higher] * 2 if the tone generator phase reset bit (0x1c bit 1) is set. } } @@ -280,12 +280,14 @@ void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t * for (ch = 0; ch < 2; ch++) { - /* check the actual position in noise generator */ + /* update the state of the noise generator + * polynomial is x^18 + x^11 + x (i.e. 0x20400) and is a plain XOR, initial state is probably all 1s + * see http://www.vogons.org/viewtopic.php?f=9&t=51695 */ m_noise[ch].counter -= m_noise[ch].freq; while (m_noise[ch].counter < 0) { m_noise[ch].counter += m_sample_rate; - if( ((m_noise[ch].level & 0x4000) == 0) == ((m_noise[ch].level & 0x0040) == 0) ) + if( ((m_noise[ch].level & 0x20000) == 0) != ((m_noise[ch].level & 0x0400) == 0) ) m_noise[ch].level = (m_noise[ch].level << 1) | 1; else m_noise[ch].level <<= 1; diff --git a/src/devices/sound/saa1099.h b/src/devices/sound/saa1099.h index 58b29c58989..6863bd73e76 100644 --- a/src/devices/sound/saa1099.h +++ b/src/devices/sound/saa1099.h @@ -56,12 +56,12 @@ struct saa1099_noise saa1099_noise() : counter(0.0), freq(0.0), - level(0) {} + level(0xFFFFFFFF) {} /* vars to simulate the noise generator output */ double counter; double freq; - int level; /* noise polynomial shifter */ + uint32_t level; /* noise polynomial shifter */ };