Sound should now work again. Music looping does probably not work, however (at least now with mp3).

This commit is contained in:
rude
2009-10-24 23:48:06 +02:00
parent ff06834934
commit 0d897b0b0f
14 changed files with 551 additions and 564 deletions
+1 -1
View File
@@ -61,7 +61,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libmodplug.lib libmpg123.lib libogg.lib libvorbis.lib libvorbisfile.lib libFLAC_static.lib libFLAC++_static.lib"
AdditionalDependencies="libmodplug.lib libmpg123.lib libogg.lib libvorbis.lib libvorbisfile.lib libFLAC_static_d.lib libFLAC++_static_d.lib"
OutputFile="$(OutDir)\love\$(ProjectName).dll"
LinkIncremental="2"
AdditionalLibraryDirectories="..\lib"
+1 -1
View File
@@ -45,7 +45,7 @@ namespace audio
virtual void pause() = 0;
virtual void resume() = 0;
virtual void rewind() = 0;
virtual bool isFinished() const = 0;
virtual bool isStopped() const = 0;
virtual void update() = 0;
virtual void setPitch(float pitch) = 0;
+1 -1
View File
@@ -60,7 +60,7 @@ namespace null
{
}
bool Source::isFinished() const
bool Source::isStopped() const
{
return true;
}
+1 -1
View File
@@ -48,7 +48,7 @@ namespace null
void pause();
void resume();
void rewind();
bool isFinished() const;
bool isStopped() const;
void update();
void setPitch(float pitch);
+1 -4
View File
@@ -55,10 +55,7 @@ namespace openal
{
finish = true;
int status;
SDL_WaitThread(thread, &status);
pool->stop();
SDL_WaitThread(thread, 0);
delete pool;
+1 -7
View File
@@ -96,19 +96,13 @@ namespace openal
alSourceStop(source);
alSourceUnqueueBuffers(source, NUM_BUFFERS, bufs);
source = 0;
rewind(s);
}
}
void Music::rewind(love::audio::Source * s)
{
// Stop source, unqueue buffers.
stop(s);
// Rewind data pointer.
decoder->rewind();
// Requeue buffers.
play(s);
}
bool Music::stream(love::audio::Source * source, ALuint buffer)
+26 -31
View File
@@ -27,8 +27,8 @@
exit(-1); \
} \
#define LOCK(m) MUTEX_ASSERT(SDL_mutexP(m), 0)
#define UNLOCK(m) MUTEX_ASSERT(SDL_mutexV(m), 0);
#define LOCK(m) MUTEX_ASSERT(SDL_LockMutex(m), 0)
#define UNLOCK(m) MUTEX_ASSERT(SDL_UnlockMutex(m), 0)
namespace love
{
@@ -54,16 +54,9 @@ namespace openal
Pool::~Pool()
{
SDL_DestroyMutex(mutex);
std::map<love::audio::Source *, ALuint>::iterator i = playing.begin();
stop();
while(i != playing.end())
{
i->first->stop();
i->first->release();
i++;
}
SDL_DestroyMutex(mutex);
// Free all sources.
alDeleteSources(NUM_SOURCES, sources);
@@ -106,25 +99,14 @@ namespace openal
// Insert into map of playing sources.
playing.insert(std::pair<love::audio::Source *, ALuint>(source, s));
source->retain();
}
UNLOCK(mutex);
return s;
}
void Pool::release(love::audio::Source * source)
{
LOCK(mutex);
ALuint s = findi(source);
if(s != 0)
{
available.push(s);
playing.erase(source);
}
UNLOCK(mutex);
}
ALuint Pool::find(const love::audio::Source * source) const
{
ALuint r = 0;
@@ -152,18 +134,14 @@ namespace openal
LOCK(mutex);
std::map<love::audio::Source *, ALuint>::iterator i = playing.begin();
while(i != playing.end())
{
if(i->first->isFinished())
if(i->first->isStopped())
{
// Stop the source.
i->first->stop();
// Make it available.
i->first->release();
available.push(i->second);
// Remove if from the playing list.
playing.erase(i++);
}
else
@@ -190,7 +168,13 @@ namespace openal
{
LOCK(mutex);
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
{
i->first->stop();
available.push(i->second);
}
playing.clear();
UNLOCK(mutex);
}
@@ -218,6 +202,17 @@ namespace openal
UNLOCK(mutex);
}
void Pool::release(love::audio::Source * source)
{
ALuint s = findi(source);
if(s != 0)
{
available.push(s);
playing.erase(source);
}
}
ALuint Pool::findi(const love::audio::Source * source) const
{
std::map<love::audio::Source *, ALuint>::const_iterator i = playing.find((love::audio::Source *)source);
+6 -6
View File
@@ -102,12 +102,6 @@ namespace openal
**/
ALuint claim(love::audio::Source * source);
/**
* Makes the specified OpenAL source available for use.
* @param source The OpenAL source.
**/
void release(love::audio::Source * source);
ALuint find(const love::audio::Source * source) const;
void update();
@@ -122,6 +116,12 @@ namespace openal
private:
/**
* Makes the specified OpenAL source available for use.
* @param source The OpenAL source.
**/
void release(love::audio::Source * source);
ALuint findi(const love::audio::Source * source) const;
}; // Pool
+2 -1
View File
@@ -72,7 +72,8 @@ namespace openal
void Sound::stop(love::audio::Source * s)
{
// Also no need.
if(source)
alSourceStop(source);
}
void Sound::rewind(love::audio::Source * s)
+1 -8
View File
@@ -75,7 +75,6 @@ namespace openal
alSourceStop(source);
audible->stop(this);
source = 0;
pool->release(this);
}
}
@@ -101,7 +100,7 @@ namespace openal
audible->rewind(this);
}
bool Source::isFinished() const
bool Source::isStopped() const
{
if(source)
{
@@ -115,12 +114,6 @@ namespace openal
void Source::update()
{
if(isFinished())
{
stop();
return;
}
if(audible != 0)
audible->update(this);
}
+1 -1
View File
@@ -64,7 +64,7 @@ namespace openal
void pause();
void resume();
void rewind();
bool isFinished() const;
bool isStopped() const;
void update();
void setPitch(float pitch);
+4 -8
View File
@@ -101,29 +101,25 @@ namespace audio
int w_stop(lua_State * L)
{
Source * c = luax_checksource(L, 1);
instance->stop(c);
instance->stop();
return 0;
}
int w_pause(lua_State * L)
{
Source * c = luax_checksource(L, 1);
instance->pause(c);
instance->pause();
return 0;
}
int w_resume(lua_State * L)
{
Source * c = luax_checksource(L, 1);
instance->resume(c);
instance->resume();
return 0;
}
int w_rewind(lua_State * L)
{
Source * c = luax_checksource(L, 1);
instance->rewind(c);
instance->rewind();
return 0;
}
+9 -2
View File
@@ -197,7 +197,12 @@ function love.run()
-- Process events.
for e,a,b,c in love.event.poll() do
if e == "q" then return end
if e == "q" then
if love.audio then
love.audio.stop()
end
return
end
love.handlers[e](a,b,c)
end
@@ -671,7 +676,9 @@ function love.errhand(msg)
while true do
e, a, b, c = love.event.wait()
if e == "q" then return end
if e == "q" then
return
end
if e == "kp" and a == "escape" then
return
end
+496 -492
View File
File diff suppressed because it is too large Load Diff