Added Source:clone() and love.audio.newSource(source): creates a new (stopped) Source which has all of the settable state of the original.

Static sources don’t duplicate their OpenAL data buffer when cloned (resolves issue #319). Cloned streaming sources also clone the original Decoder.
This commit is contained in:
Alex Szpakowski
2013-12-20 00:20:41 -04:00
parent d0d629a314
commit e6f2d4f1ac
8 changed files with 126 additions and 24 deletions
+26 -2
View File
@@ -47,14 +47,35 @@ namespace openal
class Audio;
class Pool;
// Basically just a reference-counted non-streaming OpenAL buffer object.
class StaticDataBuffer : public love::Object
{
public:
StaticDataBuffer(ALenum format, const ALvoid *data, ALsizei size, ALsizei freq);
virtual ~StaticDataBuffer();
inline ALuint getBuffer() const
{
return buffer;
}
private:
ALuint buffer;
}; // StaticDataBuffer
class Source : public love::audio::Source
{
public:
Source(Pool *pool, love::sound::SoundData *soundData);
Source(Pool *pool, love::sound::Decoder *decoder);
Source(Source *s);
virtual ~Source();
virtual love::audio::Source *copy();
virtual love::audio::Source *clone();
virtual void play();
virtual void stop();
virtual void pause();
@@ -123,8 +144,11 @@ private:
Pool *pool;
ALuint source;
bool valid;
static const unsigned int MAX_BUFFERS = 32;
ALuint buffers[MAX_BUFFERS];
ALuint streamBuffers[MAX_BUFFERS];
StaticDataBuffer *staticBuffer;
float pitch;
float volume;