diff options
Diffstat (limited to 'src/devices/sound/qsoundhle.cpp')
-rw-r--r-- | src/devices/sound/qsoundhle.cpp | 183 |
1 files changed, 67 insertions, 116 deletions
diff --git a/src/devices/sound/qsoundhle.cpp b/src/devices/sound/qsoundhle.cpp index 19634e5c062..5a57f098454 100644 --- a/src/devices/sound/qsoundhle.cpp +++ b/src/devices/sound/qsoundhle.cpp @@ -76,29 +76,31 @@ void qsound_hle_device::device_start() // init sound regs memset(m_channel, 0, sizeof(m_channel)); - for (int adr = 0x7f; adr >= 0; adr--) - write_data(adr, 0); for (int adr = 0x80; adr < 0x90; adr++) write_data(adr, 0x120); // state save for (int i = 0; i < 16; i++) { - save_item(NAME(m_channel[i].bank), i); - save_item(NAME(m_channel[i].address), i); - save_item(NAME(m_channel[i].freq), i); - save_item(NAME(m_channel[i].loop), i); - save_item(NAME(m_channel[i].end), i); - save_item(NAME(m_channel[i].vol), i); - save_item(NAME(m_channel[i].enabled), i); + save_item(NAME(m_channel[i].reg), i); save_item(NAME(m_channel[i].lvol), i); save_item(NAME(m_channel[i].rvol), i); - save_item(NAME(m_channel[i].step_ptr), i); } } //------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void qsound_hle_device::device_reset() +{ + for (qsound_channel &ch : m_channel) + std::fill(std::begin(ch.reg), std::end(ch.reg), 0U); +} + + +//------------------------------------------------- // sound_stream_update - handle a stream update //------------------------------------------------- @@ -108,45 +110,32 @@ void qsound_hle_device::sound_stream_update(sound_stream &stream, stream_sample_ memset(outputs[0], 0, samples * sizeof(*outputs[0])); memset(outputs[1], 0, samples * sizeof(*outputs[1])); - for (auto & elem : m_channel) + for (unsigned n = 0; ARRAY_LENGTH(m_channel) > n; ++n) { - if (elem.enabled) + qsound_channel &ch(m_channel[n]); + stream_sample_t *lmix(outputs[0]); + stream_sample_t *rmix(outputs[1]); + + // Go through the buffer and add voice contributions + offs_t const bank(m_channel[(n + ARRAY_LENGTH(m_channel) - 1) & (ARRAY_LENGTH(m_channel) - 1)].reg[0] & 0x7fff); + for (int i = 0; i < samples; i++) { - stream_sample_t *lmix=outputs[0]; - stream_sample_t *rmix=outputs[1]; - - // Go through the buffer and add voice contributions - for (int i = 0; i < samples; i++) - { - elem.address += (elem.step_ptr >> 12); - elem.step_ptr &= 0xfff; - elem.step_ptr += elem.freq; - - if (elem.address >= elem.end) - { - if (elem.loop) - { - // Reached the end, restart the loop - elem.address -= elem.loop; - - // Make sure we don't overflow (what does the real chip do in this case?) - if (elem.address >= elem.end) - elem.address = elem.end - elem.loop; - - elem.address &= 0xffff; - } - else - { - // Reached the end of a non-looped sample - elem.enabled = false; - break; - } - } - - int8_t sample = read_sample(elem.bank | elem.address); - *lmix++ += ((sample * elem.lvol * elem.vol) >> 14); - *rmix++ += ((sample * elem.rvol * elem.vol) >> 14); - } + // current sample address (bank comes from previous channel) + offs_t const addr(ch.reg[1] | (bank << 16)); + + // update based on playback rate + uint32_t updated(uint32_t(ch.reg[2] << 4) + ((uint32_t(ch.reg[1]) << 16) | ch.reg[3])); + ch.reg[3] = uint16_t(updated); + if (updated >= (uint32_t(ch.reg[5]) << 16)) + updated -= uint32_t(ch.reg[4]) << 16; + ch.reg[1] = uint16_t(updated >> 16); + + // get the scaled sample + int32_t const scaled(int32_t(int16_t(ch.reg[6])) * read_sample(addr)); + + // apply simple panning + *lmix++ += (((scaled >> 8) * ch.lvol) >> 14); + *rmix++ += (((scaled >> 8) * ch.rvol) >> 14); } } } @@ -187,14 +176,11 @@ void qsound_hle_device::write_data(uint8_t address, uint16_t data) { int ch = 0, reg; - // direct sound reg if (address < 0x80) { ch = address >> 3; reg = address & 7; } - - // >= 0x80 is probably for the dsp? else if (address < 0x90) { ch = address & 0xf; @@ -213,73 +199,38 @@ void qsound_hle_device::write_data(uint8_t address, uint16_t data) switch (reg) { - case 0: - // bank, high bits unknown - ch = (ch + 1) & 0xf; // strange ... - m_channel[ch].bank = data << 16; - break; - - case 1: - // start/cur address - m_channel[ch].address = data; - break; - - case 2: - // frequency - m_channel[ch].freq = data; - if (data == 0) - { - // key off - m_channel[ch].enabled = false; - } - break; - - case 3: - // key on (does the value matter? it always writes 0x8000) - m_channel[ch].enabled = true; - m_channel[ch].step_ptr = 0; - break; - - case 4: - // loop address - m_channel[ch].loop = data; - break; - - case 5: - // end address - m_channel[ch].end = data; - break; - - case 6: - // master volume - m_channel[ch].vol = data; - break; - - case 7: - // unused? - break; - - case 8: - { - // panning (left=0x0110, centre=0x0120, right=0x0130) - // looks like it doesn't write other values than that - int pan = (data & 0x3f) - 0x10; - if (pan > 0x20) - pan = 0x20; - if (pan < 0) - pan = 0; - - m_channel[ch].rvol = m_pan_table[pan]; - m_channel[ch].lvol = m_pan_table[0x20 - pan]; - break; - } + case 0: // bank + case 1: // current sample + case 2: // playback rate + case 3: // sample interval counter + case 4: // loop offset + case 5: // end sample + case 6: // channel volume + case 7: // unused + m_channel[ch].reg[reg] = data; + break; + + case 8: + { + // panning (left=0x0110, centre=0x0120, right=0x0130) + // looks like it doesn't write other values than that + int pan = (data & 0x3f) - 0x10; + if (pan > 0x20) + pan = 0x20; + if (pan < 0) + pan = 0; + + m_channel[ch].rvol = m_pan_table[pan]; + m_channel[ch].lvol = m_pan_table[0x20 - pan]; + break; + } - case 9: - // unknown - break; + case 9: + // unknown + break; - default: - //logerror("%s: write_data %02x = %04x\n", machine().describe_context(), address, data); - break; + default: + //logerror("%s: write_data %02x = %04x\n", machine().describe_context(), address, data); + break; } } |