Mostly-merge master.
[dcpomatic.git] / test / resampler_test.cc
1 /*
2     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <boost/test/unit_test.hpp>
21 #include "lib/audio_buffers.h"
22 #include "lib/resampler.h"
23
24 using std::pair;
25 using std::cout;
26 using boost::shared_ptr;
27
28 static void
29 resampler_test_one (int from, int to)
30 {
31         Resampler resamp (from, to, 1);
32
33         int total_out = 0;
34
35         /* 3 hours */
36         int64_t const N = int64_t (from) * 60 * 60 * 3;
37                 
38         /* XXX: no longer checks anything */
39         for (int64_t i = 0; i < N; i += 1000) {
40                 shared_ptr<AudioBuffers> a (new AudioBuffers (1, 1000));
41                 a->make_silent ();
42                 shared_ptr<const AudioBuffers> r = resamp.run (a);
43                 total_out += r->frames ();
44         }
45 }       
46                 
47 /** Check that the timings that come back from the resampler correspond
48     to the number of samples it generates.
49 */
50 BOOST_AUTO_TEST_CASE (resampler_test)
51 {
52         resampler_test_one (44100, 48000);
53         resampler_test_one (44100, 46080);
54         resampler_test_one (44100, 50000);
55 }