diff options
author | Paul Gilbert | 2017-02-01 21:43:10 -0500 |
---|---|---|
committer | Paul Gilbert | 2017-02-01 21:43:10 -0500 |
commit | 29f913289cd059ecfc7bed61b6faa635c4ace3a9 (patch) | |
tree | f1fa7e091a5b8839159d105d32ae2016780f1a25 /engines | |
parent | 0d6578dac704dc1ae3c3658245ed2320fb05e05a (diff) | |
download | scummvm-rg350-29f913289cd059ecfc7bed61b6faa635c4ace3a9.tar.gz scummvm-rg350-29f913289cd059ecfc7bed61b6faa635c4ace3a9.tar.bz2 scummvm-rg350-29f913289cd059ecfc7bed61b6faa635c4ace3a9.zip |
TITANIC: Implemented CAudioBuffer class
Diffstat (limited to 'engines')
-rw-r--r-- | engines/titanic/module.mk | 1 | ||||
-rw-r--r-- | engines/titanic/sound/audio_buffer.cpp | 90 | ||||
-rw-r--r-- | engines/titanic/sound/audio_buffer.h | 68 | ||||
-rw-r--r-- | engines/titanic/sound/music_room.cpp | 2 | ||||
-rw-r--r-- | engines/titanic/sound/music_room_handler.cpp | 5 | ||||
-rw-r--r-- | engines/titanic/sound/music_room_handler.h | 7 |
6 files changed, 169 insertions, 4 deletions
diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk index 51c77ba1dd..d805f11fb8 100644 --- a/engines/titanic/module.mk +++ b/engines/titanic/module.mk @@ -399,6 +399,7 @@ MODULE_OBJS := \ pet_control/pet_show_translation.o \ pet_control/pet_slider.o \ pet_control/pet_sound.o \ + sound/audio_buffer.o \ sound/auto_music_player.o \ sound/auto_music_player_base.o \ sound/auto_sound_player.o \ diff --git a/engines/titanic/sound/audio_buffer.cpp b/engines/titanic/sound/audio_buffer.cpp new file mode 100644 index 0000000000..7de7c47ef1 --- /dev/null +++ b/engines/titanic/sound/audio_buffer.cpp @@ -0,0 +1,90 @@ +/* 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 "titanic/sound/audio_buffer.h" + +namespace Titanic { + +CAudioBuffer::CAudioBuffer(int bufferSize) : _flag(true), _field18(0) { + _buffer.resize(bufferSize); + reset(); +} + +CAudioBuffer::~CAudioBuffer() { + _buffer.clear(); +} + +void CAudioBuffer::reset() { + _flag = true; + _fieldC = _field10 = _buffer.size() / 2; +} + +const byte *CAudioBuffer::getDataPtr1() const { + return _flag ? &_buffer[_buffer.size() / 2] : &_buffer[0]; +} + +const byte *CAudioBuffer::getDataPtr2() const { + return _flag ? &_buffer[0] : &_buffer[_buffer.size() / 2]; +} + +const byte *CAudioBuffer::getPtr1() const { + const byte *ptr = getDataPtr1(); + return ptr + (_buffer.size() / 2 - _fieldC); +} + +const byte *CAudioBuffer::getPtr2() const { + const byte *ptr = getDataPtr2(); + return ptr + (_buffer.size() / 2 - _field10); +} + +void CAudioBuffer::setC(int val) { + _fieldC -= val; + if (_fieldC < 0) { + _fieldC = 0; + } else if (val && !_field10) { + update(); + } +} + +void CAudioBuffer::set10(int val) { + _field10 -= val; + if (_field10 < 0) { + _field10 = 0; + } else if (val && !_field10) { + update(); + } +} + +void CAudioBuffer::update() { + _flag = !_flag; + _fieldC = _field10 = _buffer.size() / 2; +} + +void CAudioBuffer::enterCriticalSection() { + _mutex.lock(); +} + +void CAudioBuffer::leaveCriticalSection() { + _mutex.unlock(); +} + +} // End of namespace Titanic diff --git a/engines/titanic/sound/audio_buffer.h b/engines/titanic/sound/audio_buffer.h new file mode 100644 index 0000000000..77027ac042 --- /dev/null +++ b/engines/titanic/sound/audio_buffer.h @@ -0,0 +1,68 @@ +/* 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 TITANIC_AUDIO_BUFFER_H +#define TITANIC_AUDIO_BUFFER_H + +#include "common/array.h" +#include "common/mutex.h" + +namespace Titanic { + +class CAudioBuffer { +private: + Common::Mutex _mutex; +public: + Common::Array<byte> _buffer; + int _fieldC; + int _field10; + bool _flag; + int _field18; +public: + CAudioBuffer(int bufferSize); + ~CAudioBuffer(); + + void reset(); + const byte *getDataPtr1() const; + const byte *getDataPtr2() const; + const byte *getPtr1() const; + const byte *getPtr2() const; + int getC() const { return _fieldC; } + int get10() const { return _field10; } + void setC(int val); + void set10(int val); + void update(); + + /** + * Enters a critical section + */ + void enterCriticalSection(); + + /** + * Leave a critical section + */ + void leaveCriticalSection(); +}; + +} // End of namespace Titanic + +#endif /* TITANIC_AUDIO_BUFFER_H */ diff --git a/engines/titanic/sound/music_room.cpp b/engines/titanic/sound/music_room.cpp index 9db8900d54..4ef3b1dfc7 100644 --- a/engines/titanic/sound/music_room.cpp +++ b/engines/titanic/sound/music_room.cpp @@ -85,7 +85,7 @@ void CMusicRoom::setupMusic(int volume) { _musicHandler->setMuteControl(idx, instr._muteControl); } - _musicHandler->createWaveFile(volume); + _musicHandler->setVolume(volume); } } diff --git a/engines/titanic/sound/music_room_handler.cpp b/engines/titanic/sound/music_room_handler.cpp index c9e4d76fe4..0b9c734859 100644 --- a/engines/titanic/sound/music_room_handler.cpp +++ b/engines/titanic/sound/music_room_handler.cpp @@ -34,6 +34,7 @@ CMusicRoomHandler::CMusicRoomHandler(CProjectItem *project, CSoundManager *sound _field108 = 0; _field118 = 0; _startTicks = _soundStartTicks = 0; + _audioBuffer = new CAudioBuffer(176400); } CMusicRoomHandler::~CMusicRoomHandler() { @@ -64,8 +65,8 @@ CMusicWave *CMusicRoomHandler::createMusicWave(MusicInstrument instrument, int c return _musicWaves[instrument]; } -void CMusicRoomHandler::createWaveFile(int musicVolume) { - _volume = musicVolume; +void CMusicRoomHandler::setVolume(int volume) { + _volume = volume; // TODO // _waveFile = _soundManager->loadMusic() } diff --git a/engines/titanic/sound/music_room_handler.h b/engines/titanic/sound/music_room_handler.h index b8ab277a1e..2240778c2a 100644 --- a/engines/titanic/sound/music_room_handler.h +++ b/engines/titanic/sound/music_room_handler.h @@ -23,6 +23,7 @@ #ifndef TITANIC_MUSIC_ROOM_HANDLER_H #define TITANIC_MUSIC_ROOM_HANDLER_H +#include "titanic/sound/audio_buffer.h" #include "titanic/sound/music_wave.h" #include "titanic/sound/wave_file.h" @@ -69,6 +70,7 @@ private: CWaveFile *_waveFile; int _soundHandle; int _field108; + CAudioBuffer *_audioBuffer; int _field118; uint _soundStartTicks; uint _startTicks; @@ -90,7 +92,10 @@ public: */ CMusicWave *createMusicWave(MusicInstrument instrument, int count); - void createWaveFile(int musicVolume); + /** + * Sets the volume and ??? other stuff + */ + void setVolume(int volume); /** * Flags whether the music handler is active |