[Scummvm-git-logs] scummvm master -> 527ce3cb79489c2cfc12146eb68e9a1f9e21f4d9

dreammaster dreammaster at scummvm.org
Sun Feb 5 23:26:05 CET 2017


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
527ce3cb79 TITANIC: Start of getting CWaveFile to handling audio streaming


Commit: 527ce3cb79489c2cfc12146eb68e9a1f9e21f4d9
    https://github.com/scummvm/scummvm/commit/527ce3cb79489c2cfc12146eb68e9a1f9e21f4d9
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-02-05T17:25:55-05:00

Commit Message:
TITANIC: Start of getting CWaveFile to handling audio streaming

Changed paths:
    engines/titanic/sound/music_room_handler.cpp
    engines/titanic/sound/music_wave.cpp
    engines/titanic/sound/sound_manager.cpp
    engines/titanic/sound/sound_manager.h
    engines/titanic/sound/wave_file.cpp
    engines/titanic/sound/wave_file.h


diff --git a/engines/titanic/sound/music_room_handler.cpp b/engines/titanic/sound/music_room_handler.cpp
index f25bee7..c7f3040 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 821a4fd..0cbd5d1 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 7c995c2..09ba1ae 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 1d522a7..3c21732 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 78be580..3082bbf 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 5601885..976979b 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





More information about the Scummvm-git-logs mailing list