Skip to content

Commit

Permalink
DIRECTOR: Play sound from MCI command
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Iskrich authored and sev- committed Aug 3, 2016
1 parent 82094ed commit 2387e72
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 12 deletions.
6 changes: 3 additions & 3 deletions engines/director/director.cpp
Expand Up @@ -68,8 +68,8 @@ DirectorEngine::~DirectorEngine() {
Common::Error DirectorEngine::run() {
debug("Starting v%d Director game", getVersion());

_lingo = new Lingo();

_lingo = new Lingo(this);
_soundManager = new DirectorSound();
_lingo->parse("mci \"open MM\\T005045a.wav type WaveAudio alias T005045a\"\n\
mci \"play T005045a from 22710 to 32872\"");

Expand All @@ -80,7 +80,7 @@ Common::Error DirectorEngine::run() {
-- some more\n");
#endif

_soundManager = new DirectorSound();


//FIXME
_mainArchive = new RIFFArchive();
Expand Down
6 changes: 3 additions & 3 deletions engines/director/director.h
Expand Up @@ -26,7 +26,7 @@
#include "common/scummsys.h"

#include "engines/engine.h"

#include "engines/director/sound.h"
class OSystem;

namespace Common {
Expand All @@ -42,7 +42,7 @@ enum DirectorGameID {
class Archive;
struct DirectorGameDescription;
class Lingo;
class DirectorSound;


class DirectorEngine : public ::Engine {
public:
Expand All @@ -56,7 +56,7 @@ class DirectorEngine : public ::Engine {
Common::Platform getPlatform() const;
Common::Language getLanguage() const;
Common::String getEXEName() const;

DirectorSound *getSoundManager() const { return _soundManager; }
bool hasFeature(EngineFeature f) const;

protected:
Expand Down
27 changes: 24 additions & 3 deletions engines/director/lingo/lingo-funcs.cpp
Expand Up @@ -21,9 +21,10 @@
*/

#include "engines/director/lingo/lingo.h"
#include "common/file.h"
#include "audio/decoders/wave.h"

namespace Director {

enum MCITokenType {
kMCITokenNone,

Expand Down Expand Up @@ -119,11 +120,31 @@ int Lingo::func_mci(Common::String *s) {
}

switch (command) {
case kMCITokenOpen:
case kMCITokenOpen: {
warning("MCI open file: %s, type: %s, alias: %s buffer: %s", params[0].c_str(), params[1].c_str(), params[2].c_str(), params[3].c_str());
Common::File *file = new Common::File();
if (!file->open(params[0])) {
warning("Failed to open %s", params[0].c_str());
delete file;
return 0;
}
if (params[1] == "waveaudio") {
Audio::AudioStream *sound = Audio::makeWAVStream(file, DisposeAfterUse::YES);
_audioAliases[params[2]] = sound;
}
else
warning("Unhandled audio type %s", params[2].c_str());
}
break;
case kMCITokenPlay:
case kMCITokenPlay: {
warning("MCI play file: %s, from: %s, to: %s, repeat: %s", params[0].c_str(), params[1].c_str(), params[2].c_str(), params[3].c_str());
if (!_audioAliases.contains(params[0])) {
warning("Unknown alias %s", params[0].c_str());
return 0;
}
//TODO seek
_vm->getSoundManager()->playMCI(*_audioAliases[params[0]]);
}
break;
default:
warning("Unhandled MCI command: %s", s->c_str());
Expand Down
2 changes: 1 addition & 1 deletion engines/director/lingo/lingo.cpp
Expand Up @@ -66,7 +66,7 @@ struct EventHandlerType {
{ kEventNone, 0 },
};

Lingo::Lingo() {
Lingo::Lingo(DirectorEngine *vm) : _vm(vm) {
g_lingo = this;

for (const EventHandlerType *t = &eventHanlerDescs[0]; t->handler != kEventNone; ++t)
Expand Down
8 changes: 7 additions & 1 deletion engines/director/lingo/lingo.h
Expand Up @@ -25,6 +25,10 @@

#include "common/debug.h"
#include "common/hashmap.h"
#include "common/hash-str.h"
#include "audio/audiostream.h"
#include "common/str.h"
#include "engines/director/director.h"

namespace Director {

Expand Down Expand Up @@ -67,7 +71,7 @@ enum LEvent {

class Lingo {
public:
Lingo();
Lingo(DirectorEngine *vm);
~Lingo();

void processEvent(LEvent event, int entityId);
Expand All @@ -78,6 +82,8 @@ class Lingo {

private:
Common::HashMap<uint32, const char *> _eventHandlerTypes;
Common::HashMap<Common::String, Audio::AudioStream *> _audioAliases;
DirectorEngine *_vm;
};

} // End of namespace Director
Expand Down
5 changes: 5 additions & 0 deletions engines/director/sound.cpp
Expand Up @@ -32,6 +32,7 @@ namespace Director {
DirectorSound::DirectorSound() {
_sound1 = new Audio::SoundHandle();
_sound2 = new Audio::SoundHandle();
_scriptSound = new Audio::SoundHandle();
_mixer = g_system->getMixer();
}

Expand Down Expand Up @@ -66,6 +67,10 @@ void DirectorSound::playAIFF(Common::String filename, uint8 soundChannel) {
_mixer->playStream(Audio::Mixer::kSFXSoundType, _sound2, sound);
}

void DirectorSound::playMCI(Audio::AudioStream &stream) {
_mixer->playStream(Audio::Mixer::kSFXSoundType, _scriptSound, &stream);
}

bool DirectorSound::isChannelActive(uint8 channelID) {
if (channelID == 1) {
return _mixer->isSoundHandleActive(*_sound1);
Expand Down
3 changes: 2 additions & 1 deletion engines/director/sound.h
Expand Up @@ -34,14 +34,15 @@ class DirectorSound {
private:
Audio::SoundHandle *_sound1;
Audio::SoundHandle *_sound2;

Audio::SoundHandle *_scriptSound;
Audio::Mixer *_mixer;

public:
DirectorSound();

void playWAV(Common::String filename, uint8 channelID);
void playAIFF(Common::String filename, uint8 channelID);
void playMCI(Audio::AudioStream &stream);
bool isChannelActive(uint8 channelID);
void stopSound();
};
Expand Down

0 comments on commit 2387e72

Please sign in to comment.