spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit ae8fa4da6d5c6dd494c7b05ce926a20f10f8a8b3
parent 5c3a9086e6112e4b6e955ded6a7e223ac7e1c681
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Wed,  6 Mar 2013 09:36:55 -0800

Test audio decoding

Diffstat:
Mtests/Makefile.am | 1+
Atests/test-audio-read.cc | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/test.cc | 1+
Mtests/test.h | 1+
4 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am @@ -8,6 +8,7 @@ check_PROGRAMS = $(TESTS) test_SOURCES = \ test-audio-info.cc \ + test-audio-read.cc \ test-utils.cc \ test.cc \ test.h diff --git a/tests/test-audio-read.cc b/tests/test-audio-read.cc @@ -0,0 +1,64 @@ +/* test-audio-read.cc + * + * Copyright (C) 2013 Alexander Kojevnikov <alexander@kojevnikov.com> + * + * Spek is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Spek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Spek. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <map> + +#include "spek-audio.h" + +#include "test.h" + +static void test_silence(const std::string& name, int samples) +{ + Audio audio; + auto file = audio.open(SAMPLES_DIR "/" + name); + + int samples_read = 0; + double power = 0.0; + int len; + while ((len = file->read()) > 0) { + samples_read += len; + for (int i = 0; i < len; ++i) { + float level = file->get_buffer()[i]; + power += level * level; + } + } + power /= samples_read; + + test("error", 0, len); + test("samples", samples, samples_read); + test("power", 0.0, power); +} + +void test_audio_read() +{ + std::map<std::string, int> files = { + {"1ch-96000Hz-24bps.flac", 1 * 96000 / 10}, + {"2ch-48000Hz-16bps.flac", 2 * 48000 / 10}, + {"2ch-44100Hz-16bps.wav", 2 * 44100 / 10}, + {"2ch-44100Hz-128cbr.mp3", 2 * 1152 * 4 + 94}, + {"2ch-44100Hz-320cbr.mp3", 2 * 1152 * 4 + 94}, + {"2ch-44100Hz-V0.mp3", 2 * 1152 * 4 + 94}, + {"2ch-44100Hz-V2.mp3", 2 * 1152 * 4 + 94}, + }; + for (const auto& item : files) { + run( + "audio read: " + item.first, + [&] () { test_silence(item.first, item.second); } + ); + } +} diff --git a/tests/test.cc b/tests/test.cc @@ -26,6 +26,7 @@ int main() std::cerr << "-------------" << std::endl; test_audio_info(); + test_audio_read(); test_utils(); std::cerr << g_passes << "/" << g_total << " tests passed" << std::endl; diff --git a/tests/test.h b/tests/test.h @@ -52,6 +52,7 @@ template<class T> void test(const std::string& message, const T& expected, const } void test_audio_info(); +void test_audio_read(); void test_utils(); #endif