diff options
author | Max Kellermann <max@musicpd.org> | 2018-10-29 22:41:48 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-10-29 23:06:40 +0100 |
commit | c92f0a133633a294c70de558abd03faffbb908fd (patch) | |
tree | 782fa1869fdfe0581a6998f3f9c9041ddf89f293 /test | |
parent | 8463441afed54f7712f7071d5eecc1bf2e6fac9a (diff) |
test/PcmFormat: add Float/32 bit test
Diffstat (limited to 'test')
-rw-r--r-- | test/test_pcm_format.cxx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/test_pcm_format.cxx b/test/test_pcm_format.cxx index d4adbd634..76dd8827e 100644 --- a/test/test_pcm_format.cxx +++ b/test/test_pcm_format.cxx @@ -115,3 +115,49 @@ TEST(PcmTest, FormatFloat16) for (size_t i = 4; i < N; ++i) EXPECT_EQ(src[i], d[i]); } + +TEST(PcmTest, FormatFloat32) +{ + constexpr size_t N = 509; + const auto src = TestDataBuffer<int32_t, N>(); + + PcmBuffer buffer1, buffer2; + + auto f = pcm_convert_to_float(buffer1, SampleFormat::S32, src); + EXPECT_EQ(N, f.size); + + for (size_t i = 0; i != f.size; ++i) { + EXPECT_GE(f[i], -1.); + EXPECT_LE(f[i], 1.); + } + + auto d = pcm_convert_to_32(buffer2, + SampleFormat::FLOAT, + f.ToVoid()); + EXPECT_EQ(N, d.size); + + constexpr int error = 64; + + for (size_t i = 0; i < N; ++i) + EXPECT_NEAR(src[i], d[i], error); + + /* check if clamping works */ + float *writable = const_cast<float *>(f.data); + *writable++ = 1.01; + *writable++ = 10; + *writable++ = -1.01; + *writable++ = -10; + + d = pcm_convert_to_32(buffer2, + SampleFormat::FLOAT, + f.ToVoid()); + EXPECT_EQ(N, d.size); + + EXPECT_EQ(2147483647, int(d[0])); + EXPECT_EQ(2147483647, int(d[1])); + EXPECT_EQ(-2147483648, int(d[2])); + EXPECT_EQ(-2147483648, int(d[3])); + + for (size_t i = 4; i < N; ++i) + EXPECT_NEAR(src[i], d[i], error); +} |