aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/sound
diff options
context:
space:
mode:
authorPaul Gilbert2017-02-05 17:25:55 -0500
committerPaul Gilbert2017-02-05 17:25:55 -0500
commit527ce3cb79489c2cfc12146eb68e9a1f9e21f4d9 (patch)
tree3c667d35bfb098d7dbc270b76d78ec1385faa1f4 /engines/titanic/sound
parent10d97ce37947362e6fa7161cd85221f59ca49490 (diff)
downloadscummvm-rg350-527ce3cb79489c2cfc12146eb68e9a1f9e21f4d9.tar.gz
scummvm-rg350-527ce3cb79489c2cfc12146eb68e9a1f9e21f4d9.tar.bz2
scummvm-rg350-527ce3cb79489c2cfc12146eb68e9a1f9e21f4d9.zip
TITANIC: Start of getting CWaveFile to handling audio streaming
Diffstat (limited to 'engines/titanic/sound')
-rw-r--r--engines/titanic/sound/music_room_handler.cpp2
-rw-r--r--engines/titanic/sound/music_wave.cpp4
-rw-r--r--engines/titanic/sound/sound_manager.cpp4
-rw-r--r--engines/titanic/sound/sound_manager.h4
-rw-r--r--engines/titanic/sound/wave_file.cpp64
-rw-r--r--engines/titanic/sound/wave_file.h25
6 files changed, 67 insertions, 36 deletions
diff --git a/engines/titanic/sound/music_room_handler.cpp b/engines/titanic/sound/music_room_handler.cpp
index f25bee727a..c7f3040d20 100644
--- a/engines/titanic/sound/music_room_handler.cpp
+++ b/engines/titanic/sound/music_room_handler.cpp
@@ -95,7 +95,7 @@ void CMusicRoomHandler::setVolume(int volume) {
_field118 = 1;
update();
- _waveFile = _soundManager->loadMusic(_audioBuffer);
+ _waveFile = _soundManager->loadMusic(_audioBuffer, DisposeAfterUse::NO);
_audioBuffer->setC(_audioBuffer->getC());
update();
}
diff --git a/engines/titanic/sound/music_wave.cpp b/engines/titanic/sound/music_wave.cpp
index 821a4fd0f4..0cbd5d1b98 100644
--- a/engines/titanic/sound/music_wave.cpp
+++ b/engines/titanic/sound/music_wave.cpp
@@ -276,7 +276,7 @@ int CMusicWave::read(uint16 *ptr, uint size) {
size = _size;
if (_field34 != -1) {
- const byte *data = _items[_field34]._waveFile->lock(0, 0);
+ const byte *data = _items[_field34]._waveFile->lock();
assert(data);
const uint16 *src = (const uint16 *)data;
@@ -317,7 +317,7 @@ void CMusicWave::processArray(int index, int size) {
_readPos = 0;
_readIncrement = (int)(_array[arrIndex] * 256);
_size = size;
- _count = _items[minIndex]._waveFile->getSize() / 2;
+ _count = _items[minIndex]._waveFile->size() / 2;
}
void CMusicWave::setupArray(int minVal, int maxVal) {
diff --git a/engines/titanic/sound/sound_manager.cpp b/engines/titanic/sound/sound_manager.cpp
index 7c995c29f7..09ba1ae4a7 100644
--- a/engines/titanic/sound/sound_manager.cpp
+++ b/engines/titanic/sound/sound_manager.cpp
@@ -155,11 +155,11 @@ CWaveFile *QSoundManager::loadMusic(const CString &name) {
return waveFile;
}
-CWaveFile *QSoundManager::loadMusic(CAudioBuffer *buffer) {
+CWaveFile *QSoundManager::loadMusic(CAudioBuffer *buffer, DisposeAfterUse::Flag disposeAfterUse) {
CWaveFile *waveFile = new CWaveFile();
// Try to load the specified audio buffer
- if (!waveFile->loadMusic(buffer)) {
+ if (!waveFile->loadMusic(buffer, disposeAfterUse)) {
delete waveFile;
return nullptr;
}
diff --git a/engines/titanic/sound/sound_manager.h b/engines/titanic/sound/sound_manager.h
index 1d522a7edf..3c217324c2 100644
--- a/engines/titanic/sound/sound_manager.h
+++ b/engines/titanic/sound/sound_manager.h
@@ -76,7 +76,7 @@ public:
* @param buffer Audio buffer
* @returns Loaded wave file
*/
- virtual CWaveFile *loadMusic(CAudioBuffer *buffer) { return nullptr; }
+ virtual CWaveFile *loadMusic(CAudioBuffer *buffer, DisposeAfterUse::Flag disposeAfterUse) { return nullptr; }
/**
* Start playing a previously loaded wave file
@@ -352,7 +352,7 @@ public:
* @param buffer Audio buffer
* @returns Loaded wave file
*/
- virtual CWaveFile *loadMusic(CAudioBuffer *buffer);
+ virtual CWaveFile *loadMusic(CAudioBuffer *buffer, DisposeAfterUse::Flag disposeAfterUse);
/**
* Start playing a previously loaded sound resource
diff --git a/engines/titanic/sound/wave_file.cpp b/engines/titanic/sound/wave_file.cpp
index 78be580801..3082bbfb86 100644
--- a/engines/titanic/sound/wave_file.cpp
+++ b/engines/titanic/sound/wave_file.cpp
@@ -28,19 +28,34 @@
namespace Titanic {
-CWaveFile::CWaveFile() : _owner(nullptr), _stream(nullptr),
+CWaveFile::CWaveFile() : _soundManager(nullptr), _stream(nullptr),
_soundType(Audio::Mixer::kPlainSoundType) {
+ setup();
}
-CWaveFile::CWaveFile(QSoundManager *owner) : _owner(owner), _stream(nullptr),
+CWaveFile::CWaveFile(QSoundManager *owner) : _soundManager(owner), _stream(nullptr),
_soundType(Audio::Mixer::kPlainSoundType) {
+ setup();
+}
+
+void CWaveFile::setup() {
+ _loadMode = LOADMODE_SCUMMVM;
+ _field4 = 0;
+ _field14 = 1;
+ _dataSize = 0;
+ _audioBuffer = nullptr;
+ _disposeAudioBuffer = DisposeAfterUse::NO;
+ _channel = -1;
}
CWaveFile::~CWaveFile() {
if (_stream) {
- _owner->soundFreed(_soundHandle);
+ _soundManager->soundFreed(_soundHandle);
delete _stream;
}
+
+ if (_disposeAudioBuffer == DisposeAfterUse::YES && _audioBuffer)
+ delete _audioBuffer;
}
uint CWaveFile::getDurationTicks() const {
@@ -51,7 +66,7 @@ uint CWaveFile::getDurationTicks() const {
// a desired size. Since I have no idea how the system API
// method works, for now I'm using a simple ratio of a
// sample output to input value
- uint dataSize = _size - 0x46;
+ uint dataSize = _dataSize - 0x46;
double newSize = (double)dataSize * (1475712.0 / 199836.0);
return (uint)(newSize * 1000.0 / _stream->getRate());
}
@@ -64,8 +79,8 @@ bool CWaveFile::loadSound(const CString &name) {
return false;
Common::SeekableReadStream *stream = file.readStream();
- _size = stream->size();
- _stream = Audio::makeWAVStream(stream->readStream(_size), DisposeAfterUse::YES);
+ _dataSize = stream->size();
+ _stream = Audio::makeWAVStream(stream->readStream(_dataSize), DisposeAfterUse::YES);
_soundType = Audio::Mixer::kSFXSoundType;
return true;
@@ -79,8 +94,8 @@ bool CWaveFile::loadSpeech(CDialogueFile *dialogueFile, int speechIndex) {
byte *data = (byte *)malloc(res->_size);
dialogueFile->read(res, data, res->_size);
- _size = res->_size;
- _stream = Audio::makeWAVStream(new Common::MemoryReadStream(data, _size, DisposeAfterUse::YES),
+ _dataSize = res->_size;
+ _stream = Audio::makeWAVStream(new Common::MemoryReadStream(data, _dataSize, DisposeAfterUse::YES),
DisposeAfterUse::YES);
_soundType = Audio::Mixer::kSpeechSoundType;
@@ -95,17 +110,20 @@ bool CWaveFile::loadMusic(const CString &name) {
return false;
Common::SeekableReadStream *stream = file.readStream();
- _size = stream->size();
- _stream = Audio::makeWAVStream(stream->readStream(_size), DisposeAfterUse::YES);
+ _dataSize = stream->size();
+ _stream = Audio::makeWAVStream(stream->readStream(_dataSize), DisposeAfterUse::YES);
_soundType = Audio::Mixer::kMusicSoundType;
return true;
}
-bool CWaveFile::loadMusic(CAudioBuffer *buffer) {
- assert(!_stream && buffer);
- warning("TODO: CWaveFile::loadMusic");
- return false;
+bool CWaveFile::loadMusic(CAudioBuffer *buffer, DisposeAfterUse::Flag disposeAfterUse) {
+ _audioBuffer = buffer;
+ _disposeAudioBuffer = disposeAfterUse;
+ _loadMode = LOADMODE_AUDIO_BUFFER;
+ _field14 = 0;
+
+ return true;
}
uint CWaveFile::getFrequency() const {
@@ -116,18 +134,20 @@ void CWaveFile::reset() {
_stream->rewind();
}
-uint CWaveFile::getSize() const {
- // TODO
- return _stream->getLength().totalNumberOfFrames() * 2;
-}
+const byte *CWaveFile::lock() {
+ switch (_loadMode) {
+ case LOADMODE_AUDIO_BUFFER:
+ // TODO: At this point, locking returning a pointer to a buffer
+ // into a QSound wave mixer, for pushing out
+ error("TODO: Handle pushing data to sound");
-const byte *CWaveFile::lock(int val1, int val2) {
- // TODO
- return nullptr;
+ default:
+ return nullptr;
+ }
}
void CWaveFile::unlock(const byte *ptr) {
- // TODO
+ // No implementation needed in ScummVM
}
} // End of namespace Titanic z
diff --git a/engines/titanic/sound/wave_file.h b/engines/titanic/sound/wave_file.h
index 560188576b..976979b58e 100644
--- a/engines/titanic/sound/wave_file.h
+++ b/engines/titanic/sound/wave_file.h
@@ -31,16 +31,29 @@
namespace Titanic {
+enum LoadMode { LOADMODE_AUDIO_BUFFER = 1, LOADMODE_SCUMMVM = 2 };
+
class QSoundManager;
class CWaveFile {
private:
- uint _size;
+ /**
+ * Handles setup of fields shared by the constructors
+ */
+ void setup();
public:
- QSoundManager *_owner;
+ QSoundManager *_soundManager;
Audio::SeekableAudioStream *_stream;
Audio::SoundHandle _soundHandle;
Audio::Mixer::SoundType _soundType;
+
+ LoadMode _loadMode;
+ int _field4;
+ int _field14;
+ uint _dataSize;
+ CAudioBuffer *_audioBuffer;
+ DisposeAfterUse::Flag _disposeAudioBuffer;
+ int _channel;
public:
CWaveFile();
CWaveFile(QSoundManager *owner);
@@ -56,7 +69,7 @@ public:
/**
* Return the size of the wave file
*/
- uint size() const { return _size; }
+ uint size() const { return _dataSize; }
/**
* Tries to load the specified wave file sound
@@ -76,7 +89,7 @@ public:
/**
* Tries to load the specified audio buffer
*/
- bool loadMusic(CAudioBuffer *buffer);
+ bool loadMusic(CAudioBuffer *buffer, DisposeAfterUse::Flag disposeAfterUse);
/**
* Returns true if the wave file has data loaded
@@ -93,12 +106,10 @@ public:
*/
void reset();
- uint getSize() const;
-
/**
* Lock sound data for access
*/
- const byte *lock(int val1, int val2);
+ const byte *lock();
/**
* Unlock sound data after a prior call to lock