Audio: Add some fixes and tests

This commit is contained in:
SirLynix
2022-05-06 12:41:02 +02:00
parent 81085508ec
commit 21a38fb31b
4 changed files with 127 additions and 8 deletions

View File

@@ -53,12 +53,53 @@ SCENARIO("Music", "[AUDIO][MUSIC]")
CHECK(music.GetStatus() == Nz::SoundStatus::Playing);
music.Pause();
Nz::UInt32 playingOffset = music.GetPlayingOffset();
CHECK(music.GetStatus() == Nz::SoundStatus::Paused);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
CHECK(music.GetStatus() == Nz::SoundStatus::Paused);
CHECK(music.GetPlayingOffset() == playingOffset);
music.SetPlayingOffset(3500);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
CHECK(music.GetPlayingOffset() == 3500);
music.Play();
std::this_thread::sleep_for(std::chrono::milliseconds(200));
CHECK(music.GetPlayingOffset() >= 3650);
AND_WHEN("We let the sound stop by itself")
{
REQUIRE(music.GetDuration() == 63059);
music.SetPlayingOffset(62900);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
CHECK(music.GetStatus() == Nz::SoundStatus::Stopped);
CHECK(music.GetPlayingOffset() == 0);
music.SetPlayingOffset(64000);
music.Play();
std::this_thread::sleep_for(std::chrono::milliseconds(50));
CHECK(music.GetStatus() == Nz::SoundStatus::Playing);
CHECK(music.GetPlayingOffset() < 100);
music.Stop();
music.SetPlayingOffset(62900);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
CHECK(music.GetStatus() == Nz::SoundStatus::Stopped);
CHECK(music.GetPlayingOffset() == 0); //< playing offset has no effect until Play()
AND_WHEN("We enable looping")
{
music.EnableLooping(true);
CHECK(music.IsLooping());
music.Play();
CHECK(music.GetStatus() == Nz::SoundStatus::Playing);
CHECK(music.GetPlayingOffset() >= 62900);
std::this_thread::sleep_for(std::chrono::milliseconds(300));
CHECK(music.GetStatus() == Nz::SoundStatus::Playing);
CHECK(music.GetPlayingOffset() < 300);
}
}
Nz::Audio::Instance()->GetDefaultDevice()->SetGlobalVolume(100.f);
}
}

View File

@@ -41,11 +41,52 @@ SCENARIO("Sound", "[AUDIO][SOUND]")
std::this_thread::sleep_for(std::chrono::milliseconds(200));
CHECK(sound.GetPlayingOffset() <= 1500);
sound.Pause();
Nz::UInt32 playingOffset = sound.GetPlayingOffset();
CHECK(sound.GetStatus() == Nz::SoundStatus::Paused);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
CHECK(sound.GetStatus() == Nz::SoundStatus::Paused);
CHECK(sound.GetPlayingOffset() == playingOffset);
sound.SetPlayingOffset(3500);
CHECK(sound.GetPlayingOffset() == 3500);
sound.Play();
std::this_thread::sleep_for(std::chrono::milliseconds(200));
CHECK(sound.GetPlayingOffset() >= 1650);
AND_WHEN("We let the sound stop by itself")
{
REQUIRE(sound.GetDuration() == 8192);
sound.SetPlayingOffset(8000);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
CHECK(sound.GetStatus() == Nz::SoundStatus::Stopped);
CHECK(sound.GetPlayingOffset() == 0);
sound.SetPlayingOffset(9000);
sound.Play();
std::this_thread::sleep_for(std::chrono::milliseconds(50));
CHECK(sound.GetStatus() == Nz::SoundStatus::Playing);
sound.Stop();
sound.SetPlayingOffset(8000);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
CHECK(sound.GetStatus() == Nz::SoundStatus::Stopped);
CHECK(sound.GetPlayingOffset() == 0); //< playing offset has no effect until Play()
AND_WHEN("We enable looping")
{
sound.EnableLooping(true);
CHECK(sound.IsLooping());
sound.Play();
CHECK(sound.GetStatus() == Nz::SoundStatus::Playing);
CHECK(sound.GetPlayingOffset() >= 8000);
std::this_thread::sleep_for(std::chrono::milliseconds(300));
CHECK(sound.GetStatus() == Nz::SoundStatus::Playing);
CHECK(sound.GetPlayingOffset() < 300);
}
}
Nz::Audio::Instance()->GetDefaultDevice()->SetGlobalVolume(100.f);
}
}