Audio: Final fixes
This commit is contained in:
parent
82641c6653
commit
45f0825a6e
|
|
@ -24,10 +24,7 @@ int main()
|
||||||
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory(".." / resourceDir))
|
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory(".." / resourceDir))
|
||||||
resourceDir = ".." / resourceDir;
|
resourceDir = ".." / resourceDir;
|
||||||
|
|
||||||
Nz::Audio::Config config;
|
Nz::Modules<Nz::Audio> audio;
|
||||||
config.noAudio = true;
|
|
||||||
|
|
||||||
Nz::Modules<Nz::Audio, Nz::Platform> audio(config);
|
|
||||||
|
|
||||||
Nz::Sound sound;
|
Nz::Sound sound;
|
||||||
if (!sound.LoadFromFile(resourceDir / "siren.wav"))
|
if (!sound.LoadFromFile(resourceDir / "siren.wav"))
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,7 @@ int main()
|
||||||
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory(".." / resourceDir))
|
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory(".." / resourceDir))
|
||||||
resourceDir = ".." / resourceDir;
|
resourceDir = ".." / resourceDir;
|
||||||
|
|
||||||
Nz::Audio::Config config;
|
Nz::Modules<Nz::Audio> audio;
|
||||||
config.noAudio = true;
|
|
||||||
|
|
||||||
Nz::Modules<Nz::Audio> audio(config);
|
|
||||||
|
|
||||||
Nz::SoundStreamParams streamParams;
|
Nz::SoundStreamParams streamParams;
|
||||||
streamParams.forceMono = false;
|
streamParams.forceMono = false;
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,16 @@ namespace Nz
|
||||||
m_hasDummyDevice(config.allowDummyDevice)
|
m_hasDummyDevice(config.allowDummyDevice)
|
||||||
{
|
{
|
||||||
// Load OpenAL
|
// Load OpenAL
|
||||||
if (!config.noAudio && !s_openalLibrary.Load())
|
if (!config.noAudio)
|
||||||
throw std::runtime_error("failed to load OpenAL");
|
{
|
||||||
|
if (!s_openalLibrary.Load())
|
||||||
|
{
|
||||||
|
if (!config.allowDummyDevice)
|
||||||
|
throw std::runtime_error("failed to load OpenAL");
|
||||||
|
|
||||||
|
NazaraError("failed to load OpenAL");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Loaders
|
// Loaders
|
||||||
m_soundBufferLoader.RegisterLoader(Loaders::GetSoundBufferLoader_drwav());
|
m_soundBufferLoader.RegisterLoader(Loaders::GetSoundBufferLoader_drwav());
|
||||||
|
|
@ -52,8 +60,21 @@ namespace Nz
|
||||||
m_soundStreamLoader.RegisterLoader(Loaders::GetSoundStreamLoader_minimp3());
|
m_soundStreamLoader.RegisterLoader(Loaders::GetSoundStreamLoader_minimp3());
|
||||||
|
|
||||||
if (s_openalLibrary.IsLoaded())
|
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>();
|
m_defaultDevice = std::make_shared<DummyAudioDevice>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,55 @@ SCENARIO("SoundBuffer", "[AUDIO][SOUNDBUFFER]")
|
||||||
{
|
{
|
||||||
GIVEN("A sound buffer")
|
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");
|
std::shared_ptr<Nz::SoundBuffer> soundBuffer = Nz::SoundBuffer::LoadFromFile(GetResourceDir() / "Engine/Audio/Cat.flac");
|
||||||
REQUIRE(soundBuffer);
|
REQUIRE(soundBuffer);
|
||||||
|
|
||||||
THEN("We can ask the informations of the file")
|
THEN("We can ask the informations of the file")
|
||||||
{
|
{
|
||||||
REQUIRE(soundBuffer->GetDuration() <= 8500); // 8s = 8000ms
|
CHECK(soundBuffer->GetDuration() == 8192);
|
||||||
REQUIRE(soundBuffer->GetDuration() >= 8000);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue