mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Merged in rcoaxil/love-patches/minor-manual-decoders (pull request #67)
decoder manual decoding and seeking implemented --HG-- branch : minor
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.
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
#include "wrap_Decoder.h"
|
#include "wrap_Decoder.h"
|
||||||
|
#include "SoundData.h"
|
||||||
|
#include "Sound.h"
|
||||||
|
|
||||||
|
#define instance() (Module::getInstance<Sound>(Module::M_SOUND))
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
@@ -58,12 +62,46 @@ int w_Decoder_getDuration(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_Decoder_decode(lua_State *L)
|
||||||
|
{
|
||||||
|
Decoder *t = luax_checkdecoder(L, 1);
|
||||||
|
|
||||||
|
int decoded = t->decode();
|
||||||
|
if (decoded > 0)
|
||||||
|
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);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_Decoder_seek(lua_State *L)
|
||||||
|
{
|
||||||
|
Decoder *t = luax_checkdecoder(L, 1);
|
||||||
|
float offset = luaL_checknumber(L, 2);
|
||||||
|
if (offset < 0)
|
||||||
|
return luaL_argerror(L, 2, "can't seek to a negative position");
|
||||||
|
else if (offset == 0)
|
||||||
|
t->rewind();
|
||||||
|
else
|
||||||
|
t->seek(offset);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static const luaL_Reg w_Decoder_functions[] =
|
static const luaL_Reg w_Decoder_functions[] =
|
||||||
{
|
{
|
||||||
{ "getChannels", w_Decoder_getChannels },
|
{ "getChannels", w_Decoder_getChannels },
|
||||||
{ "getBitDepth", w_Decoder_getBitDepth },
|
{ "getBitDepth", w_Decoder_getBitDepth },
|
||||||
{ "getSampleRate", w_Decoder_getSampleRate },
|
{ "getSampleRate", w_Decoder_getSampleRate },
|
||||||
{ "getDuration", w_Decoder_getDuration },
|
{ "getDuration", w_Decoder_getDuration },
|
||||||
|
{ "decode", w_Decoder_decode },
|
||||||
|
{ "seek", w_Decoder_seek },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user