Simplified Source constructors.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-10-16 16:04:00 -03:00
parent a3f381be07
commit a844c16657
2 changed files with 32 additions and 78 deletions
+1 -58
View File
@@ -24,7 +24,6 @@
// STD
#include <iostream>
#include <float.h>
#include <algorithm>
namespace love
@@ -34,13 +33,6 @@ namespace audio
namespace openal
{
#ifdef LOVE_IOS
// OpenAL on iOS barfs if the max distance is +inf.
static const float MAX_ATTENUATION_DISTANCE = 1000000.0f;
#else
static const float MAX_ATTENUATION_DISTANCE = FLT_MAX;
#endif
class InvalidFormatException : public love::Exception
{
public:
@@ -123,25 +115,9 @@ StaticDataBuffer::~StaticDataBuffer()
Source::Source(Pool *pool, love::sound::SoundData *soundData)
: love::audio::Source(Source::TYPE_STATIC)
, pool(pool)
, valid(false)
, staticBuffer(nullptr)
, pitch(1.0f)
, volume(1.0f)
, relative(false)
, looping(false)
, minVolume(0.0f)
, maxVolume(1.0f)
, referenceDistance(1.0f)
, rolloffFactor(1.0f)
, maxDistance(MAX_ATTENUATION_DISTANCE)
, cone()
, offsetSamples(0)
, offsetSeconds(0)
, sampleRate(soundData->getSampleRate())
, channels(soundData->getChannels())
, bitDepth(soundData->getBitDepth())
, decoder(nullptr)
, toLoop(0)
{
ALenum fmt = getFormat(soundData->getChannels(), soundData->getBitDepth());
if (fmt == 0)
@@ -159,25 +135,10 @@ Source::Source(Pool *pool, love::sound::SoundData *soundData)
Source::Source(Pool *pool, love::sound::Decoder *decoder)
: love::audio::Source(Source::TYPE_STREAM)
, pool(pool)
, valid(false)
, staticBuffer(nullptr)
, pitch(1.0f)
, volume(1.0f)
, relative(false)
, looping(false)
, minVolume(0.0f)
, maxVolume(1.0f)
, referenceDistance(1.0f)
, rolloffFactor(1.0f)
, maxDistance(MAX_ATTENUATION_DISTANCE)
, cone()
, offsetSamples(0)
, offsetSeconds(0)
, sampleRate(decoder->getSampleRate())
, channels(decoder->getChannels())
, bitDepth(decoder->getBitDepth())
, decoder(decoder)
, toLoop(0)
, unusedBufferTop(MAX_BUFFERS - 1)
{
if (getFormat(decoder->getChannels(), decoder->getBitDepth()) == 0)
@@ -197,27 +158,9 @@ Source::Source(Pool *pool, love::sound::Decoder *decoder)
Source::Source(Pool *pool, int sampleRate, int bitDepth, int channels)
: love::audio::Source(Source::TYPE_QUEUE)
, pool(pool)
, valid(false)
, staticBuffer(nullptr)
, pitch(1.0f)
, volume(1.0f)
, relative(false)
, looping(false)
, minVolume(0.0f)
, maxVolume(1.0f)
, referenceDistance(1.0f)
, rolloffFactor(1.0f)
, maxDistance(MAX_ATTENUATION_DISTANCE)
, cone()
, offsetSamples(0)
, offsetSeconds(0)
, sampleRate(sampleRate)
, channels(channels)
, bitDepth(bitDepth)
, decoder(nullptr)
, toLoop(0)
, unusedBufferTop(-1)
, bufferedBytes(0)
{
ALenum fmt = getFormat(channels, bitDepth);
if (fmt == 0)
@@ -256,7 +199,7 @@ Source::Source(const Source &s)
, bitDepth(s.bitDepth)
, decoder(nullptr)
, toLoop(0)
, unusedBufferTop(-1)
, unusedBufferTop(s.type == TYPE_STREAM ? MAX_BUFFERS - 1 : -1)
{
if (type == TYPE_STREAM)
{
+31 -20
View File
@@ -31,6 +31,9 @@
// STL
#include <vector>
// C
#include <float.h>
// OpenAL
#ifdef LOVE_APPLE_USE_FRAMEWORKS
#ifdef LOVE_IOS
@@ -52,6 +55,13 @@ namespace audio
namespace openal
{
#ifdef LOVE_IOS
// OpenAL on iOS barfs if the max distance is +inf.
static const float MAX_ATTENUATION_DISTANCE = 1000000.0f;
#else
static const float MAX_ATTENUATION_DISTANCE = FLT_MAX;
#endif
class Audio;
class Pool;
@@ -170,9 +180,9 @@ private:
void unusedBufferPush(ALuint buffer);
void unusedBufferQueue(ALuint buffer);
Pool *pool;
ALuint source;
bool valid;
Pool *pool = nullptr;
ALuint source = 0;
bool valid = false;
static const unsigned int MAX_BUFFERS = 8;
ALuint streamBuffers[MAX_BUFFERS];
@@ -180,18 +190,18 @@ private:
StrongRef<StaticDataBuffer> staticBuffer;
float pitch;
float volume;
float pitch = 1.0f;
float volume = 1.0f;
float position[3];
float velocity[3];
float direction[3];
bool relative;
bool looping;
float minVolume;
float maxVolume;
float referenceDistance;
float rolloffFactor;
float maxDistance;
bool relative = false;
bool looping = false;
float minVolume = 0.0f;
float maxVolume = 1.0f;
float referenceDistance = 1.0f;
float rolloffFactor = 1.0f;
float maxDistance = MAX_ATTENUATION_DISTANCE;
struct Cone
{
@@ -200,18 +210,19 @@ private:
float outerVolume = 0.0f;
} cone;
float offsetSamples;
float offsetSeconds;
float offsetSamples = 0.0f;
float offsetSeconds = 0.0f;
int sampleRate;
int channels;
int bitDepth;
int sampleRate = 0;
int channels = 0;
int bitDepth = 0;
StrongRef<love::sound::Decoder> decoder;
unsigned int toLoop;
int unusedBufferTop;
ALsizei bufferedBytes;
unsigned int toLoop = 0;
int unusedBufferTop = -1;
ALsizei bufferedBytes = 0;
}; // Source
} // openal