aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/test_pcm_format.cxx56
-rw-r--r--test/test_pcm_util.hxx10
2 files changed, 31 insertions, 35 deletions
diff --git a/test/test_pcm_format.cxx b/test/test_pcm_format.cxx
index 49f4ccd4b..3b0dbb8fe 100644
--- a/test/test_pcm_format.cxx
+++ b/test/test_pcm_format.cxx
@@ -29,86 +29,72 @@
void
PcmFormatTest::TestFormat8to16()
{
- constexpr unsigned N = 256;
+ constexpr size_t N = 256;
const auto src = TestDataBuffer<int8_t, N>();
PcmBuffer buffer;
- size_t d_size;
PcmDither dither;
- auto d = pcm_convert_to_16(buffer, dither, SampleFormat::S8,
- src, sizeof(src), &d_size);
- auto d_end = pcm_end_pointer(d, d_size);
- CPPUNIT_ASSERT_EQUAL(N, unsigned(d_end - d));
+ auto d = pcm_convert_to_16(buffer, dither, SampleFormat::S8, src);
+ CPPUNIT_ASSERT_EQUAL(N, d.size);
for (size_t i = 0; i < N; ++i)
- CPPUNIT_ASSERT_EQUAL(int(src[i]), d[i] >> 8);
+ CPPUNIT_ASSERT_EQUAL(int(src[i]), d.data[i] >> 8);
}
void
PcmFormatTest::TestFormat16to24()
{
- constexpr unsigned N = 256;
+ constexpr size_t N = 256;
const auto src = TestDataBuffer<int16_t, N>();
PcmBuffer buffer;
- size_t d_size;
- auto d = pcm_convert_to_24(buffer, SampleFormat::S16,
- src, sizeof(src), &d_size);
- auto d_end = pcm_end_pointer(d, d_size);
- CPPUNIT_ASSERT_EQUAL(N, unsigned(d_end - d));
+ auto d = pcm_convert_to_24(buffer, SampleFormat::S16, src);
+ CPPUNIT_ASSERT_EQUAL(N, d.size);
for (size_t i = 0; i < N; ++i)
- CPPUNIT_ASSERT_EQUAL(int(src[i]), d[i] >> 8);
+ CPPUNIT_ASSERT_EQUAL(int(src[i]), d.data[i] >> 8);
}
void
PcmFormatTest::TestFormat16to32()
{
- constexpr unsigned N = 256;
+ constexpr size_t N = 256;
const auto src = TestDataBuffer<int16_t, N>();
PcmBuffer buffer;
- size_t d_size;
- auto d = pcm_convert_to_32(buffer, SampleFormat::S16,
- src, sizeof(src), &d_size);
- auto d_end = pcm_end_pointer(d, d_size);
- CPPUNIT_ASSERT_EQUAL(N, unsigned(d_end - d));
+ auto d = pcm_convert_to_32(buffer, SampleFormat::S16, src);
+ CPPUNIT_ASSERT_EQUAL(N, d.size);
for (size_t i = 0; i < N; ++i)
- CPPUNIT_ASSERT_EQUAL(int(src[i]), d[i] >> 16);
+ CPPUNIT_ASSERT_EQUAL(int(src[i]), d.data[i] >> 16);
}
void
PcmFormatTest::TestFormatFloat()
{
- constexpr unsigned N = 256;
+ constexpr size_t N = 256;
const auto src = TestDataBuffer<int16_t, N>();
PcmBuffer buffer1, buffer2;
- size_t f_size;
- auto f = pcm_convert_to_float(buffer1, SampleFormat::S16,
- src, sizeof(src), &f_size);
- auto f_end = pcm_end_pointer(f, f_size);
- CPPUNIT_ASSERT_EQUAL(N, unsigned(f_end - f));
+ auto f = pcm_convert_to_float(buffer1, SampleFormat::S16, src);
+ CPPUNIT_ASSERT_EQUAL(N, f.size);
- for (auto i = f; i != f_end; ++i) {
- CPPUNIT_ASSERT(*i >= -1.);
- CPPUNIT_ASSERT(*i <= 1.);
+ for (size_t i = 0; i != f.size; ++i) {
+ CPPUNIT_ASSERT(f.data[i] >= -1.);
+ CPPUNIT_ASSERT(f.data[i] <= 1.);
}
PcmDither dither;
- size_t d_size;
auto d = pcm_convert_to_16(buffer2, dither,
SampleFormat::FLOAT,
- f, f_size, &d_size);
- auto d_end = pcm_end_pointer(d, d_size);
- CPPUNIT_ASSERT_EQUAL(N, unsigned(d_end - d));
+ f.ToVoid());
+ CPPUNIT_ASSERT_EQUAL(N, d.size);
for (size_t i = 0; i < N; ++i)
- CPPUNIT_ASSERT_EQUAL(src[i], d[i]);
+ CPPUNIT_ASSERT_EQUAL(src[i], d.data[i]);
}
diff --git a/test/test_pcm_util.hxx b/test/test_pcm_util.hxx
index b378c75a7..216e360ce 100644
--- a/test/test_pcm_util.hxx
+++ b/test/test_pcm_util.hxx
@@ -17,6 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "util/ConstBuffer.hxx"
+
#include <array>
#include <random>
@@ -76,6 +78,14 @@ public:
operator typename std::array<T, N>::const_pointer() const {
return begin();
}
+
+ operator ConstBuffer<T>() const {
+ return { begin(), size() };
+ }
+
+ operator ConstBuffer<void>() const {
+ return { begin(), size() * sizeof(T) };
+ }
};
template<typename T>