2011-10-09 13:22:08 +02:00
|
|
|
/*
|
2021-01-01 19:54:25 +01:00
|
|
|
* Copyright 2003-2021 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 22:58:27 +01:00
|
|
|
#include "test_pcm_util.hxx"
|
2019-06-17 11:10:33 +02:00
|
|
|
#include "pcm/Dither.cxx"
|
2011-10-09 13:22:08 +02:00
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
TEST(PcmTest, Dither24)
|
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) {
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_GE(dest[i], (src[i] >> 8) - 8);
|
|
|
|
EXPECT_LT(dest[i], (src[i] >> 8) + 8);
|
2011-10-09 13:22:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
TEST(PcmTest, Dither32)
|
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) {
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_GE(dest[i], (src[i] >> 16) - 8);
|
|
|
|
EXPECT_LT(dest[i], (src[i] >> 16) + 8);
|
2011-10-09 13:22:08 +02:00
|
|
|
}
|
|
|
|
}
|