From e42734c3f3f669039f5e088371ab1ef8c7674bb5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 31 Jan 2013 22:58:27 +0100 Subject: test/test_pcm: merge source buffer generator --- test/test_pcm_dither.cxx | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'test/test_pcm_dither.cxx') diff --git a/test/test_pcm_dither.cxx b/test/test_pcm_dither.cxx index 6d1ed686a..2fb976db5 100644 --- a/test/test_pcm_dither.cxx +++ b/test/test_pcm_dither.cxx @@ -18,35 +18,20 @@ */ #include "test_pcm_all.hxx" +#include "test_pcm_util.hxx" #include "PcmDither.hxx" #include -/** - * Generate a random 24 bit PCM sample. - */ -static int32_t -random24() -{ - int32_t x = g_random_int() & 0xffffff; - if (x & 0x800000) - x |= 0xff000000; - return x; -} - void test_pcm_dither_24() { - PcmDither dither; - - enum { N = 256 }; - int32_t src[N]; - for (unsigned i = 0; i < N; ++i) - src[i] = random24(); + constexpr unsigned N = 256; + const auto src = TestDataBuffer(GlibRandomInt24()); int16_t dest[N]; - - dither.Dither24To16(dest, src, src + N); + PcmDither dither; + dither.Dither24To16(dest, src.begin(), src.end()); for (unsigned i = 0; i < N; ++i) { g_assert_cmpint(dest[i], >=, (src[i] >> 8) - 8); @@ -57,16 +42,12 @@ test_pcm_dither_24() void test_pcm_dither_32() { - PcmDither dither; - - enum { N = 256 }; - int32_t src[N]; - for (unsigned i = 0; i < N; ++i) - src[i] = g_random_int(); + constexpr unsigned N = 256; + const auto src = TestDataBuffer(); int16_t dest[N]; - - dither.Dither32To16(dest, src, src + N); + PcmDither dither; + dither.Dither32To16(dest, src.begin(), src.end()); for (unsigned i = 0; i < N; ++i) { g_assert_cmpint(dest[i], >=, (src[i] >> 16) - 8); -- cgit v1.2.3