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

Rewrite Resample::Process to take and return size_t values

This commit is contained in:
Paul Licameli 2016-09-05 13:44:23 -04:00
parent b093a8e406
commit c8e7372886
11 changed files with 31 additions and 45 deletions

View File

@ -58,7 +58,6 @@
#include "NoteTrack.h" #include "NoteTrack.h"
#include "Prefs.h" #include "Prefs.h"
#include "Project.h" #include "Project.h"
#include "Resample.h"
#include "SampleFormat.h" #include "SampleFormat.h"
#include "Sequence.h" #include "Sequence.h"
#include "TimeTrack.h" #include "TimeTrack.h"

View File

@ -3657,7 +3657,7 @@ void AudioIO::FillBuffers()
} }
else else
{ {
int size = lrint(avail * mFactor); size_t size = lrint(avail * mFactor);
SampleBuffer temp1(avail, floatSample); SampleBuffer temp1(avail, floatSample);
SampleBuffer temp2(size, floatSample); SampleBuffer temp2(size, floatSample);
mCaptureBuffers[i]->Get(temp1.ptr(), floatSample, avail); mCaptureBuffers[i]->Get(temp1.ptr(), floatSample, avail);
@ -3665,8 +3665,10 @@ void AudioIO::FillBuffers()
* must flush any samples left in the rate conversion buffer * must flush any samples left in the rate conversion buffer
* so that they get recorded * so that they get recorded
*/ */
size = mResample[i]->Process(mFactor, (float *)temp1.ptr(), avail, !IsStreamActive(), const auto results =
&size, (float *)temp2.ptr(), size); mResample[i]->Process(mFactor, (float *)temp1.ptr(), avail,
!IsStreamActive(), (float *)temp2.ptr(), size);
size = results.second;
mCaptureTracks[i]-> Append(temp2.ptr(), floatSample, size, 1, mCaptureTracks[i]-> Append(temp2.ptr(), floatSample, size, 1,
&appendLog); &appendLog);
} }

View File

@ -15,7 +15,6 @@ been abandoned.
#include "CrossFade.h" #include "CrossFade.h"
#include "SampleFormat.h" #include "SampleFormat.h"
#include "Resample.h"
#include "WaveClip.h" #include "WaveClip.h"
#include <iostream> #include <iostream>

View File

@ -16,7 +16,6 @@
/// to produce the desired crossfading /// to produce the desired crossfading
#include "SampleFormat.h" #include "SampleFormat.h"
#include "Resample.h"
#include "WaveClip.h" #include "WaveClip.h"

View File

@ -91,7 +91,6 @@ simplifies construction of menu items.
#include "Screenshot.h" #include "Screenshot.h"
#include "ondemand/ODManager.h" #include "ondemand/ODManager.h"
#include "Resample.h"
#include "BatchProcessDialog.h" #include "BatchProcessDialog.h"
#include "BatchCommands.h" #include "BatchCommands.h"
#include "prefs/BatchPrefs.h" #include "prefs/BatchPrefs.h"

View File

@ -508,23 +508,18 @@ sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrackCache &cache,
(t, t + (double)thisProcessLen / trackRate); (t, t + (double)thisProcessLen / trackRate);
} }
int input_used; auto results = pResample->Process(factor,
int outgen = pResample->Process(factor,
&queue[*queueStart], &queue[*queueStart],
thisProcessLen, thisProcessLen,
last, last,
&input_used,
&mFloatBuffer[out], &mFloatBuffer[out],
mMaxOut - out); mMaxOut - out);
if (outgen < 0) { const auto input_used = results.first;
return 0;
}
*queueStart += input_used; *queueStart += input_used;
*queueLen -= input_used; *queueLen -= input_used;
out += outgen; out += results.second;
t += ((backwards ? -input_used : input_used) / trackRate); t += (input_used / trackRate) * (backwards ? -1 : 1);
if (last) { if (last) {
break; break;

View File

@ -74,20 +74,20 @@ const wxString Resample::GetBestMethodKey()
int Resample::GetFastMethodDefault() {return 1;} int Resample::GetFastMethodDefault() {return 1;}
int Resample::GetBestMethodDefault() {return 3;} int Resample::GetBestMethodDefault() {return 3;}
int Resample::Process(double factor, std::pair<size_t, size_t>
Resample::Process(double factor,
float *inBuffer, float *inBuffer,
int inBufferLen, size_t inBufferLen,
bool lastFlag, bool lastFlag,
int *inBufferUsed,
float *outBuffer, float *outBuffer,
int outBufferLen) size_t outBufferLen)
{ {
size_t idone, odone; size_t idone, odone;
if (mbWantConstRateResampling) if (mbWantConstRateResampling)
{ {
soxr_process((soxr_t)mHandle, soxr_process((soxr_t)mHandle,
inBuffer , (size_t)(lastFlag? ~inBufferLen : inBufferLen), &idone, inBuffer , (lastFlag? ~inBufferLen : inBufferLen), &idone,
outBuffer, (size_t) outBufferLen, &odone); outBuffer, outBufferLen, &odone);
} }
else else
{ {
@ -95,11 +95,10 @@ int Resample::Process(double factor,
inBufferLen = lastFlag? ~inBufferLen : inBufferLen; inBufferLen = lastFlag? ~inBufferLen : inBufferLen;
soxr_process((soxr_t)mHandle, soxr_process((soxr_t)mHandle,
inBuffer , (size_t)inBufferLen , &idone, inBuffer , inBufferLen , &idone,
outBuffer, (size_t)outBufferLen, &odone); outBuffer, outBufferLen, &odone);
} }
*inBufferUsed = (int)idone; return { idone, odone };
return (int)odone;
} }
void Resample::SetMethod(const bool useBestMethod) void Resample::SetMethod(const bool useBestMethod)

View File

@ -58,20 +58,20 @@ class Resample final
@param inBufferLen Length of the input buffer, in samples. @param inBufferLen Length of the input buffer, in samples.
@param lastFlag Flag to indicate this is the last lot of input samples and @param lastFlag Flag to indicate this is the last lot of input samples and
the buffer needs to be emptied out into the rate converter. the buffer needs to be emptied out into the rate converter.
@param inBufferUsed Number of samples from inBuffer that have been used
(unless lastFlag is true, we don't garuntee to process all the samples in (unless lastFlag is true, we don't garuntee to process all the samples in
the input this time, we may leave some for next time) the input this time, we may leave some for next time)
@param outBuffer Buffer to write output (converted) samples to. @param outBuffer Buffer to write output (converted) samples to.
@param outBufferLen How big outBuffer is. @param outBufferLen How big outBuffer is.
@return Number of output samples created by this call @return Number of input samples consumed, and number of output samples
created by this call
*/ */
int Process(double factor, std::pair<size_t, size_t>
Process(double factor,
float *inBuffer, float *inBuffer,
int inBufferLen, size_t inBufferLen,
bool lastFlag, bool lastFlag,
int *inBufferUsed,
float *outBuffer, float *outBuffer,
int outBufferLen); size_t outBufferLen);
protected: protected:
void SetMethod(const bool useBestMethod); void SetMethod(const bool useBestMethod);

View File

@ -22,7 +22,6 @@
#include "Envelope.h" #include "Envelope.h"
#include "Prefs.h" #include "Prefs.h"
#include "Internat.h" #include "Internat.h"
#include "Resample.h"
#include "ViewInfo.h" #include "ViewInfo.h"
//TODO-MB: are these sensible values? //TODO-MB: are these sensible values?

View File

@ -1793,11 +1793,11 @@ bool WaveClip::Resample(int rate, ProgressDialog *progress)
break; break;
} }
int inBufferUsed = 0; const auto results = resample.Process(factor, inBuffer, inLen, isLast,
outGenerated = resample.Process(factor, inBuffer, inLen, isLast, outBuffer, bufsize);
&inBufferUsed, outBuffer, bufsize); outGenerated = results.second;
pos += inBufferUsed; pos += results.first;
if (outGenerated < 0) if (outGenerated < 0)
{ {

View File

@ -510,25 +510,20 @@ bool EffectChangeSpeed::ProcessOne(WaveTrack * track,
//Get the samples from the track and put them in the buffer //Get the samples from the track and put them in the buffer
track->Get((samplePtr) inBuffer, floatSample, samplePos, blockSize); track->Get((samplePtr) inBuffer, floatSample, samplePos, blockSize);
int inUsed; const auto results = resample.Process(mFactor,
int outgen = resample.Process(mFactor,
inBuffer, inBuffer,
blockSize, blockSize,
((samplePos + blockSize) >= end), ((samplePos + blockSize) >= end),
&inUsed,
outBuffer, outBuffer,
outBufferSize); outBufferSize);
if (outgen < 0) { const auto outgen = results.second;
bResult = false;
break;
}
if (outgen > 0) if (outgen > 0)
outputTrack->Append((samplePtr)outBuffer, floatSample, outputTrack->Append((samplePtr)outBuffer, floatSample,
outgen); outgen);
// Increment samplePos // Increment samplePos
samplePos += inUsed; samplePos += results.first;
// Update the Progress meter // Update the Progress meter
if (TrackProgress(mCurTrackNum, (samplePos - start) / len)) { if (TrackProgress(mCurTrackNum, (samplePos - start) / len)) {