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

Fix to build on Linux, and error in destructor.

This commit is contained in:
v.audacity 2012-11-03 22:51:50 +00:00
parent 5460b5c668
commit 88d2c85c15
2 changed files with 193 additions and 194 deletions

View File

@ -35,8 +35,6 @@
#include "Resample.h"
#include <wx/intl.h>
//v Currently unused.
//void Resample::SetFastMethod(int index)
//{
@ -64,9 +62,8 @@
ConstRateResample::~ConstRateResample()
{
delete mHandle;
mHandle = NULL;
soxr_delete((soxr_t)mHandle);
mHandle = NULL;
}
//v Currently unused.
@ -128,62 +125,13 @@
#endif
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// variable-rate resampler(s)
#if USE_LIBRESAMPLE
#include "libresample.h"
bool Resample::ResamplingEnabled()
{
return true;
}
//v Currently unused.
//wxString Resample::GetResamplingLibraryName()
//{
// return _("Libresample by Dominic Mazzoni and Julius Smith");
//}
int Resample::GetNumMethods()
{
return 2;
}
wxString Resample::GetMethodName(int index)
{
if (index == 1)
return _("High-quality Sinc Interpolation");
return _("Fast Sinc Interpolation");
}
const wxString Resample::GetFastMethodKey()
{
return wxT("/Quality/LibresampleSampleRateConverter");
}
const wxString Resample::GetBestMethodKey()
{
return wxT("/Quality/LibresampleHQSampleRateConverter");
}
int Resample::GetFastMethodDefault()
{
return 0;
}
int Resample::GetBestMethodDefault()
{
return 1;
}
Resample::Resample(bool useBestMethod, double minFactor, double maxFactor)
VarRateResample::VarRateResample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor)
{
if (useBestMethod)
mMethod = GetBestMethod();
@ -193,12 +141,48 @@ Resample::Resample(bool useBestMethod, double minFactor, double maxFactor)
mHandle = resample_open(mMethod, minFactor, maxFactor);
}
bool Resample::Ok()
VarRateResample::~VarRateResample()
{
return (mHandle != NULL);
resample_close(mHandle);
}
int Resample::Process(double factor,
//v Currently unused.
//wxString VarRateResample::GetResamplingLibraryName()
//{
// return _("Libresample by Dominic Mazzoni and Julius Smith");
//}
int VarRateResample::GetNumMethods() { return 2; }
wxString VarRateResample::GetMethodName(int index)
{
if (index == 1)
return _("High-quality Sinc Interpolation");
return _("Fast Sinc Interpolation");
}
const wxString VarRateResample::GetFastMethodKey()
{
return wxT("/Quality/LibresampleSampleRateConverter");
}
const wxString VarRateResample::GetBestMethodKey()
{
return wxT("/Quality/LibresampleHQSampleRateConverter");
}
int VarRateResample::GetFastMethodDefault()
{
return 0;
}
int VarRateResample::GetBestMethodDefault()
{
return 1;
}
int VarRateResample::Process(double factor,
float *inBuffer,
int inBufferLen,
bool lastFlag,
@ -210,70 +194,13 @@ int Resample::Process(double factor,
(int)lastFlag, inBufferUsed, outBuffer, outBufferLen);
}
Resample::~Resample()
{
resample_close(mHandle);
}
#elif USE_LIBSAMPLERATE
#include <samplerate.h>
bool Resample::ResamplingEnabled()
VarRateResample::VarRateResample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor)
{
return true;
}
//v Currently unused.
//wxString Resample::GetResamplingLibraryName()
//{
//#ifdef USE_LIBSAMPLERATE
// return _("Libsamplerate by Erik de Castro Lopo");
//#elif USE_LIBSOXR
// return _("Libsoxr by Rob Sykes");
//#else
// return _("Unknown");
//#endif
//}
int Resample::GetNumMethods()
{
int i = 0;
while(src_get_name(i))
i++;
return i;
}
wxString Resample::GetMethodName(int index)
{
return wxString(wxString::FromAscii(src_get_name(index)));
}
const wxString Resample::GetFastMethodKey()
{
return wxT("/Quality/SampleRateConverter");
}
const wxString Resample::GetBestMethodKey()
{
return wxT("/Quality/HQSampleRateConverter");
}
int Resample::GetFastMethodDefault()
{
return SRC_SINC_FASTEST;
}
int Resample::GetBestMethodDefault()
{
return SRC_SINC_BEST_QUALITY;
}
Resample::Resample(bool useBestMethod, double minFactor, double maxFactor)
{
if (!src_is_valid_ratio (minFactor) || !src_is_valid_ratio (maxFactor)) {
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");
// FIX-ME: Audacity will hang after this if branch.
mHandle = NULL;
@ -291,12 +218,53 @@ Resample::Resample(bool useBestMethod, double minFactor, double maxFactor)
mInitial = true;
}
bool Resample::Ok()
VarRateResample::~VarRateResample()
{
return (mHandle != NULL);
src_delete((SRC_STATE *)mHandle);
}
int Resample::Process(double factor,
//v Currently unused.
//wxString Resample::GetResamplingLibraryName()
//{
// return _("Libsamplerate by Erik de Castro Lopo");
//}
int VarRateResample::GetNumMethods()
{
int i = 0;
while(src_get_name(i))
i++;
return i;
}
wxString VarRateResample::GetMethodName(int index)
{
return wxString(wxString::FromAscii(src_get_name(index)));
}
const wxString VarRateResample::GetFastMethodKey()
{
return wxT("/Quality/SampleRateConverter");
}
const wxString VarRateResample::GetBestMethodKey()
{
return wxT("/Quality/HQSampleRateConverter");
}
int VarRateResample::GetFastMethodDefault()
{
return SRC_SINC_FASTEST;
}
int VarRateResample::GetBestMethodDefault()
{
return SRC_SINC_BEST_QUALITY;
}
int VarRateResample::Process(double factor,
float *inBuffer,
int inBufferLen,
bool lastFlag,
@ -330,9 +298,13 @@ int Resample::Process(double factor,
return (int)data.output_frames_gen;
}
Resample::~Resample()
#else // no var-rate resampler
VarRateResample::VarRateResample(const bool useBestMethod, const double dFactor)
: Resample()
{
src_delete((SRC_STATE *)mHandle);
}
VarRateResample::~VarRateResample()
{
}
#endif

View File

@ -14,6 +14,7 @@
#include "Audacity.h"
#include <wx/intl.h>
#include <wx/string.h>
#include "Prefs.h"
@ -140,4 +141,30 @@ class ConstRateResample : public Resample
#endif
};
class VarRateResample : public Resample
{
public:
VarRateResample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor);
virtual ~VarRateResample();
// Override base class methods only if we actually have a var-rate library.
#if USE_LIBRESAMPLE || USE_LIBSAMPLERATE
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);
#endif
};
#endif // __AUDACITY_RESAMPLE_H__