You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
All synths will eventually be implemented using this API. Change also has a test synth that exercises code that is a hello-world style "tone generator". #rb Ethan.Geller, Phil.Popp # #ROBOMERGE-OWNER: aaron.mcleran #ROBOMERGE-AUTHOR: aaron.mcleran #ROBOMERGE-SOURCE: CL 12996583 via CL 12996736 via CL 12996749 #ROBOMERGE-BOT: RELEASE (Release-Engine-Staging -> Main) (v682-12900288) [CL 12996768 by aaron mcleran in Main branch]
59 lines
1.6 KiB
C++
59 lines
1.6 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
namespace Audio
|
|
{
|
|
/**
|
|
* FOsc
|
|
* Direct-form sinusoid oscillator.
|
|
* Created with a biquad filter (using only feedback coefficients) with poles directly on unit circle in z-plane.
|
|
* Setting frequency uses current filter state to compute initial conditions to avoid pops when changing frequency.
|
|
* Extremely cheap to run but expensive to set new frequencies. Good for test tones.
|
|
*/
|
|
class SIGNALPROCESSING_API FSineOsc
|
|
{
|
|
public:
|
|
/** Constructor */
|
|
FSineOsc();
|
|
|
|
/** Non-default constructor */
|
|
FSineOsc(const int32 InSampleRate, const float InFrequencyHz, const float Scale = 1.0f, const float Add = 0.0f);
|
|
|
|
/** Virtual destructor */
|
|
virtual ~FSineOsc();
|
|
|
|
/** Initialize the oscillator with a sample rate and new frequency. Must be called before playing oscillator. */
|
|
void Init(const int32 InSampleRate, const float InFrequencyHz, const float Scale = 1.0f, const float Add = 0.0f);
|
|
|
|
/** Sets the scale of the oscillator. */
|
|
void SetScale(const float InScale);
|
|
|
|
/** Sets the scale of the oscillator. */
|
|
void SetAdd(const float InAdd);
|
|
|
|
/** Sets the frequency of the oscillator in Hz (based on sample rate). Performs initial condition calculation to avoid pops. */
|
|
void SetFrequency(const float InFrequencyHz);
|
|
|
|
/** Returns the current frequency. */
|
|
float GetFrequency() const;
|
|
|
|
/** Generates the next sample of the oscillator. */
|
|
float ProcessAudio();
|
|
|
|
protected:
|
|
int32 SampleRate;
|
|
float FrequencyHz;
|
|
float B1; // Biquad feedback coefficients
|
|
float B2;
|
|
float Yn_1; // y(n - 1)
|
|
float Yn_2; // y(n - 2)
|
|
float Scale;
|
|
float Add;
|
|
};
|
|
|
|
|
|
}
|