audio::Speaker.getDuration()

This commit is contained in:
MihailRis
2024-03-06 18:55:38 +03:00
parent f5b4976b18
commit cea4867567
4 changed files with 31 additions and 1 deletions
+13 -1
View File
@@ -25,7 +25,10 @@ Speaker* ALSound::newInstance(int priority, int channel) const {
return nullptr;
}
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)
@@ -77,6 +80,11 @@ void ALStream::bindSpeaker(speakerid_t speaker) {
sp->stop();
}
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 {
@@ -207,6 +215,10 @@ duration_t ALSpeaker::getTime() const {
return static_cast<duration_t>(AL::getSourcef(source, AL_SEC_OFFSET));
}
duration_t ALSpeaker::getDuration() const {
return duration;
}
void ALSpeaker::setTime(duration_t time) {
AL_CHECK(alSourcef(source, AL_SEC_OFFSET, static_cast<float>(time)));
}
+2
View File
@@ -79,6 +79,7 @@ namespace audio {
bool stopped = true;
bool paused = false;
uint source;
duration_t duration = 0.0f;
ALSpeaker(ALAudio* al, uint source, int priority, int channel);
~ALSpeaker();
@@ -102,6 +103,7 @@ namespace audio {
void stop() override;
duration_t getTime() const override;
duration_t getDuration() const override;
void setTime(duration_t time) override;
void setPosition(glm::vec3 pos) override;
+3
View File
@@ -269,6 +269,9 @@ namespace audio {
/// @return time position in seconds
virtual duration_t getTime() const = 0;
/// @brief Get playing audio total duration
virtual duration_t getDuration() const = 0;
/// @brief Set playing audio time position
/// @param time time position in seconds
virtual void setTime(duration_t time) = 0;