Bart van Strien avatar Bart van Strien committed 130db8d

Add SoundData:getDuration, returns the duration in seconds

Comments (0)

Files changed (4)

src/modules/sound/SoundData.cpp

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

src/modules/sound/SoundData.h

 	virtual int getBits() const;
 	virtual int getSampleRate() const;
 
+	virtual int getDuration() const;
+
 	void setSample(int i, float sample);
 	float getSample(int i) const;
 

src/modules/sound/wrap_SoundData.cpp

 	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 }

src/modules/sound/wrap_SoundData.h

 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);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.