1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-05 23:19:06 +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 "Prefs.h"
#include "Project.h"
#include "Resample.h"
#include "SampleFormat.h"
#include "Sequence.h"
#include "TimeTrack.h"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -74,20 +74,20 @@ const wxString Resample::GetBestMethodKey()
int Resample::GetFastMethodDefault() {return 1;}
int Resample::GetBestMethodDefault() {return 3;}
int Resample::Process(double factor,
std::pair<size_t, size_t>
Resample::Process(double factor,
float *inBuffer,
int inBufferLen,
size_t inBufferLen,
bool lastFlag,
int *inBufferUsed,
float *outBuffer,
int outBufferLen)
size_t outBufferLen)
{
size_t idone, odone;
if (mbWantConstRateResampling)
{
soxr_process((soxr_t)mHandle,
inBuffer , (size_t)(lastFlag? ~inBufferLen : inBufferLen), &idone,
outBuffer, (size_t) outBufferLen, &odone);
inBuffer , (lastFlag? ~inBufferLen : inBufferLen), &idone,
outBuffer, outBufferLen, &odone);
}
else
{
@ -95,11 +95,10 @@ int Resample::Process(double factor,
inBufferLen = lastFlag? ~inBufferLen : inBufferLen;
soxr_process((soxr_t)mHandle,
inBuffer , (size_t)inBufferLen , &idone,
outBuffer, (size_t)outBufferLen, &odone);
inBuffer , inBufferLen , &idone,
outBuffer, outBufferLen, &odone);
}
*inBufferUsed = (int)idone;
return (int)odone;
return { idone, odone };
}
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 lastFlag Flag to indicate this is the last lot of input samples and
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
the input this time, we may leave some for next time)
@param outBuffer Buffer to write output (converted) samples to.
@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,
int inBufferLen,
size_t inBufferLen,
bool lastFlag,
int *inBufferUsed,
float *outBuffer,
int outBufferLen);
size_t outBufferLen);
protected:
void SetMethod(const bool useBestMethod);

View File

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

View File

@ -1793,11 +1793,11 @@ bool WaveClip::Resample(int rate, ProgressDialog *progress)
break;
}
int inBufferUsed = 0;
outGenerated = resample.Process(factor, inBuffer, inLen, isLast,
&inBufferUsed, outBuffer, bufsize);
const auto results = resample.Process(factor, inBuffer, inLen, isLast,
outBuffer, bufsize);
outGenerated = results.second;
pos += inBufferUsed;
pos += results.first;
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
track->Get((samplePtr) inBuffer, floatSample, samplePos, blockSize);
int inUsed;
int outgen = resample.Process(mFactor,
const auto results = resample.Process(mFactor,
inBuffer,
blockSize,
((samplePos + blockSize) >= end),
&inUsed,
outBuffer,
outBufferSize);
if (outgen < 0) {
bResult = false;
break;
}
const auto outgen = results.second;
if (outgen > 0)
outputTrack->Append((samplePtr)outBuffer, floatSample,
outgen);
// Increment samplePos
samplePos += inUsed;
samplePos += results.first;
// Update the Progress meter
if (TrackProgress(mCurTrackNum, (samplePos - start) / len)) {