2022-07-25 14:36:05 +08:00
|
|
|
#include <SFML/Audio/InputSoundFile.hpp>
|
|
|
|
|
2023-11-27 07:43:22 +08:00
|
|
|
// Other 1st party headers
|
|
|
|
#include <SFML/System/FileInputStream.hpp>
|
|
|
|
#include <SFML/System/Time.hpp>
|
|
|
|
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
|
|
|
#include <SystemUtil.hpp>
|
|
|
|
#include <array>
|
|
|
|
#include <fstream>
|
2022-07-25 14:36:05 +08:00
|
|
|
#include <type_traits>
|
|
|
|
|
2023-11-27 07:43:22 +08:00
|
|
|
TEST_CASE("[Audio] sf::InputSoundFile")
|
|
|
|
{
|
|
|
|
SECTION("Type traits")
|
|
|
|
{
|
|
|
|
STATIC_CHECK(!std::is_copy_constructible_v<sf::InputSoundFile>);
|
|
|
|
STATIC_CHECK(!std::is_copy_assignable_v<sf::InputSoundFile>);
|
|
|
|
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::InputSoundFile>);
|
|
|
|
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::InputSoundFile>);
|
|
|
|
}
|
|
|
|
|
2024-07-06 09:38:32 +08:00
|
|
|
SECTION("Construction")
|
|
|
|
{
|
|
|
|
const sf::InputSoundFile inputSoundFile;
|
|
|
|
CHECK(inputSoundFile.getSampleCount() == 0);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 0);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 0);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
|
2023-11-27 07:43:22 +08:00
|
|
|
SECTION("openFromFile()")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
sf::InputSoundFile inputSoundFile;
|
|
|
|
|
2023-11-27 07:43:22 +08:00
|
|
|
SECTION("Invalid file")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
CHECK(!inputSoundFile.openFromFile("does/not/exist.wav"));
|
2023-11-27 07:43:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Valid file")
|
|
|
|
{
|
|
|
|
SECTION("flac")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
REQUIRE(inputSoundFile.openFromFile("Audio/ding.flac"));
|
2023-11-27 07:43:22 +08:00
|
|
|
CHECK(inputSoundFile.getSampleCount() == 87'798);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(1'990'884));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("mp3")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
REQUIRE(inputSoundFile.openFromFile("Audio/ding.mp3"));
|
2023-11-27 07:43:22 +08:00
|
|
|
CHECK(inputSoundFile.getSampleCount() == 87'798);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(1'990'884));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("ogg")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
REQUIRE(inputSoundFile.openFromFile("Audio/doodle_pop.ogg"));
|
2023-11-27 07:43:22 +08:00
|
|
|
CHECK(inputSoundFile.getSampleCount() == 2'116'992);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 2);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(24'002'176));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("wav")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
REQUIRE(inputSoundFile.openFromFile("Audio/killdeer.wav"));
|
2023-11-27 07:43:22 +08:00
|
|
|
CHECK(inputSoundFile.getSampleCount() == 112'941);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 22'050);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(5'122'040));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("openFromMemory()")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
const auto memory = loadIntoMemory("Audio/killdeer.wav");
|
|
|
|
sf::InputSoundFile inputSoundFile;
|
|
|
|
REQUIRE(inputSoundFile.openFromMemory(memory.data(), memory.size()));
|
2023-11-27 07:43:22 +08:00
|
|
|
CHECK(inputSoundFile.getSampleCount() == 112'941);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 22'050);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(5'122'040));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("openFromStream()")
|
2024-07-06 09:38:32 +08:00
|
|
|
{
|
|
|
|
sf::InputSoundFile inputSoundFile;
|
|
|
|
sf::FileInputStream stream;
|
|
|
|
|
|
|
|
SECTION("Invalid stream")
|
|
|
|
{
|
|
|
|
CHECK(!inputSoundFile.openFromStream(stream));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Valid stream")
|
|
|
|
{
|
|
|
|
SECTION("flac")
|
|
|
|
{
|
|
|
|
REQUIRE(stream.open("Audio/ding.flac"));
|
|
|
|
REQUIRE(inputSoundFile.openFromStream(stream));
|
|
|
|
CHECK(inputSoundFile.getSampleCount() == 87'798);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(1'990'884));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("mp3")
|
|
|
|
{
|
|
|
|
REQUIRE(stream.open("Audio/ding.mp3"));
|
|
|
|
REQUIRE(inputSoundFile.openFromStream(stream));
|
|
|
|
CHECK(inputSoundFile.getSampleCount() == 87'798);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(1'990'884));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("ogg")
|
|
|
|
{
|
|
|
|
REQUIRE(stream.open("Audio/doodle_pop.ogg"));
|
|
|
|
REQUIRE(inputSoundFile.openFromStream(stream));
|
|
|
|
CHECK(inputSoundFile.getSampleCount() == 2'116'992);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 2);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(24'002'176));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("wav")
|
|
|
|
{
|
|
|
|
REQUIRE(stream.open("Audio/killdeer.wav"));
|
|
|
|
REQUIRE(inputSoundFile.openFromStream(stream));
|
|
|
|
CHECK(inputSoundFile.getSampleCount() == 112'941);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 22'050);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(5'122'040));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("createFromFile()")
|
|
|
|
{
|
|
|
|
SECTION("Invalid file")
|
|
|
|
{
|
|
|
|
CHECK(!sf::InputSoundFile::createFromFile("does/not/exist.wav"));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Valid file")
|
|
|
|
{
|
|
|
|
SECTION("flac")
|
|
|
|
{
|
|
|
|
const auto inputSoundFile = sf::InputSoundFile::createFromFile("Audio/ding.flac").value();
|
|
|
|
CHECK(inputSoundFile.getSampleCount() == 87'798);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(1'990'884));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("mp3")
|
|
|
|
{
|
|
|
|
const auto inputSoundFile = sf::InputSoundFile::createFromFile("Audio/ding.mp3").value();
|
|
|
|
CHECK(inputSoundFile.getSampleCount() == 87'798);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(1'990'884));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("ogg")
|
|
|
|
{
|
|
|
|
const auto inputSoundFile = sf::InputSoundFile::createFromFile("Audio/doodle_pop.ogg").value();
|
|
|
|
CHECK(inputSoundFile.getSampleCount() == 2'116'992);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 2);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(24'002'176));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("wav")
|
|
|
|
{
|
|
|
|
const auto inputSoundFile = sf::InputSoundFile::createFromFile("Audio/killdeer.wav").value();
|
|
|
|
CHECK(inputSoundFile.getSampleCount() == 112'941);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 22'050);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(5'122'040));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("createFromMemory()")
|
|
|
|
{
|
|
|
|
const auto memory = loadIntoMemory("Audio/killdeer.wav");
|
|
|
|
const auto inputSoundFile = sf::InputSoundFile::createFromMemory(memory.data(), memory.size()).value();
|
|
|
|
CHECK(inputSoundFile.getSampleCount() == 112'941);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 22'050);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(5'122'040));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("createFromStream()")
|
2023-11-27 07:43:22 +08:00
|
|
|
{
|
2024-06-10 11:02:54 +08:00
|
|
|
SECTION("flac")
|
2023-11-27 07:43:22 +08:00
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
auto stream = sf::FileInputStream::create("Audio/ding.flac").value();
|
|
|
|
const auto inputSoundFile = sf::InputSoundFile::createFromStream(stream).value();
|
2024-06-10 11:02:54 +08:00
|
|
|
CHECK(inputSoundFile.getSampleCount() == 87'798);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(1'990'884));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
2023-11-27 07:43:22 +08:00
|
|
|
}
|
|
|
|
|
2024-06-10 11:02:54 +08:00
|
|
|
SECTION("mp3")
|
2023-11-27 07:43:22 +08:00
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
auto stream = sf::FileInputStream::create("Audio/ding.mp3").value();
|
|
|
|
const auto inputSoundFile = sf::InputSoundFile::createFromStream(stream).value();
|
2024-06-10 11:02:54 +08:00
|
|
|
CHECK(inputSoundFile.getSampleCount() == 87'798);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(1'990'884));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
2023-11-27 07:43:22 +08:00
|
|
|
|
2024-06-10 11:02:54 +08:00
|
|
|
SECTION("ogg")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
auto stream = sf::FileInputStream::create("Audio/doodle_pop.ogg").value();
|
|
|
|
const auto inputSoundFile = sf::InputSoundFile::createFromStream(stream).value();
|
2024-06-10 11:02:54 +08:00
|
|
|
CHECK(inputSoundFile.getSampleCount() == 2'116'992);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 2);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(24'002'176));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
2023-11-27 07:43:22 +08:00
|
|
|
|
2024-06-10 11:02:54 +08:00
|
|
|
SECTION("wav")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
auto stream = sf::FileInputStream::create("Audio/killdeer.wav").value();
|
|
|
|
const auto inputSoundFile = sf::InputSoundFile::createFromStream(stream).value();
|
2024-06-10 11:02:54 +08:00
|
|
|
CHECK(inputSoundFile.getSampleCount() == 112'941);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 22'050);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(5'122'040));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
2023-11-27 07:43:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("seek(std::uint64_t)")
|
|
|
|
{
|
|
|
|
SECTION("flac")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
auto inputSoundFile = sf::InputSoundFile::createFromFile("Audio/ding.flac").value();
|
2023-11-27 07:43:22 +08:00
|
|
|
inputSoundFile.seek(1'000);
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::microseconds(22'675));
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 1'000);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("mp3")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
auto inputSoundFile = sf::InputSoundFile::createFromFile("Audio/ding.mp3").value();
|
2023-11-27 07:43:22 +08:00
|
|
|
inputSoundFile.seek(1'000);
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::microseconds(22'675));
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 1'000);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("ogg")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
auto inputSoundFile = sf::InputSoundFile::createFromFile("Audio/doodle_pop.ogg").value();
|
2023-11-27 07:43:22 +08:00
|
|
|
inputSoundFile.seek(1'000);
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::microseconds(11'337));
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 1'000);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("wav")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
auto inputSoundFile = sf::InputSoundFile::createFromFile("Audio/killdeer.wav").value();
|
2023-11-27 07:43:22 +08:00
|
|
|
inputSoundFile.seek(1'000);
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::microseconds(45'351));
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 1'000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("seek(Time)")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
auto inputSoundFile = sf::InputSoundFile::createFromFile("Audio/ding.flac").value();
|
2023-11-27 07:43:22 +08:00
|
|
|
inputSoundFile.seek(sf::milliseconds(100));
|
|
|
|
CHECK(inputSoundFile.getSampleCount() == 87'798);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 1);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 44'100);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::microseconds(1'990'884));
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::milliseconds(100));
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 4'410);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("read()")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
auto inputSoundFile = sf::InputSoundFile::createFromFile("Audio/ding.flac").value();
|
2023-11-27 07:43:22 +08:00
|
|
|
|
|
|
|
SECTION("Null address")
|
|
|
|
{
|
|
|
|
CHECK(inputSoundFile.read(nullptr, 10) == 0);
|
|
|
|
}
|
|
|
|
|
2024-05-21 09:42:43 +08:00
|
|
|
std::array<std::int16_t, 4> samples{};
|
|
|
|
|
2023-11-27 07:43:22 +08:00
|
|
|
SECTION("Zero count")
|
|
|
|
{
|
|
|
|
CHECK(inputSoundFile.read(samples.data(), 0) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Successful read")
|
|
|
|
{
|
|
|
|
SECTION("flac")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
inputSoundFile = sf::InputSoundFile::createFromFile("Audio/ding.flac").value();
|
2023-11-27 07:43:22 +08:00
|
|
|
CHECK(inputSoundFile.read(samples.data(), samples.size()) == 4);
|
|
|
|
CHECK(samples == std::array<std::int16_t, 4>{0, 1, -1, 4});
|
|
|
|
CHECK(inputSoundFile.read(samples.data(), samples.size()) == 4);
|
|
|
|
CHECK(samples == std::array<std::int16_t, 4>{1, 4, 9, 6});
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("mp3")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
inputSoundFile = sf::InputSoundFile::createFromFile("Audio/ding.mp3").value();
|
2023-11-27 07:43:22 +08:00
|
|
|
CHECK(inputSoundFile.read(samples.data(), samples.size()) == 4);
|
|
|
|
CHECK(samples == std::array<std::int16_t, 4>{0, -2, 0, 2});
|
|
|
|
CHECK(inputSoundFile.read(samples.data(), samples.size()) == 4);
|
|
|
|
CHECK(samples == std::array<std::int16_t, 4>{1, 4, 6, 8});
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("ogg")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
inputSoundFile = sf::InputSoundFile::createFromFile("Audio/doodle_pop.ogg").value();
|
2023-11-27 07:43:22 +08:00
|
|
|
CHECK(inputSoundFile.read(samples.data(), samples.size()) == 4);
|
|
|
|
CHECK(samples == std::array<std::int16_t, 4>{-827, -985, -1168, -1319});
|
|
|
|
CHECK(inputSoundFile.read(samples.data(), samples.size()) == 4);
|
|
|
|
CHECK(samples == std::array<std::int16_t, 4>{-1738, -1883, -2358, -2497});
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("wav")
|
|
|
|
{
|
|
|
|
// Cannot be tested since reading from a .wav file triggers UB
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("close()")
|
|
|
|
{
|
2024-07-06 09:38:32 +08:00
|
|
|
auto inputSoundFile = sf::InputSoundFile::createFromFile("Audio/ding.flac").value();
|
2023-11-27 07:43:22 +08:00
|
|
|
inputSoundFile.close();
|
|
|
|
CHECK(inputSoundFile.getSampleCount() == 0);
|
|
|
|
CHECK(inputSoundFile.getChannelCount() == 0);
|
|
|
|
CHECK(inputSoundFile.getSampleRate() == 0);
|
|
|
|
CHECK(inputSoundFile.getDuration() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getTimeOffset() == sf::Time::Zero);
|
|
|
|
CHECK(inputSoundFile.getSampleOffset() == 0);
|
|
|
|
}
|
|
|
|
}
|