2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2015-06-22 15:08:17 +02:00
|
|
|
|
|
|
|
#include "pcm/Interleave.hxx"
|
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2015-06-22 15:08:17 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static void
|
|
|
|
TestInterleaveN()
|
|
|
|
{
|
|
|
|
static constexpr T src1[] = { 1, 4, 7 };
|
|
|
|
static constexpr T src2[] = { 2, 5, 8 };
|
|
|
|
static constexpr T src3[] = { 3, 6, 9 };
|
|
|
|
static constexpr const T *src_all[] = { src1, src2, src3 };
|
|
|
|
|
2019-08-03 13:10:49 +02:00
|
|
|
static constexpr size_t n_frames = std::size(src1);
|
|
|
|
static constexpr unsigned channels = std::size(src_all);
|
2015-06-22 15:08:17 +02:00
|
|
|
|
2022-07-04 15:27:03 +02:00
|
|
|
static const std::span<const void *const> src{
|
|
|
|
(const void *const*)src_all,
|
|
|
|
channels,
|
|
|
|
};
|
2015-06-22 15:08:17 +02:00
|
|
|
|
|
|
|
static constexpr T poison = T(0xdeadbeef);
|
|
|
|
T dest[n_frames * channels + 1];
|
2019-08-03 13:10:49 +02:00
|
|
|
std::fill_n(dest, std::size(dest), poison);
|
2015-06-22 15:08:17 +02:00
|
|
|
|
|
|
|
PcmInterleave(dest, src, n_frames, sizeof(T));
|
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_EQ(T(1), dest[0]);
|
|
|
|
EXPECT_EQ(T(2), dest[1]);
|
|
|
|
EXPECT_EQ(T(3), dest[2]);
|
|
|
|
EXPECT_EQ(T(4), dest[3]);
|
|
|
|
EXPECT_EQ(T(5), dest[4]);
|
|
|
|
EXPECT_EQ(T(6), dest[5]);
|
|
|
|
EXPECT_EQ(T(7), dest[6]);
|
|
|
|
EXPECT_EQ(T(8), dest[7]);
|
|
|
|
EXPECT_EQ(T(9), dest[8]);
|
|
|
|
EXPECT_EQ(poison, dest[9]);
|
2015-06-22 15:08:17 +02:00
|
|
|
}
|
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
TEST(PcmTest, Interleave8)
|
2015-06-22 15:08:17 +02:00
|
|
|
{
|
|
|
|
TestInterleaveN<uint8_t>();
|
|
|
|
}
|
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
TEST(PcmTest, Interleave16)
|
2015-06-22 15:08:17 +02:00
|
|
|
{
|
|
|
|
TestInterleaveN<uint16_t>();
|
|
|
|
}
|
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
TEST(PcmTest, Interleave24)
|
2015-06-22 15:08:17 +02:00
|
|
|
{
|
2020-02-01 13:38:55 +01:00
|
|
|
using T = uint8_t;
|
2015-06-22 15:08:17 +02:00
|
|
|
static constexpr T src1[] = { 1, 2, 3, 4, 5, 6 };
|
|
|
|
static constexpr T src2[] = { 7, 8, 9, 10, 11, 12 };
|
|
|
|
static constexpr T src3[] = { 13, 14, 15, 16, 17, 18 };
|
|
|
|
static constexpr const T *src_all[] = { src1, src2, src3 };
|
|
|
|
|
2019-08-03 13:10:49 +02:00
|
|
|
static constexpr size_t n_frames = std::size(src1) / 3;
|
|
|
|
static constexpr unsigned channels = std::size(src_all);
|
2015-06-22 15:08:17 +02:00
|
|
|
|
2022-07-04 15:27:03 +02:00
|
|
|
static const std::span<const void *const> src{
|
|
|
|
(const void *const*)src_all,
|
|
|
|
channels,
|
|
|
|
};
|
2015-06-22 15:08:17 +02:00
|
|
|
|
|
|
|
static constexpr T poison = 0xff;
|
|
|
|
T dest[n_frames * channels * 3 + 1];
|
2019-08-03 13:10:49 +02:00
|
|
|
std::fill_n(dest, std::size(dest), poison);
|
2015-06-22 15:08:17 +02:00
|
|
|
|
|
|
|
PcmInterleave(dest, src, n_frames, 3);
|
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_EQ(T(1), dest[0]);
|
|
|
|
EXPECT_EQ(T(2), dest[1]);
|
|
|
|
EXPECT_EQ(T(3), dest[2]);
|
|
|
|
EXPECT_EQ(T(7), dest[3]);
|
|
|
|
EXPECT_EQ(T(8), dest[4]);
|
|
|
|
EXPECT_EQ(T(9), dest[5]);
|
|
|
|
EXPECT_EQ(T(13), dest[6]);
|
|
|
|
EXPECT_EQ(T(14), dest[7]);
|
|
|
|
EXPECT_EQ(T(15), dest[8]);
|
|
|
|
EXPECT_EQ(T(4), dest[9]);
|
|
|
|
EXPECT_EQ(T(5), dest[10]);
|
|
|
|
EXPECT_EQ(T(6), dest[11]);
|
|
|
|
EXPECT_EQ(T(10), dest[12]);
|
|
|
|
EXPECT_EQ(T(11), dest[13]);
|
|
|
|
EXPECT_EQ(T(12), dest[14]);
|
|
|
|
EXPECT_EQ(T(16), dest[15]);
|
|
|
|
EXPECT_EQ(T(17), dest[16]);
|
|
|
|
EXPECT_EQ(T(18), dest[17]);
|
|
|
|
EXPECT_EQ(poison, dest[18]);
|
2015-06-22 15:08:17 +02:00
|
|
|
|
|
|
|
TestInterleaveN<uint16_t>();
|
|
|
|
}
|
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
TEST(PcmTest, Interleave32)
|
2015-06-22 15:08:17 +02:00
|
|
|
{
|
|
|
|
TestInterleaveN<uint8_t>();
|
|
|
|
}
|
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
TEST(PcmTest, Interleave64)
|
2015-06-22 15:08:17 +02:00
|
|
|
{
|
|
|
|
TestInterleaveN<uint64_t>();
|
|
|
|
}
|