diff options
author | Sakari Bergen <sakari.bergen@beatwaves.net> | 2014-01-08 20:33:17 +0200 |
---|---|---|
committer | Sakari Bergen <sakari.bergen@beatwaves.net> | 2014-01-08 20:33:17 +0200 |
commit | 054ead24cc25945199d0d6dcb986e807ac12911d (patch) | |
tree | 46f643da4a526edbd0e498635b223ffb4dc794cb /libs | |
parent | 382eb0fc6842f202901245709534477b90bda461 (diff) |
Fix dither data width assertions and related tests
Fixes 32-bit export
This was broken from the start, and was broken in a new way in
52309c0c4fc107cdde9a99f2340fe4d8cf4ff382
Diffstat (limited to 'libs')
-rw-r--r-- | libs/audiographer/src/general/sample_format_converter.cc | 14 | ||||
-rw-r--r-- | libs/audiographer/tests/general/sample_format_converter_test.cc | 18 |
2 files changed, 20 insertions, 12 deletions
diff --git a/libs/audiographer/src/general/sample_format_converter.cc b/libs/audiographer/src/general/sample_format_converter.cc index 5fe9a1185b..aaeda09477 100644 --- a/libs/audiographer/src/general/sample_format_converter.cc +++ b/libs/audiographer/src/general/sample_format_converter.cc @@ -54,10 +54,14 @@ template <> void SampleFormatConverter<int32_t>::init (framecnt_t max_frames, int type, int data_width) { - // GDither is broken with GDither32bit if the dither depth is bigger than 24 - if(throw_level (ThrowObject) && data_width > 24) { - throw Exception (*this, "Trying to use SampleFormatConverter<int32_t> a data width > 24"); + if(throw_level (ThrowObject) && data_width > 32) { + throw Exception (*this, "Trying to use SampleFormatConverter<int32_t> with a data width > 32"); } + + // GDither is broken with GDither32bit if the dither depth is bigger than 24. + // And since floats only have 24 bits of data, we are fine with this. + data_width = std::min(data_width, 24); + init_common (max_frames); dither = gdither_new ((GDitherType) type, channels, GDither32bit, data_width); } @@ -68,7 +72,7 @@ SampleFormatConverter<int16_t>::init (framecnt_t max_frames, int type, int data_ { if (throw_level (ThrowObject) && data_width > 16) { throw Exception (*this, boost::str(boost::format - ("Data width (%1) too large for int16_t") + ("Data width (%1%) too large for int16_t") % data_width)); } init_common (max_frames); @@ -81,7 +85,7 @@ SampleFormatConverter<uint8_t>::init (framecnt_t max_frames, int type, int data_ { if (throw_level (ThrowObject) && data_width > 8) { throw Exception (*this, boost::str(boost::format - ("Data width (%1) too large for uint8_t") + ("Data width (%1%) too large for uint8_t") % data_width)); } init_common (max_frames); diff --git a/libs/audiographer/tests/general/sample_format_converter_test.cc b/libs/audiographer/tests/general/sample_format_converter_test.cc index 9239564d5b..977e2b390a 100644 --- a/libs/audiographer/tests/general/sample_format_converter_test.cc +++ b/libs/audiographer/tests/general/sample_format_converter_test.cc @@ -31,27 +31,31 @@ class SampleFormatConverterTest : public CppUnit::TestFixture void testInit() { + // Float never uses dithering and should always use full 32 bits of data boost::shared_ptr<SampleFormatConverter<float> > f_converter (new SampleFormatConverter<float>(1)); f_converter->init (frames, D_Tri, 32); // Doesn't throw CPPUNIT_ASSERT_THROW (f_converter->init (frames, D_Tri, 24), Exception); CPPUNIT_ASSERT_THROW (f_converter->init (frames, D_Tri, 48), Exception); - + + /* Test that too large data widths throw. + We are fine with unnecessarily narrow data widths */ + boost::shared_ptr<SampleFormatConverter<int32_t> > i_converter (new SampleFormatConverter<int32_t>(1)); i_converter->init (frames, D_Tri, 32); // Doesn't throw i_converter->init (frames, D_Tri, 24); // Doesn't throw - CPPUNIT_ASSERT_THROW (i_converter->init (frames, D_Tri, 8), Exception); - CPPUNIT_ASSERT_THROW (i_converter->init (frames, D_Tri, 16), Exception); + i_converter->init (frames, D_Tri, 8); // Doesn't throw + i_converter->init (frames, D_Tri, 16); // Doesn't throw CPPUNIT_ASSERT_THROW (i_converter->init (frames, D_Tri, 48), Exception); - + boost::shared_ptr<SampleFormatConverter<int16_t> > i16_converter (new SampleFormatConverter<int16_t>(1)); i16_converter->init (frames, D_Tri, 16); // Doesn't throw - CPPUNIT_ASSERT_THROW (i16_converter->init (frames, D_Tri, 8), Exception); + i16_converter->init (frames, D_Tri, 8); // Doesn't throw CPPUNIT_ASSERT_THROW (i16_converter->init (frames, D_Tri, 32), Exception); CPPUNIT_ASSERT_THROW (i16_converter->init (frames, D_Tri, 48), Exception); - + boost::shared_ptr<SampleFormatConverter<uint8_t> > ui_converter (new SampleFormatConverter<uint8_t>(1)); ui_converter->init (frames, D_Tri, 8); // Doesn't throw - CPPUNIT_ASSERT_THROW (ui_converter->init (frames, D_Tri, 4), Exception); + ui_converter->init (frames, D_Tri, 4); // Doesn't throw CPPUNIT_ASSERT_THROW (ui_converter->init (frames, D_Tri, 16), Exception); } |