AUDIO: (FM-TOWNS) - cleanup

This commit is contained in:
athrxx 2018-12-14 21:44:43 +01:00
parent 1237eb496b
commit 8d4418fa36
2 changed files with 86 additions and 80 deletions

View file

@ -25,24 +25,43 @@
#include "common/util.h" #include "common/util.h"
#include "common/textconsole.h" #include "common/textconsole.h"
#define EUP_EVENT(x) _euphonyEvents.push_back(new EuphonyEvent(this, &EuphonyPlayer::event_##x))
EuphonyPlayer::EuphonyPlayer(Audio::Mixer *mixer) : _partConfig_enable(0), _partConfig_type(0), _partConfig_ordr(0), _partConfig_volume(0), EuphonyPlayer::EuphonyPlayer(Audio::Mixer *mixer) : _partConfig_enable(0), _partConfig_type(0), _partConfig_ordr(0), _partConfig_volume(0),
_partConfig_transpose(0), _musicPos(0), _musicStart(0), _playing(false), _savedEventsChain(0), _tempoModifier(0), _bar(0), _partConfig_transpose(0), _musicPos(0), _musicStart(0), _playing(false), _pendingEventsChain(0), _tempoModifier(0), _bar(0),
_beat(0), _defaultBarLength(0), _barLength(0), _playerUpdatesLeft(0), _updatesPerPulseRemainder(0), _updatesPerPulse(0), _beat(0), _defaultBarLength(0), _barLength(0), _playerUpdatesLeft(0), _updatesPerPulseRemainder(0), _updatesPerPulse(0),
_deltaTicks(0), _defaultTempo(0), _trackTempo(0), _tempoControlMode(0), _timerSetting(0), _tempoMode1PulseCounter(0), _deltaTicks(0), _defaultTempo(0), _trackTempo(0), _tempoControlMode(0), _timerSetting(0), _tempoMode1PulseCounter(0),
_parseToBar(0), _tempoMode1UpdateF8(0), _loop(false), _endOfTrack(false), _paused(false), _musicTrackSize(0) { _parseToBar(0), _tempoMode1UpdateF8(0), _loop(false), _endOfTrack(false), _paused(false), _musicTrackSize(0) {
EUP_EVENT(notImpl);
EUP_EVENT(noteOn);
EUP_EVENT(polyphonicAftertouch);
EUP_EVENT(controlChange_pitchWheel);
EUP_EVENT(programChange_channelAftertouch);
EUP_EVENT(programChange_channelAftertouch);
EUP_EVENT(controlChange_pitchWheel);
EUP_EVENT(sysex);
EUP_EVENT(advanceBar);
EUP_EVENT(notImpl);
EUP_EVENT(notImpl);
EUP_EVENT(setTempo);
EUP_EVENT(notImpl);
EUP_EVENT(typeOrdrChange);
_drivers[0] = _eupDriver = new EuphonyDriver(mixer, this); _drivers[0] = _eupDriver = new EuphonyDriver(mixer, this);
_drivers[1] = new Type0Driver(this); _drivers[1] = new Type0Driver(this);
_drivers[2] = 0; _drivers[2] = 0;
resetTempo(); resetTempo();
} }
#undef EUP_EVENT
EuphonyPlayer::~EuphonyPlayer() { EuphonyPlayer::~EuphonyPlayer() {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
delete _drivers[i]; delete _drivers[i];
while (_savedEventsChain) { while (_pendingEventsChain) {
SavedEvent *evt = _savedEventsChain; PendingEvent *evt = _pendingEventsChain;
_savedEventsChain = _savedEventsChain->next; _pendingEventsChain = _pendingEventsChain->next;
delete evt; delete evt;
} }
@ -51,6 +70,9 @@ EuphonyPlayer::~EuphonyPlayer() {
delete[] _partConfig_ordr; delete[] _partConfig_ordr;
delete[] _partConfig_volume; delete[] _partConfig_volume;
delete[] _partConfig_transpose; delete[] _partConfig_transpose;
for (EuphonyEventsArray::iterator i = _euphonyEvents.begin(); i != _euphonyEvents.end(); ++i)
delete *i;
} }
bool EuphonyPlayer::init() { bool EuphonyPlayer::init() {
@ -67,9 +89,9 @@ bool EuphonyPlayer::init() {
if (!_drivers[0] || !_drivers[1]) if (!_drivers[0] || !_drivers[1])
return false; return false;
while (_savedEventsChain) { while (_pendingEventsChain) {
SavedEvent *evt = _savedEventsChain; PendingEvent *evt = _pendingEventsChain;
_savedEventsChain = _savedEventsChain->next; _pendingEventsChain = _pendingEventsChain->next;
delete evt; delete evt;
} }
@ -204,9 +226,9 @@ void EuphonyPlayer::reset() {
resetPartConfig(); resetPartConfig();
while (_savedEventsChain) { while (_pendingEventsChain) {
SavedEvent *evt = _savedEventsChain; PendingEvent *evt = _pendingEventsChain;
_savedEventsChain = _savedEventsChain->next; _pendingEventsChain = _pendingEventsChain->next;
delete evt; delete evt;
} }
@ -309,35 +331,15 @@ void EuphonyPlayer::updateParser() {
} }
void EuphonyPlayer::updateCheckEot() { void EuphonyPlayer::updateCheckEot() {
if (!_endOfTrack || _savedEventsChain) if (!_endOfTrack || _pendingEventsChain)
return; return;
stop(); stop();
} }
bool EuphonyPlayer::parseEvent() { bool EuphonyPlayer::parseEvent() {
#define EVENT(x) &EuphonyPlayer::event_##x
static const EuphonyEvent events[] = {
EVENT(notImpl),
EVENT(noteOn),
EVENT(polyphonicAftertouch),
EVENT(controlChange_pitchWheel),
EVENT(programChange_channelAftertouch),
EVENT(programChange_channelAftertouch),
EVENT(controlChange_pitchWheel),
EVENT(sysex),
EVENT(advanceBar),
EVENT(notImpl),
EVENT(notImpl),
EVENT(setTempo),
EVENT(notImpl),
EVENT(typeOrdrChange)
};
#undef EVENT
uint cmd = _musicPos[0]; uint cmd = _musicPos[0];
if (cmd != 0xfe && cmd != 0xfd) { if (cmd != 0xfe && cmd != 0xfd) {
bool result = (cmd >= 0xf0) ? (this->*events[((cmd - 0xf0) >> 1) + 7])() : (this->*events[(cmd - 0x80) >> 4])(); bool result = (cmd >= 0xf0) ? (*_euphonyEvents[((cmd - 0xf0) >> 1) + 7])() : (*_euphonyEvents[(cmd - 0x80) >> 4])();
if (!result) { if (!result) {
proceedToNextEvent(); proceedToNextEvent();
return false; return false;
@ -369,8 +371,8 @@ void EuphonyPlayer::proceedToNextEvent() {
} }
void EuphonyPlayer::updateHangingNotes() { void EuphonyPlayer::updateHangingNotes() {
SavedEvent *l = 0; PendingEvent *l = 0;
SavedEvent *e = _savedEventsChain; PendingEvent *e = _pendingEventsChain;
while (e) { while (e) {
if (--e->len) { if (--e->len) {
@ -379,13 +381,13 @@ void EuphonyPlayer::updateHangingNotes() {
continue; continue;
} }
SavedEvent *n = e->next; PendingEvent *n = e->next;
if (l) if (l)
l->next = n; l->next = n;
if (_savedEventsChain == e) if (_pendingEventsChain == e)
_savedEventsChain = n; _pendingEventsChain = n;
sendNoteEvent(e->type, e->evt, e->note, e->velo); sendPendingEvent(e->type, e->evt, e->note, e->velo);
delete e; delete e;
e = n; e = n;
@ -393,10 +395,10 @@ void EuphonyPlayer::updateHangingNotes() {
} }
void EuphonyPlayer::clearHangingNotes() { void EuphonyPlayer::clearHangingNotes() {
while (_savedEventsChain) { while (_pendingEventsChain) {
SavedEvent *e = _savedEventsChain; PendingEvent *e = _pendingEventsChain;
_savedEventsChain = _savedEventsChain->next; _pendingEventsChain = _pendingEventsChain->next;
sendNoteEvent(e->type, e->evt, e->note, e->velo); sendPendingEvent(e->type, e->evt, e->note, e->velo);
delete e; delete e;
} }
} }
@ -445,9 +447,9 @@ bool EuphonyPlayer::event_noteOn() {
uint8 note = _musicPos[4]; uint8 note = _musicPos[4];
uint8 velo = _musicPos[5]; uint8 velo = _musicPos[5];
sendEvent(type, evt); sendByte(type, evt);
sendEvent(type, applyTranspose(note)); sendByte(type, applyTranspose(note));
sendEvent(type, applyVolumeAdjust(velo)); sendByte(type, applyVolumeAdjust(velo));
proceedToNextEvent(); proceedToNextEvent();
if (_musicPos[0] == 0xfe || _musicPos[0] == 0xfd) if (_musicPos[0] == 0xfe || _musicPos[0] == 0xfd)
@ -456,7 +458,7 @@ bool EuphonyPlayer::event_noteOn() {
velo = _musicPos[5]; velo = _musicPos[5];
uint16 len = (_musicPos[1] & 0x0f) | ((_musicPos[2] & 0x0f) << 4) | ((_musicPos[3] & 0x0f) << 8) | ((_musicPos[4] & 0x0f) << 12); uint16 len = (_musicPos[1] & 0x0f) | ((_musicPos[2] & 0x0f) << 4) | ((_musicPos[3] & 0x0f) << 8) | ((_musicPos[4] & 0x0f) << 12);
_savedEventsChain = new SavedEvent(evt, type, note, velo, len ? len : 1, _savedEventsChain); _pendingEventsChain = new PendingEvent(evt, type, note, velo, len ? len : 1, _pendingEventsChain);
return false; return false;
} }
@ -470,9 +472,9 @@ bool EuphonyPlayer::event_polyphonicAftertouch() {
uint8 evt = appendEvent(_musicPos[0], _musicPos[1]); uint8 evt = appendEvent(_musicPos[0], _musicPos[1]);
uint8 type = _partConfig_type[_musicPos[1]]; uint8 type = _partConfig_type[_musicPos[1]];
sendEvent(type, evt); sendByte(type, evt);
sendEvent(type, applyTranspose(_musicPos[4])); sendByte(type, applyTranspose(_musicPos[4]));
sendEvent(type, _musicPos[5]); sendByte(type, _musicPos[5]);
return false; return false;
} }
@ -486,9 +488,9 @@ bool EuphonyPlayer::event_controlChange_pitchWheel() {
uint8 evt = appendEvent(_musicPos[0], _musicPos[1]); uint8 evt = appendEvent(_musicPos[0], _musicPos[1]);
uint8 type = _partConfig_type[_musicPos[1]]; uint8 type = _partConfig_type[_musicPos[1]];
sendEvent(type, evt); sendByte(type, evt);
sendEvent(type, _musicPos[4]); sendByte(type, _musicPos[4]);
sendEvent(type, _musicPos[5]); sendByte(type, _musicPos[5]);
return false; return false;
} }
@ -502,21 +504,21 @@ bool EuphonyPlayer::event_programChange_channelAftertouch() {
uint8 evt = appendEvent(_musicPos[0], _musicPos[1]); uint8 evt = appendEvent(_musicPos[0], _musicPos[1]);
uint8 type = _partConfig_type[_musicPos[1]]; uint8 type = _partConfig_type[_musicPos[1]];
sendEvent(type, evt); sendByte(type, evt);
sendEvent(type, _musicPos[4]); sendByte(type, _musicPos[4]);
return false; return false;
} }
bool EuphonyPlayer::event_sysex() { bool EuphonyPlayer::event_sysex() {
uint8 type = _partConfig_type[_musicPos[1]]; uint8 type = _partConfig_type[_musicPos[1]];
sendEvent(type, 0xF0); sendByte(type, 0xF0);
proceedToNextEvent(); proceedToNextEvent();
for (bool loop = true; loop; ) { for (bool loop = true; loop; ) {
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
if (_musicPos[i] != 0xFF) { if (_musicPos[i] != 0xFF) {
sendEvent(type, _musicPos[i]); sendByte(type, _musicPos[i]);
if (_musicPos[i] >= 0x80) { if (_musicPos[i] >= 0x80) {
loop = false; loop = false;
break; break;
@ -579,36 +581,36 @@ uint8 EuphonyPlayer::applyVolumeAdjust(uint8 in) {
return out & 0xff; return out & 0xff;
} }
void EuphonyPlayer::sendEvent(uint8 type, uint8 command) { void EuphonyPlayer::sendByte(uint8 type, uint8 command) {
int drv = ((type >> 4) + 1) & 3; int drv = ((type >> 4) + 1) & 3;
if (_drivers[drv]) if (_drivers[drv])
_drivers[drv]->send(command); _drivers[drv]->send(command);
} }
void EuphonyPlayer::sendNoteEvent(int type, int evt, int note, int velo) { void EuphonyPlayer::sendPendingEvent(int type, int evt, int note, int velo) {
if (velo) if (velo)
evt &= 0x8f; evt &= 0x8f;
sendEvent(type, evt); sendByte(type, evt);
sendEvent(type, note); sendByte(type, note);
sendEvent(type, velo); sendByte(type, velo);
} }
void EuphonyPlayer::sendControllerReset(int type, int part) { void EuphonyPlayer::sendControllerReset(int type, int part) {
sendEvent(type, 0xb0 | part); sendByte(type, 0xb0 | part);
sendEvent(type, 0x40); sendByte(type, 0x40);
sendEvent(type, 0); sendByte(type, 0);
sendEvent(type, 0xb0 | part); sendByte(type, 0xb0 | part);
sendEvent(type, 0x7b); sendByte(type, 0x7b);
sendEvent(type, 0); sendByte(type, 0);
sendEvent(type, 0xb0 | part); sendByte(type, 0xb0 | part);
sendEvent(type, 0x79); sendByte(type, 0x79);
sendEvent(type, 0x40); sendByte(type, 0x40);
} }
void EuphonyPlayer::sendAllNotesOff(int type, int part) { void EuphonyPlayer::sendAllNotesOff(int type, int part) {
sendEvent(type, 0xb0 | part); sendByte(type, 0xb0 | part);
sendEvent(type, 0x40); sendByte(type, 0x40);
sendEvent(type, 0); sendByte(type, 0);
} }
void EuphonyPlayer::sendTempo(int tempo) { void EuphonyPlayer::sendTempo(int tempo) {

View file

@ -25,6 +25,7 @@
#include "audio/softsynth/fmtowns_pc98/towns_audio.h" #include "audio/softsynth/fmtowns_pc98/towns_audio.h"
#include "common/array.h" #include "common/array.h"
#include "common/func.h"
class EuphonyBaseDriver { class EuphonyBaseDriver {
public: public:
@ -154,7 +155,6 @@ private:
uint8 appendEvent(uint8 evt, uint8 chan); uint8 appendEvent(uint8 evt, uint8 chan);
typedef bool(EuphonyPlayer::*EuphonyEvent)();
bool event_notImpl(); bool event_notImpl();
bool event_noteOn(); bool event_noteOn();
bool event_polyphonicAftertouch(); bool event_polyphonicAftertouch();
@ -169,8 +169,8 @@ private:
uint8 applyTranspose(uint8 in); uint8 applyTranspose(uint8 in);
uint8 applyVolumeAdjust(uint8 in); uint8 applyVolumeAdjust(uint8 in);
void sendEvent(uint8 type, uint8 command); void sendByte(uint8 type, uint8 command);
void sendNoteEvent(int type, int evt, int note, int velo); void sendPendingEvent(int type, int evt, int note, int velo);
void sendControllerReset(int type, int part); void sendControllerReset(int type, int part);
void sendAllNotesOff(int type, int part); void sendAllNotesOff(int type, int part);
void sendTempo(int tempo); void sendTempo(int tempo);
@ -181,17 +181,21 @@ private:
int8 *_partConfig_volume; int8 *_partConfig_volume;
int8 *_partConfig_transpose; int8 *_partConfig_transpose;
struct SavedEvent { struct PendingEvent {
SavedEvent(int ev, int tp, int nt, int vl, int ln, SavedEvent *chain) : evt(ev), type(tp), note(nt), velo(vl), len(ln), next(chain) {} PendingEvent(int ev, int tp, int nt, int vl, int ln, PendingEvent *chain) : evt(ev), type(tp), note(nt), velo(vl), len(ln), next(chain) {}
uint8 evt; uint8 evt;
uint8 type; uint8 type;
uint8 note; uint8 note;
uint8 velo; uint8 velo;
uint16 len; uint16 len;
SavedEvent *next; PendingEvent *next;
}; };
SavedEvent *_savedEventsChain; PendingEvent *_pendingEventsChain;
typedef Common::Functor0Mem<bool, EuphonyPlayer> EuphonyEvent;
typedef Common::Array<const EuphonyEvent*> EuphonyEventsArray;
EuphonyEventsArray _euphonyEvents;
uint8 _defaultBarLength; uint8 _defaultBarLength;
uint8 _barLength; uint8 _barLength;