From 160f1a074d4e97a9e67773d2a33ad13950a4bfc3 Mon Sep 17 00:00:00 2001 From: athrxx Date: Mon, 14 Apr 2014 19:51:13 +0200 Subject: AUDIO: (FM-TOWNS) - fix looping pcm sounds --- audio/softsynth/fmtowns_pc98/towns_audio.cpp | 29 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'audio') diff --git a/audio/softsynth/fmtowns_pc98/towns_audio.cpp b/audio/softsynth/fmtowns_pc98/towns_audio.cpp index 7fa55ef6c1..9db45bd8aa 100644 --- a/audio/softsynth/fmtowns_pc98/towns_audio.cpp +++ b/audio/softsynth/fmtowns_pc98/towns_audio.cpp @@ -83,7 +83,7 @@ public: bool _activeOutput; private: - void setupLoop(uint32 loopStart, uint32 len); + void setupLoop(uint32 loopStart, uint32 loopLen); void setNote(uint8 note, TownsAudio_WaveTable *w, bool stepLimit = false); void setVelo(uint8 velo); @@ -104,10 +104,10 @@ private: uint8 _panRight; int8 *_data; - int8 *_dataEnd; - int8 *_loopEnd; + uint32 _loopStart; uint32 _loopLen; + uint32 _dataEnd; uint16 _stepNote; uint16 _stepPitch; @@ -1571,7 +1571,7 @@ void TownsAudio_PcmChannel::clear() { _loopLen = 0; _pos = 0; - _loopEnd = 0; + _loopStart = 0; _step = 0; _stepNote = 0x4000; @@ -1592,7 +1592,8 @@ void TownsAudio_PcmChannel::clear() { void TownsAudio_PcmChannel::loadData(TownsAudio_WaveTable *w) { _data = w->data; - _dataEnd = w->data + w->size; + _dataEnd = w->size << 11; + _pos = 0; } void TownsAudio_PcmChannel::loadData(uint8 *buffer, uint32 size) { @@ -1604,7 +1605,7 @@ void TownsAudio_PcmChannel::loadData(uint8 *buffer, uint32 size) { *dst++ = *src & 0x80 ? (*src++ & 0x7f) : -*src++; _data = _extData; - _dataEnd = _extData + size; + _dataEnd = size << 11; _pos = 0; } @@ -1643,7 +1644,7 @@ int TownsAudio_PcmChannel::initInstrument(uint8 ¬e, TownsAudio_WaveTable *&ta } void TownsAudio_PcmChannel::keyOn(uint8 note, uint8 velo, TownsAudio_WaveTable *w) { - setupLoop(w->loopStart, w->loopLen); + setupLoop(w->loopLen ? w->loopStart : w->size, w->loopLen); setNote(note, w, _reserved); setVelo(velo); @@ -1744,9 +1745,10 @@ void TownsAudio_PcmChannel::updateOutput() { if (_activeKey || _activeEffect) { _pos += _step; - if (&_data[_pos >> 11] >= _loopEnd) { - if (_loopLen) { - _pos -= _loopLen; + if (_pos >= _dataEnd) { + if (_loopStart != _dataEnd) { + _pos = _loopStart; + _dataEnd = _loopLen; } else { _pos = 0; _activeKey = _activeEffect = false; @@ -1763,10 +1765,9 @@ int32 TownsAudio_PcmChannel::currentSampleRight() { return (_activeOutput && _panRight) ? (((_data[_pos >> 11] * _tl) * _panRight) >> 3) : 0; } -void TownsAudio_PcmChannel::setupLoop(uint32 loopStart, uint32 len) { - _loopLen = len << 11; - _loopEnd = _loopLen ? &_data[(loopStart + _loopLen) >> 11] : _dataEnd; - _pos = loopStart; +void TownsAudio_PcmChannel::setupLoop(uint32 loopStart, uint32 loopLen) { + _loopStart = loopStart << 11; + _loopLen = loopLen << 11; } void TownsAudio_PcmChannel::setNote(uint8 note, TownsAudio_WaveTable *w, bool stepLimit) { -- cgit v1.2.3