More details when the SRC fails.
[dcpomatic.git] / src / lib / resampler.cc
index b12b549bf1f4618ccaacfdc4c401f7fd54adfd36..43dc501625800a66a6e0ad39ea44aedf72abda88 100644 (file)
 #include "compose.hpp"
 #include "dcpomatic_assert.h"
 #include <samplerate.h>
+#include <iostream>
 
 #include "i18n.h"
 
 using std::cout;
 using std::pair;
 using std::make_pair;
+using std::runtime_error;
 using boost::shared_ptr;
 
-Resampler::Resampler (int in, int out, int channels)
+/** @param in Input sampling rate (Hz)
+ *  @param out Output sampling rate (Hz)
+ *  @param channels Number of channels.
+ *  @param fast true to be fast rather than good.
+ */
+Resampler::Resampler (int in, int out, int channels, bool fast)
        : _in_rate (in)
        , _out_rate (out)
        , _channels (channels)
 {
        int error;
-       _src = src_new (SRC_SINC_BEST_QUALITY, _channels, &error);
+       _src = src_new (fast ? SRC_LINEAR : SRC_SINC_BEST_QUALITY, _channels, &error);
        if (!_src) {
-               throw StringError (String::compose (N_("could not create sample-rate converter (%1)"), error));
+               throw runtime_error (String::compose (N_("could not create sample-rate converter (%1)"), error));
        }
 }
 
@@ -86,7 +93,15 @@ Resampler::run (shared_ptr<const AudioBuffers> in)
                if (r) {
                        delete[] data.data_in;
                        delete[] data.data_out;
-                       throw EncodeError (String::compose (N_("could not run sample-rate converter (%1)"), src_strerror (r)));
+                       throw EncodeError (
+                               String::compose (
+                                       N_("could not run sample-rate converter (%1) [processing %2 to %3, %4 channels]"),
+                                       src_strerror (r),
+                                       in_frames,
+                                       max_resampled_frames,
+                                       _channels
+                                       )
+                               );
                }
 
                if (data.output_frames_gen == 0) {