resampler : minor fixes

This commit is contained in:
Georgi Gerganov
2021-02-21 00:40:11 +02:00
parent 62b71c3322
commit 5b9c561579
2 changed files with 9 additions and 10 deletions

View File

@@ -9,16 +9,15 @@ double linear_interp(double first_number, double second_number, double fraction)
}
}
Resampler::Resampler() {
make_sinc();
}
int Resampler::resample(
float factor,
int nSamples,
const float * samplesInp,
float * samplesOut) {
if (factor != m_lastFactor) {
make_sinc();
m_lastFactor = factor;
}
int idxInp = 0;
int idxOut = 0;
int notDone = 1;
@@ -31,8 +30,8 @@ int Resampler::resample(
double one_over_factor = 1.0;
while (notDone) {
double temp1 = 0.0;
long left_limit = time_now - kWidth + 1; /* leftmost neighboring sample used for interp.*/
long right_limit = time_now + kWidth; /* rightmost leftmost neighboring sample used for interp.*/
long left_limit = time_now - kWidth + 1; /* leftmost neighboring sample used for interp.*/
long right_limit = time_now + kWidth; /* rightmost leftmost neighboring sample used for interp.*/
if (left_limit<0) left_limit = 0;
if (right_limit>num_samples) right_limit = num_samples;
if (factor<1.0) {
@@ -57,7 +56,7 @@ int Resampler::resample(
time_now += factor;
last_time = int_time;
int_time = time_now;
while(last_time<int_time) {
while (last_time<int_time) {
if (++idxInp == nSamples) {
notDone = 0;
} else {

View File

@@ -2,6 +2,8 @@
class Resampler {
public:
Resampler();
int resample(
float factor,
int nSamples,
@@ -28,6 +30,4 @@ private:
float m_sincTable[kWidth*kSamplesPerZeroCrossing] = { 0.0 };
float m_delayBuffer[3*kWidth] = { 0 };
float m_lastFactor = -1.0f;
};