Skip to content

Commit

Permalink
ACCESS: Rewrite sound queueing (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke committed Dec 27, 2014
1 parent e862172 commit 39eab59
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 43 deletions.
52 changes: 28 additions & 24 deletions engines/access/amazon/amazon_logic.cpp
Expand Up @@ -341,15 +341,12 @@ void Opening::doTitle() {
_vm->_objectsTable[0] = new SpriteResource(_vm, spriteData);
delete spriteData;

_vm->_sound->playSound(1);

_vm->_files->_setPaletteFlag = false;
_vm->_files->loadScreen(0, 4);
_vm->_sound->playSound(1);

_vm->_buffer2.copyFrom(*_vm->_screen);
_vm->_buffer1.copyFrom(*_vm->_screen);
_vm->_sound->playSound(1);

const int COUNTDOWN[6] = { 2, 0x80, 1, 0x7d, 0, 0x87 };
for (_pCount = 0; _pCount < 3 && !_vm->shouldQuit(); ++_pCount) {
Expand Down Expand Up @@ -508,40 +505,47 @@ void Opening::doTent() {
_vm->_screen->forceFadeIn();

_vm->_video->setVideo(_vm->_screen, Common::Point(126, 73), FileIdent(2, 1), 10);
int previousFrame = -1;
while (!_vm->shouldQuit() && !_vm->_video->_videoEnd) {
_vm->_video->playVideo();
if ((_vm->_video->_videoFrame == 32) || (_vm->_video->_videoFrame == 34))
_vm->_sound->playSound(4);
else if (_vm->_video->_videoFrame == 36) {
if (step != 2) {
_vm->_sound->playSound(2);
step = 2;
}
} else if (_vm->_video->_videoFrame == 18) {
if (step != 1) {
_vm->_midi->newMusic(73, 1);
_vm->_midi->newMusic(11, 0);
step = 1;
_vm->_sound->playSound(1);
if (previousFrame != _vm->_video->_videoFrame) {
previousFrame = _vm->_video->_videoFrame;

if ((_vm->_video->_videoFrame == 32) || (_vm->_video->_videoFrame == 34))
_vm->_sound->playSound(4);
else if (_vm->_video->_videoFrame == 36) {
if (step != 2) {
_vm->_sound->playSound(2);
step = 2;
}
} else if (_vm->_video->_videoFrame == 18) {
if (step != 1) {
_vm->_midi->newMusic(73, 1);
_vm->_midi->newMusic(11, 0);
step = 1;
_vm->_sound->playSound(1);
}
}
}

_vm->_events->pollEventsAndWait();
}

_vm->_sound->playSound(5);
_vm->_video->setVideo(_vm->_screen, Common::Point(43, 11), FileIdent(2, 2), 10);
previousFrame = -1;
while (!_vm->shouldQuit() && !_vm->_video->_videoEnd) {
_vm->_video->playVideo();
if (_vm->_video->_videoFrame == 26) {
_vm->_sound->playSound(5);
} else if (_vm->_video->_videoFrame == 15) {
if (step !=3) {
_vm->_sound->playSound(3);
step = 3;
if (previousFrame != _vm->_video->_videoFrame) {
previousFrame = _vm->_video->_videoFrame;
if (_vm->_video->_videoFrame == 26) {
_vm->_sound->playSound(5);
} else if (_vm->_video->_videoFrame == 15) {
if (step !=3) {
_vm->_sound->playSound(3);
step = 3;
}
}
}

_vm->_events->pollEventsAndWait();
}

Expand Down
2 changes: 2 additions & 0 deletions engines/access/events.cpp
Expand Up @@ -140,6 +140,8 @@ void EventsManager::pollEvents(bool skipTimers) {
if (checkForNextTimerUpdate() && !skipTimers)
nextTimer();

_vm->_sound->checkSoundQueue();

_wheelUp = _wheelDown = false;

Common::Event event;
Expand Down
50 changes: 32 additions & 18 deletions engines/access/sound.cpp
Expand Up @@ -22,7 +22,6 @@

#include "common/algorithm.h"
#include "audio/mixer.h"
#include "audio/audiostream.h"
#include "audio/decoders/raw.h"
#include "audio/decoders/wave.h"
#include "access/access.h"
Expand All @@ -44,7 +43,19 @@ void SoundManager::clearSounds() {

for (uint i = 0; i < _soundTable.size(); ++i)
delete _soundTable[i]._res;

_soundTable.clear();

if (_mixer->isSoundHandleActive(_effectsHandle))
_mixer->stopHandle(_effectsHandle);

if (_queue.size())
_queue.remove_at(0);

while (_queue.size()) {
delete _queue[0];
_queue.remove_at(0);
}
}

void SoundManager::queueSound(int idx, int fileNum, int subfile) {
Expand Down Expand Up @@ -77,19 +88,14 @@ void SoundManager::playSound(Resource *res, int priority) {
debugC(1, kDebugSound, "playSound");

byte *resourceData = res->data();
Audio::SoundHandle audioHandle;
Audio::RewindableAudioStream *audioStream = 0;

assert(res->_size >= 32);

// HACK: Simulates queueing for the rare sounds played one after the other
while (_mixer->hasActiveChannelOfType(Audio::Mixer::kSFXSoundType))
;

if (READ_BE_UINT32(resourceData) == MKTAG('R','I','F','F')) {
// CD version uses WAVE-files
Common::SeekableReadStream *waveStream = new Common::MemoryReadStream(resourceData, res->_size, DisposeAfterUse::NO);
audioStream = Audio::makeWAVStream(waveStream, DisposeAfterUse::YES);
Audio::RewindableAudioStream *audioStream = Audio::makeWAVStream(waveStream, DisposeAfterUse::YES);
_queue.push_back(audioStream);

} else if (READ_BE_UINT32(resourceData) == MKTAG('S', 'T', 'E', 'V')) {
// sound files have a fixed header of 32 bytes in total
Expand Down Expand Up @@ -130,22 +136,30 @@ void SoundManager::playSound(Resource *res, int priority) {
return;
}

audioStream = Audio::makeRawStream(resourceData + 32, sampleSize, sampleRate, 0);
Audio::RewindableAudioStream *audioStream = Audio::makeRawStream(resourceData + 32, sampleSize, sampleRate, 0);
_queue.push_back(audioStream);

} else
error("Unknown format");

audioHandle = Audio::SoundHandle();
_mixer->playStream(Audio::Mixer::kSFXSoundType, &audioHandle,
audioStream, -1, _mixer->kMaxChannelVolume, 0,
if (!_mixer->isSoundHandleActive(_effectsHandle))
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_effectsHandle,
_queue[0], -1, _mixer->kMaxChannelVolume, 0,
DisposeAfterUse::NO);
}

void SoundManager::checkSoundQueue() {
debugC(5, kDebugSound, "checkSoundQueue");

if (_queue.empty() || _mixer->isSoundHandleActive(_effectsHandle))
return;

_queue.remove_at(0);

/*
Audio::QueuingAudioStream *audioStream = Audio::makeQueuingAudioStream(22050, false);
audioStream->queueBuffer(data, size, DisposeAfterUse::YES, 0);
_mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, audioStream, -1,
Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::YES, false);
*/
if (_queue.size())
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_effectsHandle,
_queue[0], -1, _mixer->kMaxChannelVolume, 0,
DisposeAfterUse::YES);
}

void SoundManager::loadSounds(Common::Array<RoomInfo::SoundIdent> &sounds) {
Expand Down
5 changes: 4 additions & 1 deletion engines/access/sound.h
Expand Up @@ -24,6 +24,7 @@
#define ACCESS_SOUND_H

#include "common/scummsys.h"
#include "audio/audiostream.h"
#include "audio/mixer.h"
#include "access/files.h"
#include "audio/midiplayer.h"
Expand All @@ -47,7 +48,8 @@ class SoundManager {
private:
AccessEngine *_vm;
Audio::Mixer *_mixer;
Audio::SoundHandle _soundHandle;
Audio::SoundHandle _effectsHandle;
Common::Array<Audio::RewindableAudioStream *> _queue;

void clearSounds();

Expand All @@ -63,6 +65,7 @@ class SoundManager {
void queueSound(int idx, int fileNum, int subfile);

void playSound(int soundIndex);
void checkSoundQueue();

Resource *loadSound(int fileNum, int subfile);
void loadSounds(Common::Array<RoomInfo::SoundIdent> &sounds);
Expand Down

0 comments on commit 39eab59

Please sign in to comment.