mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
Initial Mercurial commit.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_AUDIBLE_H
|
||||
#define LOVE_AUDIO_AUDIBLE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
class Source;
|
||||
|
||||
class Audible : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~Audible(){};
|
||||
virtual void play(Source * source) = 0;
|
||||
virtual void update(Source * source) = 0;
|
||||
virtual void stop(Source * source) = 0;
|
||||
virtual void rewind(Source * source) = 0;
|
||||
|
||||
}; // Audible
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_AUDIBLE_H
|
||||
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented = 0; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_AUDIO_H
|
||||
#define LOVE_AUDIO_AUDIO_H
|
||||
|
||||
#include <common/Module.h>
|
||||
#include "Source.h"
|
||||
#include "Sound.h"
|
||||
#include "Music.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
/**
|
||||
* The Audio module is responsible for playing back raw sound samples.
|
||||
**/
|
||||
class Audio : public Module
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~Audio(){};
|
||||
|
||||
/**
|
||||
* Creates a new Sound with the specified SoundData.
|
||||
* @param data The SoundData from which to create the sound.
|
||||
* @return A new Sound if successful, zero otherwise.
|
||||
**/
|
||||
virtual Sound * newSound(love::sound::SoundData * data) = 0;
|
||||
|
||||
/**
|
||||
* Creates a new Music (stream) using the specified SoundData.
|
||||
* @param decoder The object to use to decode the sound stream.
|
||||
**/
|
||||
virtual Music * newMusic(love::sound::Decoder * decoder) = 0;
|
||||
|
||||
/**
|
||||
* Creates a new Source.
|
||||
* @returns A new Source.
|
||||
**/
|
||||
virtual Source * newSource() = 0;
|
||||
|
||||
/**
|
||||
* Gets the current number of simulatenous playing sources.
|
||||
* @return The current number of simulatenous playing sources.
|
||||
**/
|
||||
virtual int getNumSources() const = 0;
|
||||
|
||||
/**
|
||||
* Gets the maximum supported number of simulatenous playing sources.
|
||||
* @return The maximum supported number of simulatenous playing sources.
|
||||
**/
|
||||
virtual int getMaxSources() const = 0;
|
||||
|
||||
/**
|
||||
* Play the specified Source.
|
||||
* @param source The Source to play.
|
||||
**/
|
||||
virtual void play(Source * source) = 0;
|
||||
|
||||
/**
|
||||
* Plays one Sound on the specified Source. We need separate
|
||||
* Sound and Music play functions because Music must be cloned,
|
||||
* whereas Sound needs not be.
|
||||
*
|
||||
* @param sound The Sound to play.
|
||||
* @param source The Source on which to play the Sound.
|
||||
**/
|
||||
virtual void play(Sound * sound) = 0;
|
||||
|
||||
/**
|
||||
* Plays one Music on the specified Source. We need separate
|
||||
* Sound and Music play functions because Music must be cloned,
|
||||
* whereas Sound needs not be.
|
||||
*
|
||||
* @param music The Music to play.
|
||||
* @param source The Source on which to play the Music.
|
||||
**/
|
||||
virtual void play(Music * music) = 0;
|
||||
|
||||
/**
|
||||
* Stops playback on the specified source.
|
||||
* @param source The source on which to stop the playback.
|
||||
**/
|
||||
virtual void stop(Source * source) = 0;
|
||||
|
||||
/**
|
||||
* Stops all playing audio.
|
||||
**/
|
||||
virtual void stop() = 0;
|
||||
|
||||
/**
|
||||
* Pauses playback on the specified source.
|
||||
* @param source The source on which to pause the playback.
|
||||
**/
|
||||
virtual void pause(Source * source) = 0;
|
||||
|
||||
/**
|
||||
* Pauses all audio.
|
||||
**/
|
||||
virtual void pause() = 0;
|
||||
|
||||
/**
|
||||
* Resumes playback on the specified source.
|
||||
* @param source The source on which to resume the playback.
|
||||
**/
|
||||
virtual void resume(Source * source) = 0;
|
||||
|
||||
/**
|
||||
* Resumes all audio.
|
||||
**/
|
||||
virtual void resume() = 0;
|
||||
|
||||
/**
|
||||
* Rewinds the specified source. Whatever is playing on this
|
||||
* source gets rewound to the start.
|
||||
* @param source The source to rewind.
|
||||
**/
|
||||
virtual void rewind(Source * source) = 0;
|
||||
|
||||
/**
|
||||
* Rewinds all playing audio.
|
||||
**/
|
||||
virtual void rewind() = 0;
|
||||
|
||||
/**
|
||||
* Sets the master volume, where 0.0f is min (off) and 1.0f is max.
|
||||
* @param volume The new master volume.
|
||||
**/
|
||||
virtual void setVolume(float volume) = 0;
|
||||
|
||||
/**
|
||||
* Gets the master volume.
|
||||
* @return The current master volume.
|
||||
**/
|
||||
virtual float getVolume() const = 0;
|
||||
|
||||
}; // Audio
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_AUDIO_H
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_MUSIC_H
|
||||
#define LOVE_AUDIO_MUSIC_H
|
||||
|
||||
// LOVE
|
||||
#include "Audible.h"
|
||||
#include <sound/Decoder.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
/**
|
||||
* A Music object represents a stream of sound samples which are gradually
|
||||
* acquired somehow. Compare with Sounds, which have all the needed sound
|
||||
* samples pre-decoded.
|
||||
*
|
||||
* Typically, you would want to use love::sound::Decoder to decode samples
|
||||
* from some encoded format, like OGG or MP3, however, Music can come from
|
||||
* other sources as well.
|
||||
**/
|
||||
class Music : public Audible
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~Music(){};
|
||||
|
||||
/**
|
||||
* Creates a clone of the music stream. Music objects are gradually
|
||||
* decoded, so if the client wants to play the same Music object, we can't
|
||||
* use the same object. We must clone the entire stream.
|
||||
* @return A clone of this object, but rewound to the start.
|
||||
**/
|
||||
virtual Music * clone() = 0;
|
||||
|
||||
}; // Music
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_MUSIC_H
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_SOUND_H
|
||||
#define LOVE_AUDIO_SOUND_H
|
||||
|
||||
// LOVE
|
||||
#include <sound/SoundData.h>
|
||||
#include "Audible.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
class Sound : public Audible
|
||||
{
|
||||
private:
|
||||
public:
|
||||
virtual ~Sound(){};
|
||||
}; // Sound
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_SOUND_H
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Source.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Source::Source()
|
||||
: audible(0)
|
||||
{
|
||||
}
|
||||
|
||||
Source::~Source()
|
||||
{
|
||||
if(audible != 0)
|
||||
{
|
||||
audible->stop(this);
|
||||
audible->release();
|
||||
}
|
||||
}
|
||||
|
||||
void Source::setAudible(Audible * audible)
|
||||
{
|
||||
// If this source already has an audible, remove it.
|
||||
if(this->audible != 0)
|
||||
{
|
||||
this->audible->stop(this);
|
||||
this->audible->release();
|
||||
}
|
||||
|
||||
this->audible = audible;
|
||||
audible->retain();
|
||||
}
|
||||
|
||||
Audible * Source::getAudible() const
|
||||
{
|
||||
return audible;
|
||||
}
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_SOURCE_H
|
||||
#define LOVE_AUDIO_SOURCE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
#include "Audible.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
class Source : public Object
|
||||
{
|
||||
protected:
|
||||
Audible * audible;
|
||||
public:
|
||||
Source();
|
||||
virtual ~Source();
|
||||
void setAudible(Audible * audible);
|
||||
Audible * getAudible() const;
|
||||
|
||||
virtual void play() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void pause() = 0;
|
||||
virtual void resume() = 0;
|
||||
virtual void rewind() = 0;
|
||||
virtual bool isFinished() const = 0;
|
||||
virtual void update() = 0;
|
||||
|
||||
virtual void setPitch(float pitch) = 0;
|
||||
virtual float getPitch() const = 0;
|
||||
|
||||
virtual void setVolume(float volume) = 0;
|
||||
virtual float getVolume() const = 0;
|
||||
|
||||
}; // Source
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_SOURCE_H
|
||||
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Audio.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
Audio::Audio()
|
||||
{
|
||||
}
|
||||
|
||||
Audio::~Audio()
|
||||
{
|
||||
}
|
||||
|
||||
const char * Audio::getName() const
|
||||
{
|
||||
return "love.audio.null";
|
||||
}
|
||||
|
||||
love::audio::Sound * Audio::newSound(love::sound::SoundData * data)
|
||||
{
|
||||
return new Sound(data);
|
||||
}
|
||||
|
||||
love::audio::Music * Audio::newMusic(love::sound::Decoder * decoder)
|
||||
{
|
||||
return new Music(decoder);
|
||||
}
|
||||
|
||||
love::audio::Source * Audio::newSource()
|
||||
{
|
||||
return new Source();
|
||||
}
|
||||
|
||||
int Audio::getNumSources() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Audio::getMaxSources() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Audio::play(love::audio::Source * source)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::play(love::audio::Sound * sound)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::play(love::audio::Music * music)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::play()
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::stop(love::audio::Source * source)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::stop()
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::pause(love::audio::Source * source)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::pause()
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::resume(love::audio::Source * source)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::resume()
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::rewind(love::audio::Source * source)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::rewind()
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::setVolume(float volume)
|
||||
{
|
||||
this->volume = volume;
|
||||
}
|
||||
|
||||
float Audio::getVolume() const
|
||||
{
|
||||
return volume;
|
||||
}
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_NULL_AUDIO_H
|
||||
#define LOVE_AUDIO_NULL_AUDIO_H
|
||||
|
||||
// LOVE
|
||||
#include <audio/Audio.h>
|
||||
|
||||
#include "Sound.h"
|
||||
#include "Music.h"
|
||||
#include "Source.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
class Audio : public love::audio::Audio
|
||||
{
|
||||
private:
|
||||
float volume;
|
||||
public:
|
||||
|
||||
Audio();
|
||||
~Audio();
|
||||
|
||||
// Implements Module.
|
||||
const char * getName() const;
|
||||
|
||||
// Implements Audio.
|
||||
love::audio::Sound * newSound(love::sound::SoundData * data);
|
||||
love::audio::Music * newMusic(love::sound::Decoder * decoder);
|
||||
love::audio::Source * newSource();
|
||||
int getNumSources() const;
|
||||
int getMaxSources() const;
|
||||
void play(love::audio::Source * source);
|
||||
void play(love::audio::Sound * sound);
|
||||
void play(love::audio::Music * music);
|
||||
void play();
|
||||
void stop(love::audio::Source * source);
|
||||
void stop();
|
||||
void pause(love::audio::Source * source);
|
||||
void pause();
|
||||
void resume(love::audio::Source * source);
|
||||
void resume();
|
||||
void rewind(love::audio::Source * source);
|
||||
void rewind();
|
||||
void setVolume(float volume);
|
||||
float getVolume() const;
|
||||
|
||||
}; // Audio
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_NULL_AUDIO_H
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Music.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
Music::Music(love::sound::Decoder * decoder)
|
||||
: decoder(decoder)
|
||||
{
|
||||
decoder->retain();
|
||||
}
|
||||
|
||||
Music::~Music()
|
||||
{
|
||||
decoder->release();
|
||||
}
|
||||
|
||||
love::audio::Music * Music::clone()
|
||||
{
|
||||
return new Music(decoder->clone());
|
||||
}
|
||||
|
||||
void Music::play(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
void Music::update(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
void Music::stop(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
void Music::rewind(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_NULL_MUSIC_H
|
||||
#define LOVE_AUDIO_NULL_MUSIC_H
|
||||
|
||||
// LOVE
|
||||
#include <audio/Music.h>
|
||||
#include <sound/Decoder.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
class Music : public love::audio::Music
|
||||
{
|
||||
private:
|
||||
love::sound::Decoder * decoder;
|
||||
public:
|
||||
Music(love::sound::Decoder * decoder);
|
||||
virtual ~Music();
|
||||
|
||||
// Implements Audible.
|
||||
void play(love::audio::Source * source);
|
||||
void update(love::audio::Source * source);
|
||||
void stop(love::audio::Source * source);
|
||||
void rewind(love::audio::Source * source);
|
||||
|
||||
// Implements Music.
|
||||
love::audio::Music * clone();
|
||||
|
||||
}; // Music
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_NULL_MUSIC_H
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Sound.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
Sound::Sound(love::sound::SoundData * data)
|
||||
{
|
||||
}
|
||||
|
||||
Sound::~Sound()
|
||||
{
|
||||
}
|
||||
|
||||
void Sound::play(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
void Sound::update(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
void Sound::stop(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
void Sound::rewind(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_NULL_SOUND_H
|
||||
#define LOVE_AUDIO_NULL_SOUND_H
|
||||
|
||||
// LOVE
|
||||
#include <sound/SoundData.h>
|
||||
#include <audio/Sound.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
class Sound : public love::audio::Sound
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
Sound(love::sound::SoundData * data);
|
||||
virtual ~Sound();
|
||||
|
||||
// Implements Audible.
|
||||
void play(love::audio::Source * s);
|
||||
void update(love::audio::Source * s);
|
||||
void stop(love::audio::Source * s);
|
||||
void rewind(love::audio::Source * s);
|
||||
|
||||
}; // Sound
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_NULL_SOUND_H
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Source.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
|
||||
Source::Source()
|
||||
{
|
||||
}
|
||||
|
||||
Source::Source(Audible * audible)
|
||||
{
|
||||
setAudible(audible);
|
||||
}
|
||||
|
||||
Source::~Source()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::play()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::stop()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::pause()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::resume()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::rewind()
|
||||
{
|
||||
}
|
||||
|
||||
bool Source::isFinished() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Source::update()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::setPitch(float pitch)
|
||||
{
|
||||
this->pitch = pitch;
|
||||
}
|
||||
|
||||
float Source::getPitch() const
|
||||
{
|
||||
return pitch;
|
||||
}
|
||||
|
||||
void Source::setVolume(float volume)
|
||||
{
|
||||
this->volume = volume;
|
||||
}
|
||||
|
||||
float Source::getVolume() const
|
||||
{
|
||||
return volume;
|
||||
}
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_NULL_SOURCE_H
|
||||
#define LOVE_AUDIO_NULL_SOURCE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
#include <audio/Source.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
class Source : public love::audio::Source
|
||||
{
|
||||
private:
|
||||
|
||||
float pitch;
|
||||
float volume;
|
||||
|
||||
public:
|
||||
Source();
|
||||
Source(Audible * audible);
|
||||
virtual ~Source();
|
||||
|
||||
void play();
|
||||
void stop();
|
||||
void pause();
|
||||
void resume();
|
||||
void rewind();
|
||||
bool isFinished() const;
|
||||
void update();
|
||||
|
||||
void setPitch(float pitch);
|
||||
float getPitch() const;
|
||||
|
||||
void setVolume(float volume);
|
||||
float getVolume() const;
|
||||
|
||||
}; // Source
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_NULL_SOURCE_H
|
||||
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Audio.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
Audio::Audio()
|
||||
{
|
||||
// Passing zero for default device.
|
||||
device = alcOpenDevice(0);
|
||||
|
||||
if(device == 0)
|
||||
throw love::Exception("Could not open device.");
|
||||
|
||||
context = alcCreateContext(device, 0);
|
||||
|
||||
if(context == 0)
|
||||
throw love::Exception("Could not create context.");
|
||||
|
||||
alcMakeContextCurrent(context);
|
||||
|
||||
if(alcGetError(device) != ALC_NO_ERROR)
|
||||
throw love::Exception("Could not make context current.");
|
||||
|
||||
// pool must be allocated after AL context.
|
||||
pool = new Pool();
|
||||
|
||||
thread = SDL_CreateThread(Audio::run, (void*)this);
|
||||
}
|
||||
|
||||
Audio::~Audio()
|
||||
{
|
||||
SDL_KillThread(thread);
|
||||
|
||||
delete pool;
|
||||
|
||||
alcMakeContextCurrent(0);
|
||||
alcDestroyContext(context);
|
||||
alcCloseDevice(device);
|
||||
}
|
||||
|
||||
int Audio::run(void * d)
|
||||
{
|
||||
Audio * instance = (Audio*)d;
|
||||
|
||||
while(true)
|
||||
{
|
||||
instance->pool->update();
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * Audio::getName() const
|
||||
{
|
||||
return "love.audio.openal";
|
||||
}
|
||||
|
||||
love::audio::Sound * Audio::newSound(love::sound::SoundData * data)
|
||||
{
|
||||
return new Sound(pool, data);
|
||||
}
|
||||
|
||||
love::audio::Music * Audio::newMusic(love::sound::Decoder * decoder)
|
||||
{
|
||||
return new Music(pool, decoder);
|
||||
}
|
||||
|
||||
love::audio::Source * Audio::newSource()
|
||||
{
|
||||
return new Source(pool);
|
||||
}
|
||||
|
||||
int Audio::getNumSources() const
|
||||
{
|
||||
return pool->getNumSources();
|
||||
}
|
||||
|
||||
int Audio::getMaxSources() const
|
||||
{
|
||||
return pool->getMaxSources();
|
||||
}
|
||||
|
||||
void Audio::play(love::audio::Source * source)
|
||||
{
|
||||
source->play();
|
||||
}
|
||||
|
||||
void Audio::play(love::audio::Sound * sound)
|
||||
{
|
||||
Source * source = new Source(pool, sound);
|
||||
play(source);
|
||||
source->release();
|
||||
}
|
||||
|
||||
void Audio::play(love::audio::Music * music)
|
||||
{
|
||||
Source * source = new Source(pool, music->clone());
|
||||
play(source);
|
||||
source->release();
|
||||
}
|
||||
|
||||
void Audio::stop(love::audio::Source * source)
|
||||
{
|
||||
source->stop();
|
||||
}
|
||||
|
||||
void Audio::stop()
|
||||
{
|
||||
pool->stop();
|
||||
}
|
||||
|
||||
void Audio::pause(love::audio::Source * source)
|
||||
{
|
||||
source->pause();
|
||||
}
|
||||
|
||||
void Audio::pause()
|
||||
{
|
||||
pool->pause();
|
||||
}
|
||||
|
||||
void Audio::resume(love::audio::Source * source)
|
||||
{
|
||||
source->resume();
|
||||
}
|
||||
|
||||
void Audio::resume()
|
||||
{
|
||||
pool->resume();
|
||||
}
|
||||
|
||||
void Audio::rewind(love::audio::Source * source)
|
||||
{
|
||||
source->rewind();
|
||||
}
|
||||
|
||||
void Audio::rewind()
|
||||
{
|
||||
pool->rewind();
|
||||
}
|
||||
|
||||
void Audio::setVolume(float volume)
|
||||
{
|
||||
alListenerf(AL_GAIN, volume);
|
||||
}
|
||||
|
||||
float Audio::getVolume() const
|
||||
{
|
||||
ALfloat volume;
|
||||
alGetListenerf(AL_GAIN, &volume);
|
||||
return volume;
|
||||
}
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_OPENAL_AUDIO_H
|
||||
#define LOVE_AUDIO_OPENAL_AUDIO_H
|
||||
|
||||
// STD
|
||||
#include <queue>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
// SDL
|
||||
#include <SDL.h>
|
||||
|
||||
// OpenAL
|
||||
#include <AL/alc.h>
|
||||
#include <AL/al.h>
|
||||
|
||||
// LOVE
|
||||
#include <audio/Audio.h>
|
||||
#include <common/config.h>
|
||||
#include <common/constants.h>
|
||||
#include <sound/SoundData.h>
|
||||
|
||||
#include "Sound.h"
|
||||
#include "Music.h"
|
||||
#include "Source.h"
|
||||
#include "Pool.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
class Audio : public love::audio::Audio
|
||||
{
|
||||
private:
|
||||
|
||||
// The OpenAL device.
|
||||
ALCdevice * device;
|
||||
|
||||
// The OpenAL context.
|
||||
ALCcontext * context;
|
||||
|
||||
SDL_Thread * thread;
|
||||
|
||||
// The Pool.
|
||||
Pool * pool;
|
||||
|
||||
static int run(void * unused);
|
||||
|
||||
public:
|
||||
|
||||
Audio();
|
||||
~Audio();
|
||||
|
||||
// Implements Module.
|
||||
const char * getName() const;
|
||||
|
||||
// Implements Audio.
|
||||
love::audio::Sound * newSound(love::sound::SoundData * data);
|
||||
love::audio::Music * newMusic(love::sound::Decoder * decoder);
|
||||
love::audio::Source * newSource();
|
||||
int getNumSources() const;
|
||||
int getMaxSources() const;
|
||||
void play(love::audio::Source * source);
|
||||
void play(love::audio::Sound * sound);
|
||||
void play(love::audio::Music * music);
|
||||
void play();
|
||||
void stop(love::audio::Source * source);
|
||||
void stop();
|
||||
void pause(love::audio::Source * source);
|
||||
void pause();
|
||||
void resume(love::audio::Source * source);
|
||||
void resume();
|
||||
void rewind(love::audio::Source * source);
|
||||
void rewind();
|
||||
void setVolume(float volume);
|
||||
float getVolume() const;
|
||||
|
||||
}; // Audio
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_OPENAL_AUDIO_H
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Music.h"
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
Music::Music(Pool * pool, love::sound::Decoder * decoder)
|
||||
: pool(pool), decoder(decoder), source(0)
|
||||
{
|
||||
decoder->retain();
|
||||
alGenBuffers(NUM_BUFFERS, buffers);
|
||||
}
|
||||
|
||||
Music::~Music()
|
||||
{
|
||||
decoder->release();
|
||||
alDeleteBuffers(NUM_BUFFERS, buffers);
|
||||
}
|
||||
|
||||
love::audio::Music * Music::clone()
|
||||
{
|
||||
return new Music(pool, decoder->clone());
|
||||
}
|
||||
|
||||
void Music::play(love::audio::Source * s)
|
||||
{
|
||||
source = pool->find(s);
|
||||
|
||||
if(source)
|
||||
{
|
||||
for(int i = 0; i < NUM_BUFFERS; i++)
|
||||
{
|
||||
if(!stream(buffers[i]))
|
||||
{
|
||||
std::cout << "Could not stream music." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
alSourceQueueBuffers(source, NUM_BUFFERS, buffers);
|
||||
}
|
||||
}
|
||||
|
||||
void Music::update(love::audio::Source * s)
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
// Number of processed buffers.
|
||||
ALint processed;
|
||||
|
||||
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
|
||||
|
||||
while(processed--)
|
||||
{
|
||||
ALuint buffer;
|
||||
|
||||
// Get a free buffer.
|
||||
alSourceUnqueueBuffers(source, 1, &buffer);
|
||||
|
||||
if(stream(buffer))
|
||||
alSourceQueueBuffers(source, 1, &buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Music::stop(love::audio::Source * s)
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
ALuint bufs[NUM_BUFFERS];
|
||||
alSourceStop(source);
|
||||
alSourceUnqueueBuffers(source, NUM_BUFFERS, bufs);
|
||||
source = 0;
|
||||
}
|
||||
}
|
||||
|
||||
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(ALuint buffer)
|
||||
{
|
||||
// Get more sound data.
|
||||
int decoded = decoder->decode();
|
||||
|
||||
int fmt = pool->getFormat(decoder->getChannels(), decoder->getBits());
|
||||
|
||||
if(fmt == 0)
|
||||
return false;
|
||||
|
||||
if(decoded > 0)
|
||||
{
|
||||
alBufferData(buffer, fmt, decoder->getBuffer(),
|
||||
decoder->getSize(), decoder->getSampleRate());
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_OPENAL_MUSIC_H
|
||||
#define LOVE_AUDIO_OPENAL_MUSIC_H
|
||||
|
||||
// LOVE
|
||||
#include <audio/Music.h>
|
||||
#include <sound/Decoder.h>
|
||||
#include "Pool.h"
|
||||
|
||||
// OpenAL
|
||||
#include <AL/alc.h>
|
||||
#include <AL/al.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
|
||||
// Forward declarations.
|
||||
class Audio;
|
||||
|
||||
class Music : public love::audio::Music
|
||||
{
|
||||
private:
|
||||
static const unsigned int NUM_BUFFERS = 32;
|
||||
ALuint buffers[NUM_BUFFERS];
|
||||
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);
|
||||
void update(love::audio::Source * source);
|
||||
void stop(love::audio::Source * source);
|
||||
void rewind(love::audio::Source * source);
|
||||
|
||||
// Implements Music.
|
||||
love::audio::Music * clone();
|
||||
|
||||
private:
|
||||
bool stream(ALuint buffer);
|
||||
}; // Sound
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_OPENAL_MUSIC_H
|
||||
@@ -0,0 +1,237 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Pool.h"
|
||||
|
||||
#define MUTEX_ASSERT(fn, sval) \
|
||||
if(fn != sval) \
|
||||
{ \
|
||||
std::cout << "Mutex lock/unlock failure. " << SDL_GetError() << std::endl; \
|
||||
exit(-1); \
|
||||
} \
|
||||
|
||||
#define LOCK(m) MUTEX_ASSERT(SDL_mutexP(m), 0)
|
||||
#define UNLOCK(m) MUTEX_ASSERT(SDL_mutexV(m), 0);
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
Pool::Pool()
|
||||
{
|
||||
// Generate sources.
|
||||
alGenSources(NUM_SOURCES, sources);
|
||||
|
||||
// Create the mutex.
|
||||
mutex = SDL_CreateMutex();
|
||||
|
||||
if(alGetError() != AL_NO_ERROR)
|
||||
throw love::Exception("Could not generate sources.");
|
||||
|
||||
// Make all sources available initially.
|
||||
for(int i = 0; i < NUM_SOURCES; i++)
|
||||
available.push(sources[i]);
|
||||
}
|
||||
|
||||
Pool::~Pool()
|
||||
{
|
||||
SDL_DestroyMutex(mutex);
|
||||
|
||||
std::map<love::audio::Source *, ALuint>::iterator i = playing.begin();
|
||||
|
||||
while(i != playing.end())
|
||||
{
|
||||
i->first->stop();
|
||||
i->first->release();
|
||||
i++;
|
||||
}
|
||||
|
||||
// Free all sources.
|
||||
alDeleteSources(NUM_SOURCES, sources);
|
||||
}
|
||||
|
||||
ALenum Pool::getFormat(int channels, int bits) const
|
||||
{
|
||||
if(channels == 1 && bits == 8)
|
||||
return AL_FORMAT_MONO8;
|
||||
else if(channels == 1 && bits == 16)
|
||||
return AL_FORMAT_MONO16;
|
||||
else if(channels == 2 && bits == 8)
|
||||
return AL_FORMAT_STEREO8;
|
||||
else if(channels == 2 && bits == 16)
|
||||
return AL_FORMAT_STEREO16;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Pool::isAvailable() const
|
||||
{
|
||||
bool has = false;
|
||||
LOCK(mutex);
|
||||
has = !available.empty();
|
||||
UNLOCK(mutex);
|
||||
return has;
|
||||
}
|
||||
|
||||
ALuint Pool::claim(love::audio::Source * source)
|
||||
{
|
||||
ALuint s = 0;
|
||||
LOCK(mutex);
|
||||
if(!available.empty())
|
||||
{
|
||||
// Get the first available source.
|
||||
s = available.front();
|
||||
|
||||
// Remove it.
|
||||
available.pop();
|
||||
|
||||
// Insert into map of playing sources.
|
||||
playing.insert(std::pair<love::audio::Source *, ALuint>(source, s));
|
||||
|
||||
// Retain the source.
|
||||
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);
|
||||
source->release();
|
||||
}
|
||||
UNLOCK(mutex);
|
||||
}
|
||||
|
||||
ALuint Pool::find(const love::audio::Source * source) const
|
||||
{
|
||||
ALuint r = 0;
|
||||
LOCK(mutex);
|
||||
r = findi(source);
|
||||
UNLOCK(mutex);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool Pool::isPlaying(love::audio::Source * s)
|
||||
{
|
||||
bool p = false;
|
||||
LOCK(mutex);
|
||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||
{
|
||||
if(i->first == s)
|
||||
p = true;
|
||||
}
|
||||
UNLOCK(mutex);
|
||||
return p;
|
||||
}
|
||||
|
||||
void Pool::update()
|
||||
{
|
||||
LOCK(mutex);
|
||||
|
||||
std::map<love::audio::Source *, ALuint>::iterator i = playing.begin();
|
||||
|
||||
while(i != playing.end())
|
||||
{
|
||||
if(i->first->isFinished())
|
||||
{
|
||||
// Stop the source.
|
||||
i->first->stop();
|
||||
|
||||
// Make it available.
|
||||
available.push(i->second);
|
||||
|
||||
// Remove if from the playing list.
|
||||
playing.erase(i++);
|
||||
}
|
||||
else
|
||||
{
|
||||
i->first->update();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
UNLOCK(mutex);
|
||||
}
|
||||
|
||||
int Pool::getNumSources() const
|
||||
{
|
||||
return playing.size();
|
||||
}
|
||||
|
||||
int Pool::getMaxSources() const
|
||||
{
|
||||
return NUM_SOURCES;
|
||||
}
|
||||
|
||||
void Pool::stop()
|
||||
{
|
||||
LOCK(mutex);
|
||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||
i->first->stop();
|
||||
UNLOCK(mutex);
|
||||
}
|
||||
|
||||
void Pool::pause()
|
||||
{
|
||||
LOCK(mutex);
|
||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||
i->first->pause();
|
||||
UNLOCK(mutex);
|
||||
}
|
||||
|
||||
void Pool::resume()
|
||||
{
|
||||
LOCK(mutex);
|
||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||
i->first->resume();
|
||||
UNLOCK(mutex);
|
||||
}
|
||||
|
||||
void Pool::rewind()
|
||||
{
|
||||
LOCK(mutex);
|
||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||
i->first->rewind();
|
||||
UNLOCK(mutex);
|
||||
}
|
||||
|
||||
ALuint Pool::findi(const love::audio::Source * source) const
|
||||
{
|
||||
std::map<love::audio::Source *, ALuint>::const_iterator i = playing.find((love::audio::Source *)source);
|
||||
|
||||
if(i != playing.end())
|
||||
return i->second;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_OPENAL_POOL_H
|
||||
#define LOVE_AUDIO_OPENAL_POOL_H
|
||||
|
||||
// STD
|
||||
#include <queue>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
// SDL
|
||||
#include <SDL.h>
|
||||
|
||||
// OpenAL
|
||||
#include <AL/alc.h>
|
||||
#include <AL/al.h>
|
||||
|
||||
// LOVE
|
||||
#include <audio/Source.h>
|
||||
#include <common/Exception.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
class Pool
|
||||
{
|
||||
private:
|
||||
|
||||
// Number of OpenAL sources.
|
||||
static const int NUM_SOURCES = 16;
|
||||
|
||||
// OpenAL sources
|
||||
ALuint sources[NUM_SOURCES];
|
||||
|
||||
// A queue of available sources.
|
||||
std::queue<ALuint> available;
|
||||
|
||||
// A map of playing sources.
|
||||
std::map<love::audio::Source *, ALuint> playing;
|
||||
|
||||
// Only one thread can access this object at the same time. This mutex will
|
||||
// make sure of that.
|
||||
SDL_mutex * mutex;
|
||||
|
||||
public:
|
||||
|
||||
Pool();
|
||||
~Pool();
|
||||
|
||||
/**
|
||||
* Gets the OpenAL format identifier based on number of
|
||||
* channels and bits.
|
||||
* @param channels Either 1 (mono) or 2 (stereo).
|
||||
* @param bits Either 8-bit samples, or 16-bit samples.
|
||||
* @return One of AL_FORMAT_*, or 0 if unsupported format.
|
||||
**/
|
||||
ALenum getFormat(int channels, int bits) const;
|
||||
|
||||
/**
|
||||
* Checks whether an OpenAL source is available.
|
||||
* @return True if at least one is available, false otherwise.
|
||||
**/
|
||||
bool isAvailable() const;
|
||||
|
||||
/**
|
||||
* Checks whether a Source is currently in the playing list.
|
||||
**/
|
||||
bool isPlaying(love::audio::Source * s);
|
||||
|
||||
/**
|
||||
* Returns an available OpenAL source identifier, or 0 if
|
||||
* none is available.
|
||||
* @return An OpenAL source ID, or 0 if unavailable.
|
||||
**/
|
||||
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();
|
||||
|
||||
int getNumSources() const;
|
||||
int getMaxSources() const;
|
||||
|
||||
void stop();
|
||||
void pause();
|
||||
void resume();
|
||||
void rewind();
|
||||
|
||||
private:
|
||||
|
||||
ALuint findi(const love::audio::Source * source) const;
|
||||
}; // Pool
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_OPENAL_POOL_H
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Sound.h"
|
||||
|
||||
#include <common/Exception.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
Sound::Sound(Pool * pool, love::sound::SoundData * data)
|
||||
: pool(pool), buffer(0), source(source)
|
||||
{
|
||||
|
||||
// Generate the buffer.
|
||||
alGenBuffers(1, &buffer);
|
||||
|
||||
int fmt = pool->getFormat(data->getChannels(), data->getBits());
|
||||
|
||||
if(fmt == 0)
|
||||
throw love::Exception("Unsopported audio format.");
|
||||
|
||||
alBufferData(buffer, fmt, data->getData(), data->getSize(), data->getSampleRate());
|
||||
|
||||
// Note: we're done with the sound data
|
||||
// at this point. No need to retain.
|
||||
}
|
||||
|
||||
Sound::~Sound()
|
||||
{
|
||||
if(buffer)
|
||||
alDeleteBuffers(1, &buffer);
|
||||
}
|
||||
|
||||
void Sound::play(love::audio::Source * s)
|
||||
{
|
||||
// Set the buffer for the sound.
|
||||
source = pool->find(s);
|
||||
|
||||
if(source)
|
||||
alSourcei(source, AL_BUFFER, buffer);
|
||||
}
|
||||
|
||||
void Sound::update(love::audio::Source * s)
|
||||
{
|
||||
// No need.
|
||||
}
|
||||
|
||||
void Sound::stop(love::audio::Source * s)
|
||||
{
|
||||
// Also no need.
|
||||
}
|
||||
|
||||
void Sound::rewind(love::audio::Source * s)
|
||||
{
|
||||
if(source)
|
||||
alSourceRewind(source);
|
||||
}
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_OPENAL_SOUND_H
|
||||
#define LOVE_AUDIO_OPENAL_SOUND_H
|
||||
|
||||
// LOVE
|
||||
#include <sound/SoundData.h>
|
||||
#include <audio/Sound.h>
|
||||
#include "Pool.h"
|
||||
|
||||
// OpenAL
|
||||
#include <AL/alc.h>
|
||||
#include <AL/al.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
// Forward declarations.
|
||||
class Audio;
|
||||
|
||||
class Sound : public love::audio::Sound
|
||||
{
|
||||
private:
|
||||
|
||||
Pool * pool;
|
||||
|
||||
// Sounds only need one buffer.
|
||||
ALuint buffer;
|
||||
|
||||
ALuint source;
|
||||
|
||||
public:
|
||||
Sound(Pool * pool, love::sound::SoundData * data);
|
||||
virtual ~Sound();
|
||||
|
||||
// Implements Audible.
|
||||
void play(love::audio::Source * s);
|
||||
void update(love::audio::Source * s);
|
||||
void stop(love::audio::Source * s);
|
||||
void rewind(love::audio::Source * s);
|
||||
|
||||
}; // Sound
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_OPENAL_SOUND_H
|
||||
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Source.h"
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
|
||||
Source::Source(Pool * pool)
|
||||
: pool(pool), source(0), pitch(1.0f), volume(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
Source::Source(Pool * pool, Audible * audible)
|
||||
: pool(pool), source(0), pitch(1.0f), volume(1.0f)
|
||||
{
|
||||
setAudible(audible);
|
||||
}
|
||||
|
||||
Source::~Source()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::play()
|
||||
{
|
||||
if(source != 0)
|
||||
return; // Already playing.
|
||||
|
||||
if(pool->isAvailable())
|
||||
source = pool->claim(this);
|
||||
|
||||
if(source != 0)
|
||||
{
|
||||
audible->play(this);
|
||||
|
||||
// Set these properties. These may have changed while we've
|
||||
// been without an AL source.
|
||||
alSourcef(source, AL_PITCH, pitch);
|
||||
alSourcef(source, AL_GAIN, volume);
|
||||
|
||||
alSourcePlay(source);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Source::stop()
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
alSourceStop(source);
|
||||
audible->stop(this);
|
||||
source = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Source::pause()
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
alSourcePause(source);
|
||||
}
|
||||
}
|
||||
|
||||
void Source::resume()
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
alSourcePlay(source);
|
||||
}
|
||||
}
|
||||
|
||||
void Source::rewind()
|
||||
{
|
||||
if(audible != 0)
|
||||
audible->rewind(this);
|
||||
}
|
||||
|
||||
bool Source::isFinished() const
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
ALenum state;
|
||||
alGetSourcei(source, AL_SOURCE_STATE, &state);
|
||||
return (state == AL_STOPPED);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Source::update()
|
||||
{
|
||||
if(audible != 0)
|
||||
audible->update(this);
|
||||
}
|
||||
|
||||
void Source::setPitch(float pitch)
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
alSourcef(source, AL_PITCH, pitch);
|
||||
}
|
||||
|
||||
this->pitch = pitch;
|
||||
}
|
||||
|
||||
float Source::getPitch() const
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
ALfloat f;
|
||||
alGetSourcef(source, AL_PITCH, &f);
|
||||
return f;
|
||||
}
|
||||
|
||||
// In case the Source isn't playing.
|
||||
return pitch;
|
||||
}
|
||||
|
||||
void Source::setVolume(float volume)
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
alSourcef(source, AL_GAIN, volume);
|
||||
}
|
||||
|
||||
this->volume = volume;
|
||||
}
|
||||
|
||||
float Source::getVolume() const
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
ALfloat f;
|
||||
alGetSourcef(source, AL_GAIN, &f);
|
||||
return f;
|
||||
}
|
||||
|
||||
// In case the Source isn't playing.
|
||||
return volume;
|
||||
}
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_OPENAL_SOURCE_H
|
||||
#define LOVE_AUDIO_OPENAL_SOURCE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
#include <audio/Source.h>
|
||||
#include "Pool.h"
|
||||
|
||||
// OpenAL
|
||||
#include <AL/alc.h>
|
||||
#include <AL/al.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
class Audio;
|
||||
|
||||
class Source : public love::audio::Source
|
||||
{
|
||||
private:
|
||||
|
||||
Pool * pool;
|
||||
ALuint source;
|
||||
|
||||
float pitch;
|
||||
float volume;
|
||||
|
||||
public:
|
||||
Source(Pool * pool);
|
||||
Source(Pool * pool, Audible * audible);
|
||||
virtual ~Source();
|
||||
|
||||
void play();
|
||||
void stop();
|
||||
void pause();
|
||||
void resume();
|
||||
void rewind();
|
||||
bool isFinished() const;
|
||||
void update();
|
||||
|
||||
void setPitch(float pitch);
|
||||
float getPitch() const;
|
||||
|
||||
void setVolume(float volume);
|
||||
float getVolume() const;
|
||||
|
||||
}; // Source
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_OPENAL_SOURCE_H
|
||||
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Audio.h"
|
||||
|
||||
#include "openal/Audio.h"
|
||||
#include "null/Audio.h"
|
||||
|
||||
#include <sound/wrap_Decoder.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
static Audio * instance = 0;
|
||||
|
||||
int _wrap_getNumSources(lua_State * L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getNumSources());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newSound(lua_State * L)
|
||||
{
|
||||
// Convert to File, if necessary.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_strtofile(L, 1);
|
||||
|
||||
// Convert to SoundData, if necessary.
|
||||
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
|
||||
luax_convobj(L, 1, "sound", "newSoundData");
|
||||
|
||||
love::sound::SoundData * data = luax_checktype<love::sound::SoundData>(L, 1, "SoundData", LOVE_SOUND_SOUND_DATA_BITS);
|
||||
Sound * t = instance->newSound(data);
|
||||
luax_newtype(L, "Sound", LOVE_AUDIO_SOUND_BITS, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int _wrap_newMusic(lua_State * L)
|
||||
{
|
||||
// Convert to Decoder, if necessary.
|
||||
if(!luax_istype(L, 1, LOVE_SOUND_DECODER_BITS))
|
||||
luax_convobj(L, 1, "sound", "newDecoder");
|
||||
|
||||
love::sound::Decoder * decoder = love::sound::luax_checkdecoder(L, 1);
|
||||
Music * t = instance->newMusic(decoder);
|
||||
luax_newtype(L, "Music", LOVE_AUDIO_MUSIC_BITS, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newSource(lua_State * L)
|
||||
{
|
||||
Source * t = instance->newSource();
|
||||
luax_newtype(L, "Source", LOVE_AUDIO_SOURCE_BITS, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_play(lua_State * L)
|
||||
{
|
||||
int argn = lua_gettop(L);
|
||||
|
||||
if(luax_istype(L, 1, LOVE_AUDIO_SOUND_BITS))
|
||||
{
|
||||
Sound * s = luax_checksound(L, 1);
|
||||
instance->play(s);
|
||||
return 0;
|
||||
}
|
||||
else if(luax_istype(L, 1, LOVE_AUDIO_MUSIC_BITS))
|
||||
{
|
||||
Music * m = luax_checkmusic(L, 1);
|
||||
instance->play(m);
|
||||
return 0;
|
||||
}
|
||||
else if(luax_istype(L, 1, LOVE_AUDIO_SOURCE_BITS))
|
||||
{
|
||||
Source * s = luax_checksource(L, 1);
|
||||
instance->play(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return luaL_error(L, "No matching overload");
|
||||
}
|
||||
|
||||
int _wrap_stop(lua_State * L)
|
||||
{
|
||||
Source * c = luax_checksource(L, 1);
|
||||
instance->stop(c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_pause(lua_State * L)
|
||||
{
|
||||
Source * c = luax_checksource(L, 1);
|
||||
instance->pause(c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_rewind(lua_State * L)
|
||||
{
|
||||
Source * c = luax_checksource(L, 1);
|
||||
instance->rewind(c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setVolume(lua_State * L)
|
||||
{
|
||||
float v = (float)luaL_checknumber(L, 1);
|
||||
instance->setVolume(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getVolume(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getVolume());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg wrap_Audio_functions[] = {
|
||||
{ "getNumSources", _wrap_getNumSources },
|
||||
{ "newSound", _wrap_newSound },
|
||||
{ "newMusic", _wrap_newMusic },
|
||||
{ "newSource", _wrap_newSource },
|
||||
{ "play", _wrap_play },
|
||||
{ "stop", _wrap_stop },
|
||||
{ "pause", _wrap_pause },
|
||||
{ "rewind", _wrap_rewind },
|
||||
{ "setVolume", _wrap_setVolume },
|
||||
{ "getVolume", _wrap_getVolume },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static const lua_CFunction wrap_Audio_types[] = {
|
||||
wrap_Source_open,
|
||||
wrap_Music_open,
|
||||
wrap_Sound_open,
|
||||
0
|
||||
};
|
||||
|
||||
int wrap_Audio_open(lua_State * L)
|
||||
{
|
||||
if(instance == 0)
|
||||
{
|
||||
// Try OpenAL first.
|
||||
try
|
||||
{
|
||||
instance = new love::audio::openal::Audio();
|
||||
}
|
||||
catch(love::Exception & e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if(instance == 0)
|
||||
{
|
||||
// Fall back to nullaudio.
|
||||
try
|
||||
{
|
||||
instance = new love::audio::null::Audio();
|
||||
}
|
||||
catch(love::Exception & e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if(instance == 0)
|
||||
return luaL_error(L, "Could not open any audio module.");
|
||||
|
||||
luax_register_gc(L, "love.audio", instance);
|
||||
|
||||
return luax_register_module(L, wrap_Audio_functions, wrap_Audio_types);
|
||||
}
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_WRAP_AUDIO_H
|
||||
#define LOVE_AUDIO_WRAP_AUDIO_H
|
||||
|
||||
// LOVE
|
||||
#include "Audio.h"
|
||||
#include "wrap_Sound.h"
|
||||
#include "wrap_Music.h"
|
||||
#include "wrap_Source.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
int _wrap_getNumSources(lua_State * L);
|
||||
int _wrap_newSound(lua_State * L);
|
||||
int _wrap_newMusic(lua_State * L);
|
||||
int _wrap_newSource(lua_State * L);
|
||||
int _wrap_play(lua_State * L);
|
||||
int _wrap_stop(lua_State * L);
|
||||
int _wrap_pause(lua_State * L);
|
||||
int _wrap_rewind(lua_State * L);
|
||||
int _wrap_setVolume(lua_State * L);
|
||||
int _wrap_getVolume(lua_State * L);
|
||||
int wrap_Audio_open(lua_State * L);
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
|
||||
#endif // LOVE_AUDIO_WRAP_AUDIO_H
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_Music.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Music * luax_checkmusic(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Music>(L, idx, "Music", LOVE_AUDIO_MUSIC_BITS);
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Music_functions[] = {
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Music_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Music", wrap_Music_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_WRAP_MUSIC_H
|
||||
#define LOVE_AUDIO_WRAP_MUSIC_H
|
||||
|
||||
#include <common/runtime.h>
|
||||
#include "Music.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Music * luax_checkmusic(lua_State * L, int idx);
|
||||
int wrap_Music_open(lua_State * L);
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_WRAP_MUSIC_H
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_Sound.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Sound * luax_checksound(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Sound>(L, idx, "Sound", LOVE_AUDIO_SOUND_BITS);
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Sound_functions[] = {
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Sound_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Sound", wrap_Sound_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_WRAP_SOUND_H
|
||||
#define LOVE_AUDIO_WRAP_SOUND_H
|
||||
|
||||
#include <common/runtime.h>
|
||||
#include "Sound.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Sound * luax_checksound(lua_State * L, int idx);
|
||||
int wrap_Sound_open(lua_State * L);
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_WRAP_SOUND_H
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_Source.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Source * luax_checksource(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Source>(L, idx, "Source", LOVE_AUDIO_SOURCE_BITS);
|
||||
}
|
||||
|
||||
int _wrap_Source_setPitch(lua_State * L)
|
||||
{
|
||||
Source * t = luax_checksource(L, 1);
|
||||
float p = (float)luaL_checknumber(L, 2);
|
||||
t->setPitch(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Source_getPitch(lua_State * L)
|
||||
{
|
||||
Source * t = luax_checksource(L, 1);
|
||||
lua_pushnumber(L, t->getPitch());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Source_setVolume(lua_State * L)
|
||||
{
|
||||
Source * t = luax_checksource(L, 1);
|
||||
float p = (float)luaL_checknumber(L, 2);
|
||||
t->setVolume(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Source_getVolume(lua_State * L)
|
||||
{
|
||||
Source * t = luax_checksource(L, 1);
|
||||
lua_pushnumber(L, t->getVolume());
|
||||
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 },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Source_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Source", wrap_Source_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_AUDIO_WRAP_SOURCE_H
|
||||
#define LOVE_AUDIO_WRAP_SOURCE_H
|
||||
|
||||
#include <common/runtime.h>
|
||||
#include "Source.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Source * luax_checksource(lua_State * L, int idx);
|
||||
int _wrap_Source_setPitch(lua_State * L);
|
||||
int _wrap_Source_getPitch(lua_State * L);
|
||||
int _wrap_Source_setVolume(lua_State * L);
|
||||
int _wrap_Source_getVolume(lua_State * L);
|
||||
int wrap_Source_open(lua_State * L);
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_WRAP_SOURCE_H
|
||||
Reference in New Issue
Block a user