Skip to content

Commit

Permalink
TSAGE: Sound Fx is now playing
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jul 27, 2011
1 parent 034bbde commit 0034257
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 54 deletions.
65 changes: 20 additions & 45 deletions engines/tsage/sound.cpp
Expand Up @@ -20,6 +20,7 @@
*
*/

#include "audio/decoders/raw.h"
#include "common/config-manager.h"
#include "tsage/core.h"
#include "tsage/globals.h"
Expand Down Expand Up @@ -158,9 +159,7 @@ Common::List<SoundDriverEntry> &SoundManager::buildDriverList(bool detectFlag) {

void SoundManager::installConfigDrivers() {
installDriver(ADLIB_DRIVER_NUM);
#ifdef DEBUG
installDriver(SBLASTER_DRIVER_NUM);
#endif
}

Common::List<SoundDriverEntry> &SoundManager::getDriverList(bool detectFlag) {
Expand Down Expand Up @@ -2801,6 +2800,7 @@ AdlibFxSoundDriver::AdlibFxSoundDriver(): SoundDriver() {

_mixer = _vm->_mixer;
_sampleRate = _mixer->getOutputRate();
_audioStream = NULL;
// _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
/*
Common::set_to(_channelVoiced, _channelVoiced + ADLIB_CHANNEL_COUNT, false);
Expand All @@ -2818,7 +2818,7 @@ AdlibFxSoundDriver::AdlibFxSoundDriver(): SoundDriver() {
}

AdlibFxSoundDriver::~AdlibFxSoundDriver() {
// _mixer->stopHandle(_soundHandle);
_mixer->stopHandle(_soundHandle);
}

bool AdlibFxSoundDriver::open() {
Expand Down Expand Up @@ -2878,14 +2878,28 @@ void AdlibFxSoundDriver::proc32(const byte *channelData, int dataOffset, int pro
_channelData = channelData + dataOffset;
_soundData = _channelData + 18;

// Make a copy of the buffer
int dataSize = _vm->_memoryManager.getSize(channelData);
byte *soundData = (byte *)malloc(dataSize - dataOffset);
Common::copy(_channelData, _channelData + (dataSize - dataOffset), soundData);

_audioStream = Audio::makeQueuingAudioStream(11025, false);
_audioStream->queueBuffer(soundData, dataSize - dataOffset, DisposeAfterUse::YES, Audio::FLAG_UNSIGNED);

// Start the new sound
debug("Start sound");
if (!_mixer->isSoundHandleActive(_soundHandle))
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, _audioStream);
}

void AdlibFxSoundDriver::updateVoice(int channel) {
if (_channelData) {
write(208);

/*
if (_audioStream && _audioStream->numQueuedStreams() != 0) {
_mixer->stopAll();
_audioStream = NULL;
}
*/
_channelData = NULL;
_v45062 = 0;
_v45066 = 0;
Expand All @@ -2911,46 +2925,7 @@ void AdlibFxSoundDriver::proc42(int channel, int cmd, int value, int *v1, int *v
}

void AdlibFxSoundDriver::write(int v) {
/*
port[adlib_port + 12] = v;
for (int i = 0; i < 100; ++i) {
if (!port[adlib_port + 12] & 0x80)
break;
}
*/
}

void AdlibFxSoundDriver::flush() {
Common::StackLock slock(SoundManager::sfManager()._serverDisabledMutex);

// No data output yet
}



int AdlibFxSoundDriver::readBuffer(int16 *buffer, const int numSamples) {
update(buffer, numSamples);
return numSamples;
}

void AdlibFxSoundDriver::update(int16 *buf, int len) {
/*
static int samplesLeft = 0;
while (len != 0) {
int count = samplesLeft;
if (count > len) {
count = len;
}
samplesLeft -= count;
len -= count;
YM3812UpdateOne(_opl, buf, count);
if (samplesLeft == 0) {
flush();
samplesLeft = _sampleRate / 50;
}
buf += count;
}
*/
// No implementation
}

void AdlibFxSoundDriver::write209() {
Expand Down
11 changes: 2 additions & 9 deletions engines/tsage/sound.h
Expand Up @@ -459,12 +459,13 @@ class AdlibSoundDriver: public SoundDriver, Audio::AudioStream {
void update(int16 *buf, int len);
};

class AdlibFxSoundDriver: public SoundDriver, Audio::AudioStream {
class AdlibFxSoundDriver: public SoundDriver {
private:
Common::Queue<RegisterValue> _queue;
GroupData _groupData;
Audio::Mixer *_mixer;
Audio::SoundHandle _soundHandle;
Audio::QueuingAudioStream *_audioStream;
int _sampleRate;

int _v45062;
Expand Down Expand Up @@ -497,14 +498,6 @@ class AdlibFxSoundDriver: public SoundDriver, Audio::AudioStream {
virtual void updateVoice(int channel);
virtual void proc38(int channel, int cmd, int value);
virtual void proc42(int channel, int cmd, int value, int *v1, int *v2);

// AudioStream interface
virtual int readBuffer(int16 *buffer, const int numSamples);
virtual bool isStereo() const { return false; }
virtual bool endOfData() const { return false; }
virtual int getRate() const { return _sampleRate; }

void update(int16 *buf, int len);
};


Expand Down

0 comments on commit 0034257

Please sign in to comment.