diff options
author | Johannes Schickel | 2014-06-04 18:51:15 +0200 |
---|---|---|
committer | Johannes Schickel | 2014-06-04 18:51:15 +0200 |
commit | 051034f811c2e08a9473d9fe42f9183eb62293f3 (patch) | |
tree | b41b87b53061f90977da184084c26bd1e47d80d6 /engines/scumm/players | |
parent | 727cb7661cb67098541eed074ab8c74d6c3f5b4f (diff) | |
download | scummvm-rg350-051034f811c2e08a9473d9fe42f9183eb62293f3.tar.gz scummvm-rg350-051034f811c2e08a9473d9fe42f9183eb62293f3.tar.bz2 scummvm-rg350-051034f811c2e08a9473d9fe42f9183eb62293f3.zip |
SCUMM: Simplify voice channel allocation in AD code.
Diffstat (limited to 'engines/scumm/players')
-rw-r--r-- | engines/scumm/players/player_ad.cpp | 41 | ||||
-rw-r--r-- | engines/scumm/players/player_ad.h | 3 |
2 files changed, 10 insertions, 34 deletions
diff --git a/engines/scumm/players/player_ad.cpp b/engines/scumm/players/player_ad.cpp index 3bbb429b02..882e5f52a6 100644 --- a/engines/scumm/players/player_ad.cpp +++ b/engines/scumm/players/player_ad.cpp @@ -74,9 +74,6 @@ Player_AD::Player_AD(ScummEngine *scumm, Audio::Mixer *mixer) _numHWChannels = ARRAYSIZE(_hwChannels); memset(_voiceChannels, 0, sizeof(_voiceChannels)); - for (int i = 0; i < ARRAYSIZE(_voiceChannels); ++i) { - _voiceChannels[i].hardwareChannel = -1; - } _musicVolume = _sfxVolume = 255; } @@ -510,9 +507,11 @@ void Player_AD::updateMusic() { if (_musicData[instrOffset + 13] != 0) { setupRhythm(_musicData[instrOffset + 13], instrOffset); } else { - int channel = allocateVoiceChannel(); + // Priority 256 makes sure we always prefer music + // channels over SFX channels. + int channel = allocateHWChannel(256); if (channel != -1) { - setupChannel(_voiceChannels[channel].hardwareChannel, _musicData + instrOffset); + setupChannel(channel, _musicData + instrOffset); _voiceChannels[channel].lastEvent = command + 0x90; _voiceChannels[channel].frequency = _musicData[_curOffset]; setupFrequency(channel, _musicData[_curOffset]); @@ -576,8 +575,7 @@ void Player_AD::updateMusic() { } void Player_AD::noteOff(uint channel) { - VoiceChannel &vChannel = _voiceChannels[channel]; - writeReg(0xB0 + vChannel.hardwareChannel, vChannel.b0Reg & 0xDF); + writeReg(0xB0 + channel, _voiceChannels[channel].b0Reg & 0xDF); freeVoiceChannel(channel); } @@ -593,14 +591,13 @@ void Player_AD::setupFrequency(uint channel, int8 frequency) { ++octave; } - VoiceChannel &vChannel = _voiceChannels[channel]; const uint noteFrequency = _noteFrequencies[frequency]; octave <<= 2; octave |= noteFrequency >> 8; octave |= 0x20; - writeReg(0xA0 + vChannel.hardwareChannel, noteFrequency & 0xFF); - vChannel.b0Reg = octave; - writeReg(0xB0 + vChannel.hardwareChannel, octave); + writeReg(0xA0 + channel, noteFrequency & 0xFF); + _voiceChannels[channel].b0Reg = octave; + writeReg(0xB0 + channel, octave); } void Player_AD::setupRhythm(uint rhythmInstr, uint instrOffset) { @@ -621,29 +618,11 @@ void Player_AD::setupRhythm(uint rhythmInstr, uint instrOffset) { } } -int Player_AD::allocateVoiceChannel() { - for (int i = 0; i < ARRAYSIZE(_voiceChannels); ++i) { - if (!_voiceChannels[i].lastEvent) { - // 256 makes sure it's a higher prority than any SFX - _voiceChannels[i].hardwareChannel = allocateHWChannel(256); - if (_voiceChannels[i].hardwareChannel != -1) { - return i; - } else { - // No free HW channels => cancel - return -1; - } - } - } - - return -1; -} - void Player_AD::freeVoiceChannel(uint channel) { VoiceChannel &vChannel = _voiceChannels[channel]; - assert(vChannel.hardwareChannel != -1); + assert(vChannel.lastEvent); - freeHWChannel(vChannel.hardwareChannel); - vChannel.hardwareChannel = -1; + freeHWChannel(channel); vChannel.lastEvent = 0; vChannel.b0Reg = 0; vChannel.frequency = 0; diff --git a/engines/scumm/players/player_ad.h b/engines/scumm/players/player_ad.h index 0a0ba8aba1..d061c1acdd 100644 --- a/engines/scumm/players/player_ad.h +++ b/engines/scumm/players/player_ad.h @@ -128,10 +128,7 @@ private: uint lastEvent; uint frequency; uint b0Reg; - - int hardwareChannel; } _voiceChannels[9]; - int allocateVoiceChannel(); void freeVoiceChannel(uint channel); uint _mdvdrState; |