Audio: Final fixes

This commit is contained in:
Lynix 2022-03-19 12:16:52 +01:00
parent 82641c6653
commit 45f0825a6e
4 changed files with 70 additions and 15 deletions

View File

@ -24,10 +24,7 @@ int main()
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory(".." / resourceDir))
resourceDir = ".." / resourceDir;
Nz::Audio::Config config;
config.noAudio = true;
Nz::Modules<Nz::Audio, Nz::Platform> audio(config);
Nz::Modules<Nz::Audio> audio;
Nz::Sound sound;
if (!sound.LoadFromFile(resourceDir / "siren.wav"))

View File

@ -18,10 +18,7 @@ int main()
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory(".." / resourceDir))
resourceDir = ".." / resourceDir;
Nz::Audio::Config config;
config.noAudio = true;
Nz::Modules<Nz::Audio> audio(config);
Nz::Modules<Nz::Audio> audio;
Nz::SoundStreamParams streamParams;
streamParams.forceMono = false;

View File

@ -38,8 +38,16 @@ namespace Nz
m_hasDummyDevice(config.allowDummyDevice)
{
// Load OpenAL
if (!config.noAudio && !s_openalLibrary.Load())
throw std::runtime_error("failed to load OpenAL");
if (!config.noAudio)
{
if (!s_openalLibrary.Load())
{
if (!config.allowDummyDevice)
throw std::runtime_error("failed to load OpenAL");
NazaraError("failed to load OpenAL");
}
}
// Loaders
m_soundBufferLoader.RegisterLoader(Loaders::GetSoundBufferLoader_drwav());
@ -52,8 +60,21 @@ namespace Nz
m_soundStreamLoader.RegisterLoader(Loaders::GetSoundStreamLoader_minimp3());
if (s_openalLibrary.IsLoaded())
m_defaultDevice = s_openalLibrary.OpenDevice();
else
{
try
{
m_defaultDevice = s_openalLibrary.OpenDevice();
}
catch (const std::exception& e)
{
if (!config.allowDummyDevice)
throw;
NazaraError(std::string("failed to open default OpenAL device: ") + e.what());
}
}
if (!m_defaultDevice)
m_defaultDevice = std::make_shared<DummyAudioDevice>();
}

View File

@ -7,15 +7,55 @@ SCENARIO("SoundBuffer", "[AUDIO][SOUNDBUFFER]")
{
GIVEN("A sound buffer")
{
WHEN("We load our sound")
WHEN("We load a .flac file")
{
std::shared_ptr<Nz::SoundBuffer> soundBuffer = Nz::SoundBuffer::LoadFromFile(GetResourceDir() / "Engine/Audio/Cat.flac");
REQUIRE(soundBuffer);
THEN("We can ask the informations of the file")
{
REQUIRE(soundBuffer->GetDuration() <= 8500); // 8s = 8000ms
REQUIRE(soundBuffer->GetDuration() >= 8000);
CHECK(soundBuffer->GetDuration() == 8192);
CHECK(soundBuffer->GetFormat() == Nz::AudioFormat::I16_Stereo);
CHECK(soundBuffer->GetSampleRate() == 96000);
}
}
WHEN("We load a .mp3 file")
{
std::shared_ptr<Nz::SoundBuffer> soundBuffer = Nz::SoundBuffer::LoadFromFile(GetResourceDir() / "file_example_MP3_700KB.mp3");
REQUIRE(soundBuffer);
THEN("We can ask the informations of the file")
{
CHECK(soundBuffer->GetDuration() == 27193);
CHECK(soundBuffer->GetFormat() == Nz::AudioFormat::I16_Stereo);
CHECK(soundBuffer->GetSampleRate() == 32000);
}
}
WHEN("We load a .ogg file")
{
std::shared_ptr<Nz::SoundBuffer> soundBuffer = Nz::SoundBuffer::LoadFromFile(GetResourceDir() / "Engine/Audio/The_Brabanconne.ogg");
REQUIRE(soundBuffer);
THEN("We can ask the informations of the file")
{
CHECK(soundBuffer->GetDuration() == 63059);
CHECK(soundBuffer->GetFormat() == Nz::AudioFormat::I16_Stereo);
CHECK(soundBuffer->GetSampleRate() == 44100);
}
}
WHEN("We load a .wav file")
{
std::shared_ptr<Nz::SoundBuffer> soundBuffer = Nz::SoundBuffer::LoadFromFile(GetResourceDir() / "explosion.wav");
REQUIRE(soundBuffer);
THEN("We can ask the informations of the file")
{
CHECK(soundBuffer->GetDuration() == 2064);
CHECK(soundBuffer->GetFormat() == Nz::AudioFormat::I16_Stereo);
CHECK(soundBuffer->GetSampleRate() == 48000);
}
}
}