From c889930a0cfa03f8757b472497a4eb166d46acb5 Mon Sep 17 00:00:00 2001 From: "v.audacity" Date: Sun, 4 Nov 2012 19:19:15 +0000 Subject: [PATCH] Make the base class set mMethod, so descendants don't need to duplicate that code. --- src/Resample.cpp | 25 +++++-------------------- src/Resample.h | 8 ++++++-- 2 files changed, 11 insertions(+), 22 deletions(-) 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; };