made decode() always return new SoundData

--HG--
branch : minor-manual-decoders
This commit is contained in:
Raidho
2016-10-23 21:09:13 +03:00
parent 78f5779214
commit a605243709
3 changed files with 23 additions and 23 deletions
+7 -23
View File
@@ -65,35 +65,19 @@ int w_Decoder_getDuration(lua_State *L)
int w_Decoder_decode(lua_State *L)
{
Decoder *t = luax_checkdecoder(L, 1);
SoundData *s = nullptr;
if (luax_istype(L, 2, SOUND_SOUND_DATA_ID))
{
s = luax_totype<SoundData>(L, 2, SOUND_SOUND_DATA_ID);
if (s->getSampleRate() != t->getSampleRate() ||
s->getBitDepth() != t->getBitDepth() ||
s->getChannels() != t->getChannels() )
return luaL_error(L, "SoundData sound format doesn't match Decoder sound format.");
s->retain();
}
else if (lua_gettop(L) > 1)
luax_typerror(L, 2, "SoundData" );
else
luax_catchexcept(L, [&](){
s = instance()->newSoundData(t->getSize() / (t->getBitDepth() / 8 * t->getChannels()), t->getSampleRate(), t->getBitDepth(), t->getChannels());
});
int decoded = t->decode();
if (decoded > 0)
{
luax_catchexcept(L, [&](){
s->load(decoded / (t->getBitDepth() / 8 * t->getChannels()), t->getSampleRate(), t->getBitDepth(), t->getChannels(), t->getBuffer());
});
luax_catchexcept(L, [&](){
SoundData *s = instance()->newSoundData(t->getBuffer(),
decoded / (t->getBitDepth() / 8 * t->getChannels()),
t->getSampleRate(), t->getBitDepth(), t->getChannels());
luax_pushtype(L, SOUND_SOUND_DATA_ID, s);
}
s->release();
});
else
lua_pushnil(L);
s->release();
return 1;
}