1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-26 15:23:48 +01:00

Fix problems introduced in r12170.

This commit is contained in:
v.audacity
2013-01-18 00:22:01 +00:00
parent cc7e5eb313
commit 4bd37d90f7
2 changed files with 63 additions and 56 deletions

View File

@@ -12,7 +12,7 @@
\class Resample \class Resample
\brief Combined interface to libresample, libsamplerate, and libsoxr. \brief Combined interface to libresample, libsamplerate, and libsoxr.
This class abstracts the interface to three different resampling libraries: This class abstracts the interface to different resampling libraries:
libresample, written by Dominic Mazzoni based on Resample-1.7 libresample, written by Dominic Mazzoni based on Resample-1.7
by Julius Smith. LGPL. by Julius Smith. LGPL.
@@ -55,6 +55,11 @@
{ {
this->SetMethod(useBestMethod); this->SetMethod(useBestMethod);
mHandle = resample_open(mMethod, dFactor, dFactor); mHandle = resample_open(mMethod, dFactor, dFactor);
if(mHandle == NULL) {
fprintf(stderr, "libresample doesn't support factor %f.\n", dFactor);
// FIX-ME: Audacity will hang after this if branch.
return;
}
} }
ConstRateResample::~ConstRateResample() ConstRateResample::~ConstRateResample()
@@ -89,8 +94,8 @@
return wxT("/Quality/LibresampleHQSampleRateConverter"); return wxT("/Quality/LibresampleHQSampleRateConverter");
} }
int ConstRateResample::GetFastMethodDefault() {return 0;} int ConstRateResample::GetFastMethodDefault() { return 0; }
int ConstRateResample::GetBestMethodDefault() {return 1;} int ConstRateResample::GetBestMethodDefault() { return 1; }
int ConstRateResample::Process(double factor, int ConstRateResample::Process(double factor,
float *inBuffer, float *inBuffer,
@@ -112,7 +117,8 @@
: Resample() : Resample()
{ {
this->SetMethod(useBestMethod); this->SetMethod(useBestMethod);
if (!src_is_valid_ratio (dFactor) || !src_is_valid_ratio (dFactor)) { if (!src_is_valid_ratio(dFactor))
{
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");
// FIX-ME: Audacity will hang after this if branch. // FIX-ME: Audacity will hang after this if branch.
mHandle = NULL; mHandle = NULL;
@@ -181,9 +187,15 @@
float *outBuffer, float *outBuffer,
int outBufferLen) int outBufferLen)
{ {
if (mInitial) {
src_set_ratio((SRC_STATE *)mHandle, factor); src_set_ratio((SRC_STATE *)mHandle, factor);
mInitial = false;
if(mShouldReset) {
if(inBufferLen > mSamplesLeft) {
mShouldReset = false;
src_reset((SRC_STATE *)mHandle);
} else {
mSamplesLeft -= inBufferLen;
}
} }
SRC_DATA data; SRC_DATA data;
@@ -203,12 +215,17 @@
return 0; return 0;
} }
if(lastFlag) {
mShouldReset = true;
mSamplesLeft = inBufferLen - (int)data.input_frames_used;
}
*inBufferUsed = (int)data.input_frames_used; *inBufferUsed = (int)data.input_frames_used;
return (int)data.output_frames_gen; return (int)data.output_frames_gen;
} }
#elif USE_LIBSOXR #elif USE_LIBSOXR
#include <soxr.h> #include <soxr.h>
ConstRateResample::ConstRateResample(const bool useBestMethod, const double dFactor) ConstRateResample::ConstRateResample(const bool useBestMethod, const double dFactor)
@@ -283,10 +300,10 @@
#endif #endif
// variable-rate resampler(s) // variable-rate resamplers
#if USE_LIBRESAMPLE #if USE_LIBRESAMPLE
#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()
@@ -294,9 +311,8 @@
this->SetMethod(useBestMethod); this->SetMethod(useBestMethod);
mHandle = resample_open(mMethod, dMinFactor, dMaxFactor); mHandle = resample_open(mMethod, dMinFactor, dMaxFactor);
if(mHandle == NULL) { if(mHandle == NULL) {
fprintf(stderr, "libresample doesn't support range %f .. %f.\n", dMinFactor, dMaxFactor); fprintf(stderr, "libresample doesn't support range of factors %f to %f.\n", dMinFactor, dMaxFactor);
// FIX-ME: Audacity will hang after this if branch. // FIX-ME: Audacity will hang after this if branch.
mHandle = NULL;
return; return;
} }
} }
@@ -333,15 +349,8 @@
return wxT("/Quality/LibresampleHQSampleRateConverter"); return wxT("/Quality/LibresampleHQSampleRateConverter");
} }
int VarRateResample::GetFastMethodDefault() int VarRateResample::GetFastMethodDefault() { return 0; }
{ int VarRateResample::GetBestMethodDefault() { return 1; }
return 0;
}
int VarRateResample::GetBestMethodDefault()
{
return 1;
}
int VarRateResample::Process(double factor, int VarRateResample::Process(double factor,
float *inBuffer, float *inBuffer,

View File

@@ -143,8 +143,6 @@ class ConstRateResample : public Resample
else else
mMethod = gPrefs->Read(GetFastMethodKey(), GetFastMethodDefault()); mMethod = gPrefs->Read(GetFastMethodKey(), GetFastMethodDefault());
}; };
private:
bool mInitial;
}; };
class VarRateResample : public Resample class VarRateResample : public Resample