2
Copyright (C) 2008 Romulo Fernandes Machado (nightz)
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
#ifndef SOUND_SAMPLE_H
20
#define SOUND_SAMPLE_H
22
#include "SoundGeneral.h"
23
#include "SoundBinding.h"
24
#include "framework/IResourceProvider.h"
27
#include <OpenAL/al.h>
35
class StaticSoundSample;
39
@brief A binding to a "static" sound source, i.e. a sound source which doesn't have to be updated.
41
A "static" sound is one that is small enough to fit into one continous buffer, and thus doesn't need to be dynamically updated as is the case with "streaming" sounds. As a result, this binding is very simple and will just bind the sound data to the source in the constructor, without having to provide any functionality in the update() method.
43
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
45
class StaticSoundBinding : public SoundBinding
50
* @brief Ctor. All bindings between the buffer and the sound source will occur here.
51
* @param source The sound source.
52
* @param sample The static sound sample to bind to the source.
54
StaticSoundBinding(SoundSource& source, StaticSoundSample& sample);
57
* @copydoc SoundBinding::update()
61
///Since it's a static sound we don't need to update anything.
67
* @brief The static sound samle used for binding.
68
* There's really no need to keep this around here, since the binding will occur in the constructor, but hey, someday we might provide some kind of dynamic unloading/reloading...
70
StaticSoundSample& mSample;
76
* Defines general properties of sound data
82
typedef std::vector<ALuint> BufferStore;
84
virtual ~BaseSoundSample() {}
89
SoundGeneral::SoundSampleType getType();
91
virtual unsigned int getNumberOfBuffers() = 0;
94
* @brief Returns a store of the sound data buffers stored by this sample.
95
* The buffers will be returned as ALuint which is the internal buffer reference within OpenAL. Any further operation on the buffer must therefore go through OpenAL (i.e. the values returned are _not_ memory pointers).
96
* @return A store of OpenAL buffer identifiers.
98
virtual BufferStore getBuffers() = 0;
101
* @brief Creates a new binding to this buffer, to be used together with an instance of SoundInstance.
102
* If you want the sound held by this buffer to be played, one way would be to call this to create a binding which you then feed to an instance of SoundInstance.
103
* Note that ownership of the created binding is transferred to the caller, and thus it's the caller's responsibility to make sure it's properly deleted. Under normal circumstances that will be taken care of by SoundInstance however.
104
* @see SoundInstance::bind()
105
* @param source The sound source to which we should bind this sound sample.
106
* @return A new sound binding instance.
108
virtual SoundBinding* createBinding(SoundSource& source) = 0;
112
* @brief Ctor. This is protected to disallow direct creation of this class except by subclasses.
118
SoundGeneral::SoundSampleType mType;
122
* The class StaticSoundSample is responsible
123
* to keep track of samples that doesnt need
124
* often updates and only have one buffer
126
class StaticSoundSample : public BaseSoundSample
129
StaticSoundSample(const ResourceWrapper& resource, bool playsLocal, float volume);
130
~StaticSoundSample();
133
* Returns the unique buffer this sample has.
138
* Within this class, this is always 1.
140
unsigned int getNumberOfBuffers();
143
* @copydoc BaseSoundSample::createBinding()
145
virtual SoundBinding* createBinding(SoundSource& source);
148
* @copydoc BaseSoundSample::getBuffers()
150
virtual BaseSoundSample::BufferStore getBuffers();
158
* @brief The resource wrapper instance which holds the actual data.
160
ResourceWrapper mResource;
165
* The class StreamedSoundSample is responsible
166
* to keep track of samples that often need
167
* updates and requires more than a buffer to stream
170
// class StreamedSoundSample : public BaseSoundSample
174
// * Filename with full path to the data.
176
// std::string mFilename;
179
// * A pointer to the file specified in mFilename
184
// * VORBIS Internal Stream
186
// OggVorbis_File mStream;
189
// * Front and back buffers for openAl
191
// ALuint mBuffers[2];
194
// * Format of the stream (checked from ogg/vorbis)
199
// * Rate of the stream (checked from ogg/vorbis)
204
// * If this stream is playing
209
// * This function is responsible to fill
210
// * buffers from stream data
212
// * @param buffer The destination openAl buffer
213
// * @return Status of the streaming
215
// bool stream(ALuint buffer);
218
// StreamedSoundSample(const std::string& filename, bool playsLocal, float volume);
219
// ~StreamedSoundSample();
222
// * Set the file to be used in stream proccess.
224
// * @param ptr A pointer to the file.
225
// * @param filename The file name with full path.
227
// void setFile(FILE* ptr, const std::string& filename);
230
// * Set stream format
232
// void setFormat(ALenum fmt);
237
// void setRate(ALuint rate);
240
// * Set the stream status (if playing or not)
242
// void setPlaying(bool play);
245
// * Returns a pointer to the buffers array
247
// ALuint* getBufferPtr();
250
// * Returns a pointer to the stream information (vorbis internals).
252
// OggVorbis_File* getStreamPtr();
255
// * Return the state of the stream.
260
// * Return the number of buffers in this stream. In this case this is 2.
262
// unsigned int getNumberOfBuffers();
265
// * Return the full filename of the stream file.
267
// const std::string& getFilename();