diff options
| -rw-r--r-- | engines/adl/adl.cpp | 55 | ||||
| -rw-r--r-- | engines/adl/adl.h | 14 | ||||
| -rw-r--r-- | engines/adl/module.mk | 3 | ||||
| -rw-r--r-- | engines/adl/speaker.cpp | 94 | ||||
| -rw-r--r-- | engines/adl/speaker.h | 49 | 
5 files changed, 189 insertions, 26 deletions
| diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp index 3ce3989212..74fc93c12e 100644 --- a/engines/adl/adl.cpp +++ b/engines/adl/adl.cpp @@ -39,12 +39,14 @@  #include "adl/display.h"  #include "adl/detection.h"  #include "adl/graphics.h" +#include "adl/speaker.h"  namespace Adl {  AdlEngine::~AdlEngine() {  	delete _display;  	delete _graphics; +	delete _speaker;  }  AdlEngine::AdlEngine(OSystem *syst, const AdlGameDescription *gd) : @@ -62,6 +64,24 @@ AdlEngine::AdlEngine(OSystem *syst, const AdlGameDescription *gd) :  		_canRestoreNow(false) {  } +bool AdlEngine::pollEvent(Common::Event &event) { +	if (g_system->getEventManager()->pollEvent(event)) { +		if (event.type != Common::EVENT_KEYDOWN) +			return false; + +		if (event.kbd.flags & Common::KBD_CTRL) { +			if (event.kbd.keycode == Common::KEYCODE_q) { +				quitGame(); +				return false; +			} +		} + +		return true; +	} + +	return false; +} +  Common::String AdlEngine::readString(Common::ReadStream &stream, byte until) const {  	Common::String str; @@ -100,23 +120,11 @@ void AdlEngine::printMessage(uint idx, bool wait) const {  }  void AdlEngine::delay(uint32 ms) const { -	Common::EventManager *ev = g_system->getEventManager(); -  	uint32 start = g_system->getMillis(); -	while (!g_engine->shouldQuit() && g_system->getMillis() - start < ms) { +	while (!shouldQuit() && g_system->getMillis() - start < ms) {  		Common::Event event; -		if (ev->pollEvent(event)) { -			if (event.type == Common::EVENT_KEYDOWN && (event.kbd.flags & Common::KBD_CTRL)) { -				switch(event.kbd.keycode) { -				case Common::KEYCODE_q: -					g_engine->quitGame(); -					break; -				default: -					break; -				} -			} -		} +		pollEvent(event);  		g_system->delayMillis(16);  	}  } @@ -130,7 +138,7 @@ Common::String AdlEngine::inputString(byte prompt) const {  	while (1) {  		byte b = inputKey(); -		if (g_engine->shouldQuit() || _isRestoring) +		if (shouldQuit() || _isRestoring)  			return 0;  		if (b == 0) @@ -162,25 +170,17 @@ Common::String AdlEngine::inputString(byte prompt) const {  }  byte AdlEngine::inputKey(bool showCursor) const { -	Common::EventManager *ev = g_system->getEventManager(); -  	byte key = 0;  	if (showCursor)  		_display->showCursor(true); -	while (!g_engine->shouldQuit() && !_isRestoring && key == 0) { +	while (!shouldQuit() && !_isRestoring && key == 0) {  		Common::Event event; -		if (ev->pollEvent(event)) { +		if (pollEvent(event)) {  			if (event.type != Common::EVENT_KEYDOWN)  				continue; -			if (event.kbd.flags & Common::KBD_CTRL) { -				if (event.kbd.keycode == Common::KEYCODE_q) -					g_engine->quitGame(); -				continue; -			} -  			switch (event.kbd.keycode) {  			case Common::KEYCODE_BACKSPACE:  			case Common::KEYCODE_RETURN: @@ -307,6 +307,10 @@ void AdlEngine::drawItems() const {  	}  } +void AdlEngine::bell(uint count) const { +	_speaker->bell(count); +} +  const Room &AdlEngine::getRoom(uint i) const {  	if (i < 1 || i > _state.rooms.size())  		error("Room %i out of range [1, %i]", i, _state.rooms.size()); @@ -403,6 +407,7 @@ void AdlEngine::dropItem(byte noun) {  }  Common::Error AdlEngine::run() { +	_speaker = new Speaker();  	_display = new Display();  	init(); diff --git a/engines/adl/adl.h b/engines/adl/adl.h index b118a3741a..9ccd02ba6a 100644 --- a/engines/adl/adl.h +++ b/engines/adl/adl.h @@ -26,18 +26,26 @@  #include "common/array.h"  #include "common/rect.h"  #include "common/str.h" +#include "common/hashmap.h" +#include "common/hash-str.h"  #include "engines/engine.h" +#include "audio/mixer.h" +#include "audio/softsynth/pcspk.h" +  namespace Common {  class ReadStream;  class SeekableReadStream; +class File; +struct Event;  }  namespace Adl {  class Display;  class GraphicsMan; +class Speaker;  struct AdlGameDescription;  // Conditional opcodes @@ -138,6 +146,8 @@ class AdlEngine : public Engine {  public:  	virtual ~AdlEngine(); +	static bool pollEvent(Common::Event &event); +  protected:  	AdlEngine(OSystem *syst, const AdlGameDescription *gd); @@ -158,6 +168,9 @@ protected:  	void clearScreen() const;  	void drawItems() const; +	// Sound +	void bell(uint count = 1) const; +  	// Game state functions  	const Room &getRoom(uint i) const;  	Room &getRoom(uint i); @@ -176,6 +189,7 @@ protected:  	Display *_display;  	GraphicsMan *_graphics; +	Speaker *_speaker;  	// Message strings in data file  	Common::Array<Common::String> _messages; diff --git a/engines/adl/module.mk b/engines/adl/module.mk index de4d645dbc..35e1228da0 100644 --- a/engines/adl/module.mk +++ b/engines/adl/module.mk @@ -8,7 +8,8 @@ MODULE_OBJS := \  	graphics_v1.o \  	graphics_v2.o \  	hires1.o \ -	hires2.o +	hires2.o \ +	speaker.o  MODULE_DIRS += \  	engines/adl diff --git a/engines/adl/speaker.cpp b/engines/adl/speaker.cpp new file mode 100644 index 0000000000..532d361cd9 --- /dev/null +++ b/engines/adl/speaker.cpp @@ -0,0 +1,94 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/system.h" +#include "common/events.h" + +#include "engines/engine.h" + +#include "audio/audiostream.h" +#include "audio/decoders/raw.h" + +#include "adl/speaker.h" +#include "adl/adl.h" + +namespace Adl { + +// Number of times to duplicate each sample +#define SAMPLE_DUP 4 +// Bell frequency in Hz +#define BELL_FREQ 1000 +// Sample rate +#define SAMPLE_RATE (BELL_FREQ * SAMPLE_DUP * 2) +// Number of waves per 0.1 seconds (bell length) +#define BELL_WAVE_COUNT (SAMPLE_RATE / 10 / SAMPLE_DUP / 2) +// Length of bell in samples +#define BELL_LEN (BELL_WAVE_COUNT * SAMPLE_DUP * 2) +// Length of silence in samples +#define SILENCE_LEN (SAMPLE_RATE / 80) + +Speaker::~Speaker() { +	delete[] _bell; +	delete[] _silence; +} + +Speaker::Speaker() { +	_bell = new byte[BELL_LEN]; + +	byte *buf = _bell; +	for (uint i = 0; i < BELL_WAVE_COUNT; ++i) { +		for (uint j = 0; j < SAMPLE_DUP; ++j) +			*buf++ = 0x00; +		for (uint j = 0; j < SAMPLE_DUP; ++j) +			*buf++ = 0xff; +	} + +	_silence = new byte[SILENCE_LEN]; + +	buf = _silence; +	for (uint i = 0; i < SILENCE_LEN; ++i) +		*buf++ = 0x80; +} + +void Speaker::bell(uint count) { +	Audio::QueuingAudioStream *stream = Audio::makeQueuingAudioStream(SAMPLE_RATE, false); +	Audio::SoundHandle handle; + +	stream->queueBuffer(_bell, BELL_LEN, DisposeAfterUse::NO, Audio::FLAG_UNSIGNED); + +	for (uint i = 1; i < count; ++i) { +		stream->queueBuffer(_silence, SILENCE_LEN, DisposeAfterUse::NO, Audio::FLAG_UNSIGNED); +		stream->queueBuffer(_bell, BELL_LEN, DisposeAfterUse::NO, Audio::FLAG_UNSIGNED); +	} + +	stream->finish(); + +	g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &handle, stream); + +	while (!g_engine->shouldQuit() && g_system->getMixer()->isSoundHandleActive(handle)) { +		Common::Event event; +		static_cast<AdlEngine *>(g_engine)->pollEvent(event); +		g_system->delayMillis(16); +	} +} + +} // End of namespace Adl diff --git a/engines/adl/speaker.h b/engines/adl/speaker.h new file mode 100644 index 0000000000..31aaac32d2 --- /dev/null +++ b/engines/adl/speaker.h @@ -0,0 +1,49 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef ADL_SPEAKER_H +#define ADL_SPEAKER_H + +#include "common/types.h" + +#include "audio/mixer.h" + +namespace Audio { +class AudioStream; +} + +namespace Adl { + +class Speaker { +public: +	Speaker(); +	~Speaker(); + +	void bell(uint count); + +private: +	byte *_bell, *_silence; +}; + +} // End of namespace Adl + +#endif | 
