From a844c16657f4cf848ed3bf4fafd74cde97ce3259 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 16 Oct 2016 16:04:00 -0300 Subject: [PATCH] Simplified Source constructors. --HG-- branch : minor --- src/modules/audio/openal/Source.cpp | 59 +---------------------------- src/modules/audio/openal/Source.h | 51 +++++++++++++++---------- 2 files changed, 32 insertions(+), 78 deletions(-) diff --git a/src/modules/audio/openal/Source.cpp b/src/modules/audio/openal/Source.cpp index 87a9cf5bf..1de16979e 100644 --- a/src/modules/audio/openal/Source.cpp +++ b/src/modules/audio/openal/Source.cpp @@ -24,7 +24,6 @@ // STD #include -#include #include 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) { diff --git a/src/modules/audio/openal/Source.h b/src/modules/audio/openal/Source.h index 67febe0cb..c5b42fe25 100644 --- a/src/modules/audio/openal/Source.h +++ b/src/modules/audio/openal/Source.h @@ -31,6 +31,9 @@ // STL #include +// C +#include + // 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 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 decoder; - unsigned int toLoop; - int unusedBufferTop; - ALsizei bufferedBytes; + unsigned int toLoop = 0; + int unusedBufferTop = -1; + ALsizei bufferedBytes = 0; + }; // Source } // openal