mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
added Source:seek/tell
--HG-- branch : minor
This commit is contained in:
@@ -42,6 +42,16 @@ namespace audio
|
||||
{
|
||||
return types.find(in, out);
|
||||
}
|
||||
|
||||
bool Source::getConstant(const char * in, Unit & out)
|
||||
{
|
||||
return units.find(in, out);
|
||||
}
|
||||
|
||||
bool Source::getConstant(Unit in, const char *& out)
|
||||
{
|
||||
return units.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Source::Type, Source::TYPE_MAX_ENUM>::Entry Source::typeEntries[] =
|
||||
{
|
||||
@@ -50,6 +60,14 @@ namespace audio
|
||||
};
|
||||
|
||||
StringMap<Source::Type, Source::TYPE_MAX_ENUM> Source::types(Source::typeEntries, sizeof(Source::typeEntries));
|
||||
|
||||
StringMap<Source::Unit, Source::UNIT_MAX_ENUM>::Entry Source::unitEntries[] =
|
||||
{
|
||||
{"seconds", Source::UNIT_SECONDS},
|
||||
{"samples", Source::UNIT_SAMPLES},
|
||||
};
|
||||
|
||||
StringMap<Source::Unit, Source::UNIT_MAX_ENUM> Source::units(Source::unitEntries, sizeof(Source::unitEntries));
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
@@ -39,6 +39,13 @@ namespace audio
|
||||
TYPE_STREAM,
|
||||
TYPE_MAX_ENUM
|
||||
}; // Type
|
||||
|
||||
enum Unit
|
||||
{
|
||||
UNIT_SECONDS = 1,
|
||||
UNIT_SAMPLES,
|
||||
UNIT_MAX_ENUM
|
||||
};
|
||||
|
||||
protected:
|
||||
Type type;
|
||||
@@ -64,6 +71,9 @@ namespace audio
|
||||
|
||||
virtual void setVolume(float volume) = 0;
|
||||
virtual float getVolume() const = 0;
|
||||
|
||||
virtual void seek(float offset, Unit unit) = 0;
|
||||
virtual float tell(Unit unit) const = 0;
|
||||
|
||||
// all float * v must be of size 3
|
||||
virtual void setPosition(float * v) = 0;
|
||||
@@ -79,11 +89,15 @@ namespace audio
|
||||
|
||||
static bool getConstant(const char * in, Type & out);
|
||||
static bool getConstant(Type in, const char *& out);
|
||||
static bool getConstant(const char * in, Unit & out);
|
||||
static bool getConstant(Unit in, const char *& out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[];
|
||||
static StringMap<Type, TYPE_MAX_ENUM> types;
|
||||
static StringMap<Unit, UNIT_MAX_ENUM>::Entry unitEntries[];
|
||||
static StringMap<Unit, UNIT_MAX_ENUM> units;
|
||||
|
||||
}; // Source
|
||||
|
||||
|
||||
@@ -100,6 +100,15 @@ namespace null
|
||||
{
|
||||
return volume;
|
||||
}
|
||||
|
||||
void Source::seek(float, Source::Unit)
|
||||
{
|
||||
}
|
||||
|
||||
float Source::tell(Source::Unit) const
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
void Source::setPosition(float *)
|
||||
{
|
||||
|
||||
@@ -57,6 +57,8 @@ namespace null
|
||||
virtual float getPitch() const;
|
||||
virtual void setVolume(float volume);
|
||||
virtual float getVolume() const;
|
||||
virtual void seek(float offset, Unit unit);
|
||||
virtual float tell(Unit unit) const;
|
||||
virtual void setPosition(float * v);
|
||||
virtual void getPosition(float * v) const;
|
||||
virtual void setVelocity(float * v);
|
||||
|
||||
@@ -200,6 +200,41 @@ namespace openal
|
||||
// In case the Source isn't playing.
|
||||
return volume;
|
||||
}
|
||||
|
||||
void Source::seek(float offset, Source::Unit unit)
|
||||
{
|
||||
if (valid)
|
||||
{
|
||||
switch (unit) {
|
||||
case Source::UNIT_SAMPLES:
|
||||
alSourcef(source, AL_SAMPLE_OFFSET, offset);
|
||||
break;
|
||||
case Source::UNIT_SECONDS:
|
||||
default:
|
||||
alSourcef(source, AL_SEC_OFFSET, offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float Source::tell(Source::Unit unit) const
|
||||
{
|
||||
if (valid)
|
||||
{
|
||||
ALfloat offset;
|
||||
switch (unit) {
|
||||
case Source::UNIT_SAMPLES:
|
||||
alGetSourcef(source, AL_SAMPLE_OFFSET, &offset);
|
||||
break;
|
||||
case Source::UNIT_SECONDS:
|
||||
default:
|
||||
alGetSourcef(source, AL_SEC_OFFSET, &offset);
|
||||
break;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
void Source::setPosition(float * v)
|
||||
{
|
||||
|
||||
@@ -84,6 +84,8 @@ namespace openal
|
||||
virtual float getPitch() const;
|
||||
virtual void setVolume(float volume);
|
||||
virtual float getVolume() const;
|
||||
virtual void seek(float offset, Unit unit);
|
||||
virtual float tell(Unit unit) const;
|
||||
virtual void setPosition(float * v);
|
||||
virtual void getPosition(float * v) const;
|
||||
virtual void setVelocity(float * v);
|
||||
|
||||
@@ -93,6 +93,27 @@ namespace audio
|
||||
lua_pushnumber(L, t->getVolume());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Source_seek(lua_State * L)
|
||||
{
|
||||
Source * t = luax_checksource(L, 1);
|
||||
float offset = (float)luaL_checknumber(L, 2);
|
||||
const char * unit = luaL_optstring(L, 3, "seconds");
|
||||
Source::Unit u;
|
||||
t->getConstant(unit, u);
|
||||
t->seek(offset, u);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Source_tell(lua_State * L)
|
||||
{
|
||||
Source * t = luax_checksource(L, 1);
|
||||
const char * unit = luaL_optstring(L, 2, "seconds");
|
||||
Source::Unit u;
|
||||
t->getConstant(unit, u);
|
||||
lua_pushnumber(L, t->tell(u));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Source_setPosition(lua_State * L)
|
||||
{
|
||||
@@ -206,6 +227,8 @@ namespace audio
|
||||
{ "getPitch", w_Source_getPitch },
|
||||
{ "setVolume", w_Source_setVolume },
|
||||
{ "getVolume", w_Source_getVolume },
|
||||
{ "seek", w_Source_seek },
|
||||
{ "tell", w_Source_tell },
|
||||
{ "setPosition", w_Source_setPosition },
|
||||
{ "getPosition", w_Source_getPosition },
|
||||
{ "setVelocity", w_Source_setVelocity },
|
||||
|
||||
@@ -38,6 +38,8 @@ namespace audio
|
||||
int w_Source_getPitch(lua_State * L);
|
||||
int w_Source_setVolume(lua_State * L);
|
||||
int w_Source_getVolume(lua_State * L);
|
||||
int w_Source_seek(lua_State * L);
|
||||
int w_Source_tell(lua_State * L);
|
||||
int w_Source_setPosition(lua_State * L);
|
||||
int w_Source_getPosition(lua_State * L);
|
||||
int w_Source_setVelocity(lua_State * L);
|
||||
|
||||
Reference in New Issue
Block a user