1. rude
  2. love

Commits

Bart van Strien  committed 130db8d

Add SoundData:getDuration, returns the duration in seconds

  • Participants
  • Parent commits 9d43618
  • Branches default

Comments (0)

Files changed (4)

File src/modules/sound/SoundData.cpp

View file
  • Ignore whitespace
 	return sampleRate;
 }
 
+int SoundData::getDuration() const
+{
+	return size/(channels*sampleRate*bits/8);
+}
+
 void SoundData::setSample(int i, float sample)
 {
 	// Check range.

File src/modules/sound/SoundData.h

View file
  • Ignore whitespace
 	virtual int getBits() const;
 	virtual int getSampleRate() const;
 
+	virtual int getDuration() const;
+
 	void setSample(int i, float sample);
 	float getSample(int i) const;
 

File src/modules/sound/wrap_SoundData.cpp

View file
  • Ignore whitespace
 	return 1;
 }
 
+int w_SoundData_getDuration(lua_State *L)
+{
+	SoundData *t = luax_checksounddata(L, 1);
+	lua_pushinteger(L, t->getDuration());
+	return 1;
+}
+
 int w_SoundData_setSample(lua_State *L)
 {
 	SoundData *sd = luax_checksounddata(L, 1);
 	{ "getChannels", w_SoundData_getChannels },
 	{ "getBits", w_SoundData_getBits },
 	{ "getSampleRate", w_SoundData_getSampleRate },
+	{ "getDuration", w_SoundData_getDuration },
 	{ "setSample", w_SoundData_setSample },
 	{ "getSample", w_SoundData_getSample },
 	{ 0, 0 }

File src/modules/sound/wrap_SoundData.h

View file
  • Ignore whitespace
 int w_getChannels(lua_State *L);
 int w_getBits(lua_State *L);
 int w_getSampleRate(lua_State *L);
+int w_getDuration(lua_State *L);
 int w_setSample(lua_State *L);
 int w_getSample(lua_State *L);
 extern "C" int luaopen_sounddata(lua_State *L);