Browse Source

Simplified Source constructors.

--HG--
branch : minor
Alex Szpakowski 8 years ago
parent
commit
a844c16657
2 changed files with 32 additions and 78 deletions
  1. 1 58
      src/modules/audio/openal/Source.cpp
  2. 31 20
      src/modules/audio/openal/Source.h

+ 1 - 58
src/modules/audio/openal/Source.cpp

@@ -24,7 +24,6 @@
 
 
 // STD
 // STD
 #include <iostream>
 #include <iostream>
-#include <float.h>
 #include <algorithm>
 #include <algorithm>
 
 
 namespace love
 namespace love
@@ -34,13 +33,6 @@ namespace audio
 namespace openal
 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
 class InvalidFormatException : public love::Exception
 {
 {
 public:
 public:
@@ -123,25 +115,9 @@ StaticDataBuffer::~StaticDataBuffer()
 Source::Source(Pool *pool, love::sound::SoundData *soundData)
 Source::Source(Pool *pool, love::sound::SoundData *soundData)
 	: love::audio::Source(Source::TYPE_STATIC)
 	: love::audio::Source(Source::TYPE_STATIC)
 	, pool(pool)
 	, 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())
 	, sampleRate(soundData->getSampleRate())
 	, channels(soundData->getChannels())
 	, channels(soundData->getChannels())
 	, bitDepth(soundData->getBitDepth())
 	, bitDepth(soundData->getBitDepth())
-	, decoder(nullptr)
-	, toLoop(0)
 {
 {
 	ALenum fmt = getFormat(soundData->getChannels(), soundData->getBitDepth());
 	ALenum fmt = getFormat(soundData->getChannels(), soundData->getBitDepth());
 	if (fmt == 0)
 	if (fmt == 0)
@@ -159,25 +135,10 @@ Source::Source(Pool *pool, love::sound::SoundData *soundData)
 Source::Source(Pool *pool, love::sound::Decoder *decoder)
 Source::Source(Pool *pool, love::sound::Decoder *decoder)
 	: love::audio::Source(Source::TYPE_STREAM)
 	: love::audio::Source(Source::TYPE_STREAM)
 	, pool(pool)
 	, 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())
 	, sampleRate(decoder->getSampleRate())
 	, channels(decoder->getChannels())
 	, channels(decoder->getChannels())
 	, bitDepth(decoder->getBitDepth())
 	, bitDepth(decoder->getBitDepth())
 	, decoder(decoder)
 	, decoder(decoder)
-	, toLoop(0)
 	, unusedBufferTop(MAX_BUFFERS - 1)
 	, unusedBufferTop(MAX_BUFFERS - 1)
 {
 {
 	if (getFormat(decoder->getChannels(), decoder->getBitDepth()) == 0)
 	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)
 Source::Source(Pool *pool, int sampleRate, int bitDepth, int channels)
 	: love::audio::Source(Source::TYPE_QUEUE)
 	: love::audio::Source(Source::TYPE_QUEUE)
 	, pool(pool)
 	, 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)
 	, sampleRate(sampleRate)
 	, channels(channels)
 	, channels(channels)
 	, bitDepth(bitDepth)
 	, bitDepth(bitDepth)
-	, decoder(nullptr)
-	, toLoop(0)
-	, unusedBufferTop(-1)
-	, bufferedBytes(0)
 {
 {
 	ALenum fmt = getFormat(channels, bitDepth);
 	ALenum fmt = getFormat(channels, bitDepth);
 	if (fmt == 0)
 	if (fmt == 0)
@@ -256,7 +199,7 @@ Source::Source(const Source &s)
 	, bitDepth(s.bitDepth)
 	, bitDepth(s.bitDepth)
 	, decoder(nullptr)
 	, decoder(nullptr)
 	, toLoop(0)
 	, toLoop(0)
-	, unusedBufferTop(-1)
+	, unusedBufferTop(s.type == TYPE_STREAM ? MAX_BUFFERS - 1 : -1)
 {
 {
 	if (type == TYPE_STREAM)
 	if (type == TYPE_STREAM)
 	{
 	{

+ 31 - 20
src/modules/audio/openal/Source.h

@@ -31,6 +31,9 @@
 // STL
 // STL
 #include <vector>
 #include <vector>
 
 
+// C
+#include <float.h>
+
 // OpenAL
 // OpenAL
 #ifdef LOVE_APPLE_USE_FRAMEWORKS
 #ifdef LOVE_APPLE_USE_FRAMEWORKS
 #ifdef LOVE_IOS
 #ifdef LOVE_IOS
@@ -52,6 +55,13 @@ namespace audio
 namespace openal
 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 Audio;
 class Pool;
 class Pool;
 
 
@@ -170,9 +180,9 @@ private:
 	void unusedBufferPush(ALuint buffer);
 	void unusedBufferPush(ALuint buffer);
 	void unusedBufferQueue(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;
 	static const unsigned int MAX_BUFFERS = 8;
 	ALuint streamBuffers[MAX_BUFFERS];
 	ALuint streamBuffers[MAX_BUFFERS];
@@ -180,18 +190,18 @@ private:
 
 
 	StrongRef<StaticDataBuffer> staticBuffer;
 	StrongRef<StaticDataBuffer> staticBuffer;
 
 
-	float pitch;
-	float volume;
+	float pitch = 1.0f;
+	float volume = 1.0f;
 	float position[3];
 	float position[3];
 	float velocity[3];
 	float velocity[3];
 	float direction[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
 	struct Cone
 	{
 	{
@@ -200,18 +210,19 @@ private:
 		float outerVolume = 0.0f;
 		float outerVolume = 0.0f;
 	} cone;
 	} 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;
 	StrongRef<love::sound::Decoder> decoder;
 
 
-	unsigned int toLoop;
-	int unusedBufferTop;
-	ALsizei bufferedBytes;
+	unsigned int toLoop = 0;
+	int unusedBufferTop = -1;
+	ALsizei bufferedBytes = 0;
+
 }; // Source
 }; // Source
 
 
 } // openal
 } // openal