AVPKit
com::avpkit::core::IAudioResampler Class Referenceabstract

Used to resample IAudioSamples to different sample rates or number of channels. More...

#include <IAudioResampler.h>

Inheritance diagram for com::avpkit::core::IAudioResampler:
Collaboration diagram for com::avpkit::core::IAudioResampler:

Public Member Functions

virtual int getOutputChannels ()=0
 number of channels in output audio. More...
 
virtual int getOutputRate ()=0
 sample rate of output audio. More...
 
virtual int getInputChannels ()=0
 number of channels expected in input audio. More...
 
virtual int getInputRate ()=0
 sample rate expected in input audio. More...
 
virtual int resample (IAudioSamples *outputSamples, IAudioSamples *inputSamples, int32_t numSamples)=0
 Re-sample up to numSamples from inputSamples to outputSamples. More...
 
virtual IAudioSamples::Format getOutputFormat ()=0
 Get the sample format we expect to resample to. More...
 
virtual IAudioSamples::Format getInputFormat ()=0
 Get the sample format we expect to resample from. More...
 
virtual int32_t getFilterLen ()=0
 Get the length of each filter in the resampler filter bank. More...
 
virtual int32_t getLog2PhaseCount ()=0
 Get log2(number of entries in filter bank). More...
 
virtual bool isLinear ()=0
 Are we linearly interpolating between filters? More...
 
virtual double getCutoffFrequency ()=0
 What is the cuttoff frequency used? More...
 
virtual int32_t getMinimumNumSamplesRequiredInOutputSamples (IAudioSamples *inSamples)=0
 Get the minimum number of samples that must be placeable in an output set of samples in order for a resample with this resampler to succeed. More...
 
virtual int32_t getMinimumNumSamplesRequiredInOutputSamples (int32_t numSamples)=0
 Get the minimum number of samples that must be placeable in an output set of samples in order for a resample with this resampler to succeed. More...
 
- Public Member Functions inherited from com::avpkit::ferry::RefCounted
virtual int32_t acquire ()
 Internal Only. More...
 
virtual int32_t release ()
 Internal Only. More...
 
virtual RefCountedcopyReference ()
 Create a new Java object that refers to the same native object. More...
 
virtual int32_t getCurrentRefCount ()
 Return the current reference count on this object. More...
 
void setJavaAllocator (void *allocator)
 This method is public but not part of the standard API. More...
 
void * getJavaAllocator ()
 This method is public but not part of the standard API. More...
 

Static Public Member Functions

static IAudioResamplermake (int32_t outputChannels, int32_t inputChannels, int32_t outputRate, int32_t inputRate)
 Create a new IAudioResampler object. More...
 
static IAudioResamplermake (int32_t outputChannels, int32_t inputChannels, int32_t outputRate, int32_t inputRate, IAudioSamples::Format outputFmt, IAudioSamples::Format inputFmt)
 Create a new IAudioResampler object. More...
 
static IAudioResamplermake (int32_t outputChannels, int32_t inputChannels, int32_t outputRate, int32_t inputRate, IAudioSamples::Format outputFmt, IAudioSamples::Format inputFmt, int32_t filterLen, int32_t log2PhaseCount, bool isLinear, double cutoffFrequency)
 Create a new IAudioResampler object. More...
 

Additional Inherited Members

- Protected Member Functions inherited from com::avpkit::ferry::RefCounted
virtual void destroy ()
 This method is called by RefCounted objects when their Ref Count reaches zero and they are about to be destroyed.
 
- Protected Attributes inherited from com::avpkit::ferry::RefCounted
AtomicIntegermRefCount
 This is the internal reference count, represented as an AtomicInteger to make sure it is thread safe.
 
void * mAllocator
 Not part of public API.
 

Detailed Description

Used to resample IAudioSamples to different sample rates or number of channels.

Definition at line 32 of file IAudioResampler.h.

Member Function Documentation

◆ getCutoffFrequency()

virtual double com::avpkit::core::IAudioResampler::getCutoffFrequency ( )
pure virtual

What is the cuttoff frequency used?

Returns
the cuttoff frequency

Implemented in com::avpkit::core::AudioResampler.

◆ getFilterLen()

virtual int32_t com::avpkit::core::IAudioResampler::getFilterLen ( )
pure virtual

Get the length of each filter in the resampler filter bank.

Returns
the filter length

Implemented in com::avpkit::core::AudioResampler.

◆ getInputChannels()

virtual int com::avpkit::core::IAudioResampler::getInputChannels ( )
pure virtual

number of channels expected in input audio.

Returns
Number of channels we'll expect in the input samples

Implemented in com::avpkit::core::AudioResampler.

◆ getInputFormat()

virtual IAudioSamples::Format com::avpkit::core::IAudioResampler::getInputFormat ( )
pure virtual

Get the sample format we expect to resample from.

Returns
the sample format for input.

Implemented in com::avpkit::core::AudioResampler.

◆ getInputRate()

virtual int com::avpkit::core::IAudioResampler::getInputRate ( )
pure virtual

sample rate expected in input audio.

Returns
Sample rate we'll expect in the input samples

Implemented in com::avpkit::core::AudioResampler.

◆ getLog2PhaseCount()

virtual int32_t com::avpkit::core::IAudioResampler::getLog2PhaseCount ( )
pure virtual

Get log2(number of entries in filter bank).

Returns
log2(number of entries in filter bank).

Implemented in com::avpkit::core::AudioResampler.

◆ getMinimumNumSamplesRequiredInOutputSamples() [1/2]

virtual int32_t com::avpkit::core::IAudioResampler::getMinimumNumSamplesRequiredInOutputSamples ( IAudioSamples inSamples)
pure virtual

Get the minimum number of samples that must be placeable in an output set of samples in order for a resample with this resampler to succeed.

Parameters
inSamplesThe input samples that will be passed to resample.
Returns
The minimum number of samples, or < 0 on error.
Since
3.2

Implemented in com::avpkit::core::AudioResampler.

◆ getMinimumNumSamplesRequiredInOutputSamples() [2/2]

virtual int32_t com::avpkit::core::IAudioResampler::getMinimumNumSamplesRequiredInOutputSamples ( int32_t  numSamples)
pure virtual

Get the minimum number of samples that must be placeable in an output set of samples in order for a resample with this resampler to succeed.

Parameters
numSamplesThe number of input samples.
Returns
The minimum number of samples, or < 0 on error.
Since
3.2

Implemented in com::avpkit::core::AudioResampler.

◆ getOutputChannels()

virtual int com::avpkit::core::IAudioResampler::getOutputChannels ( )
pure virtual

number of channels in output audio.

Returns
Number of channels we'll resample the output to.

Implemented in com::avpkit::core::AudioResampler.

◆ getOutputFormat()

virtual IAudioSamples::Format com::avpkit::core::IAudioResampler::getOutputFormat ( )
pure virtual

Get the sample format we expect to resample to.

Returns
the sample format for output.

Implemented in com::avpkit::core::AudioResampler.

◆ getOutputRate()

virtual int com::avpkit::core::IAudioResampler::getOutputRate ( )
pure virtual

sample rate of output audio.

Returns
Sample Rate we'll resample the output to.

Implemented in com::avpkit::core::AudioResampler.

◆ isLinear()

virtual bool com::avpkit::core::IAudioResampler::isLinear ( )
pure virtual

Are we linearly interpolating between filters?

Returns
true if interpolating, false if just choosing closest.

Implemented in com::avpkit::core::AudioResampler.

Referenced by make().

◆ make() [1/3]

IAudioResampler * com::avpkit::core::IAudioResampler::make ( int32_t  outputChannels,
int32_t  inputChannels,
int32_t  outputRate,
int32_t  inputRate 
)
static

Create a new IAudioResampler object.

Creation of IAudioResampler objects is relatively expensive compared to the resample(IAudioSamples, IAudioSamples, long) method, so users are encouraged to create once and use often.

This method assumes all samples are in IAudioSamples.Format.FMT_S16 format.

Parameters
outputChannelsThe number of channels you will want in resampled audio we output.
inputChannelsThe number of channels you will pass in the source audio for resampling.
outputRateThe sample rate you will want in resampled audio we output.
inputRateThe sample rate you will pass in the source audio for resampling.
Returns
A new object, or null if we can't allocate one.

Definition at line 36 of file IAudioResampler.cpp.

38  {
39  Global::init();
40  return AudioResampler::make(outputChannels, inputChannels,
41  outputRate, inputRate);
42  }
static void init()
Internal Only.
Definition: Global.cpp:157

References com::avpkit::core::Global::init().

◆ make() [2/3]

IAudioResampler * com::avpkit::core::IAudioResampler::make ( int32_t  outputChannels,
int32_t  inputChannels,
int32_t  outputRate,
int32_t  inputRate,
IAudioSamples::Format  outputFmt,
IAudioSamples::Format  inputFmt 
)
static

Create a new IAudioResampler object.

Creation of IAudioResampler objects is relatively expensive compared to the resample(IAudioSamples, IAudioSamples, long) method, so users are encouraged to create once and use often.

"Sensible" defaults are passed in for filter length and other parameters.

Parameters
outputChannelsThe number of channels you will want in resampled audio we output.
inputChannelsThe number of channels you will pass in the source audio for resampling.
outputRateThe sample rate you will want in resampled audio we output.
inputRateThe sample rate you will pass in the source audio for resampling.
outputFmtThe format of the output samples.
inputFmtThe format of the input samples.
Returns
A new object, or null if we can't allocate one.

Definition at line 45 of file IAudioResampler.cpp.

48  {
49  Global::init();
50  return AudioResampler::make(outputChannels, inputChannels,
51  outputRate, inputRate,
52  outputFmt, inputFmt);
53  }

References com::avpkit::core::Global::init().

◆ make() [3/3]

IAudioResampler * com::avpkit::core::IAudioResampler::make ( int32_t  outputChannels,
int32_t  inputChannels,
int32_t  outputRate,
int32_t  inputRate,
IAudioSamples::Format  outputFmt,
IAudioSamples::Format  inputFmt,
int32_t  filterLen,
int32_t  log2PhaseCount,
bool  isLinear,
double  cutoffFrequency 
)
static

Create a new IAudioResampler object.

Creation of IAudioResampler objects is relatively expensive compared to the resample(IAudioSamples, IAudioSamples, long) method, so users are encouraged to create once and use often.

Parameters
outputChannelsThe number of channels you will want in resampled audio we output.
inputChannelsThe number of channels you will pass in the source audio for resampling.
outputRateThe sample rate you will want in resampled audio we output.
inputRateThe sample rate you will pass in the source audio for resampling.
outputFmtThe format of the output samples.
inputFmtThe format of the input samples.
filterLenThe length of each filter in the filterbank, relative to the cutoff frequency.
log2PhaseCountlog2 of the number of entries in the polyphase filterbank
isLinearIf true, the used filter will be linearly interpolated between the 2 closest filters. if false, the closest will be used.
cutoffFrequencyCutoff frequency. 1.0 is 1/2 the output sampling rate.
Returns
A new object, or null if we can't allocate one.

Definition at line 57 of file IAudioResampler.cpp.

62  {
63  Global::init();
64  return AudioResampler::make(outputChannels, inputChannels,
65  outputRate, inputRate,
66  outputFmt, inputFmt,
67  filterLen, log2PhaseCount,
68  isLinear, cutoff);
69  }
virtual bool isLinear()=0
Are we linearly interpolating between filters?

References com::avpkit::core::Global::init(), and isLinear().

◆ resample()

virtual int com::avpkit::core::IAudioResampler::resample ( IAudioSamples outputSamples,
IAudioSamples inputSamples,
int32_t  numSamples 
)
pure virtual

Re-sample up to numSamples from inputSamples to outputSamples.

This function re-samples the audio in inputSamples to have the same number of channels, and the same sample rate, as this IAudioResampler was initialized with.

Caller is responsible for making sure that the IAudioSamples object passed in has enough space. This object requires space for an additional 16-samples * output-channels per IAudioSamples passed in.

If the

outputSamples

is not large enough to fit the required resamples, then the IAudioResampler will attempt to allocate a new output buffer and override the buffer set on

outputSamples

. To ensure you have enough space in your output buffer, use the getMinimumNumSamplesRequiredInOutputSamples(int) method.

Parameters
outputSamples[out] The sample buffer we output to.
inputSamples[in] The samples we're going to re-sample.
numSamples[in] The number of samples from inputSamples to use. if 0, this defaults to inputSamples.getNumSamples().
Returns
Number of samples written to outputSamples, or <0 on error.

Implemented in com::avpkit::core::AudioResampler.


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