mirror of
https://github.com/love2d/love.git
synced 2026-08-21 13:09:56 +02:00
added Source:seek/tell
--HG-- branch : minor
This commit is contained in:
@@ -43,6 +43,16 @@ namespace audio
|
|||||||
return types.find(in, out);
|
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[] =
|
StringMap<Source::Type, Source::TYPE_MAX_ENUM>::Entry Source::typeEntries[] =
|
||||||
{
|
{
|
||||||
{"static", Source::TYPE_STATIC},
|
{"static", Source::TYPE_STATIC},
|
||||||
@@ -51,5 +61,13 @@ namespace audio
|
|||||||
|
|
||||||
StringMap<Source::Type, Source::TYPE_MAX_ENUM> Source::types(Source::typeEntries, sizeof(Source::typeEntries));
|
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
|
} // audio
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -40,6 +40,13 @@ namespace audio
|
|||||||
TYPE_MAX_ENUM
|
TYPE_MAX_ENUM
|
||||||
}; // Type
|
}; // Type
|
||||||
|
|
||||||
|
enum Unit
|
||||||
|
{
|
||||||
|
UNIT_SECONDS = 1,
|
||||||
|
UNIT_SAMPLES,
|
||||||
|
UNIT_MAX_ENUM
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Type type;
|
Type type;
|
||||||
public:
|
public:
|
||||||
@@ -65,6 +72,9 @@ namespace audio
|
|||||||
virtual void setVolume(float volume) = 0;
|
virtual void setVolume(float volume) = 0;
|
||||||
virtual float getVolume() const = 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
|
// all float * v must be of size 3
|
||||||
virtual void setPosition(float * v) = 0;
|
virtual void setPosition(float * v) = 0;
|
||||||
virtual void getPosition(float * v) const = 0;
|
virtual void getPosition(float * v) const = 0;
|
||||||
@@ -79,11 +89,15 @@ namespace audio
|
|||||||
|
|
||||||
static bool getConstant(const char * in, Type & out);
|
static bool getConstant(const char * in, Type & out);
|
||||||
static bool getConstant(Type in, const char *& 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:
|
private:
|
||||||
|
|
||||||
static StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[];
|
static StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[];
|
||||||
static StringMap<Type, TYPE_MAX_ENUM> types;
|
static StringMap<Type, TYPE_MAX_ENUM> types;
|
||||||
|
static StringMap<Unit, UNIT_MAX_ENUM>::Entry unitEntries[];
|
||||||
|
static StringMap<Unit, UNIT_MAX_ENUM> units;
|
||||||
|
|
||||||
}; // Source
|
}; // Source
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,15 @@ namespace null
|
|||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Source::seek(float, Source::Unit)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
float Source::tell(Source::Unit) const
|
||||||
|
{
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
void Source::setPosition(float *)
|
void Source::setPosition(float *)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ namespace null
|
|||||||
virtual float getPitch() const;
|
virtual float getPitch() const;
|
||||||
virtual void setVolume(float volume);
|
virtual void setVolume(float volume);
|
||||||
virtual float getVolume() const;
|
virtual float getVolume() const;
|
||||||
|
virtual void seek(float offset, Unit unit);
|
||||||
|
virtual float tell(Unit unit) const;
|
||||||
virtual void setPosition(float * v);
|
virtual void setPosition(float * v);
|
||||||
virtual void getPosition(float * v) const;
|
virtual void getPosition(float * v) const;
|
||||||
virtual void setVelocity(float * v);
|
virtual void setVelocity(float * v);
|
||||||
|
|||||||
@@ -201,6 +201,41 @@ namespace openal
|
|||||||
return volume;
|
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)
|
void Source::setPosition(float * v)
|
||||||
{
|
{
|
||||||
if(valid)
|
if(valid)
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ namespace openal
|
|||||||
virtual float getPitch() const;
|
virtual float getPitch() const;
|
||||||
virtual void setVolume(float volume);
|
virtual void setVolume(float volume);
|
||||||
virtual float getVolume() const;
|
virtual float getVolume() const;
|
||||||
|
virtual void seek(float offset, Unit unit);
|
||||||
|
virtual float tell(Unit unit) const;
|
||||||
virtual void setPosition(float * v);
|
virtual void setPosition(float * v);
|
||||||
virtual void getPosition(float * v) const;
|
virtual void getPosition(float * v) const;
|
||||||
virtual void setVelocity(float * v);
|
virtual void setVelocity(float * v);
|
||||||
|
|||||||
@@ -94,6 +94,27 @@ namespace audio
|
|||||||
return 1;
|
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)
|
int w_Source_setPosition(lua_State * L)
|
||||||
{
|
{
|
||||||
Source * t = luax_checksource(L, 1);
|
Source * t = luax_checksource(L, 1);
|
||||||
@@ -206,6 +227,8 @@ namespace audio
|
|||||||
{ "getPitch", w_Source_getPitch },
|
{ "getPitch", w_Source_getPitch },
|
||||||
{ "setVolume", w_Source_setVolume },
|
{ "setVolume", w_Source_setVolume },
|
||||||
{ "getVolume", w_Source_getVolume },
|
{ "getVolume", w_Source_getVolume },
|
||||||
|
{ "seek", w_Source_seek },
|
||||||
|
{ "tell", w_Source_tell },
|
||||||
{ "setPosition", w_Source_setPosition },
|
{ "setPosition", w_Source_setPosition },
|
||||||
{ "getPosition", w_Source_getPosition },
|
{ "getPosition", w_Source_getPosition },
|
||||||
{ "setVelocity", w_Source_setVelocity },
|
{ "setVelocity", w_Source_setVelocity },
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ namespace audio
|
|||||||
int w_Source_getPitch(lua_State * L);
|
int w_Source_getPitch(lua_State * L);
|
||||||
int w_Source_setVolume(lua_State * L);
|
int w_Source_setVolume(lua_State * L);
|
||||||
int w_Source_getVolume(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_setPosition(lua_State * L);
|
||||||
int w_Source_getPosition(lua_State * L);
|
int w_Source_getPosition(lua_State * L);
|
||||||
int w_Source_setVelocity(lua_State * L);
|
int w_Source_setVelocity(lua_State * L);
|
||||||
|
|||||||
Reference in New Issue
Block a user