FQLab
A spectral audio sandbox
 
Loading...
Searching...
No Matches
FQLab.AudioEngine Class Reference

Core class responsible for managing the state and playback of the currently selected track. The lifespan of this instance matches the lifespan of the IAudioStream it consumes. More...

Inheritance diagram for FQLab.AudioEngine:
Inheritance graph
Collaboration diagram for FQLab.AudioEngine:
Collaboration graph

Public Member Functions

 AudioEngine (IAudioStream audioStream, IAudioPlayer audioPlayer, IFftProcessor fftProcessor, IFreqDataReceiver? dataReceiver=null, List< PluginInstance >? audioPlugins=null)
 
void Run ()
 Uses start and forget to run asynchronous tasks of producing/consuming audio data.
 
void Pause ()
 Pauses both processes.
 
void Resume ()
 Resumes pipeline.
 
void Abort ()
 Force quits pipeline safely.
 
void SetEq (EqSettings settings)
 Updates EQ settings based on received data.
 
void Dispose ()
 Safely gets rid of the engine when stream runs out.
 

Properties

Task[] Tasks [get]
 Gets the currently running producer and consumer tasks.
 
float VolumeFactor [get, set]
 Exposes volume factor (in ranges 0 to 1).
 
List< PluginInstance >? PluginList [get]
 Returns all detected plugins inside the engine.
 

Private Member Functions

void AudioProducerProcess (CancellationToken token)
 Core audio pipeline. Consumes data from the _audioStream and processes them. Pushes the result into a data structure for the audio consumer.
 
void AudioConsumerProcess (CancellationToken token)
 Consumes processed data from the buffer and pushes it to the player.
 
void ShiftBuffers (AudioFrame nextFrame)
 
float[] MixToMonoFromBuffer ()
 
void OverlapAddToBuffer (float[] monoIfftSamples)
 
float[] GetOutputSamplesFromBuffer ()
 
Complex[] ApplyEq (Complex[] freqBins)
 
float[] ScaleVolume (float[] samples)
 

Static Private Member Functions

static float[] GenerateHannWindow (int size)
 

Private Attributes

readonly IAudioStream _audioStream
 
readonly IFftProcessor _fftProcessor
 
readonly IAudioPlayer _audioPlayer
 
readonly? List< PluginInstance_audioPlugins
 
readonly? IFreqDataReceiver _dataReceiver
 Optional for rendering audio data.
 
EqSettings _eqSettings = new EqSettings()
 
float _volumeFactor = 0.5f
 
readonly float[] _hannWindow = GenerateHannWindow(FrameSize)
 
int _channelCount
 
float[] _inputBuffer = []
 
float[] _overlapAddBuffer = []
 
float[] _tailBuffer = []
 
int _writePos = 0
 
BlockingCollection< AudioFrame_frameBuffer = new BlockingCollection<AudioFrame>(32)
 
Task _producerTask
 
Task _consumerTask
 
CancellationTokenSource? _cancellationTokenSource
 
readonly ManualResetEventSlim _pauseEvent = new ManualResetEventSlim(true)
 

Static Private Attributes

const int FrameSize = 1024
 
const int HopSize = FrameSize / 2
 

Detailed Description

Core class responsible for managing the state and playback of the currently selected track. The lifespan of this instance matches the lifespan of the IAudioStream it consumes.

Constructor & Destructor Documentation

◆ AudioEngine()

FQLab.AudioEngine.AudioEngine ( IAudioStream  audioStream,
IAudioPlayer  audioPlayer,
IFftProcessor  fftProcessor,
IFreqDataReceiver dataReceiver = null,
List< PluginInstance >?  audioPlugins = null 
)
inline
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ Abort()

void FQLab.AudioEngine.Abort ( )
inline

Force quits pipeline safely.

Here is the call graph for this function:

◆ ApplyEq()

Complex[] FQLab.AudioEngine.ApplyEq ( Complex[]  freqBins)
inlineprivate
Here is the caller graph for this function:

◆ AudioConsumerProcess()

void FQLab.AudioEngine.AudioConsumerProcess ( CancellationToken  token)
inlineprivate

Consumes processed data from the buffer and pushes it to the player.

Parameters
token
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AudioProducerProcess()

void FQLab.AudioEngine.AudioProducerProcess ( CancellationToken  token)
inlineprivate

Core audio pipeline. Consumes data from the _audioStream and processes them. Pushes the result into a data structure for the audio consumer.

Parameters
tokenToken enabling cancellation of pipeline.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dispose()

void FQLab.AudioEngine.Dispose ( )
inline

Safely gets rid of the engine when stream runs out.

Here is the call graph for this function:

◆ GenerateHannWindow()

static float[] FQLab.AudioEngine.GenerateHannWindow ( int  size)
inlinestaticprivate

◆ GetOutputSamplesFromBuffer()

float[] FQLab.AudioEngine.GetOutputSamplesFromBuffer ( )
inlineprivate
Here is the caller graph for this function:

◆ MixToMonoFromBuffer()

float[] FQLab.AudioEngine.MixToMonoFromBuffer ( )
inlineprivate
Here is the caller graph for this function:

◆ OverlapAddToBuffer()

void FQLab.AudioEngine.OverlapAddToBuffer ( float[]  monoIfftSamples)
inlineprivate
Here is the caller graph for this function:

◆ Pause()

void FQLab.AudioEngine.Pause ( )
inline

Pauses both processes.

Here is the call graph for this function:

◆ Resume()

void FQLab.AudioEngine.Resume ( )
inline

Resumes pipeline.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Run()

void FQLab.AudioEngine.Run ( )
inline

Uses start and forget to run asynchronous tasks of producing/consuming audio data.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScaleVolume()

float[] FQLab.AudioEngine.ScaleVolume ( float[]  samples)
inlineprivate
Here is the caller graph for this function:

◆ SetEq()

void FQLab.AudioEngine.SetEq ( EqSettings  settings)

Updates EQ settings based on received data.

Parameters
settingsImmutable struct of settings from the GUI.
Here is the caller graph for this function:

◆ ShiftBuffers()

void FQLab.AudioEngine.ShiftBuffers ( AudioFrame  nextFrame)
inlineprivate
Here is the caller graph for this function:

Member Data Documentation

◆ _audioPlayer

readonly IAudioPlayer FQLab.AudioEngine._audioPlayer
private

◆ _audioPlugins

readonly? List<PluginInstance> FQLab.AudioEngine._audioPlugins
private

◆ _audioStream

readonly IAudioStream FQLab.AudioEngine._audioStream
private

◆ _cancellationTokenSource

CancellationTokenSource? FQLab.AudioEngine._cancellationTokenSource
private

◆ _channelCount

int FQLab.AudioEngine._channelCount
private

◆ _consumerTask

Task FQLab.AudioEngine._consumerTask
private

◆ _dataReceiver

readonly? IFreqDataReceiver FQLab.AudioEngine._dataReceiver
private

Optional for rendering audio data.

◆ _eqSettings

EqSettings FQLab.AudioEngine._eqSettings = new EqSettings()
private

◆ _fftProcessor

readonly IFftProcessor FQLab.AudioEngine._fftProcessor
private

◆ _frameBuffer

BlockingCollection<AudioFrame> FQLab.AudioEngine._frameBuffer = new BlockingCollection<AudioFrame>(32)
private

◆ _hannWindow

readonly float [] FQLab.AudioEngine._hannWindow = GenerateHannWindow(FrameSize)
private

◆ _inputBuffer

float [] FQLab.AudioEngine._inputBuffer = []
private

◆ _overlapAddBuffer

float [] FQLab.AudioEngine._overlapAddBuffer = []
private

◆ _pauseEvent

readonly ManualResetEventSlim FQLab.AudioEngine._pauseEvent = new ManualResetEventSlim(true)
private

◆ _producerTask

Task FQLab.AudioEngine._producerTask
private

◆ _tailBuffer

float [] FQLab.AudioEngine._tailBuffer = []
private

◆ _volumeFactor

float FQLab.AudioEngine._volumeFactor = 0.5f
private

◆ _writePos

int FQLab.AudioEngine._writePos = 0
private

◆ FrameSize

const int FQLab.AudioEngine.FrameSize = 1024
staticprivate

◆ HopSize

const int FQLab.AudioEngine.HopSize = FrameSize / 2
staticprivate

Property Documentation

◆ PluginList

List<PluginInstance>? FQLab.AudioEngine.PluginList
get

Returns all detected plugins inside the engine.

◆ Tasks

Task [] FQLab.AudioEngine.Tasks
get

Gets the currently running producer and consumer tasks.

◆ VolumeFactor

float FQLab.AudioEngine.VolumeFactor
getset

Exposes volume factor (in ranges 0 to 1).


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