diff --git a/src/Resample.cpp b/src/Resample.cpp index 93ca51b4a..66ece785e 100644 --- a/src/Resample.cpp +++ b/src/Resample.cpp @@ -54,13 +54,8 @@ #include ConstRateResample::ConstRateResample(const bool useBestMethod, const double dFactor) - : Resample() + : Resample(useBestMethod) { - if (useBestMethod) - mMethod = GetBestMethod(); - else - mMethod = GetFastMethod(); - soxr_quality_spec_t q_spec = soxr_quality_spec("\0\1\4\6"[mMethod], 0); mHandle = (void *)soxr_create(1, dFactor, 1, 0, 0, &q_spec, 0); } @@ -120,7 +115,7 @@ #else // no const-rate resampler ConstRateResample::ConstRateResample(const bool useBestMethod, const double dFactor) - : Resample() + : Resample(useBestMethod) { } @@ -136,13 +131,8 @@ #include "libresample.h" VarRateResample::VarRateResample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor) - : Resample() + : Resample(useBestMethod) { - if (useBestMethod) - mMethod = GetBestMethod(); - else - mMethod = GetFastMethod(); - mHandle = resample_open(mMethod, dMinFactor, dMaxFactor); } @@ -204,7 +194,7 @@ #include VarRateResample::VarRateResample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor) - : Resample() + : Resample(useBestMethod) { if (!src_is_valid_ratio (dMinFactor) || !src_is_valid_ratio (dMaxFactor)) { fprintf(stderr, "libsamplerate supports only resampling factors between 1/SRC_MAX_RATIO and SRC_MAX_RATIO.\n"); @@ -213,11 +203,6 @@ return; } - if (useBestMethod) - mMethod = GetBestMethod(); - else - mMethod = GetFastMethod(); - int err; SRC_STATE *state = src_new(mMethod, 1, &err); mHandle = (void *)state; @@ -306,7 +291,7 @@ #else // no var-rate resampler VarRateResample::VarRateResample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor) - : Resample() + : Resample(useBestMethod) { } diff --git a/src/Resample.h b/src/Resample.h index 54ec46461..7f7ba707b 100644 --- a/src/Resample.h +++ b/src/Resample.h @@ -31,9 +31,13 @@ class Resample /// specify the range of factors that will be used, if you plan /// to vary the factor over time. Otherwise set minFactor and /// maxFactor to the same value for optimized performance. - Resample() + Resample(const bool useBestMethod) { - mMethod = 0; + if (useBestMethod) + mMethod = GetBestMethod(); + else + mMethod = GetFastMethod(); + mHandle = NULL; mInitial = false; };