summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author cam900 <dbtlrchl@naver.com>2020-06-24 20:00:56 +0900
committer cam900 <dbtlrchl@naver.com>2020-06-24 20:00:56 +0900
commite09782d11ab3837748722800a338bbbef621fd8a (patch)
tree94583b134f51c6406e4f765725f2f903c18180b9
parent8f6dff4521bd1d2e1cf29b84b01172e165b6514a (diff)
saa1099.cpp: Fix output, frequency behavior, Add notes
Reduce unnecessary, unused valutes, Reduce duplicates, macros gblaster.cpp, sblaster.cpp: Fix output, clock inputs, verified from real hardware vgmplay.cpp: Support SAA1099 stereo output, reference: pinout, datasheet
-rw-r--r--src/devices/bus/isa/gblaster.cpp12
-rw-r--r--src/devices/bus/isa/sblaster.cpp12
-rw-r--r--src/devices/sound/saa1099.cpp66
-rw-r--r--src/devices/sound/saa1099.h14
-rw-r--r--src/mame/drivers/vgmplay.cpp10
5 files changed, 48 insertions, 66 deletions
diff --git a/src/devices/bus/isa/gblaster.cpp b/src/devices/bus/isa/gblaster.cpp
index 26778703ef1..1cbd9458c04 100644
--- a/src/devices/bus/isa/gblaster.cpp
+++ b/src/devices/bus/isa/gblaster.cpp
@@ -72,12 +72,12 @@ void isa8_gblaster_device::device_add_mconfig(machine_config &config)
{
SPEAKER(config, "lspeaker").front_left();
SPEAKER(config, "rspeaker").front_right();
- SAA1099(config, m_saa1099_1, 7159090);
- m_saa1099_1->add_route(ALL_OUTPUTS, "lspeaker", 0.50);
- m_saa1099_1->add_route(ALL_OUTPUTS, "rspeaker", 0.50);
- SAA1099(config, m_saa1099_2, 7159090);
- m_saa1099_2->add_route(ALL_OUTPUTS, "lspeaker", 0.50);
- m_saa1099_2->add_route(ALL_OUTPUTS, "rspeaker", 0.50);
+ SAA1099(config, m_saa1099_1, XTAL(14'318'181) / 2); // or CMS-301, from OSC pin in ISA bus
+ m_saa1099_1->add_route(0, "lspeaker", 0.50);
+ m_saa1099_1->add_route(1, "rspeaker", 0.50);
+ SAA1099(config, m_saa1099_2, XTAL(14'318'181) / 2); // or CMS-301, from OSC pin in ISA bus
+ m_saa1099_2->add_route(0, "lspeaker", 0.50);
+ m_saa1099_2->add_route(1, "rspeaker", 0.50);
}
//**************************************************************************
diff --git a/src/devices/bus/isa/sblaster.cpp b/src/devices/bus/isa/sblaster.cpp
index 68120388f8a..ab6c899bdf8 100644
--- a/src/devices/bus/isa/sblaster.cpp
+++ b/src/devices/bus/isa/sblaster.cpp
@@ -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, "rspeaker", 3.0);
- SAA1099(config, m_saa1099_1, 7159090);
- m_saa1099_1->add_route(ALL_OUTPUTS, "lspeaker", 0.5);
- m_saa1099_1->add_route(ALL_OUTPUTS, "rspeaker", 0.5);
+ SAA1099(config, m_saa1099_1, XTAL(14'318'181) / 2); // or CMS-301, from OSC pin in ISA bus
+ m_saa1099_1->add_route(0, "lspeaker", 0.5);
+ m_saa1099_1->add_route(1, "rspeaker", 0.5);
- SAA1099(config, m_saa1099_2, 7159090);
- m_saa1099_2->add_route(ALL_OUTPUTS, "lspeaker", 0.5);
- m_saa1099_2->add_route(ALL_OUTPUTS, "rspeaker", 0.5);
+ SAA1099(config, m_saa1099_2, XTAL(14'318'181) / 2); // or CMS-301, from OSC pin in ISA bus
+ m_saa1099_2->add_route(0, "lspeaker", 0.5);
+ m_saa1099_2->add_route(1, "rspeaker", 0.5);
}
void isa8_sblaster1_5_device::device_add_mconfig(machine_config &config)
diff --git a/src/devices/sound/saa1099.cpp b/src/devices/sound/saa1099.cpp
index 9c41ca7a939..9edec91113a 100644
--- a/src/devices/sound/saa1099.cpp
+++ b/src/devices/sound/saa1099.cpp
@@ -70,8 +70,10 @@
#include "emu.h"
#include "saa1099.h"
-#define LEFT 0x00
-#define RIGHT 0x01
+static constexpr int clock_divider = 256;
+
+static constexpr int LEFT = 0x00;
+static constexpr int RIGHT = 0x01;
static constexpr u16 amplitude_lookup[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 }
};
-
// device type definition
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_sync_state(false)
, 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()
{
- /* copy global parameters */
- m_sample_rate = clock() / 256;
-
/* 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_env_enable));
@@ -184,7 +181,6 @@ void saa1099_device::device_start()
save_item(STRUCT_MEMBER(m_channels, amplitude));
save_item(STRUCT_MEMBER(m_channels, envelope));
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_noise, counter));
@@ -199,9 +195,7 @@ void saa1099_device::device_start()
void saa1099_device::device_clock_changed()
{
- m_sample_rate = clock() / 256;
-
- m_stream->set_sample_rate(m_sample_rate);
+ m_stream->set_sample_rate(clock()/clock_divider);
}
@@ -225,10 +219,10 @@ void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t *
{
switch (m_noise_params[ch])
{
- case 0: m_noise[ch].freq = clock()/256.0 * 2; break;
- case 1: m_noise[ch].freq = clock()/512.0 * 2; break;
- case 2: m_noise[ch].freq = clock()/1024.0 * 2; 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 0:
+ case 1:
+ 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.
}
}
@@ -240,19 +234,11 @@ void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t *
/* for each channel */
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 */
- 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 */
- m_channels[ch].freq = (double)((2 * clock() / 512) << m_channels[ch].octave) /
- (511.0 - (double)m_channels[ch].frequency);
-
- m_channels[ch].counter += m_sample_rate;
+ m_channels[ch].counter += m_channels[ch].freq();
m_channels[ch].level ^= 1;
/* eventually clock the envelope counters */
@@ -261,27 +247,25 @@ void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t *
if (ch == 4 && m_env_clock[1] == 0)
envelope_w(1);
}
+ m_channels[ch].counter -= clock_divider;
// if the noise is enabled
+ u8 level = 0;
if (m_channels[ch].noise_enable)
{
// if the noise level is high (noise 0: chan 0-2, noise 1: chan 3-5)
- if (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;
- }
+ level ^= m_noise[ch/3].level & 1;
}
// if the square wave is enabled
if (m_channels[ch].freq_enable)
{
// if the channel level is high
- if (m_channels[ch].level & 1)
- {
- 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;
- }
+ level ^= m_channels[ch].level & 1;
+ }
+ if (level)
+ {
+ 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;
}
}
@@ -290,15 +274,15 @@ void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t *
/* 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)
+ 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) )
m_noise[ch].level = (m_noise[ch].level << 1) | 1;
else
m_noise[ch].level <<= 1;
}
+ m_noise[ch].counter -= clock_divider;
}
/* write sound data to the buffer */
outputs[LEFT][j] = output_l / 6;
@@ -434,7 +418,7 @@ void saa1099_device::data_w(u8 data)
for (int i = 0; i < 6; i++)
{
m_channels[i].level = 0;
- m_channels[i].counter = 0.0;
+ m_channels[i].counter = m_channels[i].freq();
}
}
break;
diff --git a/src/devices/sound/saa1099.h b/src/devices/sound/saa1099.h
index c6b7382e38e..2831b4b1f73 100644
--- a/src/devices/sound/saa1099.h
+++ b/src/devices/sound/saa1099.h
@@ -47,22 +47,19 @@ private:
u8 envelope[2]; // envelope (0x00..0x0f or 0x10 == off)
/* vars to simulate the square wave */
- double counter = 0.0;
- double freq = 0.0;
+ inline u32 freq() const { return (511 - frequency) << (8 - octave); } // clock / ((511 - frequency) * 2^(8 - octave))
+ int counter = 0;
u8 level = 0;
};
struct saa1099_noise
{
- saa1099_noise() { (void)pad; }
+ saa1099_noise() { }
/* vars to simulate the noise generator output */
- double counter = 0.0;
- double freq = 0.0;
+ int counter = 0;
+ int freq = 0;
u32 level = 0xffffffffU; // noise polynomial shifter
-
- private:
- u32 pad; // pad out structure to multiple of sizeof(double)
};
void envelope_w(int ch);
@@ -80,7 +77,6 @@ private:
u8 m_selected_reg; // selected register
saa1099_channel m_channels[6]; // channels
saa1099_noise m_noise[2]; // noise generators
- double m_sample_rate;
};
DECLARE_DEVICE_TYPE(SAA1099, saa1099_device)
diff --git a/src/mame/drivers/vgmplay.cpp b/src/mame/drivers/vgmplay.cpp
index 42439e94f22..c5ca70fc50d 100644
--- a/src/mame/drivers/vgmplay.cpp
+++ b/src/mame/drivers/vgmplay.cpp
@@ -3935,12 +3935,12 @@ void vgmplay_state::vgmplay(machine_config &config)
m_vsu_vue[1]->add_route(1, m_mixer, 1.0, AUTO_ALLOC_INPUT, 1);
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(ALL_OUTPUTS, m_mixer, 0.5, AUTO_ALLOC_INPUT, 1);
+ m_saa1099[0]->add_route(0, m_mixer, 1.0, AUTO_ALLOC_INPUT, 0);
+ m_saa1099[0]->add_route(1, m_mixer, 1.0, AUTO_ALLOC_INPUT, 1);
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(ALL_OUTPUTS, m_mixer, 0.5, AUTO_ALLOC_INPUT, 1);
+ m_saa1099[1]->add_route(0, m_mixer, 1.0, AUTO_ALLOC_INPUT, 0);
+ m_saa1099[1]->add_route(1, m_mixer, 1.0, AUTO_ALLOC_INPUT, 1);
ES5503(config, m_es5503[0], 0);
m_es5503[0]->set_channels(2);
@@ -3956,12 +3956,14 @@ void vgmplay_state::vgmplay(machine_config &config)
ES5505(config, m_es5505[0], 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]->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);
ES5505(config, m_es5505[1], 0);
// 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]->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);