mirror of
https://gitlab.com/square-game-liberation-front/F.E.I.S.git
synced 2024-09-24 03:28:28 +02:00
Even smoother playback
This commit is contained in:
parent
c224f6645a
commit
2960f8d424
@ -11,24 +11,30 @@ MorePreciseMusic::MorePreciseMusic(const std::filesystem::path& path) {
|
|||||||
throw std::runtime_error("Error: AL_SOFT_source_latency not supported");
|
throw std::runtime_error("Error: AL_SOFT_source_latency not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
(alGetSourcedvSOFT) = reinterpret_cast<LPALGETSOURCEDVSOFT>(alGetProcAddress("alGetSourcedvSOFT"));
|
alGetSourcedvSOFT = reinterpret_cast<LPALGETSOURCEDVSOFT>(alGetProcAddress("alGetSourcedvSOFT"));
|
||||||
|
|
||||||
if (not this->openFromFile(path.string())) {
|
if (not this->openFromFile(path.string())) {
|
||||||
throw std::runtime_error("Could not open "+path.string());
|
throw std::runtime_error("Could not open "+path.string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MorePreciseMusic::onGetData(sf::SoundStream::Chunk& data) {
|
std::array<sf::Time, 2> MorePreciseMusic::alSecOffsetLatencySoft() const {
|
||||||
auto result = sf::Music::onGetData(data);
|
|
||||||
time_since_last_mix.restart();
|
|
||||||
ALdouble offsets[2];
|
ALdouble offsets[2];
|
||||||
alGetSourcedvSOFT(m_source, AL_SEC_OFFSET_LATENCY_SOFT, offsets);
|
alGetSourcedvSOFT(m_source, AL_SEC_OFFSET_LATENCY_SOFT, offsets);
|
||||||
open_al_playback_position_from_lag = sf::seconds(offsets[0]);
|
return {sf::seconds(offsets[0]), sf::seconds(offsets[1])};
|
||||||
open_al_lag = sf::seconds(offsets[1]);
|
}
|
||||||
ALfloat secs = 0.f;
|
|
||||||
alGetSourcef(m_source, AL_SEC_OFFSET, &secs);
|
void MorePreciseMusic::play() {
|
||||||
open_al_offset = sf::seconds(secs);
|
sf::Music::play();
|
||||||
return result;
|
lag = this->alSecOffsetLatencySoft()[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Time MorePreciseMusic::getPrecisePlayingOffset() const {
|
||||||
|
if (this->getStatus() != sf::Music::Playing) {
|
||||||
|
return sf::Music::getPlayingOffset();
|
||||||
|
} else {
|
||||||
|
return sf::Music::getPlayingOffset() - this->alSecOffsetLatencySoft()[1] + lag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
@ -40,14 +46,11 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
auto music = MorePreciseMusic{args[1]};
|
auto music = MorePreciseMusic{args[1]};
|
||||||
music.play();
|
music.play();
|
||||||
std::cout << "getPlayingOffset, time_since_last_mix, open_al_playback_position_from_lag, open_al_lag, open_al_offset" << std::endl;
|
std::cout << "normal,Precise" << std::endl;
|
||||||
for (int i = 0; i < 5000; i++) {
|
while(music.getStatus() == sf::Music::Playing) {
|
||||||
//while (music.getStatus() == sf::Music::Playing) {
|
//for (int i = 0; i < 3000; i++) {
|
||||||
std::cout << music.getPlayingOffset().asMicroseconds() << ", ";
|
std::cout << music.getPlayingOffset().asMicroseconds() << ",";
|
||||||
std::cout << music.time_since_last_mix.getElaspedTime().asMicroseconds() << ", ";
|
std::cout << music.getPrecisePlayingOffset().asMicroseconds() << std::endl;
|
||||||
std::cout << music.open_al_playback_position_from_lag.asMicroseconds() << ", ";
|
|
||||||
std::cout << music.open_al_lag.asMicroseconds() << ", ";
|
|
||||||
std::cout << music.open_al_offset.asMicroseconds() << std::endl;
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
|
|
||||||
@ -7,12 +8,10 @@
|
|||||||
|
|
||||||
struct MorePreciseMusic : sf::Music {
|
struct MorePreciseMusic : sf::Music {
|
||||||
MorePreciseMusic(const std::filesystem::path& path);
|
MorePreciseMusic(const std::filesystem::path& path);
|
||||||
sf::Clock time_since_last_mix;
|
std::array<sf::Time, 2> alSecOffsetLatencySoft() const;
|
||||||
sf::Time open_al_playback_position_from_lag = sf::Time::Zero;
|
sf::Time getPrecisePlayingOffset() const;
|
||||||
sf::Time open_al_lag = sf::Time::Zero;
|
sf::Time lag = sf::Time::Zero;
|
||||||
sf::Time open_al_offset = sf::Time::Zero;
|
void play();
|
||||||
bool lag_measured = false;
|
|
||||||
LPALGETSOURCEDVSOFT alGetSourcedvSOFT;
|
|
||||||
protected:
|
protected:
|
||||||
bool onGetData(sf::SoundStream::Chunk& data) override;
|
LPALGETSOURCEDVSOFT alGetSourcedvSOFT;
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user