2011-10-09 13:22:08 +02:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2011-10-09 13:22:08 +02:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2013-01-31 20:45:19 +01:00
|
|
|
#include "test_pcm_all.hxx"
|
2013-01-31 22:58:27 +01:00
|
|
|
#include "test_pcm_util.hxx"
|
2013-12-28 18:30:13 +01:00
|
|
|
#include "pcm/PcmDither.cxx"
|
2011-10-09 13:22:08 +02:00
|
|
|
|
|
|
|
void
|
2013-10-16 21:55:00 +02:00
|
|
|
PcmDitherTest::TestDither24()
|
2011-10-09 13:22:08 +02:00
|
|
|
{
|
2014-03-15 10:49:50 +01:00
|
|
|
constexpr unsigned N = 509;
|
2013-10-19 15:05:48 +02:00
|
|
|
const auto src = TestDataBuffer<int32_t, N>(RandomInt24());
|
2011-10-09 13:22:08 +02:00
|
|
|
|
|
|
|
int16_t dest[N];
|
2013-01-31 22:58:27 +01:00
|
|
|
PcmDither dither;
|
|
|
|
dither.Dither24To16(dest, src.begin(), src.end());
|
2011-10-09 13:22:08 +02:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < N; ++i) {
|
2013-10-16 21:55:00 +02:00
|
|
|
CPPUNIT_ASSERT(dest[i] >= (src[i] >> 8) - 8);
|
|
|
|
CPPUNIT_ASSERT(dest[i] < (src[i] >> 8) + 8);
|
2011-10-09 13:22:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-16 21:55:00 +02:00
|
|
|
PcmDitherTest::TestDither32()
|
2011-10-09 13:22:08 +02:00
|
|
|
{
|
2014-03-15 10:49:50 +01:00
|
|
|
constexpr unsigned N = 509;
|
2013-01-31 22:58:27 +01:00
|
|
|
const auto src = TestDataBuffer<int32_t, N>();
|
2011-10-09 13:22:08 +02:00
|
|
|
|
|
|
|
int16_t dest[N];
|
2013-01-31 22:58:27 +01:00
|
|
|
PcmDither dither;
|
|
|
|
dither.Dither32To16(dest, src.begin(), src.end());
|
2011-10-09 13:22:08 +02:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < N; ++i) {
|
2013-10-16 21:55:00 +02:00
|
|
|
CPPUNIT_ASSERT(dest[i] >= (src[i] >> 16) - 8);
|
|
|
|
CPPUNIT_ASSERT(dest[i] < (src[i] >> 16) + 8);
|
2011-10-09 13:22:08 +02:00
|
|
|
}
|
|
|
|
}
|