Audacity 3.2.0
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Resample Class Referencefinal

Interface to libsoxr. More...

#include <Resample.h>

Collaboration diagram for Resample:
[legend]

Public Member Functions

 Resample (const bool useBestMethod, const double dMinFactor, const double dMaxFactor)
 
 ~Resample ()
 
std::pair< size_t, size_t > Process (double factor, const float *inBuffer, size_t inBufferLen, bool lastFlag, float *outBuffer, size_t outBufferLen)
 Main processing function. Resamples from the input buffer to the output buffer. More...
 

Static Public Attributes

static EnumSetting< int > FastMethodSetting
 
static EnumSetting< int > BestMethodSetting
 

Protected Member Functions

void SetMethod (const bool useBestMethod)
 

Protected Attributes

int mMethod
 
soxrHandle mHandle
 
bool mbWantConstRateResampling
 

Detailed Description

Interface to libsoxr.

This class abstracts the interface to different resampling libraries:

libsoxr, written by Rob Sykes. LGPL.

Since Audacity always does resampling on mono streams that are contiguous in memory, this class doesn't support multiple channels or some of the other optional features of some of these resamplers.

Definition at line 26 of file Resample.h.

Constructor & Destructor Documentation

◆ Resample()

Resample::Resample ( const bool  useBestMethod,
const double  dMinFactor,
const double  dMaxFactor 
)

Resamplers may have more than one method, offering a tradeoff between speed and quality. Audacity identifies two methods out of all of the choices: a Fast method intended for real-time audio I/O, and a Best method intended for mixing and exporting. The first parameter lets you select either the best method or the fast method.

Definition at line 32 of file Resample.cpp.

33{
34 this->SetMethod(useBestMethod);
35 soxr_quality_spec_t q_spec;
36 if (dMinFactor == dMaxFactor)
37 {
38 mbWantConstRateResampling = true; // constant rate resampling
39 q_spec = soxr_quality_spec("\0\1\4\6"[mMethod], 0);
40 }
41 else
42 {
43 mbWantConstRateResampling = false; // variable rate resampling
44 q_spec = soxr_quality_spec(SOXR_HQ, SOXR_VR);
45 }
46 mHandle.reset(soxr_create(1, dMinFactor, 1, 0, 0, &q_spec, 0));
47}
bool mbWantConstRateResampling
Definition: Resample.h:81
void SetMethod(const bool useBestMethod)
Definition: Resample.cpp:114
soxrHandle mHandle
Definition: Resample.h:80
int mMethod
Definition: Resample.h:79

References mbWantConstRateResampling, mHandle, mMethod, and SetMethod().

Here is the call graph for this function:

◆ ~Resample()

Resample::~Resample ( )

Definition at line 49 of file Resample.cpp.

50{
51}

Member Function Documentation

◆ Process()

std::pair< size_t, size_t > Resample::Process ( double  factor,
const float *  inBuffer,
size_t  inBufferLen,
bool  lastFlag,
float *  outBuffer,
size_t  outBufferLen 
)

Main processing function. Resamples from the input buffer to the output buffer.

Reads samples from the input buffer, and writes samples to the output buffer. Stops when either is exhausted, or we reach a convenient block end, unless lastFlag is set to force emptying the input buffer. The number of input samples used is returned in inBufferUsed, and the number of output samples generated is the return value of the function. This function may do nothing if you don't pass a large enough output buffer (i.e. there is no where to put a full block of output data)

Parameters
factorThe scaling factor to resample by.
inBufferBuffer of input samples to be processed (mono)
inBufferLenLength of the input buffer, in samples.
lastFlagFlag to indicate this is the last lot of input samples and the buffer needs to be emptied out into the rate converter. (unless lastFlag is true, we don't guarantee to process all the samples in the input this time, we may leave some for next time)
outBufferBuffer to write output (converted) samples to.
outBufferLenHow big outBuffer is.
Returns
Number of input samples consumed, and number of output samples created by this call

Definition at line 88 of file Resample.cpp.

94{
95 size_t idone, odone;
97 {
98 soxr_process(mHandle.get(),
99 inBuffer , (lastFlag? ~inBufferLen : inBufferLen), &idone,
100 outBuffer, outBufferLen, &odone);
101 }
102 else
103 {
104 soxr_set_io_ratio(mHandle.get(), 1/factor, 0);
105
106 inBufferLen = lastFlag? ~inBufferLen : inBufferLen;
107 soxr_process(mHandle.get(),
108 inBuffer , inBufferLen , &idone,
109 outBuffer, outBufferLen, &odone);
110 }
111 return { idone, odone };
112}

References mbWantConstRateResampling, and mHandle.

Referenced by EffectChangeSpeed::ProcessOne(), and WaveClip::Resample().

Here is the caller graph for this function:

◆ SetMethod()

void Resample::SetMethod ( const bool  useBestMethod)
protected

Definition at line 114 of file Resample.cpp.

115{
116 if (useBestMethod)
118 else
120}
Enum ReadEnum() const
Definition: Prefs.h:534
static EnumSetting< int > FastMethodSetting
Definition: Resample.h:42
static EnumSetting< int > BestMethodSetting
Definition: Resample.h:43

References BestMethodSetting, FastMethodSetting, mMethod, and EnumSetting< Enum >::ReadEnum().

Referenced by Resample().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ BestMethodSetting

EnumSetting< int > Resample::BestMethodSetting
static
Initial value:
{
wxT("/Quality/LibsoxrHQSampleRateConverterChoice"),
3,
wxT("/Quality/LibsoxrHQSampleRateConverter")
}
wxT("CloseDown"))
static const std::initializer_list< EnumValueSymbol > methodNames
Definition: Resample.cpp:54
static auto intChoicesMethod
Definition: Resample.cpp:61

Definition at line 43 of file Resample.h.

Referenced by QualityPrefs::PopulateOrExchange(), and SetMethod().

◆ FastMethodSetting

EnumSetting< int > Resample::FastMethodSetting
static
Initial value:
{
wxT("/Quality/LibsoxrSampleRateConverterChoice"),
1,
wxT("/Quality/LibsoxrSampleRateConverter")
}

Definition at line 42 of file Resample.h.

Referenced by QualityPrefs::PopulateOrExchange(), and SetMethod().

◆ mbWantConstRateResampling

bool Resample::mbWantConstRateResampling
protected

Definition at line 81 of file Resample.h.

Referenced by Process(), and Resample().

◆ mHandle

soxrHandle Resample::mHandle
protected

Definition at line 80 of file Resample.h.

Referenced by Process(), and Resample().

◆ mMethod

int Resample::mMethod
protected

Definition at line 79 of file Resample.h.

Referenced by Resample(), and SetMethod().


The documentation for this class was generated from the following files: