2019-12-26 14:45:42 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2019-08-26 18:35:22 -04:00
# pragma once
# include "CoreMinimal.h"
# if PLATFORM_SWITCH
// Switch uses page alignment for submitted buffers
# define AUDIO_BUFFER_ALIGNMENT 4096
# else
# define AUDIO_BUFFER_ALIGNMENT 16
# endif
# define AUDIO_SIMD_BYTE_ALIGNMENT (16)
2021-05-11 19:02:01 -04:00
# define AUDIO_NUM_FLOATS_PER_VECTOR_REGISTER (4)
2019-08-26 18:35:22 -04:00
namespace Audio
{
2019-09-12 13:49:12 -04:00
/** Aligned allocator used for fast operations. */
2020-09-15 13:08:34 -04:00
using FAudioBufferAlignedAllocator = TAlignedHeapAllocator < AUDIO_BUFFER_ALIGNMENT > ;
2019-09-12 13:49:12 -04:00
2020-09-15 13:08:34 -04:00
using FAlignedByteBuffer = TArray < uint8 , FAudioBufferAlignedAllocator > ;
using FAlignedFloatBuffer = TArray < float , FAudioBufferAlignedAllocator > ;
using FAlignedInt32Buffer = TArray < int32 , FAudioBufferAlignedAllocator > ;
// Deprecated in favor of versions above
2019-09-12 13:49:12 -04:00
typedef TArray < uint8 , FAudioBufferAlignedAllocator > AlignedByteBuffer ;
2020-09-15 13:08:34 -04:00
typedef TArray < float , FAudioBufferAlignedAllocator > AlignedFloatBuffer ;
2019-09-12 13:49:12 -04:00
typedef TArray < int32 , FAudioBufferAlignedAllocator > AlignedInt32Buffer ;
2019-08-26 18:35:22 -04:00
/** CHANNEL-AGNOSTIC OPERATIONS */
/* Sets a values to zero if value is denormal. Denormal numbers significantly slow down floating point operations. */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferUnderflowClampFast ( FAlignedFloatBuffer & InOutBuffer ) ;
2019-08-26 18:35:22 -04:00
/* Sets a values to zero if value is denormal. Denormal numbers significantly slow down floating point operations. */
SIGNALPROCESSING_API void BufferUnderflowClampFast ( float * RESTRICT InOutBuffer , const int32 InNum ) ;
2019-11-06 18:28:39 -05:00
2019-11-11 13:04:43 -05:00
/* Clamps the values in a buffer between a min and max value.*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferRangeClampFast ( FAlignedFloatBuffer & InOutBuffer , float InMinValue , float InMaxValue ) ;
2020-04-06 17:13:33 -04:00
SIGNALPROCESSING_API void BufferRangeClampFast ( float * RESTRICT InOutBuffer , const int32 InNum , float InMinValue , float InMaxValue ) ;
2019-11-06 18:28:39 -05:00
2019-08-26 18:35:22 -04:00
/** Multiplies the input aligned float buffer with the given value. */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferMultiplyByConstant ( const FAlignedFloatBuffer & InFloatBuffer , float InValue , FAlignedFloatBuffer & OutFloatBuffer ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void BufferMultiplyByConstant ( const float * RESTRICT InFloatBuffer , float InValue , float * RESTRICT OutFloatBuffer , const int32 InNumSamples ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferMultiplyByConstant ( const FAlignedFloatBuffer & InFloatBuffer , float InValue , FAlignedFloatBuffer & OutFloatBuffer ) ;
2019-08-26 18:35:22 -04:00
/** Similar to BufferMultiplyByConstant, but (a) assumes a buffer length divisible by 4 and (b) performs the multiply in place. */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MultiplyBufferByConstantInPlace ( FAlignedFloatBuffer & InBuffer , float InGain ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MultiplyBufferByConstantInPlace ( float * RESTRICT InBuffer , int32 NumSamples , float InGain ) ;
/** Adds a constant to a buffer (useful for DC offset removal) */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void AddConstantToBufferInplace ( FAlignedFloatBuffer & InBuffer , float Constant ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void AddConstantToBufferInplace ( float * RESTRICT InBuffer , int32 NumSamples , float Constant ) ;
2020-04-06 17:13:33 -04:00
/** Sets a constant to a buffer (useful for DC offset application) */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferSetToConstantInplace ( FAlignedFloatBuffer & InBuffer , float Constant ) ;
2020-04-06 17:13:33 -04:00
SIGNALPROCESSING_API void BufferSetToConstantInplace ( float * RESTRICT InBuffer , int32 NumSamples , float Constant ) ;
2019-08-26 18:35:22 -04:00
/* Performs an element-wise weighted sum OutputBuffer = (InBuffer1 x InGain1) + (InBuffer2 x InGain2) */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferWeightedSumFast ( const FAlignedFloatBuffer & InBuffer1 , float InGain1 , const FAlignedFloatBuffer & InBuffer2 , float InGain2 , FAlignedFloatBuffer & OutBuffer ) ;
2019-08-26 18:35:22 -04:00
/* Performs an element-wise weighted sum OutputBuffer = (InBuffer1 x InGain1) + InBuffer2 */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferWeightedSumFast ( const FAlignedFloatBuffer & InBuffer1 , float InGain1 , const FAlignedFloatBuffer & InBuffer2 , FAlignedFloatBuffer & OutBuffer ) ;
2019-08-26 18:35:22 -04:00
/* Performs an element-wise weighted sum OutputBuffer = (InBuffer1 x InGain1) + (InBuffer2 x InGain2) */
SIGNALPROCESSING_API void BufferWeightedSumFast ( const float * RESTRICT InBuffer1 , float InGain1 , const float * RESTRICT InBuffer2 , float InGain2 , float * RESTRICT OutBuffer , int32 InNum ) ;
/* Performs an element-wise weighted sum OutputBuffer = (InBuffer1 x InGain1) + InBuffer2 */
SIGNALPROCESSING_API void BufferWeightedSumFast ( const float * RESTRICT InBuffer1 , float InGain1 , const float * RESTRICT InBuffer2 , float * RESTRICT OutBuffer , int32 InNum ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MultiplyBufferByConstantInPlace ( FAlignedFloatBuffer & InBuffer , float InGain ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MultiplyBufferByConstantInPlace ( float * RESTRICT InBuffer , int32 NumSamples , float InGain ) ;
/* Takes a float buffer and quickly interpolates it's gain from StartValue to EndValue. */
/* This operation completely ignores channel counts, so avoid using this function on buffers that are not mono, stereo or quad */
/* if the buffer needs to fade all channels uniformly. */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void FadeBufferFast ( FAlignedFloatBuffer & OutFloatBuffer , const float StartValue , const float EndValue ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void FadeBufferFast ( float * RESTRICT OutFloatBuffer , int32 NumSamples , const float StartValue , const float EndValue ) ;
/** Takes buffer InFloatBuffer, optionally multiplies it by Gain, and adds it to BufferToSumTo. */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixInBufferFast ( const FAlignedFloatBuffer & InFloatBuffer , FAlignedFloatBuffer & BufferToSumTo , const float Gain ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MixInBufferFast ( const float * RESTRICT InFloatBuffer , float * RESTRICT BufferToSumTo , int32 NumSamples , const float Gain ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixInBufferFast ( const FAlignedFloatBuffer & InFloatBuffer , FAlignedFloatBuffer & BufferToSumTo , const float StartGain , const float EndGain ) ;
2019-11-01 15:17:07 -04:00
SIGNALPROCESSING_API void MixInBufferFast ( const float * RESTRICT InFloatBuffer , float * RESTRICT BufferToSumTo , int32 NumSamples , const float StartGain , const float EndGain ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixInBufferFast ( const FAlignedFloatBuffer & InFloatBuffer , FAlignedFloatBuffer & BufferToSumTo ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MixInBufferFast ( const float * RESTRICT InFloatBuffer , float * RESTRICT BufferToSumTo , int32 NumSamples ) ;
/* Subtracts two buffers together element-wise. */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferSubtractFast ( const FAlignedFloatBuffer & InMinuend , const FAlignedFloatBuffer & InSubtrahend , FAlignedFloatBuffer & OutputBuffer ) ;
2019-08-26 18:35:22 -04:00
/* Subtracts two buffers together element-wise. */
SIGNALPROCESSING_API void BufferSubtractFast ( const float * RESTRICT InMinuend , const float * RESTRICT InSubtrahend , float * RESTRICT OutputBuffer , int32 NumSamples ) ;
/* Performs element-wise in-place subtraction placing the result in the subtrahend. InOutSubtrahend = InMinuend - InOutSubtrahend */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferSubtractInPlace1Fast ( const FAlignedFloatBuffer & InMinuend , FAlignedFloatBuffer & InOutSubtrahend ) ;
2019-08-26 18:35:22 -04:00
/* Performs element-wise in-place subtraction placing the result in the subtrahend. InOutSubtrahend = InMinuend - InOutSubtrahend */
SIGNALPROCESSING_API void BufferSubtractInPlace1Fast ( const float * RESTRICT InMinuend , float * RESTRICT InOutSubtrahend , int32 NumSamples ) ;
/* Performs element-wise in-place subtraction placing the result in the minuend. InOutMinuend = InOutMinuend - InSubtrahend */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferSubtractInPlace2Fast ( FAlignedFloatBuffer & InOutMinuend , const FAlignedFloatBuffer & InSubtrahend ) ;
2019-08-26 18:35:22 -04:00
/* Performs element-wise in-place subtraction placing the result in the minuend. InOutMinuend = InOutMinuend - InSubtrahend */
SIGNALPROCESSING_API void BufferSubtractInPlace2Fast ( float * RESTRICT InOutMinuend , const float * RESTRICT InSubtrahend , int32 NumSamples ) ;
/** This version of MixInBufferFast will fade from StartGain to EndGain. */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixInBufferFast ( const FAlignedFloatBuffer & InFloatBuffer , FAlignedFloatBuffer & BufferToSumTo , const float StartGain , const float EndGain ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MixInBufferFast ( const float * RESTRICT InFloatBuffer , float * RESTRICT BufferToSumTo , int32 NumSamples , const float StartGain , const float EndGain ) ;
/** Sums two buffers together and places the result in the resulting buffer. */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void SumBuffers ( const FAlignedFloatBuffer & InFloatBuffer1 , const FAlignedFloatBuffer & InFloatBuffer2 , FAlignedFloatBuffer & OutputBuffer ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void SumBuffers ( const float * RESTRICT InFloatBuffer1 , const float * RESTRICT InFloatBuffer2 , float * RESTRICT OutputBuffer , int32 NumSamples ) ;
/** Multiply the second buffer in place by the first buffer. */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MultiplyBuffersInPlace ( const FAlignedFloatBuffer & InFloatBuffer , FAlignedFloatBuffer & BufferToMultiply ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MultiplyBuffersInPlace ( const float * RESTRICT InFloatBuffer , float * RESTRICT BufferToMultiply , int32 NumSamples ) ;
/** CHANNEL-AGNOSTIC ANALYSIS OPERATIONS */
/** Takes an audio buffer and returns the magnitude across that buffer. */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API float GetMagnitude ( const FAlignedFloatBuffer & Buffer ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API float GetMagnitude ( const float * RESTRICT Buffer , int32 NumSamples ) ;
2021-01-25 17:26:35 -04:00
/** Takes an audio buffer and gets the average amplitude across that buffer. */
SIGNALPROCESSING_API float BufferGetAverageValue ( const FAlignedFloatBuffer & Buffer ) ;
SIGNALPROCESSING_API float BufferGetAverageValue ( const float * RESTRICT Buffer , int32 NumSamples ) ;
2019-08-26 18:35:22 -04:00
/** Takes an audio buffer and gets the average absolute amplitude across that buffer. */
2021-01-25 17:26:35 -04:00
SIGNALPROCESSING_API float BufferGetAverageAbsValue ( const FAlignedFloatBuffer & Buffer ) ;
SIGNALPROCESSING_API float BufferGetAverageAbsValue ( const float * RESTRICT Buffer , int32 NumSamples ) ;
2019-08-26 18:35:22 -04:00
/** CHANNEL-SPECIFIC OPERATIONS */
/** Takes a 2 channel interleaved buffer and applies Gains to it. Gains is expected to point to a 2 float long buffer.
* StereoBuffer must have an even number of frames .
* If StartGains and EndGains are provided , this function will interpolate between the two across the buffer .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Apply2ChannelGain ( FAlignedFloatBuffer & StereoBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Apply2ChannelGain ( float * RESTRICT StereoBuffer , int32 NumSamples , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Apply2ChannelGain ( FAlignedFloatBuffer & StereoBuffer , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Apply2ChannelGain ( float * RESTRICT StereoBuffer , int32 NumSamples , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
/** Takes a 1 channel buffer and mixes it to a stereo buffer using Gains. Gains is expected to point to a 2 float long buffer.
* these buffers must have an even number of frames .
* If StartGains and EndGains are provided , this function will interpolate between the two across the buffer .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixMonoTo2ChannelsFast ( const FAlignedFloatBuffer & MonoBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MixMonoTo2ChannelsFast ( const float * RESTRICT MonoBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixMonoTo2ChannelsFast ( const FAlignedFloatBuffer & MonoBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MixMonoTo2ChannelsFast ( const float * RESTRICT MonoBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixMonoTo2ChannelsFast ( const FAlignedFloatBuffer & MonoBuffer , FAlignedFloatBuffer & DestinationBuffer ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MixMonoTo2ChannelsFast ( const float * RESTRICT MonoBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames ) ;
/** Takes a 2 channel buffer and mixes it to an 2 channel interleaved buffer using Gains. Gains is expected to point to a 16 float long buffer.
* Output gains for the left input channel should be the first 8 values in Gains , and Output gains for the right input channel should be rest .
* NumFrames must be a multiple of 4.
* If StartGains and EndGains are provided , this function will interpolate between the two across the buffer .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo2ChannelsFast ( const FAlignedFloatBuffer & SourceBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo2ChannelsFast ( const float * RESTRICT SourceBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo2ChannelsFast ( const FAlignedFloatBuffer & SourceBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo2ChannelsFast ( const float * RESTRICT SourceBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
/** Takes a 4 channel interleaved buffer and applies Gains to it. Gains is expected to point to a 2 float long buffer.
* If StartGains and EndGains are provided , this function will interpolate between the two across the buffer .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Apply4ChannelGain ( FAlignedFloatBuffer & InterleavedBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Apply4ChannelGain ( float * RESTRICT InterleavedBuffer , int32 NumSamples , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Apply4ChannelGain ( FAlignedFloatBuffer & InterleavedBuffer , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Apply4ChannelGain ( float * RESTRICT InterleavedBuffer , int32 NumSamples , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
/** Takes a 1 channel buffer and mixes it to an 8 channel interleaved buffer using Gains. Gains is expected to point to a 8 float long buffer.
* these buffers must have an even number of frames .
* If StartGains and EndGains are provided , this function will interpolate between the two across the buffer .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixMonoTo4ChannelsFast ( const FAlignedFloatBuffer & MonoBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MixMonoTo4ChannelsFast ( const float * RESTRICT MonoBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixMonoTo4ChannelsFast ( const FAlignedFloatBuffer & MonoBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MixMonoTo4ChannelsFast ( const float * RESTRICT MonoBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
/** Takes a 2 channel buffer and mixes it to an 8 channel interleaved buffer using Gains. Gains is expected to point to a 16 float long buffer.
* Output gains for the left input channel should be the first 8 values in Gains , and Output gains for the right input channel should be rest .
* NumFrames must be a multiple of 4.
* If StartGains and EndGains are provided , this function will interpolate between the two across the buffer .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo4ChannelsFast ( const FAlignedFloatBuffer & SourceBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo4ChannelsFast ( const float * RESTRICT SourceBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo4ChannelsFast ( const FAlignedFloatBuffer & SourceBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo4ChannelsFast ( const float * RESTRICT SourceBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
/** Takes a 6 channel interleaved buffer and applies Gains to it. Gains is expected to point to a 2 float long buffer.
* InterleavedBuffer must have an even number of frames .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Apply6ChannelGain ( FAlignedFloatBuffer & InterleavedBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Apply6ChannelGain ( float * RESTRICT InterleavedBuffer , int32 NumSamples , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Apply6ChannelGain ( FAlignedFloatBuffer & InterleavedBuffer , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Apply6ChannelGain ( float * RESTRICT InterleavedBuffer , int32 NumSamples , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
/** Takes a 1 channel buffer and mixes it to an 8 channel interleaved buffer using Gains. Gains is expected to point to a 8 float long buffer.
* these buffers must have an even number of frames .
* If StartGains and EndGains are provided , this function will interpolate between the two across the buffer .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixMonoTo6ChannelsFast ( const FAlignedFloatBuffer & MonoBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MixMonoTo6ChannelsFast ( const float * RESTRICT MonoBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixMonoTo6ChannelsFast ( const FAlignedFloatBuffer & MonoBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MixMonoTo6ChannelsFast ( const float * RESTRICT MonoBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
/** Takes a 2 channel buffer and mixes it to an 8 channel interleaved buffer using Gains. Gains is expected to point to a 16 float long buffer.
* Output gains for the left input channel should be the first 8 values in Gains , and Output gains for the right input channel should be rest .
* NumFrames must be a multiple of 4.
* If StartGains and EndGains are provided , this function will interpolate between the two across the buffer .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo6ChannelsFast ( const FAlignedFloatBuffer & SourceBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo6ChannelsFast ( const float * RESTRICT SourceBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo6ChannelsFast ( const FAlignedFloatBuffer & SourceBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo6ChannelsFast ( const float * RESTRICT SourceBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
/** Takes an 8 channel interleaved buffer and applies Gains to it. Gains is expected to point to an 8 float long buffer. */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Apply8ChannelGain ( FAlignedFloatBuffer & InterleavedBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Apply8ChannelGain ( float * RESTRICT InterleavedBuffer , int32 NumSamples , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Apply8ChannelGain ( FAlignedFloatBuffer & InterleavedBuffer , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Apply8ChannelGain ( float * RESTRICT InterleavedBuffer , int32 NumSamples , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
/** Takes a 1 channel buffer and mixes it to an 8 channel interleaved buffer using Gains. Gains is expected to point to a 8 float long buffer.
* these buffers must have an even number of frames .
* If StartGains and EndGains are provided , this function will interpolate between the two across the buffer .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixMonoTo8ChannelsFast ( const FAlignedFloatBuffer & MonoBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MixMonoTo8ChannelsFast ( const float * RESTRICT MonoBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void MixMonoTo8ChannelsFast ( const FAlignedFloatBuffer & MonoBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void MixMonoTo8ChannelsFast ( const float * RESTRICT MonoBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
/** Takes a 2 channel buffer and mixes it to an 8 channel interleaved buffer using Gains. Gains is expected to point to a 16 float long buffer.
* Output gains for the left input channel should be the first 8 values in Gains , and Output gains for the right input channel should be rest .
* these buffers must have an even number of frames .
* If StartGains and EndGains are provided , this function will interpolate between the two across the buffer .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo8ChannelsFast ( const FAlignedFloatBuffer & SourceBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo8ChannelsFast ( const float * RESTRICT SourceBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo8ChannelsFast ( const FAlignedFloatBuffer & SourceBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void Mix2ChannelsTo8ChannelsFast ( const float * RESTRICT SourceBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
/** This is a generalized operation that uses the channel gain matrix provided in Gains to mix an interleaved source buffer to the interleaved downmix buffer.
* This operation is not explicitly vectorized and will almost always be slower than using one of the functions above .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void DownmixBuffer ( int32 NumSourceChannels , int32 NumDestinationChannels , const FAlignedFloatBuffer & SourceBuffer , FAlignedFloatBuffer & DestinationBuffer , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void DownmixBuffer ( int32 NumSourceChannels , int32 NumDestinationChannels , const float * RESTRICT SourceBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , const float * RESTRICT Gains ) ;
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void DownmixBuffer ( int32 NumSourceChannels , int32 NumDestinationChannels , const FAlignedFloatBuffer & SourceBuffer , FAlignedFloatBuffer & DestinationBuffer , float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2019-08-26 18:35:22 -04:00
SIGNALPROCESSING_API void DownmixBuffer ( int32 NumSourceChannels , int32 NumDestinationChannels , const float * RESTRICT SourceBuffer , float * RESTRICT DestinationBuffer , int32 NumFrames , float * RESTRICT StartGains , const float * RESTRICT EndGains ) ;
2020-02-09 18:57:53 -05:00
/**
* This is similar to DownmixBuffer , except that it sums into DestinationBuffer rather than overwriting it .
*/
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void DownmixAndSumIntoBuffer ( int32 NumSourceChannels , int32 NumDestinationChannels , const FAlignedFloatBuffer & SourceBuffer , FAlignedFloatBuffer & BufferToSumTo , const float * RESTRICT Gains ) ;
2020-02-09 18:57:53 -05:00
SIGNALPROCESSING_API void DownmixAndSumIntoBuffer ( int32 NumSourceChannels , int32 NumDestinationChannels , const float * RESTRICT SourceBuffer , float * RESTRICT BufferToSumTo , int32 NumFrames , const float * RESTRICT Gains ) ;
2019-08-26 18:35:22 -04:00
/** Interleaves samples from two input buffers */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferInterleave2ChannelFast ( const FAlignedFloatBuffer & InBuffer1 , const FAlignedFloatBuffer & InBuffer2 , FAlignedFloatBuffer & OutBuffer ) ;
2019-08-26 18:35:22 -04:00
/** Interleaves samples from two input buffers */
SIGNALPROCESSING_API void BufferInterleave2ChannelFast ( const float * RESTRICT InBuffer1 , const float * RESTRICT InBuffer2 , float * RESTRICT OutBuffer , const int32 InNum ) ;
/** Deinterleaves samples from a 2 channel input buffer */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferDeinterleave2ChannelFast ( const FAlignedFloatBuffer & InBuffer , FAlignedFloatBuffer & OutBuffer1 , FAlignedFloatBuffer & OutBuffer2 ) ;
2019-08-26 18:35:22 -04:00
/** Deinterleaves samples from a 2 channel input buffer */
SIGNALPROCESSING_API void BufferDeinterleave2ChannelFast ( const float * RESTRICT InBuffer , float * RESTRICT OutBuffer1 , float * RESTRICT OutBuffer2 , const int32 InNum ) ;
/** Sums 2 channel interleaved input samples. OutSamples[n] = InSamples[2n] + InSamples[2n + 1] */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferSum2ChannelToMonoFast ( const FAlignedFloatBuffer & InSamples , FAlignedFloatBuffer & OutSamples ) ;
2019-08-26 18:35:22 -04:00
/** Sums 2 channel interleaved input samples. OutSamples[n] = InSamples[2n] + InSamples[2n + 1] */
2019-09-18 14:15:02 -04:00
SIGNALPROCESSING_API void BufferSum2ChannelToMonoFast ( const float * RESTRICT InSamples , float * RESTRICT OutSamples , const int32 InNumFrames ) ;
2019-09-12 13:49:12 -04:00
/** Compute power of complex data. Out[i] = Real[i] * Real[i] + Imaginary[i] * Imaginary[i] */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferComplexToPowerFast ( const FAlignedFloatBuffer & InRealSamples , const FAlignedFloatBuffer & InImaginarySamples , FAlignedFloatBuffer & OutPowerSamples ) ;
2019-09-12 13:49:12 -04:00
/** Compute power of complex data. Out[i] = Real[i] * Real[i] + Imaginary[i] * Imaginary[i] */
2019-09-18 14:15:02 -04:00
SIGNALPROCESSING_API void BufferComplexToPowerFast ( const float * RESTRICT InRealSamples , const float * RESTRICT InImaginarySamples , float * RESTRICT OutPowerSamples , const int32 InNum ) ;
2019-09-12 13:49:12 -04:00
/** Compute magnitude of complex data. Out[i] = Sqrt(Real[i] * Real[i] + Imaginary[i] * Imaginary[i]) */
2020-09-15 13:08:34 -04:00
SIGNALPROCESSING_API void BufferComplexToMagnitudeFast ( const FAlignedFloatBuffer & InRealSamples , const FAlignedFloatBuffer & InImaginarySamples , FAlignedFloatBuffer & OutPowerSamples ) ;
2019-09-12 13:49:12 -04:00
/** Compute magnitude of complex data. Out[i] = Sqrt(Real[i] * Real[i] + Imaginary[i] * Imaginary[i]) */
2019-09-18 14:15:02 -04:00
SIGNALPROCESSING_API void BufferComplexToMagnitudeFast ( const float * RESTRICT InRealSamples , const float * RESTRICT InImaginarySamples , float * RESTRICT OutPowerSamples , const int32 InNum ) ;
2020-02-09 18:57:53 -05:00
/** Class which handles a vectorized interpolation of an entire buffer to the values of a target buffer */
class SIGNALPROCESSING_API FBufferLinearEase
{
public :
FBufferLinearEase ( ) ;
2020-09-15 13:08:34 -04:00
FBufferLinearEase ( const FAlignedFloatBuffer & InSourceValues , const FAlignedFloatBuffer & InTargetValues , int32 InLerpLength ) ;
2020-02-09 18:57:53 -05:00
~ FBufferLinearEase ( ) ;
/** will cache SourceValues ptr and manually update SourceValues on Update() */
2020-09-15 13:08:34 -04:00
void Init ( const FAlignedFloatBuffer & InSourceValues , const FAlignedFloatBuffer & InTargetValues , int32 InLerpLength ) ;
2020-02-09 18:57:53 -05:00
/** Performs Vectorized update of SourceValues float buffer. Returns true if interpolation is complete */
2020-09-15 13:08:34 -04:00
bool Update ( FAlignedFloatBuffer & InSourceValues ) ;
2020-02-09 18:57:53 -05:00
/** Update overloaded to let you jump forward more than a single time-step */
2020-09-15 13:08:34 -04:00
bool Update ( uint32 StepsToJumpForward , FAlignedFloatBuffer & InSourceValues ) ;
2020-02-09 18:57:53 -05:00
/** returns const reference to the deltas buffer for doing interpolation elsewhere */
2020-09-15 13:08:34 -04:00
const FAlignedFloatBuffer & GetDeltaBuffer ( ) ;
2020-02-09 18:57:53 -05:00
private :
int32 BufferLength { 0 } ;
int32 LerpLength { 0 } ;
int32 CurrentLerpStep { 0 } ;
2020-09-15 13:08:34 -04:00
FAlignedFloatBuffer DeltaBuffer ;
2020-02-09 18:57:53 -05:00
} ; // class BufferLerper
2019-08-26 18:35:22 -04:00
}