2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2011-10-09 13:22:08 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|