1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-17 16:40:07 +02:00

Make the base class set mMethod, so descendants don't need to duplicate that code.

This commit is contained in:
v.audacity 2012-11-04 19:19:15 +00:00
parent 29768c2489
commit c889930a0c
2 changed files with 11 additions and 22 deletions

View File

@ -54,13 +54,8 @@
#include <soxr.h> #include <soxr.h>
ConstRateResample::ConstRateResample(const bool useBestMethod, const double dFactor) 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); 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); mHandle = (void *)soxr_create(1, dFactor, 1, 0, 0, &q_spec, 0);
} }
@ -120,7 +115,7 @@
#else // no const-rate resampler #else // no const-rate resampler
ConstRateResample::ConstRateResample(const bool useBestMethod, const double dFactor) ConstRateResample::ConstRateResample(const bool useBestMethod, const double dFactor)
: Resample() : Resample(useBestMethod)
{ {
} }
@ -136,13 +131,8 @@
#include "libresample.h" #include "libresample.h"
VarRateResample::VarRateResample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor) 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); mHandle = resample_open(mMethod, dMinFactor, dMaxFactor);
} }
@ -204,7 +194,7 @@
#include <samplerate.h> #include <samplerate.h>
VarRateResample::VarRateResample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor) 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)) { 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"); fprintf(stderr, "libsamplerate supports only resampling factors between 1/SRC_MAX_RATIO and SRC_MAX_RATIO.\n");
@ -213,11 +203,6 @@
return; return;
} }
if (useBestMethod)
mMethod = GetBestMethod();
else
mMethod = GetFastMethod();
int err; int err;
SRC_STATE *state = src_new(mMethod, 1, &err); SRC_STATE *state = src_new(mMethod, 1, &err);
mHandle = (void *)state; mHandle = (void *)state;
@ -306,7 +291,7 @@
#else // no var-rate resampler #else // no var-rate resampler
VarRateResample::VarRateResample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor) VarRateResample::VarRateResample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor)
: Resample() : Resample(useBestMethod)
{ {
} }

View File

@ -31,9 +31,13 @@ class Resample
/// specify the range of factors that will be used, if you plan /// specify the range of factors that will be used, if you plan
/// to vary the factor over time. Otherwise set minFactor and /// to vary the factor over time. Otherwise set minFactor and
/// maxFactor to the same value for optimized performance. /// maxFactor to the same value for optimized performance.
Resample() Resample(const bool useBestMethod)
{ {
mMethod = 0; if (useBestMethod)
mMethod = GetBestMethod();
else
mMethod = GetFastMethod();
mHandle = NULL; mHandle = NULL;
mInitial = false; mInitial = false;
}; };