Base class for Audio IO functionality in ShaderTech. More...
#include <ST_AudioIOBase.h>
Public Member Functions | |
| UST_AudioIOBase () | |
| ~UST_AudioIOBase () | |
| bool | Activate () |
| void | Deactivate () |
| virtual EAudioIOType | GetAudioIOType () const |
| FAudioIOConfig | GetAudioIOConfig () const |
| FFFTIOData | GetFFTIOData () const |
| bool | RegisterSampler (UObject *Sampler, bool bSamplerActivates=false) |
| void | DeregisterSampler (UObject *Sampler, bool bZeroSamplersDeactivates=false) |
| bool | MA_IsDataAvailable (uint64 PeriodSizeInFrames) |
| void | MA_ReadRealtimePcmRB (uint64 PeriodSizeInFrames, ma_format Format, uint32 Channels) |
| void | MA_DataOrganiser (void *pSamples, uint64 PeriodSizeInFrames, ma_format Format, uint32 Channels) |
| template<typename InterfaceType> | |
| bool | ContainsInterface () const |
| FIntPoint | GetIOId () const |
| virtual EST_SampleFormat | GetAudioFormat () const |
| Returns the current audio format. | |
Static Public Member Functions | |
| static void | MA_DataAvailable (ma_device *pDevice) |
Public Attributes | |
| FCriticalSection | AudioBufferLock |
| void * | SampledAudioBuffers [BufferCount] = { nullptr, nullptr } |
| void * | CurrentAudioBuffer = nullptr |
| std::atomic< uint32 > | ReadIndex |
| std::atomic< uint32 > | WriteIndex |
| FOnAudioIOStatusChanged | OnAudioIOStatusChanged |
| FOnRawMagnitudesReady | OnRawMagnitudesReady |
| FOnFrequencyBandsReady | OnFrequencyBandsReady |
| FOnAmplitudesReady | OnAmplitudesReady |
| FOnPitchesReady | OnPitchesReady |
| FOnBeatDetected | OnBeatDetected |
Static Public Attributes | |
| static constexpr uint32 | BufferCount = 2 |
Protected Member Functions | |
| virtual void | Initialize (FSubsystemCollectionBase &Collection) override |
| virtual void | Deinitialize () override |
| virtual bool | InitializeAudioIO () |
| virtual void | DeinitializeAudioIO () |
| void | BuildFFTIOData (uint32 PeriodSizeInFrames, ma_format Format, uint32 SampleRate, uint32 Channels) |
| void | DeinitializeFFT () |
| virtual ma_decoder * | GetPlaybackDecoder () const |
| virtual ma_encoder * | GetCaptureEncoder () const |
| void | GetDeviceInfo (EAudioIOType AudioIOType, FString FindDeviceName) |
Protected Attributes | |
| bool | bActivated = false |
| bool | bIsProcessingFFT = false |
| FCriticalSection | SamplerRegistrationMutex |
| TArray< UObject * > | RegisteredSamplers |
| ma_device_id * | pDeviceID = NULL |
| Pointer to the selected device ID. | |
| ma_device_info * | pPlaybackDeviceInfos = nullptr |
| Playback device information. | |
| ma_device_info * | pCaptureDeviceInfos = nullptr |
| Capture device information. | |
| ma_uint32 | playbackDeviceCount = 0 |
| Number of playback devices found. | |
| ma_uint32 | captureDeviceCount = 0 |
| Number of capture devices found. | |
| FFFTIOData | CachedFFTIOData |
| Cached FFT IO data. | |
| FAudioIOConfig | CachedAudioIOConfig |
| Cached audio IO configuration. | |
| ma_pcm_rb | RealtimePcmRingBuffer |
| Lock-free PCM ring buffer for passing audio from the realtime callback to the FFT worker thread. | |
| ma_uint32 | RealtimePcmRBFrameCapacity = 0 |
| Fixed maximum number of audio frames the ring buffer can hold. | |
| TArray< uint8 > | RealtimePcmRBBackingMemory |
| Preallocated backing memory used by the ring buffer (no runtime allocations). | |
Base class for Audio IO functionality in ShaderTech.
Base class for Audio IO functionality in ShaderTech.
| UST_AudioIOBase::UST_AudioIOBase | ( | ) |
Sets default values for this actor's properties.
| UST_AudioIOBase::~UST_AudioIOBase | ( | ) |
Default destructor.
| bool UST_AudioIOBase::Activate | ( | ) |
Activates the audio IO.
|
protected |
Builds FFT IO data from device parameters.
| PeriodSizeInFrames | Size of a period in frames. |
| Format | Audio data format. |
| SampleRate | Sample rate of the audio. |
| Channels | Number of audio channels. |
|
inline |
Checks if a registered interface type exists.
| void UST_AudioIOBase::Deactivate | ( | ) |
Deactivates the audio IO.
|
protectedvirtual |
Deinitializes the audio IO.
Reimplemented in UST_AudioIOCaptureBase, UST_AudioIOPlaybackBase, UST_AudioPlaybackEnginePlayer, UST_AudioPlaybackNoise, and UST_AudioPlaybackWaveform.
|
protected |
Deinitializes FFT data and processing.
| void UST_AudioIOBase::DeregisterSampler | ( | UObject * | Sampler, |
| bool | bZeroSamplersDeactivates = false ) |
Deregisters a sampler from the audio IO system.
| Sampler | The sampler object to deregister. |
| bZeroSamplersDeactivates | Whether deactivation should occur when no samplers remain. |
|
inlinevirtual |
Returns the current audio format.
Reimplemented in UST_AudioIOCaptureBase, and UST_AudioIOPlaybackBase.
|
inline |
Returns the current Audio IO configuration.
|
inlinevirtual |
Returns the type of Audio IO.
Reimplemented in UST_AudioCaptureLoopback, UST_AudioCaptureMicrophone, UST_AudioPlaybackEnginePlayer, UST_AudioPlaybackNoise, UST_AudioPlaybackPlayer, and UST_AudioPlaybackWaveform.
|
inlineprotectedvirtual |
Returns a pointer to the capture encoder, if any.
Reimplemented in UST_AudioIOCaptureBase.
|
protected |
Retrieves device information for a given Audio IO type.
| AudioIOType | The type of audio IO device. |
| FindDeviceName | The device name to search for. |
|
inline |
Returns the current FFT IO data.
|
inline |
Returns the IO Id used for identification purposes.
|
inlineprotectedvirtual |
Returns a pointer to the playback decoder, if any.
Reimplemented in UST_AudioIOPlaybackBase.
|
protectedvirtual |
Initializes the audio IO.
Reimplemented in UST_AudioCaptureLoopback, UST_AudioCaptureMicrophone, UST_AudioPlaybackEnginePlayer, UST_AudioPlaybackNoise, UST_AudioPlaybackPlayer, and UST_AudioPlaybackWaveform.
|
static |
Signals the FFT worker thread that sufficient audio data is available for processing.
| pDevice | The audio device. |
| void UST_AudioIOBase::MA_DataOrganiser | ( | void * | pSamples, |
| uint64 | PeriodSizeInFrames, | ||
| ma_format | Format, | ||
| uint32 | Channels ) |
Miniaudio callback function to organize audio data.
| pSamples | The buffer of samples. |
| PeriodSizeInFrames | The size of the period in frames. |
| Format | The sample format. |
| Channels | The number of audio channels. |
| bool UST_AudioIOBase::MA_IsDataAvailable | ( | uint64 | PeriodSizeInFrames | ) |
Returns true if at least one full processing period of PCM data is available in the realtime ring buffer.
| PeriodSizeInFrames | The size of the period in frames. |
| void UST_AudioIOBase::MA_ReadRealtimePcmRB | ( | uint64 | PeriodSizeInFrames, |
| ma_format | Format, | ||
| uint32 | Channels ) |
Reads one period of PCM data from the realtime ring buffer and forwards it for processing.
| PeriodSizeInFrames | The size of the period in frames. |
| Format | The sample format. |
| Channels | The number of audio channels. |
| bool UST_AudioIOBase::RegisterSampler | ( | UObject * | Sampler, |
| bool | bSamplerActivates = false ) |
Registers a sampler for the audio IO system.
| Sampler | The sampler object to register. |
| bSamplerActivates | Whether the sampler should cause activation. |
| FCriticalSection UST_AudioIOBase::AudioBufferLock |
Critical section for thread-safe audio buffer operations.
|
protected |
Whether the audio IO system is activated.
|
protected |
Whether the FFT processing is currently running.
|
staticconstexpr |
Number of buffers for double buffering.
| void* UST_AudioIOBase::CurrentAudioBuffer = nullptr |
Pointer to the currently active audio buffer.
| FOnAmplitudesReady UST_AudioIOBase::OnAmplitudesReady |
Event triggered when amplitudes are ready.
| FOnAudioIOStatusChanged UST_AudioIOBase::OnAudioIOStatusChanged |
Event triggered when audio IO activation status changes.
| FOnBeatDetected UST_AudioIOBase::OnBeatDetected |
Event triggered when beats are detected.
| FOnFrequencyBandsReady UST_AudioIOBase::OnFrequencyBandsReady |
Event triggered when frequency bands are ready.
| FOnPitchesReady UST_AudioIOBase::OnPitchesReady |
Event triggered when pitches are ready.
| FOnRawMagnitudesReady UST_AudioIOBase::OnRawMagnitudesReady |
Event triggered when raw magnitudes are ready.
| std::atomic<uint32> UST_AudioIOBase::ReadIndex |
Index to indicate which buffer the FFT thread reads.
|
protected |
Array of registered sampler objects.
| void* UST_AudioIOBase::SampledAudioBuffers[BufferCount] = { nullptr, nullptr } |
Array of sampled audio buffers.
|
protected |
Ensure the registration and deregistration of samplers is thread safe.
| std::atomic<uint32> UST_AudioIOBase::WriteIndex |
Index to indicate which buffer miniaudio writes to.