diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-05-17 23:09:24 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-05-18 11:50:29 +0100 |
| commit | 91c62a41e2643d5c5c4bd18c064f1c080dfec4aa (patch) | |
| tree | 80507b1ce3a95e26fa57bd57abbe43fd710bc1a0 /test | |
| parent | 9808dfbfff3d0c618698f19ca6c9cbbdae24a380 (diff) | |
Some more FFmpeg audio extraction testing.
Diffstat (limited to 'test')
| -rw-r--r-- | test/ffmpeg_audio_only_test.cc | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/test/ffmpeg_audio_only_test.cc b/test/ffmpeg_audio_only_test.cc index 8541cceca..36378ccca 100644 --- a/test/ffmpeg_audio_only_test.cc +++ b/test/ffmpeg_audio_only_test.cc @@ -20,20 +20,72 @@ #include "lib/film.h" #include "lib/ffmpeg_content.h" #include "lib/dcp_content_type.h" +#include "lib/player.h" +#include "lib/job_manager.h" +#include "lib/audio_buffers.h" #include "test.h" +#include <sndfile.h> #include <boost/test/unit_test.hpp> using boost::shared_ptr; /** Test the FFmpeg code with audio-only content */ -BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test) +static void +test (boost::filesystem::path file) { shared_ptr<Film> film = new_test_film ("ffmpeg_audio_only_test"); film->set_name ("test_film"); film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test")); - shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/sine_440.mp3")); + shared_ptr<FFmpegContent> c (new FFmpegContent (film, file)); film->examine_and_add_content (c); wait_for_jobs (); + film->write_metadata (); + + /* See if can make a DCP without any errors */ film->make_dcp (); wait_for_jobs (); + BOOST_CHECK (!JobManager::instance()->errors()); + + /* Compare the audio data we read with what libsndfile reads */ + + SF_INFO info; + info.format = 0; + SNDFILE* ref = sf_open (file.string().c_str(), SFM_READ, &info); + /* We don't want to test anything that requires resampling */ + BOOST_REQUIRE_EQUAL (info.samplerate, 48000); + float* ref_buffer = new float[info.samplerate * info.channels]; + + shared_ptr<Player> player (new Player (film, film->playlist ())); + + for (DCPTime t; t < film->length(); t += DCPTime::from_seconds (1)) { + int const N = sf_readf_float (ref, ref_buffer, info.samplerate); + shared_ptr<AudioBuffers> b = player->get_audio (t, DCPTime::from_frames (N, info.samplerate), true); + for (int i = 0; i < N; ++i) { + switch (info.channels) { + case 1: + BOOST_CHECK_EQUAL (ref_buffer[i], b->data(2)[i]); + break; + case 2: + BOOST_CHECK_EQUAL (ref_buffer[i*2 + 0], b->data(0)[i]); + BOOST_CHECK_EQUAL (ref_buffer[i*2 + 1], b->data(1)[i]); + break; + default: + BOOST_REQUIRE (false); + } + } + } + + sf_close (ref); +} + +BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test1) +{ + /* S16 */ + test ("test/data/staircase.wav"); +} + +BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test2) +{ + /* S32 1 channel */ + test ("test/data/sine_440.wav"); } |
