TITANIC: Start of getting CWaveFile to handling audio streaming

This commit is contained in:
Paul Gilbert 2017-02-05 17:25:55 -05:00
parent 10d97ce379
commit 527ce3cb79
6 changed files with 67 additions and 36 deletions

View File

@ -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();
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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