Added looping in love.audio (though needs implementation in love.sound).

This commit is contained in:
rude
2009-08-01 22:11:48 +02:00
parent c1ed4372d9
commit 524ef5e118
14 changed files with 87 additions and 20 deletions
+11 -1
View File
@@ -25,7 +25,7 @@ namespace love
namespace audio
{
Source::Source()
: audible(0)
: audible(0), looping(false)
{
}
@@ -56,5 +56,15 @@ namespace audio
return audible;
}
void Source::setLooping(bool looping)
{
this->looping = looping;
}
bool Source::isLooping() const
{
return looping;
}
} // audio
} // love
+4
View File
@@ -33,6 +33,7 @@ namespace audio
{
protected:
Audible * audible;
bool looping;
public:
Source();
virtual ~Source();
@@ -52,6 +53,9 @@ namespace audio
virtual void setVolume(float volume) = 0;
virtual float getVolume() const = 0;
void setLooping(bool looping);
bool isLooping() const;
}; // Source
+7 -3
View File
@@ -55,7 +55,7 @@ namespace openal
{
for(int i = 0; i < NUM_BUFFERS; i++)
{
if(!stream(buffers[i]))
if(!stream(s, buffers[i]))
{
std::cout << "Could not stream music." << std::endl;
return;
@@ -82,7 +82,7 @@ namespace openal
// Get a free buffer.
alSourceUnqueueBuffers(source, 1, &buffer);
if(stream(buffer))
if(stream(s, buffer))
alSourceQueueBuffers(source, 1, &buffer);
}
}
@@ -111,8 +111,11 @@ namespace openal
play(s);
}
bool Music::stream(ALuint buffer)
bool Music::stream(love::audio::Source * source, ALuint buffer)
{
if(source->isLooping() && decoder->isFinished())
decoder->rewind();
// Get more sound data.
int decoded = decoder->decode();
@@ -131,6 +134,7 @@ namespace openal
return false;
}
} // openal
} // audio
} // love
+2 -2
View File
@@ -48,10 +48,10 @@ namespace openal
Pool * pool;
love::sound::Decoder * decoder;
ALuint source;
public:
Music(Pool * pool, love::sound::Decoder * decoder);
virtual ~Music();
// Implements Audible.
void play(love::audio::Source * source);
@@ -63,7 +63,7 @@ namespace openal
love::audio::Music * clone();
private:
bool stream(ALuint buffer);
bool stream(love::audio::Source * source, ALuint buffer);
}; // Sound
} // openal
+5 -1
View File
@@ -58,12 +58,16 @@ namespace openal
source = pool->find(s);
if(source)
{
alSourcei(source, AL_BUFFER, buffer);
alSourcei(source, AL_LOOPING, s->isLooping() ? AL_TRUE : AL_FALSE);
}
}
void Sound::update(love::audio::Source * s)
{
// No need.
// Looping mode could have changed.
alSourcei(source, AL_LOOPING, s->isLooping() ? AL_TRUE : AL_FALSE);
}
void Sound::stop(love::audio::Source * s)
+17
View File
@@ -59,11 +59,28 @@ namespace audio
return 1;
}
int _wrap_Source_setLooping(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->setLooping(luax_toboolean(L, 2));
return 0;
}
int _wrap_Source_isLooping(lua_State * L)
{
Source * t = luax_checksource(L, 1);
luax_pushboolean(L, t->isLooping());
return 1;
}
static const luaL_Reg wrap_Source_functions[] = {
{ "setPitch", _wrap_Source_setPitch },
{ "getPitch", _wrap_Source_getPitch },
{ "setVolume", _wrap_Source_setVolume },
{ "getVolume", _wrap_Source_getVolume },
{ "setLooping", _wrap_Source_setLooping },
{ "isLooping", _wrap_Source_isLooping },
{ 0, 0 }
};
+2
View File
@@ -33,6 +33,8 @@ namespace audio
int _wrap_Source_getPitch(lua_State * L);
int _wrap_Source_setVolume(lua_State * L);
int _wrap_Source_getVolume(lua_State * L);
int _wrap_Source_setLooping(lua_State * L);
int _wrap_Source_isLooping(lua_State * L);
int wrap_Source_open(lua_State * L);
} // audio