Browse Source

Added Source:getChannels. Positional/directional audio only works with 1-channel (mono) sources.

Alex Szpakowski 11 years ago
parent
commit
cf6acfa258

+ 1 - 0
src/modules/audio/Source.h

@@ -102,6 +102,7 @@ public:
 	virtual void setMaxDistance(float distance) = 0;
 	virtual float getMaxDistance() const = 0;
 
+	virtual int getChannels() const = 0;
 	virtual Type getType() const;
 
 	static bool getConstant(const char *in, Type &out);

+ 5 - 0
src/modules/audio/null/Source.cpp

@@ -224,6 +224,11 @@ float Source::getMaxDistance() const
 	return this->maxDistance;
 }
 
+int Source::getChannels() const
+{
+	return 2;
+}
+
 } // null
 } // audio
 } // love

+ 1 - 0
src/modules/audio/null/Source.h

@@ -77,6 +77,7 @@ public:
 	virtual float getRolloffFactor() const;
 	virtual void setMaxDistance(float distance);
 	virtual float getMaxDistance() const;
+	virtual int getChannels() const;
 
 private:
 

+ 7 - 0
src/modules/audio/openal/Source.cpp

@@ -50,6 +50,7 @@ Source::Source(Pool *pool, love::sound::SoundData *soundData)
 	, cone()
 	, offsetSamples(0)
 	, offsetSeconds(0)
+	, channels(soundData->getChannels())
 	, decoder(0)
 	, toLoop(0)
 {
@@ -81,6 +82,7 @@ Source::Source(Pool *pool, love::sound::Decoder *decoder)
 	, cone()
 	, offsetSamples(0)
 	, offsetSeconds(0)
+	, channels(decoder->getChannels())
 	, decoder(decoder)
 	, toLoop(0)
 {
@@ -754,6 +756,11 @@ float Source::getMaxDistance() const
 	return this->maxDistance;
 }
 
+int Source::getChannels() const
+{
+	return channels;
+}
+
 } // openal
 } // audio
 } // love

+ 3 - 0
src/modules/audio/openal/Source.h

@@ -95,6 +95,7 @@ public:
 	virtual float getRolloffFactor() const;
 	virtual void setMaxDistance(float distance);
 	virtual float getMaxDistance() const;
+	virtual int getChannels() const;
 
 	void playAtomic();
 	void stopAtomic();
@@ -155,6 +156,8 @@ private:
 	float offsetSamples;
 	float offsetSeconds;
 
+	int channels;
+
 	love::sound::Decoder *decoder;
 
 	unsigned int toLoop;

+ 8 - 0
src/modules/audio/wrap_Source.cpp

@@ -324,6 +324,13 @@ int w_Source_getRolloff(lua_State *L)
 	return 1;
 }
 
+int w_Source_getChannels(lua_State *L)
+{
+	Source *t = luax_checksource(L, 1);
+	lua_pushinteger(L, t->getChannels());
+	return 1;
+}
+
 int w_Source_getType(lua_State *L)
 {
 	Source *t = luax_checksource(L, 1);
@@ -377,6 +384,7 @@ static const luaL_Reg functions[] =
 	{ "setRolloff", w_Source_setRolloff},
 	{ "getRolloff", w_Source_getRolloff},
 
+	{ "getChannels", w_Source_getChannels },
 	{ "getType", w_Source_getType },
 
 	{ 0, 0 }

+ 1 - 0
src/modules/audio/wrap_Source.h

@@ -63,6 +63,7 @@ int w_Source_setAttenuationDistances(lua_State *L);
 int w_Source_getAttenuationDistances(lua_State *L);
 int w_Source_setRolloff(lua_State *L);
 int w_Source_getRolloff(lua_State *L);
+int w_Source_getChannels(lua_State *L);
 int w_Source_getType(lua_State *L);
 extern "C" int luaopen_source(lua_State *L);