mirror of
https://github.com/love2d/love.git
synced 2026-08-20 20:49:54 +02:00
made decode() always return new SoundData
--HG-- branch : minor-manual-decoders
This commit is contained in:
@@ -39,6 +39,10 @@ SoundData *Sound::newSoundData(int samples, int sampleRate, int bitDepth, int ch
|
|||||||
return new SoundData(samples, sampleRate, bitDepth, channels);
|
return new SoundData(samples, sampleRate, bitDepth, channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SoundData *Sound::newSoundData(void *data, int samples, int sampleRate, int bitDepth, int channels)
|
||||||
|
{
|
||||||
|
return new SoundData(data, samples, sampleRate, bitDepth, channels);
|
||||||
|
}
|
||||||
|
|
||||||
} // sound
|
} // sound
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -66,6 +66,18 @@ public:
|
|||||||
**/
|
**/
|
||||||
SoundData *newSoundData(int samples, int sampleRate, int bitDepth, int channels);
|
SoundData *newSoundData(int samples, int sampleRate, int bitDepth, int channels);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new SoundData with the specified number of samples and format
|
||||||
|
* and loads data from specified buffer.
|
||||||
|
* @param data Buffer to load data from.
|
||||||
|
* @param samples The number of samples.
|
||||||
|
* @param sampleRate Number of samples per second.
|
||||||
|
* @param bitDepth Bits per sample (8 or 16).
|
||||||
|
* @param channels Either 1 for mono, or 2 for stereo.
|
||||||
|
* @return A new SoundData object, or zero in case of errors.
|
||||||
|
**/
|
||||||
|
SoundData *newSoundData(void *data, int samples, int sampleRate, int bitDepth, int channels);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to find a decoder for the encoded sound data in the
|
* Attempts to find a decoder for the encoded sound data in the
|
||||||
* specified file.
|
* specified file.
|
||||||
|
|||||||
@@ -65,35 +65,19 @@ int w_Decoder_getDuration(lua_State *L)
|
|||||||
int w_Decoder_decode(lua_State *L)
|
int w_Decoder_decode(lua_State *L)
|
||||||
{
|
{
|
||||||
Decoder *t = luax_checkdecoder(L, 1);
|
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();
|
int decoded = t->decode();
|
||||||
if (decoded > 0)
|
if (decoded > 0)
|
||||||
{
|
|
||||||
luax_catchexcept(L, [&](){
|
luax_catchexcept(L, [&](){
|
||||||
s->load(decoded / (t->getBitDepth() / 8 * t->getChannels()), t->getSampleRate(), t->getBitDepth(), t->getChannels(), t->getBuffer());
|
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);
|
luax_pushtype(L, SOUND_SOUND_DATA_ID, s);
|
||||||
}
|
s->release();
|
||||||
|
});
|
||||||
else
|
else
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
|
|
||||||
s->release();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user