Class SoundUtility
Sound utility methods.
Inheritance
Namespace: FM.LiveSwitch
Assembly: FM.LiveSwitch.dll
Syntax
public class SoundUtility : object
Methods
CalculateDataLength(Int32, AudioConfig)
Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.
Declaration
public static int CalculateDataLength(int duration, AudioConfig config)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | duration | The duration in ms. |
AudioConfig | config | The configuration. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDataLength(Int32, Int32, Int32)
Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.
Declaration
public static int CalculateDataLength(int duration, int clockRate, int channelCount)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | duration | The duration in ms. |
System.Int32 | clockRate | The clock rate. |
System.Int32 | channelCount | The channel count. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDataLengthFloat(Int32, AudioConfig)
Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.
Declaration
public static int CalculateDataLengthFloat(int duration, AudioConfig config)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | duration | The duration in ms. |
AudioConfig | config | The configuration. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDataLengthFloat(Int32, Int32, Int32)
Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.
Declaration
public static int CalculateDataLengthFloat(int duration, int clockRate, int channelCount)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | duration | The duration in ms. |
System.Int32 | clockRate | The clock rate. |
System.Int32 | channelCount | The channel count. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDataLengthFloatPrecise(Double, AudioConfig)
Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.
Declaration
public static int CalculateDataLengthFloatPrecise(double duration, AudioConfig config)
Parameters
Type | Name | Description |
---|---|---|
System.Double | duration | The duration in ms. |
AudioConfig | config | The configuration. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDataLengthFloatPrecise(Double, Int32, Int32)
Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.
Declaration
public static int CalculateDataLengthFloatPrecise(double duration, int clockRate, int channelCount)
Parameters
Type | Name | Description |
---|---|---|
System.Double | duration | The duration in ms. |
System.Int32 | clockRate | The clock rate. |
System.Int32 | channelCount | The channel count. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDataLengthFromTimestampDelta(Int32, Int32)
Calculates a data length in bytes given a timestamp delta and channel count.
Declaration
public static int CalculateDataLengthFromTimestampDelta(int timestampDelta, int channelCount)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | timestampDelta | The timestamp delta. |
System.Int32 | channelCount | The channel count. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDataLengthFromTimestampDelta(Int32, Int32, Int32)
Calculates a data length in bytes given a timestamp delta, channel count, and number of bytes per sample.
Declaration
public static int CalculateDataLengthFromTimestampDelta(int timestampDelta, int channelCount, int bytesPerSample)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | timestampDelta | The timestamp delta. |
System.Int32 | channelCount | The channel count. |
System.Int32 | bytesPerSample | The number of bytes per sample. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDataLengthPrecise(Double, AudioConfig)
Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.
Declaration
public static int CalculateDataLengthPrecise(double duration, AudioConfig config)
Parameters
Type | Name | Description |
---|---|---|
System.Double | duration | The duration in ms. |
AudioConfig | config | The configuration. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDataLengthPrecise(Double, Int32, Int32)
Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.
Declaration
public static int CalculateDataLengthPrecise(double duration, int clockRate, int channelCount)
Parameters
Type | Name | Description |
---|---|---|
System.Double | duration | The duration in ms. |
System.Int32 | clockRate | The clock rate. |
System.Int32 | channelCount | The channel count. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDuration(Int32, AudioConfig)
Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count.
Declaration
public static int CalculateDuration(int dataLength, AudioConfig config)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dataLength | The length of the audio chunk. |
AudioConfig | config | The configuration. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDuration(Int32, Int32, Int32)
Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count.
Declaration
public static int CalculateDuration(int dataLength, int clockRate, int channelCount)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dataLength | The length of the audio chunk. |
System.Int32 | clockRate | The clock rate. |
System.Int32 | channelCount | The channel count. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDurationFloat(Int32, AudioConfig)
Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count.
Declaration
public static int CalculateDurationFloat(int dataLength, AudioConfig config)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dataLength | The length of the audio chunk. |
AudioConfig | config | The configuration. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDurationFloat(Int32, Int32, Int32)
Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count.
Declaration
public static int CalculateDurationFloat(int dataLength, int clockRate, int channelCount)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dataLength | The length of the audio chunk. |
System.Int32 | clockRate | The clock rate. |
System.Int32 | channelCount | The channel count. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDurationFromSystemTimestampDelta(Int32)
Calculates a duration in milliseconds given a system timestamp delta in ticks.
Declaration
public static int CalculateDurationFromSystemTimestampDelta(int systemTimestampDelta)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | systemTimestampDelta | The system timestamp delta. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateDurationFromTimestampDelta(Int32, Int32)
Calculates a duration in milliseconds given a timestamp delta and its clock rate.
Declaration
public static int CalculateDurationFromTimestampDelta(int timestampDelta, int clockRate)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | timestampDelta | The timestamp delta. |
System.Int32 | clockRate | The clock rate. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateOutputLengthForChannelCount(Int32, Int32, Int32)
Calculates the length of an output data buffer after conversion from an input to an output channel count.
Declaration
public static int CalculateOutputLengthForChannelCount(int inputLength, int inputChannelCount, int outputChannelCount)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | inputLength | The input data buffer length. |
System.Int32 | inputChannelCount | The input channel count. |
System.Int32 | outputChannelCount | The output channel count. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateSystemTimestampDeltaFromDuration(Int32)
Calculates a system timestamp delta in ticks given a duration in milliseconds.
Declaration
public static int CalculateSystemTimestampDeltaFromDuration(int duration)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | duration | The duration in milliseconds. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateSystemTimestampDeltaFromTimestampDelta(Int64, Int32)
Calculates a system timestamp delta given a timestamp delta and its clock rate.
Declaration
public static long CalculateSystemTimestampDeltaFromTimestampDelta(long timestampDelta, int clockRate)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | timestampDelta | The timestamp delta. |
System.Int32 | clockRate | The clock rate. |
Returns
Type | Description |
---|---|
System.Int64 |
CalculateTimestampDeltaFromDataLength(Int32, Int32)
Calculates a timestamp delta given a data length and channel count.
Declaration
public static int CalculateTimestampDeltaFromDataLength(int dataLength, int channelCount)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dataLength | The data length in bytes. |
System.Int32 | channelCount | The channel count. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateTimestampDeltaFromDataLength(Int32, Int32, Int32)
Calculates a timestamp delta given a data length in bytes, channel count, and number of bytes per sample.
Declaration
public static int CalculateTimestampDeltaFromDataLength(int dataLength, int channelCount, int bytesPerSample)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dataLength | The data length in bytes. |
System.Int32 | channelCount | The channel count. |
System.Int32 | bytesPerSample | The number of bytes per sample. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateTimestampDeltaFromDuration(Int32, Int32)
Calculates a timestamp delta given its clock rate and a duration in milliseconds.
Declaration
public static int CalculateTimestampDeltaFromDuration(int duration, int clockRate)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | duration | The duration in milliseconds. |
System.Int32 | clockRate | The clock rate. |
Returns
Type | Description |
---|---|
System.Int32 |
CalculateTimestampDeltaFromSystemTimestampDelta(Int64, Int32)
Calculates a timestamp delta given its clock rate and a system timestamp delta.
Declaration
public static long CalculateTimestampDeltaFromSystemTimestampDelta(long systemTimestampDelta, int clockRate)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | systemTimestampDelta | The system timestamp delta. |
System.Int32 | clockRate | The clock rate. |
Returns
Type | Description |
---|---|
System.Int64 |
ConvertChannelCount(DataBuffer, Int32, DataBuffer, Int32)
Converts a data buffer to a new channel count. The input data buffer length must be a multiple of the input frame size. If the input channel count is greater than the output channel count, the input channel count must divide evenly into the output channel count, and vice versa if the output channel count is greater than the input channel count.
Declaration
public static DataBuffer ConvertChannelCount(DataBuffer input, int inputChannelCount, DataBuffer output, int outputChannelCount)
Parameters
Type | Name | Description |
---|---|---|
DataBuffer | input | The input data buffer. |
System.Int32 | inputChannelCount | The input channel count. |
DataBuffer | output | The output data buffer. |
System.Int32 | outputChannelCount | The output channel count. |
Returns
Type | Description |
---|---|
DataBuffer |
FloatFromShort(Int16)
Converts a short value to a floating-point value.
Declaration
public static float FloatFromShort(short value)
Parameters
Type | Name | Description |
---|---|---|
System.Int16 | value | The short value. |
Returns
Type | Description |
---|---|
System.Single | The floating-point value. |
MonoToStereo(DataBuffer, DataBuffer)
Converts each sample into two identical samples.
Declaration
public static DataBuffer MonoToStereo(DataBuffer mono, DataBuffer stereo)
Parameters
Type | Name | Description |
---|---|---|
DataBuffer | mono | |
DataBuffer | stereo |
Returns
Type | Description |
---|---|
DataBuffer | A new FM.LiveSwitch.DataBufferPooled or |
ReadPcmFloat(Byte[], Int32)
Reads a PCM float value from a byte array.
Declaration
public static float ReadPcmFloat(byte[] input, int index)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | input | The source byte array. |
System.Int32 | index | The source index in the byte array. |
Returns
Type | Description |
---|---|
System.Single | Float value. |
ReadPcmShort(Byte[], Int32)
Reads a PCM short value from a byte array.
Declaration
public static short ReadPcmShort(byte[] input, int index)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | input | The source byte array. |
System.Int32 | index | The source index in the byte array. |
Returns
Type | Description |
---|---|
System.Int16 | Short value. This is an int for performance reasons but can be safely cast to a short as needed. |
ShortFromFloat(Single)
Converts a floating-point value to a short value.
Declaration
public static short ShortFromFloat(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The floating-point value. |
Returns
Type | Description |
---|---|
System.Int16 | The short value. |
StereoToMono(DataBuffer, DataBuffer)
Converts each pair of samples into one mixed sample.
Declaration
public static DataBuffer StereoToMono(DataBuffer stereo, DataBuffer mono)
Parameters
Type | Name | Description |
---|---|---|
DataBuffer | stereo | |
DataBuffer | mono |
Returns
Type | Description |
---|---|
DataBuffer | A new FM.LiveSwitch.DataBufferPooled or |
WritePcmShort(Int16, Byte[], Int32)
Writes a PCM short value to a byte array.
Declaration
public static void WritePcmShort(short input, byte[] output, int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int16 | input | The short value to write. |
System.Byte[] | output | The target byte array. |
System.Int32 | index | The target index in the byte array. |