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);
}
}
}
}

View File

@@ -0,0 +1 @@
6993cbcca9ac596667135cb0f30bea4841178d3b

View File

@@ -0,0 +1 @@
94b2c47c9143adbac0fb7e81df5cc87f969f7150

View File

@@ -0,0 +1,54 @@
The_Brabanconne.ogg
https://en.wikipedia.org/wiki/File:The_Brabanconne.ogg
Original file:
The_Brabanconne.ogg (Ogg Vorbis sound file, length 1 min 3 s, 378 kbps)
Summary:
Description: The Belgian national anthem (instrumental version) performed by the United States Navy Band. Direct link is at http://www.navyband.navy.mil/anthems/ANTHEMS/Belgium.mp3.
Date: 19 October 2004
Source: http://www.navyband.navy.mil/anthems/national_anthems.htm
Author: United States Navy Band (rendition), uploaded to Wikimedia by Keith Lehwald
Licencing:
This file is a work of a sailor or employee of the U.S. Navy, taken or made as part of that person's official duties. As a work of the U.S. federal government, the image is in the public domain.
This file has been identified as being free of known restrictions under copyright law, including all related and neighboring rights.
-------------------------------------------------------------------------------------------------
Cat.flac:
http://www.freesound.org/people/EARR/sounds/148013/
Original file:
148013__earr__angry-cat.flac (Flac sound file, length 8 s, 96000 Hz, 24 bit depth)
Author:
EARR
Description:
Slightly angry cat. She is a beautiful Siamese cat called Agostina. She is angry for the recording because i pressed his tail.
Information about the recording and equipment:
-Location: Living room.
-Type of acoustic environment: Small, diffuse, moderately reflective.
-Distance from sound source to microphones: Approx a few centimeters.
-Miking technique: Jecklin disk.
-Microphones: 2 Brüel & Kjaer type 4190 capsules with type 2669L head amplifier.
-Microphone preamps: Modified Brüel & Kjaer type 5935L.
-ADC: Echo Audiofire 4. (line inputs 3 & 4).
-Recorder: Echo Audiofire 4 and Dell D630C running Samplitude 10.
Eq: Compensation only for the response of the microphones (In this case for flat response at 60º. See Brüel & Kjaer type 4190 datasheet).
No reverb, no compression, no fx.
Licencing:
Creative commons