UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Audio::FSinOsc2DRotation Class Reference

#include <Dsp.h>

Public Member Functions

 FSinOsc2DRotation (float InStartingPhaseRadians=0.f)
 
void GenerateBuffer (float SampleRate, float ClampedFrequency, float *Buffer, int32 BufferSampleCount)
 

Detailed Description

Generates a sine wave in the given buffer with the given frequency.

Uses the method of generating a 2D point on the unit circle and multiplying with a 2d rotation matrix to advance the phase. Very accurate and very fast.

Use this unless you're changing frequency every few samples on very tiny blocks (single digit sample count)

Distortion vs directly calling FMath::Sin() is on the order of -100db, and is roughly 10x faster (for constant frequency).

Frequency changes are not interpolated across the buffer, so dramatic changes could introduce aliasing due to a discontinuous derivative in the output. If you're changing frequencies by a lot, constantly, you should probably use VectorSinCos in a loop.

Usage:

constexpr const int32 ChunkSampleCount = 480; alignas (sizeof(VectorRegister4Float)) float ChunkBuffer[ChunkSampleCount]; FSinOscBufferGenerator Generator; Generator.GenerateBuffer(48000, 400, ChunkBuffer, ChunkSampleCount);

ChunkBuffer now has 10ms of sine tone at 400hz. The next call will continue the sine tone where it left off.

Constructor & Destructor Documentation

◆ FSinOsc2DRotation()

Audio::FSinOsc2DRotation::FSinOsc2DRotation ( float  InStartingPhaseRadians = 0.f)
inline

Member Function Documentation

◆ GenerateBuffer()

void Audio::FSinOsc2DRotation::GenerateBuffer ( float  SampleRate,
float  ClampedFrequency,
float Buffer,
int32  BufferSampleCount 
)
inline

Generates the sine tone, continuing from the last phase.

Parameters
SampleRatethe sample rate the buffer will be played at
ClampedFrequencythe frequency of the tone to emit, clamped to nyquist (SampleRate/2)
Bufferthe output buffer
BufferSampleCountthe number of samples in the buffer. Generally, this should be %4 granularity.

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