void Player_AD::limitHWChannels(int newCount) { for (int i = newCount; i < ARRAYSIZE(_hwChannels); ++i) { if (_hwChannels[i].allocated) { freeHWChannel(i); } } _numHWChannels = newCount; }
void Player_AD::freeVoiceChannel(uint channel) { VoiceChannel &vChannel = _voiceChannels[channel]; assert(vChannel.lastEvent); freeHWChannel(channel); vChannel.lastEvent = 0; vChannel.b0Reg = 0; vChannel.frequency = 0; }
void Player_AD::startSound(int sound) { Common::StackLock lock(_mutex); // Setup the sound volume setupVolume(); // Query the sound resource const byte *res = _vm->getResourceAddress(rtSound, sound); assert(res); if (res[2] == 0x80) { // Stop the current sounds stopMusic(); // Lock the new music resource _musicResource = sound; _vm->_res->lock(rtSound, _musicResource); // Start the new music resource _musicData = res; startMusic(); } else { const byte priority = res[0]; // The original specified the channel to use in the sound // resource. However, since we play as much as possible we sill // ignore it and simply use the priority value to determine // whether the sfx can be played or not. //const byte channel = res[1]; // Try to allocate a sfx slot for playback. SfxSlot *sfx = allocateSfxSlot(priority); if (!sfx) { ::debugC(3, DEBUG_SOUND, "AdLib: No free sfx slot for sound %d", sound); return; } // Try to start sfx playback sfx->resource = sound; sfx->priority = priority; if (startSfx(sfx, res)) { // Lock the new resource _vm->_res->lock(rtSound, sound); } else { // When starting the sfx failed we need to reset the slot. sfx->resource = -1; for (int i = 0; i < ARRAYSIZE(sfx->channels); ++i) { sfx->channels[i].state = kChannelStateOff; if (sfx->channels[i].hardwareChannel != -1) { freeHWChannel(sfx->channels[i].hardwareChannel); sfx->channels[i].hardwareChannel = -1; } } } } }
void Player_AD::stopSfx(SfxSlot *sfx) { if (sfx->resource == -1) { return; } // 1. step: Clear all the channels. for (int i = 0; i < ARRAYSIZE(sfx->channels); ++i) { if (sfx->channels[i].state) { clearChannel(sfx->channels[i]); sfx->channels[i].state = kChannelStateOff; } if (sfx->channels[i].hardwareChannel != -1) { freeHWChannel(sfx->channels[i].hardwareChannel); sfx->channels[i].hardwareChannel = -1; } } // 2. step: Unlock the resource. _vm->_res->unlock(rtSound, sfx->resource); sfx->resource = -1; }