[Scummvm-git-logs] scummvm master -> cad501e601d6dd4097da1726b0f0aab9f5feb893
grisenti
noreply at scummvm.org
Wed Jan 11 15:39:49 UTC 2023
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:
cad501e601 HPL1: improve sound data class
Commit: cad501e601d6dd4097da1726b0f0aab9f5feb893
https://github.com/scummvm/scummvm/commit/cad501e601d6dd4097da1726b0f0aab9f5feb893
Author: grisenti (emanuele at grisenti.net)
Date: 2023-01-11T16:39:15+01:00
Commit Message:
HPL1: improve sound data class
removes the need to open the audio file every time a new sound channel is created
Changed paths:
engines/hpl1/engine/impl/OpenALSoundData.cpp
engines/hpl1/engine/impl/OpenALSoundData.h
diff --git a/engines/hpl1/engine/impl/OpenALSoundData.cpp b/engines/hpl1/engine/impl/OpenALSoundData.cpp
index 5d84e607f27..bc33a40ae5b 100644
--- a/engines/hpl1/engine/impl/OpenALSoundData.cpp
+++ b/engines/hpl1/engine/impl/OpenALSoundData.cpp
@@ -27,12 +27,22 @@
#include "hpl1/engine/impl/OpenALSoundData.h"
#include "audio/audiostream.h"
+#include "audio/decoders/vorbis.h"
+#include "audio/decoders/wave.h"
+#include "common/memstream.h"
#include "hpl1/debug.h"
#include "hpl1/engine/impl/OpenALSoundChannel.h"
#include "hpl1/engine/system/SystemTypes.h"
#include "hpl1/engine/system/low_level_system.h"
+
namespace hpl {
+enum DataFormat {
+ kWav,
+ kOgg,
+ kNone,
+};
+
//////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////
@@ -56,16 +66,53 @@ cOpenALSoundData::~cOpenALSoundData() {
//-----------------------------------------------------------------------
+static uint audioDataFormat(const tString &filename) {
+ if (filename.hasSuffix("wav"))
+ return kWav;
+ else if (filename.hasSuffix("ogg"))
+ return kOgg;
+ return kNone;
+}
+
bool cOpenALSoundData::CreateFromFile(const tString &filename) {
- _filename = filename;
+ if (_audioData) {
+ Hpl1::logWarning(Hpl1::kDebugAudio, "overriding previous sound data with new audio at '%s'\n", filename.c_str());
+ }
+ Common::File file;
+ if (!file.open(filename)) {
+ Hpl1::logWarning(Hpl1::kDebugFilePath | Hpl1::kDebugResourceLoading | Hpl1::kDebugAudio, "Audio file '%s' could not be opened\n", filename.c_str());
+ return false;
+ }
+ if (file.err() || file.size() < 0) {
+ Hpl1::logError(Hpl1::kDebugResourceLoading | Hpl1::kDebugAudio, "error reading file '%s'\n", filename.c_str());
+ return false;
+ }
+ _format = audioDataFormat(filename);
+ _audioDataSize = file.size();
+ _audioData.reset(Common::SharedPtr<byte>((byte *)malloc(_audioDataSize), free));
+ file.read(_audioData.get(), _audioDataSize);
return true;
}
//-----------------------------------------------------------------------
+static Audio::SeekableAudioStream *createAudioStream(Common::MemoryReadStream *data, uint format) {
+ switch (format) {
+ case kOgg:
+ return Audio::makeVorbisStream(data, DisposeAfterUse::YES);
+ case kWav:
+ return Audio::makeWAVStream(data, DisposeAfterUse::YES);
+ }
+ return nullptr;
+}
+
iSoundChannel *cOpenALSoundData::CreateChannel(int priority) {
IncUserCount();
- return hplNew(cOpenALSoundChannel, (this, Audio::SeekableAudioStream::openStreamFile(_filename.substr(0, _filename.size() - 4)), mpSoundManger, _lowLevelSound, priority));
+ if (!_audioData)
+ return nullptr;
+ auto *dataStream = new Common::MemoryReadStream(_audioData, _audioDataSize);
+ auto *audioStream = createAudioStream(dataStream, _format);
+ return new cOpenALSoundChannel(this, audioStream, mpSoundManger, _lowLevelSound, priority);
}
} // namespace hpl
diff --git a/engines/hpl1/engine/impl/OpenALSoundData.h b/engines/hpl1/engine/impl/OpenALSoundData.h
index 36ce95e26c6..38054e1b973 100644
--- a/engines/hpl1/engine/impl/OpenALSoundData.h
+++ b/engines/hpl1/engine/impl/OpenALSoundData.h
@@ -32,6 +32,9 @@
#include "hpl1/engine/system/SystemTypes.h"
#include "common/str.h"
+#include "audio/audiostream.h"
+#include "common/ptr.h"
+
namespace hpl {
class cLowLevelSoundOpenAL;
@@ -48,7 +51,9 @@ public:
bool IsStream() { return mbStream; }
private:
- Common::String _filename;
+ Common::SharedPtr<byte> _audioData = nullptr;
+ uint32 _audioDataSize = 0;
+ uint _format = 0;
cLowLevelSoundOpenAL *_lowLevelSound;
};
More information about the Scummvm-git-logs
mailing list