1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-26 07:13:49 +01:00

Go back to simpler architecture for Resample class, now that libsoxr is proven for variable rate resampling.

This commit is contained in:
v.audacity
2013-08-04 01:58:54 +00:00
parent 51e0391b7d
commit 030d2450a8
10 changed files with 111 additions and 498 deletions

View File

@@ -23,33 +23,26 @@
class Resample
{
public:
/// The first parameter lets you select either the best method or
/// the fast method.
//v (The particular method used was previously set by
/// SetFastMethod or SetBestMethod.)
Resample()
{
mMethod = 0;
mHandle = NULL;
};
virtual ~Resample() {};
/// Returns the name of the library used for resampling
/// (long format, may include author name and version number).
//v Currently unused.
// virtual wxString GetResamplingLibraryName() { return _("Resampling disabled."); };
/// Resamplers may have more than one method, offering a
/// tradeoff between speed and quality.
/// Audacity identifies two methods out of all of the choices:
/// a Fast method intended for real-time audio I/O, and a Best
/// method intended for mixing and exporting.
//v (These were previously saved
// in the preferences when you call Set[Best,Fast]Method.
// Now done with TieChoice() in QualityPrefs.
// Implemented in descendant classes, for class-specificity.)
//static void SetFastMethod(int index);
//static void SetBestMethod(int index);
//
/// The first parameter lets you select either the best method or
/// the fast method.
// dMinFactor and dMaxFactor specify the range of factors for variable-rate resampling.
// For constant-rate, pass the same value for both.
Resample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor);
virtual ~Resample();
static int GetNumMethods();
static wxString GetMethodName(int index);
static const wxString GetFastMethodKey();
static const wxString GetBestMethodKey();
static int GetFastMethodDefault();
static int GetBestMethodDefault();
/** @brief Main processing function. Resamples from the input buffer to the
* output buffer.
@@ -73,25 +66,21 @@ class Resample
@param outBufferLen How big outBuffer is.
@return Number of output samples created by this call
*/
virtual int Process(double WXUNUSED(factor),
virtual int Process(double factor,
float *inBuffer,
int inBufferLen,
bool WXUNUSED(lastFlag),
int * WXUNUSED(inBufferUsed),
bool lastFlag,
int *inBufferUsed,
float *outBuffer,
int outBufferLen)
int outBufferLen);
protected:
void SetMethod(const bool useBestMethod)
{
// Base class method just copies data with no change.
int i;
int len = inBufferLen;
if (len > outBufferLen)
len = outBufferLen;
for(i=0; i<len; i++)
outBuffer[i] = inBuffer[i];
return len;
if (useBestMethod)
mMethod = gPrefs->Read(GetBestMethodKey(), GetBestMethodDefault());
else
mMethod = gPrefs->Read(GetFastMethodKey(), GetFastMethodDefault());
};
protected:
@@ -100,96 +89,9 @@ class Resample
#if USE_LIBSAMPLERATE
bool mShouldReset; // whether the resampler should be reset because lastFlag has been set previously
int mSamplesLeft; // number of samples left before a reset is needed
#elif USE_LIBSOXR
bool mbWantConstRateResampling;
#endif
};
class ConstRateResample : public Resample
{
public:
ConstRateResample(const bool useBestMethod, const double dFactor);
virtual ~ConstRateResample();
// Override base class methods only if we actually have a sample rate conversion library.
#if USE_LIBRESAMPLE || USE_LIBSAMPLERATE || USE_LIBSOXR
static int GetNumMethods();
static wxString GetMethodName(int index);
static const wxString GetFastMethodKey();
static const wxString GetBestMethodKey();
static int GetFastMethodDefault();
static int GetBestMethodDefault();
virtual int Process(double factor,
float *inBuffer,
int inBufferLen,
bool lastFlag,
int *inBufferUsed,
float *outBuffer,
int outBufferLen);
#else
static int GetNumMethods() { return 1; };
static wxString GetMethodName(int WXUNUSED(index)) { return _("Resampling disabled."); };
static const wxString GetFastMethodKey() { return wxT("/Quality/DisabledConverter"); };
static const wxString GetBestMethodKey() { return wxT("/Quality/DisabledConverter"); };
static int GetFastMethodDefault() { return 0; };
static int GetBestMethodDefault() { return 0; };
#endif
protected:
void SetMethod(const bool useBestMethod)
{
if (useBestMethod)
mMethod = gPrefs->Read(GetBestMethodKey(), GetBestMethodDefault());
else
mMethod = gPrefs->Read(GetFastMethodKey(), GetFastMethodDefault());
};
};
class VarRateResample : public Resample
{
public:
// dMinFactor and dMaxFactor specify the range of factors for variable-rate resampling.
VarRateResample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor);
virtual ~VarRateResample();
// Override base class methods only if we actually have a sample rate conversion library.
#if USE_LIBRESAMPLE || USE_LIBSAMPLERATE || USE_LIBSOXR
//vvv Note that we're not actually calling any of these Get* methods
// for var-rate, as the decision was to not allow QualityPrefs for it.
// However the methods already existed for libresample and libsamplerate,
// so they're now implemented for all, in case we decide to provide prefs.
static int GetNumMethods();
static wxString GetMethodName(int index);
static const wxString GetFastMethodKey();
static const wxString GetBestMethodKey();
static int GetFastMethodDefault();
static int GetBestMethodDefault();
virtual int Process(double factor,
float *inBuffer,
int inBufferLen,
bool lastFlag,
int *inBufferUsed,
float *outBuffer,
int outBufferLen);
#else
static int GetNumMethods() { return 1; };
static wxString GetMethodName(int WXUNUSED(index)) { return _("Resampling disabled."); };
static const wxString GetFastMethodKey() { return wxT("/Quality/DisabledConverter"); };
static const wxString GetBestMethodKey() { return wxT("/Quality/DisabledConverter"); };
static int GetFastMethodDefault() { return 0; };
static int GetBestMethodDefault() { return 0; };
#endif
protected:
void SetMethod(const bool useBestMethod)
{
if (useBestMethod)
mMethod = gPrefs->Read(GetBestMethodKey(), GetBestMethodDefault());
else
mMethod = gPrefs->Read(GetFastMethodKey(), GetFastMethodDefault());
};
};
#endif // __AUDACITY_RESAMPLE_H__