79 if (index >=
_files.size())
80 throw Common::Exception(
"WwiseSoundBank::getFileStruct(): Index out of range (%s >= %s)",
89 throw Common::Exception(
"WwiseSoundBank::getSoundStruct(): Index out of range (%s >= %s)",
109 std::map<uint32, size_t>::const_iterator index =
_fileIDs.find(
id);
113 return index->second;
117 std::map<uint32, size_t>::const_iterator index =
_soundIDs.find(
id);
121 return index->second;
147 return sound.isEmbedded && (sound.fileSize == 0);
164 if (!sound.isEmbedded) {
171 throw Common::Exception(
"WwiseSoundBank::getSoundData(): No such OGG file (%s, %u, %u)",
177 if (sound.fileSource ==
_bankID) {
180 _bnk->seek(sound.fileOffset);
182 return _bnk->readStream(sound.fileSize);
187 std::map<uint32, Common::UString>::const_iterator bankName =
_banks.find(sound.fileSource);
188 if (bankName ==
_banks.end())
189 throw Common::Exception(
"WwiseSoundBank::getSoundData(): Externally embedded file (%s, %u, %u, %u) " 191 sound.id, sound.fileID, sound.fileSource);
195 throw Common::Exception(
"WwiseSoundBank::getSoundData(): Bank \"%s\" for externally embedded file " 196 "(%s, %u, %u) does not exist", bankName->second.c_str(),
199 bank->seek(sound.fileOffset);
201 return bank->readStream(sound.fileSize);
243 while (!bnk.
eos() && (bnk.
pos() != bnk.
size())) {
246 const size_t sectionStart = bnk.
pos();
247 const size_t sectionEnd = sectionStart + sectionSize;
252 switch (sectionType) {
258 throw Common::Exception(
"WwiseSoundBank::load(): Unsupported BNK version %u", version);
266 if ((sectionSize % 12) != 0)
271 _files.resize(sectionSize / 12);
272 for (std::vector<File>::iterator f =
_files.begin(); f !=
_files.end(); ++f) {
277 _fileIDs.insert(std::make_pair(f->id, std::distance(
_files.begin(), f)));
293 for (
size_t i = 0; i < count; i++) {
296 const size_t start = bnk.
pos();
297 const size_t end = start + size;
314 sound.isEmbedded = embedded == 0;
315 sound.zeroLatency = embedded == 2;
320 sound.fileOffset = sound.fileSize =
SIZE_MAX;
321 if (sound.isEmbedded) {
331 embedded, sound.fileID, sound.fileSource, sound.type,
345 music.isEmbedded = embedded == 0;
346 music.zeroLatency = embedded == 2;
351 music.fileOffset = music.fileSize =
SIZE_MAX;
352 if (music.isEmbedded) {
362 embedded, music.fileID, music.fileSource, music.type,
375 for (
size_t i = 0; i < count; i++) {
390 bnk.
seek(sectionEnd);
#define ResMan
Shortcut for accessing the sound manager.
#define MKTAG(a0, a1, a2, a3)
A wrapper macro used around four character constants, like 'DATA', to ensure portability.
"GSound", global, non-engine sound.
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
void debugC(Common::DebugChannel channel, uint32 level, const char *s,...)
A class holding an UTF-8 string.
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
std::map< uint32, Common::UString > _banks
void reset(PointerType o=0)
Resets the pointer with the new value.
Utility functions for debug output.
const File & getFileStruct(size_t index) const
PointerType release()
Returns the plain pointer value and releases ScopedPtr.
UString composeString(T value)
Convert any POD integer, float/double or bool type into a string.
virtual bool eos() const =0
Returns true if a read failed because the stream has been reached.
size_t offset
Offset of the file from the beginning of the data section.
Common::ScopedPtr< Common::SeekableReadStream > _bnk
size_t findFileByID(uint32 id) const
Return the index of a file from its ID, or SIZE_MAX if not found.
Common::SeekableReadStream * getFileData(size_t index) const
RewindableAudioStream * getFile(size_t index) const
Utility templates and functions for working with strings and streams.
Sound::RewindableAudioStream * makeWwRIFFVorbisStream(Common::SeekableReadStream *wwRIFFVorbis, bool disposeAfterUse)
Exception that provides a stack of explanations.
std::map< uint32, size_t > _fileIDs
std::vector< Sound > _sounds
static UString formatHash(uint64 hash)
uint32 getSoundID(size_t index) const
Return the ID of a referenced sound.
size_t findSoundByID(uint32 id) const
Return the index of a sound from its ID, or SIZE_MAX if not found.
Basic exceptions to throw.
A rewindable audio stream.
const char * c_str() const
Return the (utf8 encoded) string data.
Utility templates and functions.
Common::SeekableReadStream * getSoundData(size_t index) const
void load(Common::SeekableReadStream &bnk)
virtual size_t skip(ptrdiff_t offset)
Skip the specified number of bytes, adding that offset to the current position in the stream...
uint32 getSoundFileID(size_t index) const
Return the ID of a file used by a referenced sound.
uint32 getFileID(size_t index) const
Return the ID of an embedded file.
Utility functions for working with differing string encodings.
WwiseSoundBank(Common::SeekableReadStream *bnk)
virtual size_t size() const =0
Obtains the total size of the stream, measured in bytes.
virtual size_t pos() const =0
Obtains the current value of the stream position indicator of the stream.
std::map< uint32, size_t > _soundIDs
uint32 readUint32BE()
Read an unsigned 32-bit word stored in big endian (MSB first) order from the stream and return it...
Plain, unextended ASCII (7bit clean).
size_t size
Size of the file in bytes.
bool isEmptyFile(size_t index) const
bool isEmptySound(size_t index) const
An empty audio stream that plays nothing.
UString debugTag(uint32 tag, bool trim)
Create an elaborate string from an integer tag, for debugging purposes.
A Wwise SoundBank, found in Dragon Age II as BNK files.
std::vector< File > _files
const Sound & getSoundStruct(size_t index) const
UString readStringFixed(SeekableReadStream &stream, Encoding encoding, size_t length)
Read length bytes as a string with the given encoding out of a stream.
size_t getFileCount() const
Return the number of embedded files.
size_t getSoundCount() const
Return the number of sounds this bank references.
RewindableAudioStream * getSound(size_t index) const
Interface for a seekable & readable data stream.
An embedded sound file within the SoundBank.
byte readByte()
Read an unsigned byte from the stream and return it.
The global resource manager for Aurora resources.