Data:clone ported to minor

minor tweaks

--HG--
branch : minor
This commit is contained in:
Raidho
2017-02-10 06:19:53 +03:00
parent bc6a2db22f
commit 6ea1ebde9c
22 changed files with 203 additions and 0 deletions
+15
View File
@@ -108,12 +108,27 @@ SoundData::SoundData(void *d, int samples, int sampleRate, int bitDepth, int cha
load(samples, sampleRate, bitDepth, channels, d);
}
SoundData::SoundData(const SoundData &c)
: data(0)
, size(0)
, sampleRate(0)
, bitDepth(0)
, channels(0)
{
load(c.getSampleCount(), c.getSampleRate(), c.getBitDepth(), c.getChannels(), c.getData());
}
SoundData::~SoundData()
{
if (data != 0)
free(data);
}
Data *SoundData::clone() const
{
return new SoundData(*this);
}
void SoundData::load(int samples, int sampleRate, int bitDepth, int channels, void *newData)
{
if (samples <= 0)
+2
View File
@@ -40,10 +40,12 @@ public:
SoundData(Decoder *decoder);
SoundData(int samples, int sampleRate, int bitDepth, int channels);
SoundData(void *d, int samples, int sampleRate, int bitDepth, int channels);
SoundData(const SoundData &c);
virtual ~SoundData();
// Implements Data.
Data *clone() const;
void *getData() const;
size_t getSize() const;
+10
View File
@@ -42,6 +42,15 @@ SoundData *luax_checksounddata(lua_State *L, int idx)
return luax_checktype<SoundData>(L, idx);
}
int w_SoundData_clone(lua_State *L)
{
SoundData *t = luax_checksounddata(L, 1)*c = nullptr;
luax_catchexcept(L, [&](){ c = (SoundData*)t->clone(); });
luax_pushtype(L, c);
c->release();
return 1;
}
int w_SoundData_getChannels(lua_State *L)
{
SoundData *t = luax_checksounddata(L, 1);
@@ -98,6 +107,7 @@ int w_SoundData_getSample(lua_State *L)
static const luaL_Reg w_SoundData_functions[] =
{
{ "clone", w_SoundData_clone },
{ "getChannels", w_SoundData_getChannels },
{ "getBitDepth", w_SoundData_getBitDepth },
{ "getSampleRate", w_SoundData_getSampleRate },