Class: Resampler

Overview

Linear or 6-point resampler, audio reverser and 16-bit to 32-bit audio converter.

It doesn't allocate any internal buffers and needs just a few bytes of memory.

How to implement

// Constructor. Has no additional parameters.
let resampler = new Superpowered.Resampler();
// The rate of the resampler. Default: 1. If rate = 1, process() is "transparent" without any effect on audio quality.
resampler.rate = 1.1;
// Reset all internals. Doesn't change rate. Has no return value.
resampler.reset();
// Processes the audio.
let outputNumberOfFrames = resampler.process(
input, // Pointer to short integer numbers, 16-bit stereo interleaved input. Should be numberOfFrames * 2 + 64 big.
output, // Pointer to floating point numbers, 32-bit stereo interleaved output. Should be big enough to store the expected number of output frames and some more.
128, // Number of frames to process.
false, // If true, the output will be backwards (reverse playback).
false, // Enables more sophisticated processing to reduce interpolation noise. Good for scratching for example, but not recommended for continous music playback above 0.5 rate.
0 // "rateAdd": Changes rate smoothly during process(). Useful for scratching or super smooth rate changes. After process() rate will be changed, but may or may not be precisely equal to the desired target value.
);
// Processes the audio.
let outputNumberOfFrames = resampler.process16(
input, // Pointer to short integer numbers, 16-bit stereo interleaved input. Should be numberOfFrames * 2 + 64 big.
temp, // Pointer to floating point numbers. Should be numberOfFrames * 2 + 64 big.
output, // Pointer to short integer numbers, 16-bit stereo interleaved output. Should be big enough to store the expected number of output frames and some more.
128, // Number of frames to process.
false, // If true, the output will be backwards (reverse playback).
false, // Enables more sophisticated processing to reduce interpolation noise. Good for scratching for example, but not recommended for continous music playback above 0.5 rate.
0 // "rateAdd": Changes rate smoothly during process(). Useful for scratching or super smooth rate changes. After process() rate will be changed, but may or may not be precisely equal to the desired target value.
);
// Destructor (to free up memory).
resampler.destruct();
#include "SuperpoweredResampler.h"
void initResampler() {
resampler = new Superpowered::Resampler();
// The rate of the resampler. Default: 1. If rate = 1, process() is "transparent" without any effect on audio quality.
resampler->rate = 1.1;
// Reset all internals. Doesn't change rate. Has no return value.
resampler->reset();
}
void processAudio(float *interleavedInput, float *interleavedOutput, unsigned int numberOfFrames) {
int outputNumberOfFrames = resampler->process(interleavedInput, interleavedOutput, numberOfFrames);
...
}

Properties

rate

PROPERTY
The rate of the resampler. If rate = 1, process() is 'transparent' without any effect on audio quality.
TypeMinMaxDefault
Number
1

rate

PROPERTY
The rate of the resampler. If rate = 1, process() is 'transparent' without any effect on audio quality.
TypeMinMaxDefault
float
1

Methods

  • constructor

    METHOD
    Creates a Resampler instance.
    Parameters
    None
    Returns
    TypeDescription
    Superpowered.ResamplerThe constructed instance.
  • constructor

    METHOD
    Creates a Resampler instance.
    Parameters
    None
    Returns
    TypeDescription
    Superpowered::ResamplerThe constructed instance.
  • destruct

    METHOD
    Destructor to free Linear Memory.
    Parameters
    None
    Returns
    None
  • process

    METHOD
    Processes the audio.
    Parameters
    NameTypeDescription
    inputNumber (pointer in Linear Memory)16-bit stereo interleaved input. Should be numberOfFrames * 2 + 64 big.
    outputNumber (pointer in Linear Memory)32-bit stereo interleaved output. Should be big enough to store the expected number of output frames and some more.
    numberOfFramesNumberNumber of frames to process.
    reverseBooleanIf true, the output will be backwards (reverse playback).
    highQualityBooleanEnables more sophisticated processing to reduce interpolation noise. Good for scratching for example, but not recommended for continous music playback above 0.5 rate.
    rateAddNumberChanges rate smoothly during process(). Useful for scratching or super smooth rate changes. After process() rate will be changed, but may or may not be precisely equal to the desired target value.
    Returns
    TypeDescription
    NumberThe number of output frames.
  • process

    METHOD
    Processes the audio.
    Parameters
    NameTypeDefaultDescription
    inputshort int *16-bit stereo interleaved input. Should be numberOfFrames * 2 + 64 big.
    outputfloat *32-bit stereo interleaved output. Should be big enough to store the expected number of output frames and some more.
    numberOfFramesintNumber of frames to process.
    reverseboolfalseIf true, the output will be backwards (reverse playback).
    highQualityboolfalseEnables more sophisticated processing to reduce interpolation noise. Good for scratching for example, but not recommended for continous music playback above 0.5 rate.
    rateAddfloat0Changes rate smoothly during process(). Useful for scratching or super smooth rate changes. After process() rate will be changed, but may or may not be precisely equal to the desired target value.
    Returns
    TypeDescription
    intThe number of output frames.
  • process16

    METHOD
    Processes the audio.
    Parameters
    NameTypeDescription
    inputNumber (pointer in Linear Memory)16-bit stereo interleaved input. Should be numberOfFrames * 2 + 64 big.
    tempNumber (pointer in Linear Memory)Floating point buffer. Should be numberOfFrames * 2 + 64 big.
    outputNumber (pointer in Linear Memory)16-bit stereo interleaved input. Should be big enough to store the expected number of output frames and some more.
    numberOfFramesNumberNumber of frames to process.
    reverseBooleanIf true, the output will be backwards (reverse playback).
    highQualityBooleanEnables more sophisticated processing to reduce interpolation noise. Good for scratching for example, but not recommended for continous music playback above 0.5 rate.
    rateAddNumberChanges rate smoothly during process(). Useful for scratching or super smooth rate changes. After process() rate will be changed, but may or may not be precisely equal to the desired target value.
    Returns
    TypeDescription
    NumberThe number of output frames.
  • process16

    METHOD
    Processes the audio.
    Parameters
    NameTypeDefaultDescription
    inputshort int *16-bit stereo interleaved input. Should be numberOfFrames * 2 + 64 big.
    tempfloat *Floating point buffer. Should be numberOfFrames * 2 + 64 big.
    outputshort int *16-bit stereo interleaved input. Should be big enough to store the expected number of output frames and some more.
    numberOfFramesintNumber of frames to process.
    reverseboolfalseIf true, the output will be backwards (reverse playback).
    highQualityboolfalseEnables more sophisticated processing to reduce interpolation noise. Good for scratching for example, but not recommended for continous music playback above 0.5 rate.
    rateAddNumber0Changes rate smoothly during process(). Useful for scratching or super smooth rate changes. After process() rate will be changed, but may or may not be precisely equal to the desired target value.
    Returns
    TypeDescription
    intThe number of output frames.
  • reset

    METHOD
    Reset all internals. Doesn't change rate.
    Parameters
    None
    Returns
    None
  • reset

    METHOD
    Reset all internals. Doesn't change rate.
    Parameters
    None
    Returns
    None
v1.0.31