summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/c6280.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/sound/c6280.cpp')
-rw-r--r--src/devices/sound/c6280.cpp250
1 files changed, 131 insertions, 119 deletions
diff --git a/src/devices/sound/c6280.cpp b/src/devices/sound/c6280.cpp
index 644269e01f7..c156033dce8 100644
--- a/src/devices/sound/c6280.cpp
+++ b/src/devices/sound/c6280.cpp
@@ -42,125 +42,131 @@
#include <algorithm>
-void c6280_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
+void c6280_device::sound_stream_update(sound_stream &stream)
{
- const u8 lmal = (m_balance >> 4) & 0x0f;
- const u8 rmal = (m_balance >> 0) & 0x0f;
+ // Fast method if none of the channels are enabled (most Data East arcade games)
+ if (!(m_enabled & 0x3f))
+ return;
- /* Clear buffer */
- outputs[0].fill(0);
- outputs[1].fill(0);
+ static const u8 scale_tab[16] =
+ {
+ 0x00, 0x03, 0x05, 0x07, 0x09, 0x0b, 0x0d, 0x0f,
+ 0x10, 0x13, 0x15, 0x17, 0x19, 0x1b, 0x1d, 0x1f
+ };
- for (int ch = 0; ch < 6; ch++)
+ const u8 lmal = scale_tab[(m_balance >> 4) & 0x0f];
+ const u8 rmal = scale_tab[(m_balance >> 0) & 0x0f];
+
+ for (int i = 0; i < stream.samples(); i++)
{
- channel *chan = &m_channel[ch];
- /* Only look at enabled channels */
- if (chan->control & 0x80)
+ s32 lout = 0, rout = 0;
+ for (int ch = 0; ch < 6; ch++)
{
- const u8 lal = (chan->balance >> 4) & 0x0f;
- const u8 ral = (chan->balance >> 0) & 0x0f;
- const u8 al = (chan->control >> 1) & 0x0f; // only high 4 bit is affected to calculating volume, low 1 bit is independent
+ // Only look at enabled channels
+ if (BIT(m_enabled, ch))
+ {
+ channel &chan = m_channel[ch];
- // verified from both patent and manual
- int vll = (0xf - lmal) + (0xf - al) + (0xf - lal);
- if (vll > 0xf) vll = 0xf;
+ const u8 lal = scale_tab[(chan.balance >> 4) & 0x0f];
+ const u8 ral = scale_tab[(chan.balance >> 0) & 0x0f];
+ const u8 al = chan.control & 0x1f;
- int vlr = (0xf - rmal) + (0xf - al) + (0xf - ral);
- if (vlr > 0xf) vlr = 0xf;
+ // Verified from both patent and manual
+ int vll = (0x1f - lmal) + (0x1f - al) + (0x1f - lal);
+ if (vll > 0x1f) vll = 0x1f;
- vll = m_volume_table[(vll << 1) | (~chan->control & 1)];
- vlr = m_volume_table[(vlr << 1) | (~chan->control & 1)];
+ int vlr = (0x1f - rmal) + (0x1f - al) + (0x1f - ral);
+ if (vlr > 0x1f) vlr = 0x1f;
- /* Check channel mode */
- if ((ch >= 4) && (chan->noise_control & 0x80))
- {
- /* Noise mode */
- const u32 step = (chan->noise_control & 0x1f) ^ 0x1f;
- for (int i = 0; i < outputs[0].samples(); i += 1)
+ vll = m_volume_table[vll];
+ vlr = m_volume_table[vlr];
+
+ // Check channel mode
+ if ((ch >= 4) && BIT(chan.noise_control, 7))
{
- s16 data = BIT(chan->noise_seed, 0) ? 0x1f : 0;
- chan->noise_counter--;
- if (chan->noise_counter <= 0)
+ // Noise mode
+ const u32 step = (chan.noise_control & 0x1f) ^ 0x1f;
+ const s16 data = BIT(chan.noise_seed, 0) ? 0x1f : 0;
+ chan.noise_counter--;
+ if (chan.noise_counter <= 0)
{
- chan->noise_counter = step << 6; // 32 * 2
- const u32 seed = chan->noise_seed;
+ chan.noise_counter = step << 6; // 32 * 2
+ const u32 seed = chan.noise_seed;
// based on Charles MacDonald's research
- chan->noise_seed = (seed >> 1) | ((BIT(seed, 0) ^ BIT(seed, 1) ^ BIT(seed, 11) ^ BIT(seed, 12) ^ BIT(seed, 17)) << 17);
+ chan.noise_seed = (seed >> 1) | ((BIT(seed, 0) ^ BIT(seed, 1) ^ BIT(seed, 11) ^ BIT(seed, 12) ^ BIT(seed, 17)) << 17);
}
- outputs[0].add_int(i, s16(vll * (data - 16)), 32768);
- outputs[1].add_int(i, s16(vlr * (data - 16)), 32768);
+ lout += vll * (data - 16);
+ rout += vlr * (data - 16);
}
- }
- else
- if (chan->control & 0x40)
- {
- /* DDA mode */
- for (int i = 0; i < outputs[0].samples(); i++)
+ else if (BIT(chan.control, 6))
{
- outputs[0].add_int(i, s16(vll * (chan->dda - 16)), 32768);
- outputs[1].add_int(i, s16(vlr * (chan->dda - 16)), 32768);
+ // DDA mode
+ lout += vll * (chan.dda - 16);
+ rout += vlr * (chan.dda - 16);
}
- }
- else
- {
- if ((m_lfo_control & 3) && (ch < 2))
+ else
{
- if (ch == 0) // CH 0 only, CH 1 is muted
+ if ((m_lfo_control & 3) && (ch < 2))
{
- /* Waveform mode with LFO */
- channel *lfo_srcchan = &m_channel[1];
- channel *lfo_dstchan = &m_channel[0];
- const u16 lfo_step = lfo_srcchan->frequency ? lfo_srcchan->frequency : 0x1000;
- for (int i = 0; i < outputs[0].samples(); i += 1)
+ if (ch == 0)
{
- s32 step = lfo_dstchan->frequency ? lfo_dstchan->frequency : 0x1000;
- if (m_lfo_control & 0x80) // reset LFO
+ // Waveform mode with LFO
+ channel &lfo_srcchan = m_channel[1];
+ channel &lfo_dstchan = m_channel[0];
+ const u16 lfo_step = lfo_srcchan.frequency ? lfo_srcchan.frequency : 0x1000;
+ s32 step = lfo_dstchan.frequency ? lfo_dstchan.frequency : 0x1000;
+ if (BIT(m_lfo_control, 7)) // reset LFO
{
- lfo_srcchan->tick = lfo_step * m_lfo_frequency;
- lfo_srcchan->index = 0;
+ lfo_srcchan.tick = lfo_step * m_lfo_frequency;
+ lfo_srcchan.index = 0;
}
else
{
- const s16 lfo_data = lfo_srcchan->waveform[lfo_srcchan->index];
- lfo_srcchan->tick--;
- if (lfo_srcchan->tick <= 0)
+ const s16 lfo_data = lfo_srcchan.waveform[lfo_srcchan.index];
+ lfo_srcchan.tick--;
+ if (lfo_srcchan.tick <= 0)
{
- lfo_srcchan->tick = lfo_step * m_lfo_frequency; // verified from manual
- lfo_srcchan->index = (lfo_srcchan->index + 1) & 0x1f;
+ lfo_srcchan.tick = lfo_step * m_lfo_frequency; // verified from manual
+ lfo_srcchan.index = (lfo_srcchan.index + 1) & 0x1f;
}
- step += ((lfo_data - 16) << (((m_lfo_control & 3)-1)<<1)); // verified from manual
+ step += ((lfo_data - 16) << (((m_lfo_control & 3) - 1) << 1)); // verified from manual
}
- const s16 data = lfo_dstchan->waveform[lfo_dstchan->index];
- lfo_dstchan->tick--;
- if (lfo_dstchan->tick <= 0)
+ const s16 data = lfo_dstchan.waveform[lfo_dstchan.index];
+ lfo_dstchan.tick--;
+ if (lfo_dstchan.tick <= 0)
{
- lfo_dstchan->tick = step;
- lfo_dstchan->index = (lfo_dstchan->index + 1) & 0x1f;
+ lfo_dstchan.tick = step;
+ lfo_dstchan.index = (lfo_dstchan.index + 1) & 0x1f;
}
- outputs[0].add_int(i, s16(vll * (data - 16)), 32768);
- outputs[1].add_int(i, s16(vlr * (data - 16)), 32768);
+ lout += vll * (data - 16);
+ rout += vlr * (data - 16);
+ }
+ else if (ch == 1) // NOT muted even when LFO is on
+ {
+ const s16 data = chan.waveform[chan.index];
+ lout += vll * (data - 16);
+ rout += vlr * (data - 16);
}
}
- }
- else
- {
- /* Waveform mode */
- const u32 step = chan->frequency ? chan->frequency : 0x1000;
- for (int i = 0; i < outputs[0].samples(); i += 1)
+ else
{
- const s16 data = chan->waveform[chan->index];
- chan->tick--;
- if (chan->tick <= 0)
+ // Waveform mode
+ const u32 step = chan.frequency ? chan.frequency : 0x1000;
+ const s16 data = chan.waveform[chan.index];
+ chan.tick--;
+ if (chan.tick <= 0)
{
- chan->tick = step;
- chan->index = (chan->index + 1) & 0x1f;
+ chan.tick = step;
+ chan.index = (chan.index + 1) & 0x1f;
}
- outputs[0].add_int(i, s16(vll * (data - 16)), 32768);
- outputs[1].add_int(i, s16(vlr * (data - 16)), 32768);
+ lout += vll * (data - 16);
+ rout += vlr * (data - 16);
}
}
}
}
+ stream.put_int(0, i, lout, 32768);
+ stream.put_int(1, i, rout, 32768);
}
}
@@ -215,73 +221,77 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vector<read_st
void c6280_device::c6280_w(offs_t offset, uint8_t data)
{
- channel *chan = &m_channel[m_select];
+ channel &chan = m_channel[m_select];
- /* Update stream */
+ // Update stream
m_stream->update();
switch (offset & 0x0f)
{
- case 0x00: /* Channel select */
+ case 0x00: // Channel select
m_select = data & 0x07;
break;
- case 0x01: /* Global balance */
- m_balance = data;
+ case 0x01: // Global balance
+ m_balance = data;
break;
- case 0x02: /* Channel frequency (LSB) */
- chan->frequency = (chan->frequency & 0x0f00) | data;
+ case 0x02: // Channel frequency (LSB)
+ chan.frequency = (chan.frequency & 0x0f00) | data;
break;
- case 0x03: /* Channel frequency (MSB) */
- chan->frequency = (chan->frequency & 0x00ff) | ((data << 8) & 0x0f00);
+ case 0x03: // Channel frequency (MSB)
+ chan.frequency = (chan.frequency & 0x00ff) | ((data << 8) & 0x0f00);
break;
- case 0x04: /* Channel control (key-on, DDA mode, volume) */
+ case 0x04: // Channel control (key-on, DDA mode, volume)
- /* 1-to-0 transition of DDA bit resets waveform index */
- if ((chan->control & 0x40) && ((data & 0x40) == 0))
+ // 1-to-0 transition of DDA bit resets waveform index
+ if (BIT(chan.control, 6) && BIT(~data, 6))
{
- chan->index = 0;
+ chan.index = 0;
}
- if (((chan->control & 0x80) == 0) && (data & 0x80))
+ if (BIT(~chan.control, 7) && BIT(data, 7))
{
- chan->tick = chan->frequency;
+ chan.tick = chan.frequency;
}
- chan->control = data;
+ chan.control = data;
+
+ // Cache channel enable flag
+ m_enabled &= ~(1 << m_select);
+ m_enabled |= BIT(data, 7) << m_select;
break;
- case 0x05: /* Channel balance */
- chan->balance = data;
+ case 0x05: // Channel balance
+ chan.balance = data;
break;
- case 0x06: /* Channel waveform data */
+ case 0x06: // Channel waveform data
- switch (chan->control & 0x40)
+ switch (chan.control & 0x40)
{
case 0x00: // Waveform
- chan->waveform[chan->index & 0x1f] = data & 0x1f;
- if (!(chan->control & 0x80)) // TODO : wave pointer is increased at writing data when sound playback is off??
- chan->index = (chan->index + 1) & 0x1f;
+ chan.waveform[chan.index & 0x1f] = data & 0x1f;
+ if (BIT(~chan.control, 7)) // TODO : wave pointer is increased at writing data when sound playback is off??
+ chan.index = (chan.index + 1) & 0x1f;
break;
case 0x40: // Direct D/A
- chan->dda = data & 0x1f;
+ chan.dda = data & 0x1f;
break;
}
break;
- case 0x07: /* Noise control (enable, frequency) */
- chan->noise_control = data;
+ case 0x07: // Noise control (enable, frequency)
+ chan.noise_control = data;
break;
- case 0x08: /* LFO frequency */
+ case 0x08: // LFO frequency
m_lfo_frequency = data;
break;
- case 0x09: /* LFO control (enable, mode) */
+ case 0x09: // LFO control (enable, mode)
m_lfo_control = data;
break;
@@ -309,11 +319,12 @@ void c6280_device::device_clock_changed()
void c6280_device::device_start()
{
- /* Loudest volume level for table */
+ // Loudest volume level for table
double level = 65535.0 / 6.0 / 32.0;
- /* Clear context */
+ // Clear context
m_select = 0;
+ m_enabled = 0;
m_balance = 0;
m_lfo_frequency = 0;
m_lfo_control = 0;
@@ -321,17 +332,18 @@ void c6280_device::device_start()
m_stream = stream_alloc(0, 2, clock());
- /* Make volume table */
- /* PSG has 48dB volume range spread over 32 steps */
+ // Make volume table
+ // PSG has 48dB volume range spread over 32 steps
double step = 48.0 / 32.0;
- for (int i = 0; i < 30; i++)
+ for (int i = 0; i < 31; i++)
{
m_volume_table[i] = (u16)level;
level /= pow(10.0, step / 20.0);
}
- m_volume_table[30] = m_volume_table[31] = 0;
+ m_volume_table[31] = 0;
save_item(NAME(m_select));
+ save_item(NAME(m_enabled));
save_item(NAME(m_balance));
save_item(NAME(m_lfo_frequency));
save_item(NAME(m_lfo_control));
@@ -352,9 +364,9 @@ void c6280_device::device_reset()
{
for (int ch = 0; ch < 6; ch++)
{
- channel *chan = &m_channel[ch];
- chan->index = 0;
+ channel &chan = m_channel[ch];
+ chan.index = 0;
if (ch >= 4)
- chan->noise_seed = 1;
+ chan.noise_seed = 1;
}
}