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.
@@ -49,12 +49,17 @@
#if USE_LIBRESAMPLE #if USE_LIBRESAMPLE
#include "libresample.h" #include "libresample.h"
ConstRateResample::ConstRateResample(const bool useBestMethod, const double dFactor) ConstRateResample::ConstRateResample(const bool useBestMethod, const double dFactor)
: Resample() : Resample()
{ {
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,
@@ -100,26 +105,27 @@
float *outBuffer, float *outBuffer,
int outBufferLen) int outBufferLen)
{ {
return resample_process(mHandle, factor, inBuffer, inBufferLen, return resample_process(mHandle, factor, inBuffer, inBufferLen,
(int)lastFlag, inBufferUsed, outBuffer, outBufferLen); (int)lastFlag, inBufferUsed, outBuffer, outBufferLen);
} }
#elif USE_LIBSAMPLERATE #elif USE_LIBSAMPLERATE
#include <samplerate.h> #include <samplerate.h>
ConstRateResample::ConstRateResample(const bool useBestMethod, const double dFactor) ConstRateResample::ConstRateResample(const bool useBestMethod, const double dFactor)
: 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;
return; return;
} }
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;
mShouldReset = false; mShouldReset = false;
@@ -174,43 +180,54 @@
} }
int ConstRateResample::Process(double factor, int ConstRateResample::Process(double factor,
float *inBuffer, float *inBuffer,
int inBufferLen, int inBufferLen,
bool lastFlag, bool lastFlag,
int *inBufferUsed, int *inBufferUsed,
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;
data.data_in = inBuffer;
data.data_out = outBuffer;
data.input_frames = inBufferLen;
data.output_frames = outBufferLen;
data.input_frames_used = 0;
data.output_frames_gen = 0;
data.end_of_input = (int)lastFlag;
data.src_ratio = factor;
int err = src_process((SRC_STATE *)mHandle, &data);
if (err) {
wxFprintf(stderr, _("Libsamplerate error: %d\n"), err);
return 0;
}
if(lastFlag) {
mShouldReset = true;
mSamplesLeft = inBufferLen - (int)data.input_frames_used;
}
*inBufferUsed = (int)data.input_frames_used;
return (int)data.output_frames_gen;
} }
SRC_DATA data;
data.data_in = inBuffer;
data.data_out = outBuffer;
data.input_frames = inBufferLen;
data.output_frames = outBufferLen;
data.input_frames_used = 0;
data.output_frames_gen = 0;
data.end_of_input = (int)lastFlag;
data.src_ratio = factor;
int err = src_process((SRC_STATE *)mHandle, &data);
if (err) {
wxFprintf(stderr, _("Libsamplerate error: %d\n"), err);
return 0;
}
*inBufferUsed = (int)data.input_frames_used;
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)
: Resample() : Resample()
{ {
@@ -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,
@@ -352,7 +361,7 @@
int outBufferLen) int outBufferLen)
{ {
return resample_process(mHandle, factor, inBuffer, inBufferLen, return resample_process(mHandle, factor, inBuffer, inBufferLen,
(int)lastFlag, inBufferUsed, outBuffer, outBufferLen); (int)lastFlag, inBufferUsed, outBuffer, outBufferLen);
} }
#elif USE_LIBSAMPLERATE #elif USE_LIBSAMPLERATE

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