audio::Speaker.getDuration()
This commit is contained in:
@@ -25,7 +25,10 @@ Speaker* ALSound::newInstance(int priority, int channel) const {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
AL_CHECK(alSourcei(source, AL_BUFFER, buffer));
|
AL_CHECK(alSourcei(source, AL_BUFFER, buffer));
|
||||||
return new ALSpeaker(al, source, priority, channel);
|
|
||||||
|
auto speaker = new ALSpeaker(al, source, priority, channel);
|
||||||
|
speaker->duration = duration;
|
||||||
|
return speaker;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALStream::ALStream(ALAudio* al, std::shared_ptr<PCMStream> source, bool keepSource)
|
ALStream::ALStream(ALAudio* al, std::shared_ptr<PCMStream> source, bool keepSource)
|
||||||
@@ -77,6 +80,11 @@ void ALStream::bindSpeaker(speakerid_t speaker) {
|
|||||||
sp->stop();
|
sp->stop();
|
||||||
}
|
}
|
||||||
this->speaker = speaker;
|
this->speaker = speaker;
|
||||||
|
sp = audio::get_speaker(speaker);
|
||||||
|
if (sp) {
|
||||||
|
auto alspeaker = dynamic_cast<ALSpeaker*>(sp);
|
||||||
|
alspeaker->duration = source->getTotalDuration();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
speakerid_t ALStream::getSpeaker() const {
|
speakerid_t ALStream::getSpeaker() const {
|
||||||
@@ -207,6 +215,10 @@ duration_t ALSpeaker::getTime() const {
|
|||||||
return static_cast<duration_t>(AL::getSourcef(source, AL_SEC_OFFSET));
|
return static_cast<duration_t>(AL::getSourcef(source, AL_SEC_OFFSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duration_t ALSpeaker::getDuration() const {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
void ALSpeaker::setTime(duration_t time) {
|
void ALSpeaker::setTime(duration_t time) {
|
||||||
AL_CHECK(alSourcef(source, AL_SEC_OFFSET, static_cast<float>(time)));
|
AL_CHECK(alSourcef(source, AL_SEC_OFFSET, static_cast<float>(time)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ namespace audio {
|
|||||||
bool stopped = true;
|
bool stopped = true;
|
||||||
bool paused = false;
|
bool paused = false;
|
||||||
uint source;
|
uint source;
|
||||||
|
duration_t duration = 0.0f;
|
||||||
|
|
||||||
ALSpeaker(ALAudio* al, uint source, int priority, int channel);
|
ALSpeaker(ALAudio* al, uint source, int priority, int channel);
|
||||||
~ALSpeaker();
|
~ALSpeaker();
|
||||||
@@ -102,6 +103,7 @@ namespace audio {
|
|||||||
void stop() override;
|
void stop() override;
|
||||||
|
|
||||||
duration_t getTime() const override;
|
duration_t getTime() const override;
|
||||||
|
duration_t getDuration() const override;
|
||||||
void setTime(duration_t time) override;
|
void setTime(duration_t time) override;
|
||||||
|
|
||||||
void setPosition(glm::vec3 pos) override;
|
void setPosition(glm::vec3 pos) override;
|
||||||
|
|||||||
@@ -269,6 +269,9 @@ namespace audio {
|
|||||||
/// @return time position in seconds
|
/// @return time position in seconds
|
||||||
virtual duration_t getTime() const = 0;
|
virtual duration_t getTime() const = 0;
|
||||||
|
|
||||||
|
/// @brief Get playing audio total duration
|
||||||
|
virtual duration_t getDuration() const = 0;
|
||||||
|
|
||||||
/// @brief Set playing audio time position
|
/// @brief Set playing audio time position
|
||||||
/// @param time time position in seconds
|
/// @param time time position in seconds
|
||||||
virtual void setTime(duration_t time) = 0;
|
virtual void setTime(duration_t time) = 0;
|
||||||
|
|||||||
@@ -355,6 +355,18 @@ static int l_audio_get_time(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief audio.get_duration(speakerid: integer) -> number
|
||||||
|
static int l_audio_get_duration(lua_State* L) {
|
||||||
|
lua::luaint id = lua_tonumber(L, 1);
|
||||||
|
auto speaker = audio::get_speaker(id);
|
||||||
|
if (speaker != nullptr) {
|
||||||
|
lua_pushnumber(L, speaker->getDuration());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
lua_pushnumber(L, 0.0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief audio.get_position(speakerid: integer) -> number, number, number
|
/// @brief audio.get_position(speakerid: integer) -> number, number, number
|
||||||
static int l_audio_get_position(lua_State* L) {
|
static int l_audio_get_position(lua_State* L) {
|
||||||
lua::luaint id = lua_tonumber(L, 1);
|
lua::luaint id = lua_tonumber(L, 1);
|
||||||
@@ -399,6 +411,7 @@ const luaL_Reg audiolib [] = {
|
|||||||
{"get_volume", lua_wrap_errors<l_audio_get_volume>},
|
{"get_volume", lua_wrap_errors<l_audio_get_volume>},
|
||||||
{"get_pitch", lua_wrap_errors<l_audio_get_pitch>},
|
{"get_pitch", lua_wrap_errors<l_audio_get_pitch>},
|
||||||
{"get_time", lua_wrap_errors<l_audio_get_time>},
|
{"get_time", lua_wrap_errors<l_audio_get_time>},
|
||||||
|
{"get_duration", lua_wrap_errors<l_audio_get_duration>},
|
||||||
{"get_position", lua_wrap_errors<l_audio_get_position>},
|
{"get_position", lua_wrap_errors<l_audio_get_position>},
|
||||||
{"get_velocity", lua_wrap_errors<l_audio_get_velocity>},
|
{"get_velocity", lua_wrap_errors<l_audio_get_velocity>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
|
|||||||
Reference in New Issue
Block a user