Merge pull request #6856 from cam900/saa1099_freq

saa1099.cpp: Fix output, frequency behavior, Add notes
This commit is contained in:
ajrhacker 2020-07-10 23:19:23 -04:00 committed by GitHub
commit f10dafcbb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 66 deletions

View File

@ -72,12 +72,12 @@ void isa8_gblaster_device::device_add_mconfig(machine_config &config)
{ {
SPEAKER(config, "lspeaker").front_left(); SPEAKER(config, "lspeaker").front_left();
SPEAKER(config, "rspeaker").front_right(); SPEAKER(config, "rspeaker").front_right();
SAA1099(config, m_saa1099_1, 7159090); SAA1099(config, m_saa1099_1, XTAL(14'318'181) / 2); // or CMS-301, from OSC pin in ISA bus
m_saa1099_1->add_route(ALL_OUTPUTS, "lspeaker", 0.50); m_saa1099_1->add_route(0, "lspeaker", 0.50);
m_saa1099_1->add_route(ALL_OUTPUTS, "rspeaker", 0.50); m_saa1099_1->add_route(1, "rspeaker", 0.50);
SAA1099(config, m_saa1099_2, 7159090); SAA1099(config, m_saa1099_2, XTAL(14'318'181) / 2); // or CMS-301, from OSC pin in ISA bus
m_saa1099_2->add_route(ALL_OUTPUTS, "lspeaker", 0.50); m_saa1099_2->add_route(0, "lspeaker", 0.50);
m_saa1099_2->add_route(ALL_OUTPUTS, "rspeaker", 0.50); m_saa1099_2->add_route(1, "rspeaker", 0.50);
} }
//************************************************************************** //**************************************************************************

View File

@ -1171,13 +1171,13 @@ void isa8_sblaster1_0_device::device_add_mconfig(machine_config &config)
m_ym3812->add_route(ALL_OUTPUTS, "lspeaker", 3.0); m_ym3812->add_route(ALL_OUTPUTS, "lspeaker", 3.0);
m_ym3812->add_route(ALL_OUTPUTS, "rspeaker", 3.0); m_ym3812->add_route(ALL_OUTPUTS, "rspeaker", 3.0);
SAA1099(config, m_saa1099_1, 7159090); SAA1099(config, m_saa1099_1, XTAL(14'318'181) / 2); // or CMS-301, from OSC pin in ISA bus
m_saa1099_1->add_route(ALL_OUTPUTS, "lspeaker", 0.5); m_saa1099_1->add_route(0, "lspeaker", 0.5);
m_saa1099_1->add_route(ALL_OUTPUTS, "rspeaker", 0.5); m_saa1099_1->add_route(1, "rspeaker", 0.5);
SAA1099(config, m_saa1099_2, 7159090); SAA1099(config, m_saa1099_2, XTAL(14'318'181) / 2); // or CMS-301, from OSC pin in ISA bus
m_saa1099_2->add_route(ALL_OUTPUTS, "lspeaker", 0.5); m_saa1099_2->add_route(0, "lspeaker", 0.5);
m_saa1099_2->add_route(ALL_OUTPUTS, "rspeaker", 0.5); m_saa1099_2->add_route(1, "rspeaker", 0.5);
} }
void isa8_sblaster1_5_device::device_add_mconfig(machine_config &config) void isa8_sblaster1_5_device::device_add_mconfig(machine_config &config)

View File

@ -70,8 +70,10 @@
#include "emu.h" #include "emu.h"
#include "saa1099.h" #include "saa1099.h"
#define LEFT 0x00 static constexpr int clock_divider = 256;
#define RIGHT 0x01
static constexpr int LEFT = 0x00;
static constexpr int RIGHT = 0x01;
static constexpr u16 amplitude_lookup[16] = { static constexpr u16 amplitude_lookup[16] = {
0*32767/16, 1*32767/16, 2*32767/16, 3*32767/16, 0*32767/16, 1*32767/16, 2*32767/16, 3*32767/16,
@ -123,7 +125,6 @@ static constexpr u8 envelope[8][64] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15 } 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15 }
}; };
// device type definition // device type definition
DEFINE_DEVICE_TYPE(SAA1099, saa1099_device, "saa1099", "Philips SAA1099") DEFINE_DEVICE_TYPE(SAA1099, saa1099_device, "saa1099", "Philips SAA1099")
@ -149,7 +150,6 @@ saa1099_device::saa1099_device(const machine_config &mconfig, const char *tag, d
, m_all_ch_enable(false) , m_all_ch_enable(false)
, m_sync_state(false) , m_sync_state(false)
, m_selected_reg(0) , m_selected_reg(0)
, m_sample_rate(0.0)
{ {
} }
@ -160,11 +160,8 @@ saa1099_device::saa1099_device(const machine_config &mconfig, const char *tag, d
void saa1099_device::device_start() void saa1099_device::device_start()
{ {
/* copy global parameters */
m_sample_rate = clock() / 256;
/* for each chip allocate one stream */ /* for each chip allocate one stream */
m_stream = stream_alloc(0, 2, m_sample_rate); m_stream = stream_alloc(0, 2, clock()/clock_divider);
save_item(NAME(m_noise_params)); save_item(NAME(m_noise_params));
save_item(NAME(m_env_enable)); save_item(NAME(m_env_enable));
@ -184,7 +181,6 @@ void saa1099_device::device_start()
save_item(STRUCT_MEMBER(m_channels, amplitude)); save_item(STRUCT_MEMBER(m_channels, amplitude));
save_item(STRUCT_MEMBER(m_channels, envelope)); save_item(STRUCT_MEMBER(m_channels, envelope));
save_item(STRUCT_MEMBER(m_channels, counter)); save_item(STRUCT_MEMBER(m_channels, counter));
save_item(STRUCT_MEMBER(m_channels, freq));
save_item(STRUCT_MEMBER(m_channels, level)); save_item(STRUCT_MEMBER(m_channels, level));
save_item(STRUCT_MEMBER(m_noise, counter)); save_item(STRUCT_MEMBER(m_noise, counter));
@ -199,9 +195,7 @@ void saa1099_device::device_start()
void saa1099_device::device_clock_changed() void saa1099_device::device_clock_changed()
{ {
m_sample_rate = clock() / 256; m_stream->set_sample_rate(clock()/clock_divider);
m_stream->set_sample_rate(m_sample_rate);
} }
@ -225,10 +219,10 @@ void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t *
{ {
switch (m_noise_params[ch]) switch (m_noise_params[ch])
{ {
case 0: m_noise[ch].freq = clock()/256.0 * 2; break; case 0:
case 1: m_noise[ch].freq = clock()/512.0 * 2; break; case 1:
case 2: m_noise[ch].freq = clock()/1024.0 * 2; break; case 2: m_noise[ch].freq = 256 << m_noise_params[ch]; break;
case 3: m_noise[ch].freq = m_channels[ch * 3].freq; break; // todo: this case will be 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. case 3: m_noise[ch].freq = m_channels[ch * 3].freq(); break; // todo: this case will be 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.
} }
} }
@ -240,19 +234,11 @@ void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t *
/* for each channel */ /* for each channel */
for (ch = 0; ch < 6; ch++) for (ch = 0; ch < 6; ch++)
{ {
if (m_channels[ch].freq == 0.0)
m_channels[ch].freq = (double)((2 * clock() / 512) << m_channels[ch].octave) /
(511.0 - (double)m_channels[ch].frequency);
/* check the actual position in the square wave */ /* check the actual position in the square wave */
m_channels[ch].counter -= m_channels[ch].freq; while (m_channels[ch].counter <= 0)
while (m_channels[ch].counter < 0)
{ {
/* calculate new frequency now after the half wave is updated */ /* calculate new frequency now after the half wave is updated */
m_channels[ch].freq = (double)((2 * clock() / 512) << m_channels[ch].octave) / m_channels[ch].counter += m_channels[ch].freq();
(511.0 - (double)m_channels[ch].frequency);
m_channels[ch].counter += m_sample_rate;
m_channels[ch].level ^= 1; m_channels[ch].level ^= 1;
/* eventually clock the envelope counters */ /* eventually clock the envelope counters */
@ -261,44 +247,42 @@ void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t *
if (ch == 4 && m_env_clock[1] == 0) if (ch == 4 && m_env_clock[1] == 0)
envelope_w(1); envelope_w(1);
} }
m_channels[ch].counter -= clock_divider;
// if the noise is enabled // if the noise is enabled
u8 level = 0;
if (m_channels[ch].noise_enable) if (m_channels[ch].noise_enable)
{ {
// if the noise level is high (noise 0: chan 0-2, noise 1: chan 3-5) // if the noise level is high (noise 0: chan 0-2, noise 1: chan 3-5)
if (m_noise[ch/3].level & 1) level ^= m_noise[ch/3].level & 1;
{
// subtract to avoid overflows, also use only half amplitude
output_l -= m_channels[ch].amplitude[ LEFT] * m_channels[ch].envelope[ LEFT] / 16 / 2;
output_r -= m_channels[ch].amplitude[RIGHT] * m_channels[ch].envelope[RIGHT] / 16 / 2;
}
} }
// if the square wave is enabled // if the square wave is enabled
if (m_channels[ch].freq_enable) if (m_channels[ch].freq_enable)
{ {
// if the channel level is high // if the channel level is high
if (m_channels[ch].level & 1) level ^= m_channels[ch].level & 1;
}
if (level)
{ {
output_l += m_channels[ch].amplitude[ LEFT] * m_channels[ch].envelope[ LEFT] / 16; output_l += m_channels[ch].amplitude[ LEFT] * m_channels[ch].envelope[ LEFT] / 16;
output_r += m_channels[ch].amplitude[RIGHT] * m_channels[ch].envelope[RIGHT] / 16; output_r += m_channels[ch].amplitude[RIGHT] * m_channels[ch].envelope[RIGHT] / 16;
} }
} }
}
for (ch = 0; ch < 2; ch++) for (ch = 0; ch < 2; ch++)
{ {
/* update the state of the 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 * 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 */ * 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)
while (m_noise[ch].counter < 0)
{ {
m_noise[ch].counter += m_sample_rate; m_noise[ch].counter += m_noise[ch].freq; // clock / ((511 - frequency) * 2^(8 - octave)) or clock / 2^(8 + noise period)
if( ((m_noise[ch].level & 0x20000) == 0) != ((m_noise[ch].level & 0x0400) == 0) ) if( ((m_noise[ch].level & 0x20000) == 0) != ((m_noise[ch].level & 0x0400) == 0) )
m_noise[ch].level = (m_noise[ch].level << 1) | 1; m_noise[ch].level = (m_noise[ch].level << 1) | 1;
else else
m_noise[ch].level <<= 1; m_noise[ch].level <<= 1;
} }
m_noise[ch].counter -= clock_divider;
} }
/* write sound data to the buffer */ /* write sound data to the buffer */
outputs[LEFT][j] = output_l / 6; outputs[LEFT][j] = output_l / 6;
@ -434,7 +418,7 @@ void saa1099_device::data_w(u8 data)
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
m_channels[i].level = 0; m_channels[i].level = 0;
m_channels[i].counter = 0.0; m_channels[i].counter = m_channels[i].freq();
} }
} }
break; break;

View File

@ -47,22 +47,19 @@ private:
u8 envelope[2]; // envelope (0x00..0x0f or 0x10 == off) u8 envelope[2]; // envelope (0x00..0x0f or 0x10 == off)
/* vars to simulate the square wave */ /* vars to simulate the square wave */
double counter = 0.0; inline u32 freq() const { return (511 - frequency) << (8 - octave); } // clock / ((511 - frequency) * 2^(8 - octave))
double freq = 0.0; int counter = 0;
u8 level = 0; u8 level = 0;
}; };
struct saa1099_noise struct saa1099_noise
{ {
saa1099_noise() { (void)pad; } saa1099_noise() { }
/* vars to simulate the noise generator output */ /* vars to simulate the noise generator output */
double counter = 0.0; int counter = 0;
double freq = 0.0; int freq = 0;
u32 level = 0xffffffffU; // noise polynomial shifter u32 level = 0xffffffffU; // noise polynomial shifter
private:
u32 pad; // pad out structure to multiple of sizeof(double)
}; };
void envelope_w(int ch); void envelope_w(int ch);
@ -80,7 +77,6 @@ private:
u8 m_selected_reg; // selected register u8 m_selected_reg; // selected register
saa1099_channel m_channels[6]; // channels saa1099_channel m_channels[6]; // channels
saa1099_noise m_noise[2]; // noise generators saa1099_noise m_noise[2]; // noise generators
double m_sample_rate;
}; };
DECLARE_DEVICE_TYPE(SAA1099, saa1099_device) DECLARE_DEVICE_TYPE(SAA1099, saa1099_device)

View File

@ -3932,12 +3932,12 @@ void vgmplay_state::vgmplay(machine_config &config)
m_vsu_vue[1]->add_route(1, m_mixer, 1.0, AUTO_ALLOC_INPUT, 1); m_vsu_vue[1]->add_route(1, m_mixer, 1.0, AUTO_ALLOC_INPUT, 1);
SAA1099(config, m_saa1099[0], 0); SAA1099(config, m_saa1099[0], 0);
m_saa1099[0]->add_route(ALL_OUTPUTS, m_mixer, 0.5, AUTO_ALLOC_INPUT, 0); m_saa1099[0]->add_route(0, m_mixer, 1.0, AUTO_ALLOC_INPUT, 0);
m_saa1099[0]->add_route(ALL_OUTPUTS, m_mixer, 0.5, AUTO_ALLOC_INPUT, 1); m_saa1099[0]->add_route(1, m_mixer, 1.0, AUTO_ALLOC_INPUT, 1);
SAA1099(config, m_saa1099[1], 0); SAA1099(config, m_saa1099[1], 0);
m_saa1099[1]->add_route(ALL_OUTPUTS, m_mixer, 0.5, AUTO_ALLOC_INPUT, 0); m_saa1099[1]->add_route(0, m_mixer, 1.0, AUTO_ALLOC_INPUT, 0);
m_saa1099[1]->add_route(ALL_OUTPUTS, m_mixer, 0.5, AUTO_ALLOC_INPUT, 1); m_saa1099[1]->add_route(1, m_mixer, 1.0, AUTO_ALLOC_INPUT, 1);
ES5503(config, m_es5503[0], 0); ES5503(config, m_es5503[0], 0);
m_es5503[0]->set_channels(2); m_es5503[0]->set_channels(2);
@ -3953,12 +3953,14 @@ void vgmplay_state::vgmplay(machine_config &config)
ES5505(config, m_es5505[0], 0); ES5505(config, m_es5505[0], 0);
// TODO m_es5505[0]->set_addrmap(0, &vgmplay_state::es5505_map<0>); // TODO m_es5505[0]->set_addrmap(0, &vgmplay_state::es5505_map<0>);
// TODO m_es5505[0]->set_addrmap(1, &vgmplay_state::es5505_map<0>);
m_es5505[0]->set_channels(1); m_es5505[0]->set_channels(1);
m_es5505[0]->add_route(0, m_mixer, 0.5, AUTO_ALLOC_INPUT, 0); m_es5505[0]->add_route(0, m_mixer, 0.5, AUTO_ALLOC_INPUT, 0);
m_es5505[0]->add_route(1, m_mixer, 0.5, AUTO_ALLOC_INPUT, 1); m_es5505[0]->add_route(1, m_mixer, 0.5, AUTO_ALLOC_INPUT, 1);
ES5505(config, m_es5505[1], 0); ES5505(config, m_es5505[1], 0);
// TODO m_es5505[1]->set_addrmap(0, &vgmplay_state::es5505_map<1>); // TODO m_es5505[1]->set_addrmap(0, &vgmplay_state::es5505_map<1>);
// TODO m_es5505[1]->set_addrmap(1, &vgmplay_state::es5505_map<1>);
m_es5505[1]->set_channels(1); m_es5505[1]->set_channels(1);
m_es5505[1]->add_route(0, m_mixer, 0.5, AUTO_ALLOC_INPUT, 0); m_es5505[1]->add_route(0, m_mixer, 0.5, AUTO_ALLOC_INPUT, 0);
m_es5505[1]->add_route(1, m_mixer, 0.5, AUTO_ALLOC_INPUT, 1); m_es5505[1]->add_route(1, m_mixer, 0.5, AUTO_ALLOC_INPUT, 1);