xoreos  0.0.5
xactwavebank_ascii.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include <cassert>
26 
27 #include "src/common/error.h"
28 #include "src/common/strutil.h"
29 #include "src/common/scopedptr.h"
30 #include "src/common/readstream.h"
31 #include "src/common/filepath.h"
33 
34 #include "src/aurora/resman.h"
35 
37 
39 
40 namespace Sound {
41 
43  assert(xwb);
44 
46 
47  load(*xwb);
48 }
49 
51  return _waves.size();
52 }
53 
55  if (index >= _waves.size())
56  throw Common::Exception("XACTWaveBank_ASCII::getWave(): Index out of range (%s >= %s)",
58  Common::composeString(_waves.size()).c_str());
59 
60  const Wave &wave = _waves[index];
61 
63  if (!dataStream)
64  throw Common::Exception("XACTWaveBank_ASCII::getWave(): No such resource \"%s\"", wave.name.c_str());
65 
66 #ifdef ENABLE_VORBIS
67  return makeVorbisStream(dataStream.release(), true);
68 #else
69  throw Common::Exception("XACTWaveBank_ASCII::getWave(): Vorbis decoding disabled when building without libvorbis");
70 #endif
71 }
72 
74  std::vector<Common::UString> strings;
75  tokenizer.getTokens(stream, strings);
76  tokenizer.nextChunk(stream);
77 
78  if (strings.empty())
79  return "";
80 
81  return strings[0];
82 }
83 
86  tokenizer.addSeparator(' ');
87  tokenizer.addChunkEnd('\n');
88  tokenizer.addIgnore('\r');
89  tokenizer.addIgnore('\"');
90 
91  _name = getFirst(tokenizer, xwb);
92  _streaming = getFirst(tokenizer, xwb).equalsIgnoreCase("STREAMING");
93 
94  size_t waveCount;
95  Common::parseString(getFirst(tokenizer, xwb), waveCount);
96 
97  _waves.resize(waveCount);
98  for (std::vector<Wave>::iterator w = _waves.begin(); w != _waves.end(); ++w) {
99  std::vector<Common::UString> strings;
100  tokenizer.getTokens(xwb, strings);
101 
102  if (strings.size() != 8)
103  throw Common::Exception("ACTWaveBank_ASCII::load(): Invalid wave declaration");
104 
105  w->name = Common::FilePath::getStem(strings[1]);
106  w->type = strings[0];
107 
108  Common::parseString(strings[2], w->samplingRate);
109  Common::parseString(strings[3], w->channels);
110  Common::parseString(strings[4], w->bitRate);
111 
112  Common::parseString(strings[5], w->size);
113 
114  Common::parseString(strings[6], w->loopOffset);
115  Common::parseString(strings[7], w->loopLength);
116 
117  w->bitRate = (w->bitRate / w->channels) * 8;
118 
119  tokenizer.nextChunk(xwb);
120  }
121 }
122 
123 } // End of namespace Sound
std::vector< Wave > _waves
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
XACTWaveBank_ASCII(Common::SeekableReadStream *xwb)
size_t getWaveCount() const
Return the number of wave files.
A class holding an UTF-8 string.
Definition: ustring.h:48
UString composeString(T value)
Convert any POD integer, float/double or bool type into a string.
Definition: strutil.cpp:276
RewindableAudioStream * getWave(size_t index) const
Return the audio stream of a wave.
Tokenizes a stream.
bool equalsIgnoreCase(const UString &str) const
Definition: ustring.cpp:218
void addChunkEnd(uint32 c)
Add a character marking the end of a chunk.
Utility templates and functions for working with strings and streams.
Exception that provides a stack of explanations.
Definition: error.h:36
A simple scoped smart pointer template.
void load(Common::SeekableReadStream &xwb)
Definition: game.h:37
Basic exceptions to throw.
A rewindable audio stream.
Definition: audiostream.h:125
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Audio, Ogg Vorbis.
Definition: types.h:144
RewindableAudioStream * makeVorbisStream(Common::SeekableReadStream *stream, bool disposeAfterUse)
Create a new RewindableAudioStream from the Ogg Vorbis data in the given stream.
Definition: vorbis.cpp:516
StackException Exception
Definition: error.h:59
void addIgnore(uint32 c)
Add a character to ignore.
static Common::UString getFirst(Common::StreamTokenizer &tokenizer, Common::SeekableReadStream &stream)
Basic reading stream interfaces.
Common::UString name
Name of the wave resource.
size_t getTokens(SeekableReadStream &stream, std::vector< UString > &list, size_t min=0, size_t max=SIZE_MAX, const UString &def="")
Parse tokens out of the stream.
static UString getStem(const UString &p)
Return a file name&#39;s stem.
Definition: filepath.cpp:87
Decoding Ogg Vorbis.
Parse tokens out of a stream.
void nextChunk(SeekableReadStream &stream)
Skip past end of chunk characters.
Ignore all repeated separators.
void addSeparator(uint32 c)
Add a character on where to split tokens.
An ASCII XACT WaveBank, found in the non-Xbox versions of Jade Empire as _xwb.txt files...
Interface for a seekable & readable data stream.
Definition: readstream.h:265
void parseString(const UString &str, T &value, bool allowEmpty)
Parse a string into any POD integer, float/double or bool type.
Definition: strutil.cpp:215
The global resource manager for Aurora resources.
Utility class for manipulating file paths.