Navigation
API > API/Runtime > API/Runtime/SignalProcessing
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.
| Name | FSinOsc2DRotation |
| Type | class |
| Header File | /Engine/Source/Runtime/SignalProcessing/Public/DSP/Dsp.h |
| Include Path | #include "DSP/Dsp.h" |
Syntax
class FSinOsc2DRotation
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FSinOsc2DRotation
(
float InStartingPhaseRadians |
DSP/Dsp.h | ||
FSinOsc2DRotation
(
FSinOsc2DRotation const& other |
DSP/Dsp.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| Dx | float | DSP/Dsp.h | ||
| Dy | float | DSP/Dsp.h | ||
| LastPhase | float | DSP/Dsp.h | ||
| LastPhasePerSample | float | DSP/Dsp.h | ||
| QuadDxVec | VectorRegister4Float | DSP/Dsp.h | ||
| QuadDyVec | VectorRegister4Float | DSP/Dsp.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
void GenerateBuffer
(
float SampleRate, |
Generates the sine tone, continuing from the last phase. | DSP/Dsp.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FSinOsc2DRotation & operator=
(
FSinOsc2DRotation const& other |
DSP/Dsp.h |