Documentation for module: Audio

Former-commit-id: 4546f9db5579c219d708f87b7062104d24ec6da2
This commit is contained in:
Gawaboumga
2016-05-30 13:36:52 +02:00
parent 3e4051d82c
commit 406bebe717
23 changed files with 1110 additions and 56 deletions

View File

@@ -0,0 +1,19 @@
#include <Nazara/Audio/Algorithm.hpp>
#include <Catch/catch.hpp>
#include <array>
TEST_CASE("MixToMono", "[AUDIO][ALGORITHM]")
{
SECTION("Mix two channels together")
{
std::array<int, 4> input{ 1, 3, 5, 3 };
std::array<int, 2> output{ 0, 0 };
// Two channels and two frames !
Nz::MixToMono(input.data(), output.data(), 2, 2);
std::array<int, 2> theoric{ 2, 4 }; // It's the mean of the two channels
REQUIRE(output == theoric);
}
}

View File

@@ -0,0 +1,49 @@
#include <Nazara/Audio/Music.hpp>
#include <Catch/catch.hpp>
#include <Nazara/Audio/Audio.hpp>
#include <Nazara/Core/Thread.hpp>
SCENARIO("Music", "[AUDIO][MUSIC]")
{
GIVEN("A music")
{
Nz::Music music;
WHEN("We load our music")
{
REQUIRE(music.OpenFromFile("resources/Engine/Audio/The_Brabanconne.ogg"));
THEN("We can ask the informations of the file")
{
REQUIRE(music.GetDuration() <= 64000); // 1 min 03 = 63s = 63000ms
REQUIRE(music.GetDuration() >= 63000);
REQUIRE(music.GetFormat() == Nz::AudioFormat_Stereo);
REQUIRE(music.GetPlayingOffset() == 0);
REQUIRE(music.GetSampleCount() <= 5644800); // 64s * 44100 Hz * 2 (stereo)
REQUIRE(music.GetSampleCount() >= 5556600); // 63s * 44100 Hz * 2 (stereo)
REQUIRE(music.GetSampleRate() == 44100 /* Hz */);
REQUIRE(music.GetStatus() == Nz::SoundStatus_Stopped);
REQUIRE(music.IsLooping() == false);
}
THEN("We can play it and get the time offset")
{
Nz::Audio::SetGlobalVolume(0.f);
music.Play();
Nz::Thread::Sleep(1000);
REQUIRE(music.GetPlayingOffset() >= 950);
Nz::Thread::Sleep(200);
REQUIRE(music.GetPlayingOffset() <= 1300);
music.Pause();
REQUIRE(music.GetStatus() == Nz::SoundStatus_Paused);
music.SetPlayingOffset(3500);
REQUIRE(music.GetPlayingOffset() >= 3500);
Nz::Audio::SetGlobalVolume(100.f);
}
}
}
}

View File

@@ -0,0 +1,44 @@
#include <Nazara/Audio/Sound.hpp>
#include <Catch/catch.hpp>
#include <Nazara/Audio/Audio.hpp>
#include <Nazara/Core/Thread.hpp>
SCENARIO("Sound", "[AUDIO][SOUND]")
{
GIVEN("A sound")
{
Nz::Sound sound;
WHEN("We load our sound")
{
REQUIRE(sound.LoadFromFile("resources/Engine/Audio/Cat.flac"));
THEN("We can ask the informations of the file")
{
REQUIRE(sound.GetDuration() <= 8500); // 8s = 8000ms
REQUIRE(sound.GetDuration() >= 8000);
REQUIRE(sound.GetStatus() == Nz::SoundStatus_Stopped);
REQUIRE(sound.IsLooping() == false);
}
THEN("We can play it and get the time offset")
{
Nz::Audio::SetGlobalVolume(0.f);
sound.Play();
Nz::Thread::Sleep(1000);
REQUIRE(sound.GetPlayingOffset() >= 950);
Nz::Thread::Sleep(200);
REQUIRE(sound.GetPlayingOffset() <= 1300);
sound.Pause();
REQUIRE(sound.GetStatus() == Nz::SoundStatus_Paused);
sound.SetPlayingOffset(3500);
REQUIRE(sound.GetPlayingOffset() >= 3500);
Nz::Audio::SetGlobalVolume(100.f);
}
}
}
}

View File

@@ -0,0 +1,21 @@
#include <Nazara/Audio/SoundBuffer.hpp>
#include <Catch/catch.hpp>
SCENARIO("SoundBuffer", "[AUDIO][SOUNDBUFFER]")
{
GIVEN("A sound buffer")
{
Nz::SoundBuffer soundBuffer;
WHEN("We load our sound")
{
REQUIRE(soundBuffer.LoadFromFile("resources/Engine/Audio/Cat.flac"));
THEN("We can ask the informations of the file")
{
REQUIRE(soundBuffer.GetDuration() <= 8500); // 8s = 8000ms
REQUIRE(soundBuffer.GetDuration() >= 8000);
}
}
}
}

View File

@@ -0,0 +1,41 @@
#include <Nazara/Audio/Sound.hpp>
#include <Catch/catch.hpp>
#include <Nazara/Core/Thread.hpp>
SCENARIO("SoundEmitter", "[AUDIO][SOUNDEMITTER]")
{
GIVEN("A sound emitter")
{
Nz::Sound sound;
WHEN("We load our sound")
{
REQUIRE(sound.LoadFromFile("resources/Engine/Audio/Cat.flac"));
THEN("We can ask information about position and velocity")
{
sound.EnableSpatialization(true);
sound.SetPosition(Nz::Vector3f::Zero());
sound.SetVelocity(Nz::Vector3f::UnitX());
REQUIRE(sound.IsSpatialized());
REQUIRE(sound.GetPosition() == Nz::Vector3f::Zero());
REQUIRE(sound.GetVelocity() == Nz::Vector3f::UnitX());
}
THEN("We can ask information about attenuation, pitch, ...")
{
sound.SetAttenuation(0.4f);
sound.SetMinDistance(40.f);
sound.SetPitch(0.8f);
sound.SetVolume(50.f);
REQUIRE(Approx(sound.GetAttenuation()) == 0.4f);
REQUIRE(Approx(sound.GetMinDistance()) == 40.f);
REQUIRE(Approx(sound.GetPitch()) == 0.8f);
REQUIRE(Approx(sound.GetVolume()) == 50.f);
}
}
}
}