![]() |
UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
|
#include <Dsp.h>
Public Member Functions | |
| FSinOsc2DRotation (float InStartingPhaseRadians=0.f) | |
| void | GenerateBuffer (float SampleRate, float ClampedFrequency, float *Buffer, int32 BufferSampleCount) |
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.
|
inline |
|
inline |
Generates the sine tone, continuing from the last phase.
| SampleRate | the sample rate the buffer will be played at |
| ClampedFrequency | the frequency of the tone to emit, clamped to nyquist (SampleRate/2) |
| Buffer | the output buffer |
| BufferSampleCount | the number of samples in the buffer. Generally, this should be %4 granularity. |