aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/mortevielle/sound.cpp111
-rw-r--r--engines/mortevielle/sound.h44
2 files changed, 1 insertions, 154 deletions
diff --git a/engines/mortevielle/sound.cpp b/engines/mortevielle/sound.cpp
index b3edead6f2..1007ccc4aa 100644
--- a/engines/mortevielle/sound.cpp
+++ b/engines/mortevielle/sound.cpp
@@ -33,110 +33,8 @@
namespace Mortevielle {
-/**
- * Constructor
- */
-PCSpeaker::PCSpeaker(int rate) {
- _rate = rate;
- _oscLength = 0;
- _oscSamples = 0;
- _remainingSamples = 0;
- _volume = 255;
-}
-
-/**
- * Destructor
- */
-PCSpeaker::~PCSpeaker() {
-}
-
-/**
- * Adds a new note to the queue of notes to be played.
- */
-void PCSpeaker::play(int freq, uint32 length) {
- assert((freq > 0) && (length > 0));
- Common::StackLock lock(_mutex);
-
- _pendingNotes.push(SpeakerNote(freq, length));
-}
-
-/**
- * Stops the currently playing song
- */
-void PCSpeaker::stop() {
- Common::StackLock lock(_mutex);
-
- _remainingSamples = 0;
- _pendingNotes.clear();
-}
-
-void PCSpeaker::setVolume(byte volume) {
- _volume = volume;
-}
-
-/**
- * Return true if a song is currently playing
- */
-bool PCSpeaker::isPlaying() const {
- return !_pendingNotes.empty() || (_remainingSamples != 0);
-}
-
-/**
- * Method used by the mixer to pull off pending samples to play
- */
-int PCSpeaker::readBuffer(int16 *buffer, const int numSamples) {
- Common::StackLock lock(_mutex);
-
- int i;
-
- for (i = 0; (_remainingSamples || !_pendingNotes.empty()) && (i < numSamples); ++i) {
- if (!_remainingSamples)
- // Used up the current note, so queue the next one
- dequeueNote();
-
- buffer[i] = generateSquare(_oscSamples, _oscLength) * _volume;
- if (_oscSamples++ >= _oscLength)
- _oscSamples = 0;
-
- _remainingSamples--;
- }
-
- // Clear the rest of the buffer
- if (i < numSamples)
- memset(buffer + i, 0, (numSamples - i) * sizeof(int16));
-
- return numSamples;
-}
-
-/**
- * Dequeues a note from the pending note list
- */
-void PCSpeaker::dequeueNote() {
- SpeakerNote note = _pendingNotes.pop();
-
- _oscLength = _rate / note.freq;
- _oscSamples = 0;
- _remainingSamples = (_rate * note.length) / 1000000;
- assert((_oscLength > 0) && (_remainingSamples > 0));
-}
-
-/**
- * Support method for generating a square wave
- */
-int8 PCSpeaker::generateSquare(uint32 x, uint32 oscLength) {
- return (x < (oscLength / 2)) ? 127 : -128;
-}
-
-/*-------------------------------------------------------------------------*/
-
-// The PC timer chip works at a frequency of 1.19318Mhz
-#define TIMER_FREQUENCY 1193180
-
SoundManager::SoundManager(Audio::Mixer *mixer) {
_mixer = mixer;
- _speakerStream = new PCSpeaker(mixer->getOutputRate());
- _mixer->playStream(Audio::Mixer::kSFXSoundType, &_speakerHandle,
- _speakerStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
_audioStream = nullptr;
_ambiantNoiseBuf = nullptr;
_noiseBuf = nullptr;
@@ -145,8 +43,6 @@ SoundManager::SoundManager(Audio::Mixer *mixer) {
SoundManager::~SoundManager() {
if (_audioStream)
_audioStream->finish();
- _mixer->stopHandle(_speakerHandle);
- delete _speakerStream;
free(_ambiantNoiseBuf);
free(_noiseBuf);
}
@@ -240,7 +136,7 @@ void SoundManager::litph(tablint &t, int typ, int tempo) {
if (!_vm->_speechManager._buildingSentence) {
if (!_mixer->isSoundHandleActive(_soundHandle))
- _mixer->stopHandle(_speakerHandle);
+ _mixer->stopHandle(_soundHandle);
_vm->_speechManager._buildingSentence = true;
}
int freq = tempo * 10 * 25.2;
@@ -325,11 +221,6 @@ void SoundManager::litph(tablint &t, int typ, int tempo) {
}
}
-void SoundManager::playNote(int frequency, int32 length) {
- _speakerStream->play(frequency, length);
-}
-
-
void SoundManager::playSong(const byte* buf, uint size, uint loops) {
int freq = kTempoMusic * 10 * 25.2;
Audio::SeekableAudioStream *raw = Audio::makeRawStream(buf, size, freq, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO);
diff --git a/engines/mortevielle/sound.h b/engines/mortevielle/sound.h
index 101a62b348..322648140b 100644
--- a/engines/mortevielle/sound.h
+++ b/engines/mortevielle/sound.h
@@ -51,52 +51,9 @@ struct SpeakerNote {
}
};
-/**
- * This is a modified PC Speaker class that allows the queueing of an entire song
- * sequence one note at a time.
- */
-class PCSpeaker : public Audio::AudioStream {
-private:
- Common::Queue<SpeakerNote> _pendingNotes;
- Common::Mutex _mutex;
-
- int _rate;
- uint32 _oscLength;
- uint32 _oscSamples;
- uint32 _remainingSamples;
- uint32 _mixedSamples;
- byte _volume;
-
- void dequeueNote();
-protected:
- static int8 generateSquare(uint32 x, uint32 oscLength);
-public:
- PCSpeaker(int rate = 44100);
- ~PCSpeaker();
-
- /** Play a note for length microseconds.
- */
- void play(int freq, uint32 length);
- /** Stop the currently playing sequence */
- void stop();
- /** Adjust the volume. */
- void setVolume(byte volume);
-
- bool isPlaying() const;
-
- int readBuffer(int16 *buffer, const int numSamples);
-
- bool isStereo() const { return false; }
- bool endOfData() const { return false; }
- bool endOfStream() const { return false; }
- int getRate() const { return _rate; }
-};
-
class SoundManager {
private:
MortevielleEngine *_vm;
- PCSpeaker *_speakerStream;
- Audio::SoundHandle _speakerHandle;
byte *_ambiantNoiseBuf;
byte *_noiseBuf;
@@ -110,7 +67,6 @@ public:
~SoundManager();
void setParent(MortevielleEngine *vm);
- void playNote(int frequency, int32 length);
int decodeMusic(const byte *PSrc, byte *PDest, int size);
void playSong(const byte *buf, uint usize, uint loops);