From 11dc74c7dbe5af5f4703785fb4900f3afc0227af Mon Sep 17 00:00:00 2001 From: darthfodder Date: Mon, 25 Mar 2013 22:04:39 -0700 Subject: [PATCH 1/2] Add SoundData:getSampleCount() function Adds SoundData:getSampleCount(), calculates how many samples there are in this particular SoundData. resolves #578 --HG-- branch : sounddata-samplecount --- src/modules/sound/SoundData.cpp | 5 +++++ src/modules/sound/SoundData.h | 1 + src/modules/sound/wrap_SoundData.cpp | 8 ++++++++ src/modules/sound/wrap_SoundData.h | 1 + 4 files changed, 15 insertions(+) diff --git a/src/modules/sound/SoundData.cpp b/src/modules/sound/SoundData.cpp index f0646f67f..ccde1c2b0 100644 --- a/src/modules/sound/SoundData.cpp +++ b/src/modules/sound/SoundData.cpp @@ -147,6 +147,11 @@ int SoundData::getSampleRate() const return sampleRate; } +int SoundData::getSampleCount() const +{ + return (size/channels)/(bits/8); +} + int SoundData::getDuration() const { return size/(channels*sampleRate*bits/8); diff --git a/src/modules/sound/SoundData.h b/src/modules/sound/SoundData.h index 09a40c60a..41087cac6 100644 --- a/src/modules/sound/SoundData.h +++ b/src/modules/sound/SoundData.h @@ -48,6 +48,7 @@ public: virtual int getChannels() const; virtual int getBits() const; virtual int getSampleRate() const; + virtual int getSampleCount() const; virtual int getDuration() const; diff --git a/src/modules/sound/wrap_SoundData.cpp b/src/modules/sound/wrap_SoundData.cpp index 86693b003..db4010e4a 100644 --- a/src/modules/sound/wrap_SoundData.cpp +++ b/src/modules/sound/wrap_SoundData.cpp @@ -53,6 +53,13 @@ int w_SoundData_getSampleRate(lua_State *L) return 1; } +int w_SoundData_getSampleCount(lua_State *L) +{ + SoundData *t = luax_checksounddata(L, 1); + lua_pushinteger(L, t->getSampleCount()); + return 1; +} + int w_SoundData_getDuration(lua_State *L) { SoundData *t = luax_checksounddata(L, 1); @@ -87,6 +94,7 @@ static const luaL_Reg functions[] = { "getChannels", w_SoundData_getChannels }, { "getBits", w_SoundData_getBits }, { "getSampleRate", w_SoundData_getSampleRate }, + { "getSampleCount", w_SoundData_getSampleCount }, { "getDuration", w_SoundData_getDuration }, { "setSample", w_SoundData_setSample }, { "getSample", w_SoundData_getSample }, diff --git a/src/modules/sound/wrap_SoundData.h b/src/modules/sound/wrap_SoundData.h index 26177920c..d07f4bd35 100644 --- a/src/modules/sound/wrap_SoundData.h +++ b/src/modules/sound/wrap_SoundData.h @@ -36,6 +36,7 @@ int w_getSize(lua_State *L); int w_getChannels(lua_State *L); int w_getBits(lua_State *L); int w_getSampleRate(lua_State *L); +int w_getSampleCount(lua_State *L); int w_getDuration(lua_State *L); int w_setSample(lua_State *L); int w_getSample(lua_State *L); From 2bdc4b04a87a602c12c58ec9593f622d89e4c07c Mon Sep 17 00:00:00 2001 From: darthfodder Date: Sun, 7 Apr 2013 18:25:59 -0700 Subject: [PATCH 2/2] Fix formatting to be like original default --HG-- branch : sounddata-samplecount --- src/modules/sound/SoundData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/sound/SoundData.cpp b/src/modules/sound/SoundData.cpp index 753fdd472..2a4db4ac6 100644 --- a/src/modules/sound/SoundData.cpp +++ b/src/modules/sound/SoundData.cpp @@ -154,7 +154,7 @@ int SoundData::getSampleCount() const float SoundData::getDuration() const { - return float(size) /(channels*sampleRate*bits/8); + return float(size) / (channels*sampleRate*bits/8); } void SoundData::setSample(int i, float sample)