diff options
author | Matthew Hoops | 2010-07-20 16:05:25 +0000 |
---|---|---|
committer | Matthew Hoops | 2010-07-20 16:05:25 +0000 |
commit | 14c2fb2f08df8cb8e600734400ffc0c750cbcf7d (patch) | |
tree | c3f0132cc9f214c8e1f2380ab74fb0fda172b95e /engines/made/scriptfuncs.cpp | |
parent | 90d45aaa7d6aa0b63505e034430293c7b3fe352c (diff) | |
download | scummvm-rg350-14c2fb2f08df8cb8e600734400ffc0c750cbcf7d.tar.gz scummvm-rg350-14c2fb2f08df8cb8e600734400ffc0c750cbcf7d.tar.bz2 scummvm-rg350-14c2fb2f08df8cb8e600734400ffc0c750cbcf7d.zip |
Implement PlayNote/StopNote and PlayTele/StopTele for The Manhole.
svn-id: r51066
Diffstat (limited to 'engines/made/scriptfuncs.cpp')
-rw-r--r-- | engines/made/scriptfuncs.cpp | 83 |
1 files changed, 71 insertions, 12 deletions
diff --git a/engines/made/scriptfuncs.cpp b/engines/made/scriptfuncs.cpp index cd4081ea52..8d01ec70f3 100644 --- a/engines/made/scriptfuncs.cpp +++ b/engines/made/scriptfuncs.cpp @@ -28,6 +28,7 @@ #include "common/events.h" #include "graphics/cursorman.h" #include "sound/audiocd.h" +#include "sound/softsynth/pcspk.h" #include "made/made.h" #include "made/resource.h" @@ -41,6 +42,22 @@ namespace Made { +ScriptFunctions::ScriptFunctions(MadeEngine *vm) : _vm(vm), _soundStarted(false) { + // Initialize the two tone generators + _pcSpeaker1 = new Audio::PCSpeaker(); + _pcSpeaker2 = new Audio::PCSpeaker(); + _vm->_system->getMixer()->playStream(Audio::Mixer::kMusicSoundType, &_pcSpeakerHandle1, _pcSpeaker1); + _vm->_system->getMixer()->playStream(Audio::Mixer::kMusicSoundType, &_pcSpeakerHandle2, _pcSpeaker2); +} + +ScriptFunctions::~ScriptFunctions() { + for (uint i = 0; i < _externalFuncs.size(); ++i) + delete _externalFuncs[i]; + + _vm->_system->getMixer()->stopHandle(_pcSpeakerHandle1); + _vm->_system->getMixer()->stopHandle(_pcSpeakerHandle2); +} + typedef Common::Functor2Mem<int16, int16*, int16, ScriptFunctions> ExternalScriptFunc; #define External(x) \ _externalFuncs.push_back(new ExternalScriptFunc(this, &ScriptFunctions::x)); \ @@ -308,36 +325,78 @@ int16 ScriptFunctions::sfFlashScreen(int16 argc, int16 *argv) { } int16 ScriptFunctions::sfPlayNote(int16 argc, int16 *argv) { - // TODO: Used in Manhole:NE, Manhole EGA - // This is used when using the piano in the desk screen inside the ship. + // This is used when using the piano in the desk screen inside the ship + // in The Manhole (EGA/NE). + // It takes 2 parameters: - // The first parameter is the key pressed + // The first parameter is the note number of the key pressed + 1 // The second parameter is some sort of modifier (volume, perhaps?), - // depending on which of the 3 keys on the right has been pressed (12 - 14) - warning("Unimplemented opcode: sfPlayNote"); + // depending on which of the 3 keys on the right has been pressed. + // This value seems to be [12, 14] in NE and [1, 3] in EGA. + + // Note frequencies based on http://www.phy.mtu.edu/~suits/notefreqs.html + static const int freqTable[] = { + 16, 17, 18, 19, 21, 22, 23, 24, 26, 28, 29, + 30, 32, 35, 37, 39, 41, 44, 46, 49, 52, 55, + 58, 62, 65, 69, 73, 77, 82, 87, 93, 98, 104, + 110, 117, 123, 131, 139, 147, 156, 165, 175, 195, + 196, 208, 220, 233, 247, 262, 277, 294, 311, 330, + 349, 370, 392, 415, 440, 466, 494, 523, 554, 587, + 622, 659, 698, 740, 784, 831, 880, 932, 988, 1047, + 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, + 1865, 1976, 2093, 2217, 2349, 2489, 2637, 2794, 2960, + 3136, 3322, 3529, 3729, 3951, 4186, 4435, 4697, 4978 + }; + + debug(4, "sfPlayNote: Note = %d, Volume(?) = %d", argv[0] - 1, argv[1]); + + _pcSpeaker1->play(Audio::PCSpeaker::kWaveFormSine, freqTable[argv[0] - 1], -1); + + // TODO: Figure out what to do with the second parameter + //_pcSpeaker1->setVolume(argv[1]); + return 0; } int16 ScriptFunctions::sfStopNote(int16 argc, int16 *argv) { - // TODO: Used in Manhole:NE, Manhole EGA // Used in the same place as sfPlayNote, with the same parameters - warning("Unimplemented opcode: sfStopNote"); + // We just stop the wave generator here + _pcSpeaker1->stop(); return 0; } int16 ScriptFunctions::sfPlayTele(int16 argc, int16 *argv) { - // TODO: Used in Manhole:NE, Manhole EGA // This is used when pressing the phone keys while using the phone in - // the desk screen inside the ship. + // the desk screen inside the ship in The Manhole (EGA/NE). // It takes 1 parameter, the key pressed (0-9, 10 for asterisk, 11 for hash) - warning("Unimplemented opcode: sfPlayTele"); + + // A telephone keypad uses a two tones for each key. + // See http://en.wikipedia.org/wiki/Telephone_keypad for more info + + static const int freqTable1[] = { + 1336, 1209, 1336, 1477, + 1209, 1336, 1477, 1209, + 1336, 1477, 1209, 1477 + }; + + static const int freqTable2[] = { + 941, 697, 697, 697, + 770, 770, 770, 852, + 852, 852, 941, 941 + }; + + debug(4, "sfPlayTele: Button = %d", argv[0]); + + _pcSpeaker1->play(Audio::PCSpeaker::kWaveFormSine, freqTable1[argv[0]], -1); + _pcSpeaker2->play(Audio::PCSpeaker::kWaveFormSine, freqTable2[argv[0]], -1); return 0; } int16 ScriptFunctions::sfStopTele(int16 argc, int16 *argv) { - // TODO: Used in Manhole:NE, Manhole EGA // Used in the same place as sfPlayTele, with the same parameters - warning("Unimplemented opcode: sfStopTele"); + // We just stop both wave generators here + _pcSpeaker1->stop(); + _pcSpeaker2->stop(); return 0; } |