From 52309c0c4fc107cdde9a99f2340fe4d8cf4ff382 Mon Sep 17 00:00:00 2001 From: Sakari Bergen Date: Sat, 23 Nov 2013 18:42:14 +0200 Subject: [PATCH] Fix invalid assertions in AudioGrapher SampleFormatConverter This fixes an export crash with e.g. 8-bit export --- .../src/general/sample_format_converter.cc | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/libs/audiographer/src/general/sample_format_converter.cc b/libs/audiographer/src/general/sample_format_converter.cc index ea70dc6094..5fe9a1185b 100644 --- a/libs/audiographer/src/general/sample_format_converter.cc +++ b/libs/audiographer/src/general/sample_format_converter.cc @@ -52,25 +52,24 @@ SampleFormatConverter::init (framecnt_t max_frames, int /* type */, int d template <> void -SampleFormatConverter::init (framecnt_t max_frames, int /*type*/, int data_width) +SampleFormatConverter::init (framecnt_t max_frames, int type, int data_width) { - if(throw_level (ThrowObject) && data_width < 24) { - throw Exception (*this, "Trying to use SampleFormatConverter for data widths < 24"); + // 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 a data width > 24"); } - init_common (max_frames); - - // GDither is broken with GDither32bit if the dither depth - // is bigger than 24, so lets just use that... - dither = gdither_new (GDitherNone, channels, GDither32bit, 24); + dither = gdither_new ((GDitherType) type, channels, GDither32bit, data_width); } template <> void SampleFormatConverter::init (framecnt_t max_frames, int type, int data_width) { - if (throw_level (ThrowObject) && data_width != 16) { - throw Exception (*this, "Unsupported data width"); + if (throw_level (ThrowObject) && data_width > 16) { + throw Exception (*this, boost::str(boost::format + ("Data width (%1) too large for int16_t") + % data_width)); } init_common (max_frames); dither = gdither_new ((GDitherType) type, channels, GDither16bit, data_width); @@ -80,8 +79,10 @@ template <> void SampleFormatConverter::init (framecnt_t max_frames, int type, int data_width) { - if (throw_level (ThrowObject) && data_width != 8) { - throw Exception (*this, "Unsupported data width"); + if (throw_level (ThrowObject) && data_width > 8) { + throw Exception (*this, boost::str(boost::format + ("Data width (%1) too large for uint8_t") + % data_width)); } init_common (max_frames); dither = gdither_new ((GDitherType) type, channels, GDither8bit, data_width);