2014-08-12 22:05:38 +02:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2014-08-12 22:05:38 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "test_pcm_all.hxx"
|
|
|
|
#include "pcm/PcmExport.hxx"
|
2015-10-27 00:22:22 +01:00
|
|
|
#include "pcm/Traits.hxx"
|
2014-08-12 22:05:38 +02:00
|
|
|
#include "system/ByteOrder.hxx"
|
2014-08-12 21:40:06 +02:00
|
|
|
#include "util/ConstBuffer.hxx"
|
2014-08-12 22:05:38 +02:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
PcmExportTest::TestShift8()
|
|
|
|
{
|
|
|
|
static constexpr int32_t src[] = { 0x0, 0x1, 0x100, 0x10000, 0xffffff };
|
|
|
|
static constexpr uint32_t expected[] = { 0x0, 0x100, 0x10000, 0x1000000, 0xffffff00 };
|
|
|
|
|
2016-02-26 18:54:13 +01:00
|
|
|
PcmExport::Params params;
|
|
|
|
params.shift8 = true;
|
|
|
|
|
2017-01-10 23:48:26 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(params.CalcOutputSampleRate(42u), 42u);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(params.CalcInputSampleRate(42u), 42u);
|
|
|
|
|
2014-08-12 22:05:38 +02:00
|
|
|
PcmExport e;
|
2016-02-26 18:54:13 +01:00
|
|
|
e.Open(SampleFormat::S24_P32, 2, params);
|
2014-08-12 22:05:38 +02:00
|
|
|
|
2014-08-12 21:40:06 +02:00
|
|
|
auto dest = e.Export({src, sizeof(src)});
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sizeof(expected), dest.size);
|
|
|
|
CPPUNIT_ASSERT(memcmp(dest.data, expected, dest.size) == 0);
|
2014-08-12 22:05:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PcmExportTest::TestPack24()
|
|
|
|
{
|
|
|
|
static constexpr int32_t src[] = { 0x0, 0x1, 0x100, 0x10000, 0xffffff };
|
|
|
|
|
|
|
|
static constexpr uint8_t expected_be[] = {
|
|
|
|
0, 0, 0x0,
|
|
|
|
0, 0, 0x1,
|
|
|
|
0, 0x1, 0x00,
|
|
|
|
0x1, 0x00, 0x00,
|
|
|
|
0xff, 0xff, 0xff,
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr uint8_t expected_le[] = {
|
|
|
|
0, 0, 0x0,
|
|
|
|
0x1, 0, 0,
|
|
|
|
0x00, 0x1, 0,
|
|
|
|
0, 0x00, 0x01,
|
|
|
|
0xff, 0xff, 0xff,
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr size_t expected_size = sizeof(expected_be);
|
|
|
|
static const uint8_t *const expected = IsBigEndian()
|
|
|
|
? expected_be : expected_le;
|
|
|
|
|
2016-02-26 18:54:13 +01:00
|
|
|
PcmExport::Params params;
|
|
|
|
params.pack24 = true;
|
|
|
|
|
2017-01-10 23:48:26 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(params.CalcOutputSampleRate(42u), 42u);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(params.CalcInputSampleRate(42u), 42u);
|
|
|
|
|
2014-08-12 22:05:38 +02:00
|
|
|
PcmExport e;
|
2016-02-26 18:54:13 +01:00
|
|
|
e.Open(SampleFormat::S24_P32, 2, params);
|
2014-08-12 22:05:38 +02:00
|
|
|
|
2014-08-12 21:40:06 +02:00
|
|
|
auto dest = e.Export({src, sizeof(src)});
|
|
|
|
CPPUNIT_ASSERT_EQUAL(expected_size, dest.size);
|
|
|
|
CPPUNIT_ASSERT(memcmp(dest.data, expected, dest.size) == 0);
|
2014-08-12 22:05:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PcmExportTest::TestReverseEndian()
|
|
|
|
{
|
|
|
|
static constexpr uint8_t src[] = {
|
|
|
|
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr uint8_t expected2[] = {
|
|
|
|
2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr uint8_t expected4[] = {
|
|
|
|
4, 3, 2, 1, 8, 7, 6, 5, 12, 11, 10, 9,
|
|
|
|
};
|
|
|
|
|
2016-02-26 18:54:13 +01:00
|
|
|
PcmExport::Params params;
|
|
|
|
params.reverse_endian = true;
|
|
|
|
|
2017-01-10 23:48:26 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(params.CalcOutputSampleRate(42u), 42u);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(params.CalcInputSampleRate(42u), 42u);
|
|
|
|
|
2014-08-12 22:05:38 +02:00
|
|
|
PcmExport e;
|
2016-02-26 18:54:13 +01:00
|
|
|
e.Open(SampleFormat::S8, 2, params);
|
2014-08-12 22:05:38 +02:00
|
|
|
|
2014-08-12 21:40:06 +02:00
|
|
|
auto dest = e.Export({src, sizeof(src)});
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sizeof(src), dest.size);
|
|
|
|
CPPUNIT_ASSERT(memcmp(dest.data, src, dest.size) == 0);
|
2014-08-12 22:05:38 +02:00
|
|
|
|
2016-02-26 18:54:13 +01:00
|
|
|
e.Open(SampleFormat::S16, 2, params);
|
2014-08-12 21:40:06 +02:00
|
|
|
dest = e.Export({src, sizeof(src)});
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sizeof(expected2), dest.size);
|
|
|
|
CPPUNIT_ASSERT(memcmp(dest.data, expected2, dest.size) == 0);
|
2014-08-12 22:05:38 +02:00
|
|
|
|
2016-02-26 18:54:13 +01:00
|
|
|
e.Open(SampleFormat::S32, 2, params);
|
2014-08-12 21:40:06 +02:00
|
|
|
dest = e.Export({src, sizeof(src)});
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sizeof(expected4), dest.size);
|
|
|
|
CPPUNIT_ASSERT(memcmp(dest.data, expected4, dest.size) == 0);
|
2014-08-12 22:05:38 +02:00
|
|
|
}
|
|
|
|
|
2016-02-27 08:02:01 +01:00
|
|
|
#ifdef ENABLE_DSD
|
|
|
|
|
2016-02-26 18:17:11 +01:00
|
|
|
void
|
|
|
|
PcmExportTest::TestDsdU32()
|
|
|
|
{
|
|
|
|
static constexpr uint8_t src[] = {
|
|
|
|
0x01, 0x23, 0x45, 0x67,
|
|
|
|
0x89, 0xab, 0xcd, 0xef,
|
2016-02-28 09:37:01 +01:00
|
|
|
0x11, 0x22, 0x33, 0x44,
|
|
|
|
0x55, 0x66, 0x77, 0x88,
|
2016-02-26 18:17:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr uint32_t expected[] = {
|
|
|
|
0xcd894501,
|
|
|
|
0xefab6723,
|
2016-02-28 09:37:01 +01:00
|
|
|
0x77553311,
|
|
|
|
0x88664422,
|
2016-02-26 18:17:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
PcmExport::Params params;
|
|
|
|
params.dsd_u32 = true;
|
|
|
|
|
|
|
|
PcmExport e;
|
|
|
|
e.Open(SampleFormat::DSD, 2, params);
|
|
|
|
|
|
|
|
auto dest = e.Export({src, sizeof(src)});
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sizeof(expected), dest.size);
|
|
|
|
CPPUNIT_ASSERT(memcmp(dest.data, expected, dest.size) == 0);
|
|
|
|
}
|
|
|
|
|
2014-08-12 22:05:38 +02:00
|
|
|
void
|
2014-08-31 16:12:26 +02:00
|
|
|
PcmExportTest::TestDop()
|
2014-08-12 22:05:38 +02:00
|
|
|
{
|
|
|
|
static constexpr uint8_t src[] = {
|
|
|
|
0x01, 0x23, 0x45, 0x67,
|
|
|
|
0x89, 0xab, 0xcd, 0xef,
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr uint32_t expected[] = {
|
|
|
|
0xff050145,
|
|
|
|
0xff052367,
|
|
|
|
0xfffa89cd,
|
|
|
|
0xfffaabef,
|
|
|
|
};
|
|
|
|
|
2016-02-26 18:54:13 +01:00
|
|
|
PcmExport::Params params;
|
|
|
|
params.dop = true;
|
|
|
|
|
2014-08-12 22:05:38 +02:00
|
|
|
PcmExport e;
|
2016-02-26 18:54:13 +01:00
|
|
|
e.Open(SampleFormat::DSD, 2, params);
|
2014-08-12 22:05:38 +02:00
|
|
|
|
2014-08-12 21:40:06 +02:00
|
|
|
auto dest = e.Export({src, sizeof(src)});
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sizeof(expected), dest.size);
|
|
|
|
CPPUNIT_ASSERT(memcmp(dest.data, expected, dest.size) == 0);
|
2014-08-12 22:05:38 +02:00
|
|
|
}
|
2015-10-27 00:22:22 +01:00
|
|
|
|
2016-02-27 08:02:01 +01:00
|
|
|
#endif
|
|
|
|
|
2015-10-27 00:22:22 +01:00
|
|
|
template<SampleFormat F, class Traits=SampleTraits<F>>
|
|
|
|
static void
|
|
|
|
TestAlsaChannelOrder51()
|
|
|
|
{
|
|
|
|
typedef typename Traits::value_type value_type;
|
|
|
|
|
|
|
|
static constexpr value_type src[] = {
|
|
|
|
0, 1, 2, 3, 4, 5,
|
|
|
|
6, 7, 8, 9, 10, 11,
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr value_type expected[] = {
|
|
|
|
0, 1, 4, 5, 2, 3,
|
|
|
|
6, 7, 10, 11, 8, 9,
|
|
|
|
};
|
|
|
|
|
2016-02-26 18:54:13 +01:00
|
|
|
PcmExport::Params params;
|
|
|
|
params.alsa_channel_order = true;
|
|
|
|
|
2017-01-10 23:48:26 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(params.CalcOutputSampleRate(42u), 42u);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(params.CalcInputSampleRate(42u), 42u);
|
|
|
|
|
2015-10-27 00:22:22 +01:00
|
|
|
PcmExport e;
|
2016-02-26 18:54:13 +01:00
|
|
|
e.Open(F, 6, params);
|
2015-10-27 00:22:22 +01:00
|
|
|
|
|
|
|
auto dest = e.Export({src, sizeof(src)});
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sizeof(expected), dest.size);
|
|
|
|
CPPUNIT_ASSERT(memcmp(dest.data, expected, dest.size) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<SampleFormat F, class Traits=SampleTraits<F>>
|
|
|
|
static void
|
|
|
|
TestAlsaChannelOrder71()
|
|
|
|
{
|
|
|
|
typedef typename Traits::value_type value_type;
|
|
|
|
|
|
|
|
static constexpr value_type src[] = {
|
|
|
|
0, 1, 2, 3, 4, 5, 6, 7,
|
|
|
|
8, 9, 10, 11, 12, 13, 14, 15,
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr value_type expected[] = {
|
|
|
|
0, 1, 4, 5, 2, 3, 6, 7,
|
|
|
|
8, 9, 12, 13, 10, 11, 14, 15,
|
|
|
|
};
|
|
|
|
|
2016-02-26 18:54:13 +01:00
|
|
|
PcmExport::Params params;
|
|
|
|
params.alsa_channel_order = true;
|
|
|
|
|
2017-01-10 23:48:26 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(params.CalcOutputSampleRate(42u), 42u);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(params.CalcInputSampleRate(42u), 42u);
|
|
|
|
|
2015-10-27 00:22:22 +01:00
|
|
|
PcmExport e;
|
2016-02-26 18:54:13 +01:00
|
|
|
e.Open(F, 8, params);
|
2015-10-27 00:22:22 +01:00
|
|
|
|
|
|
|
auto dest = e.Export({src, sizeof(src)});
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sizeof(expected), dest.size);
|
|
|
|
CPPUNIT_ASSERT(memcmp(dest.data, expected, dest.size) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PcmExportTest::TestAlsaChannelOrder()
|
|
|
|
{
|
|
|
|
TestAlsaChannelOrder51<SampleFormat::S16>();
|
|
|
|
TestAlsaChannelOrder71<SampleFormat::S16>();
|
|
|
|
TestAlsaChannelOrder51<SampleFormat::S32>();
|
|
|
|
TestAlsaChannelOrder71<SampleFormat::S32>();
|
|
|
|
}
|