pcm/PcmPack: add pcm_unpack_24be()
This commit is contained in:
parent
b1512201ab
commit
803b73a34b
|
@ -94,3 +94,12 @@ pcm_unpack_24(int32_t *dest, const uint8_t *src, const uint8_t *src_end)
|
|||
src += 3;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pcm_unpack_24be(int32_t *dest, const uint8_t *src, const uint8_t *src_end)
|
||||
{
|
||||
while (src < src_end) {
|
||||
*dest++ = ReadS24BE(src);
|
||||
src += 3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,4 +49,11 @@ pcm_pack_24(uint8_t *dest, const int32_t *src, const int32_t *src_end);
|
|||
void
|
||||
pcm_unpack_24(int32_t *dest, const uint8_t *src, const uint8_t *src_end);
|
||||
|
||||
/**
|
||||
* Like pcm_unpack_24(), but assume the source byte order is
|
||||
* big-endian. The destination byte order ia always native.
|
||||
*/
|
||||
void
|
||||
pcm_unpack_24be(int32_t *dest, const uint8_t *src, const uint8_t *src_end);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,11 +40,13 @@ class PcmPackTest : public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST_SUITE(PcmPackTest);
|
||||
CPPUNIT_TEST(TestPack24);
|
||||
CPPUNIT_TEST(TestUnpack24);
|
||||
CPPUNIT_TEST(TestUnpack24BE);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void TestPack24();
|
||||
void TestUnpack24();
|
||||
void TestUnpack24BE();
|
||||
};
|
||||
|
||||
class PcmChannelsTest : public CppUnit::TestFixture {
|
||||
|
|
|
@ -70,3 +70,23 @@ PcmPackTest::TestUnpack24()
|
|||
CPPUNIT_ASSERT_EQUAL(s, dest[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PcmPackTest::TestUnpack24BE()
|
||||
{
|
||||
constexpr unsigned N = 509;
|
||||
const auto src = TestDataBuffer<uint8_t, N * 3>();
|
||||
|
||||
int32_t dest[N];
|
||||
pcm_unpack_24be(dest, src.begin(), src.end());
|
||||
|
||||
for (unsigned i = 0; i < N; ++i) {
|
||||
int32_t s;
|
||||
s = (src[i * 3] << 16) | (src[i * 3 + 1] << 8)
|
||||
| src[i * 3 + 2];
|
||||
if (s & 0x800000)
|
||||
s |= 0xff000000;
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(s, dest[i]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue