Navigation
API > API/Runtime > API/Runtime/SignalProcessing
FVectorLinearResampler
Performs a basic linear resampling using SIMD for optimization.
Advancing is done in fixed point - 65536 is a 1.0f sample rate.
Stereo requires a deinterleaved format.
The design is based on a "pull" model, assuming you need to fill a buffer from a source, rather than computing how much output you would need to resample a given input. If you need to do that, just run the resampler in chunks until you drain the input, appending to the output as you go.
Usage: FVectorLinearResample Resampler = {};
uint32 FixedSampleRate = (uint32)(1.0f * 65536);
/ the example source buffer is assumed to be stereo deinterleaved with the / right channel directly after the left. float* SourceFrames = 0;//; uint32 SourceBufferFrameCount = 0;//<# of frames - i.e.len(SourceFrames) / (sizeof(float) * 2) since stereo>; uint32 SourceBufferFloatsToRightChannel = SourceBufferFrameCount; // right channel directly after the left
const uint32 OutputChunkFrames = 512; while (SourceBufferFrameCount) { / stereo output chunk. Or pointer to wherever you're mixing to. float OutputFrames[OutputChunkFrames * 2];
/ find out how much input we need for the resampler to be able to generate / our chunk. uint32 SourceFramesNeeded = Resampler.SourceFramesNeeded(OutputChunkFrames, FixedSampleRate);
/ make sure we have that available. if (SourceFramesNeeded <= SourceBufferFrameCount) { / direct resample uint32 SourceFramesConsumed = Resampler.ResampleStereo(OutputChunkFrames, FixedSampleRate, SourceFrames, SourceBufferFloatsToRightChannel, OutputFrames, OutputChunkFrames);
do something with output_frames
/ advance the input SourceFrames += SourceFramesConsumed; SourceBufferFrameCount -= SourceFramesConsumed; continue; }
/ here we need to append zeroes as we don't have enough input to fill. / usually need a temp buffer unless you can make dramatic assumptions about / your source buffer. float* TempSource = FMemory::Malloc(sizeof(float) * 2 * SourceFramesNeeded); float* TempSourceLeft = TempSource; float* TempSourceRight = TempSource + SourceFramesNeeded;
uint32 ZeroedFramesNeeded = SourceFramesNeeded - SourceBufferFrameCount;
/ left FMemory::Memcpy(TempSourceLeft, SourceFrames, SourceBufferFrameCount * sizeof(float));
/ left tail FMemory::Memset(TempSourceLeft + SourceBufferFrameCount, 0, ZeroedFramesNeeded * sizeof(float));
/ right FMemory::Memcpy(TempSourceRight, SourceFrames + SourceBufferFloatsToRightChannel, SourceBufferFrameCount * sizeof(float));
/ right tail FMemory::Memset(TempSourceRight + SourceBufferFrameCount, 0, ZeroedFramesNeeded * sizeof(float));
Resampler.ResampleStereo(OutputChunkFrames, FixedSampleRate, TempSource, SourceFramesNeeded, OutputFrames, OutputChunkFrames);
FMemory::Free(TempSource);
SourceBufferFrameCount = 0; }
| Name | FVectorLinearResampler |
| Type | struct |
| Header File | /Engine/Source/Runtime/SignalProcessing/Public/DSP/VectorLinearResampler.h |
| Include Path | #include "DSP/VectorLinearResampler.h" |
Syntax
struct FVectorLinearResampler
Variables
Public
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| CurrentFrameFraction | uint32 | DSP/VectorLinearResampler.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
uint32 ResampleMono
(
uint32 OutputFramesNeeded, |
Generate OutputFramesNeeded resampled output at the given fixed point sample rate (1.0 = 65536). | DSP/VectorLinearResampler.h | |
uint32 ResampleStereo
(
uint32 OutputFramesNeeded, |
DSP/VectorLinearResampler.h | ||
uint32 SourceFramesNeeded
(
uint32 OutputFramesNeeded, |
Returns the number of source frames necessary to generate the requested output count at the given fixed point sample rate (1.0 rate is 65536) | DSP/VectorLinearResampler.h |