FMLiveSwitchSoundUtility Class Reference

Sound utility methods. More...

Instance Methods

(instancetype) - init
 

Class Methods

(int) + calculateDataLengthFloatPreciseWithDuration:clockRate:channelCount:
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
(int) + calculateDataLengthFloatPreciseWithDuration:config:
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
(int) + calculateDataLengthFloatWithDuration:clockRate:channelCount:
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
(int) + calculateDataLengthFloatWithDuration:config:
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
(int) + calculateDataLengthFromTimestampDelta:channelCount:
 Calculates a data length in bytes given a timestamp delta and channel count. More...
 
(int) + calculateDataLengthFromTimestampDelta:channelCount:bytesPerSample:
 Calculates a data length in bytes given a timestamp delta, channel count, and number of bytes per sample. More...
 
(int) + calculateDataLengthPreciseWithDuration:clockRate:channelCount:
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
(int) + calculateDataLengthPreciseWithDuration:config:
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
(int) + calculateDataLengthWithDuration:clockRate:channelCount:
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
(int) + calculateDataLengthWithDuration:config:
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
(int) + calculateDurationFloatWithDataLength:clockRate:channelCount:
 Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count. More...
 
(int) + calculateDurationFloatWithDataLength:config:
 Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count. More...
 
(int) + calculateDurationFromSystemTimestampDelta:
 Calculates a duration in milliseconds given a system timestamp delta in ticks. More...
 
(int) + calculateDurationFromTimestampDelta:clockRate:
 Calculates a duration in milliseconds given a timestamp delta and its clock rate. More...
 
(int) + calculateDurationWithDataLength:clockRate:channelCount:
 Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count. More...
 
(int) + calculateDurationWithDataLength:config:
 Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count. More...
 
(int) + calculateOutputLengthForChannelCountWithInputLength:inputChannelCount:outputChannelCount:
 Calculates the length of an output data buffer after conversion from an input to an output channel count. More...
 
(int) + calculateSystemTimestampDeltaFromDuration:
 Calculates a system timestamp delta in ticks given a duration in milliseconds. More...
 
(long long) + calculateSystemTimestampDeltaFromTimestampDelta:clockRate:
 Calculates a system timestamp delta given a timestamp delta and its clock rate. More...
 
(int) + calculateTimestampDeltaFromDataLength:channelCount:
 Calculates a timestamp delta given a data length and channel count. More...
 
(int) + calculateTimestampDeltaFromDataLength:channelCount:bytesPerSample:
 Calculates a timestamp delta given a data length in bytes, channel count, and number of bytes per sample. More...
 
(int) + calculateTimestampDeltaFromDuration:clockRate:
 Calculates a timestamp delta given its clock rate and a duration in milliseconds. More...
 
(long long) + calculateTimestampDeltaFromSystemTimestampDelta:clockRate:
 Calculates a timestamp delta given its clock rate and a system timestamp delta. More...
 
(FMLiveSwitchDataBuffer *) + convertChannelCountWithInput:inputChannelCount:output:outputChannelCount:
 Converts a data buffer to a new channel count. More...
 
(float) + floatFromShort:
 Converts a short value to a floating-point value. More...
 
(FMLiveSwitchDataBuffer *) + monoToStereoWithMono:stereo:
 Converts each sample into two identical samples. More...
 
(short) + readPcmShortWithInput:index:
 Reads a PCM short value from a byte array. More...
 
(short) + shortFromFloat:
 Converts a floating-point value to a short value. More...
 
(FMLiveSwitchSoundUtility *) + soundUtility
 
(FMLiveSwitchDataBuffer *) + stereoToMonoWithStereo:mono:
 Converts each pair of samples into one mixed sample. More...
 
(void) + writePcmShortWithInput:output:index:
 Writes a PCM short value to a byte array. More...
 

Detailed Description

Sound utility methods.

Method Documentation

◆ calculateDataLengthFloatPreciseWithDuration:clockRate:channelCount:

+ (int) calculateDataLengthFloatPreciseWithDuration: (double)  duration
clockRate: (int)  clockRate
channelCount: (int)  channelCount 

Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.

Parameters
durationThe duration in ms.
clockRateThe clock rate.
channelCountThe channel count.

◆ calculateDataLengthFloatPreciseWithDuration:config:

+ (int) calculateDataLengthFloatPreciseWithDuration: (double)  duration
config: (FMLiveSwitchAudioConfig *)  config 

Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.

Parameters
durationThe duration in ms.
configThe configuration.

◆ calculateDataLengthFloatWithDuration:clockRate:channelCount:

+ (int) calculateDataLengthFloatWithDuration: (int)  duration
clockRate: (int)  clockRate
channelCount: (int)  channelCount 

Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.

Parameters
durationThe duration in ms.
clockRateThe clock rate.
channelCountThe channel count.

◆ calculateDataLengthFloatWithDuration:config:

+ (int) calculateDataLengthFloatWithDuration: (int)  duration
config: (FMLiveSwitchAudioConfig *)  config 

Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.

Parameters
durationThe duration in ms.
configThe configuration.

◆ calculateDataLengthFromTimestampDelta:channelCount:

+ (int) calculateDataLengthFromTimestampDelta: (int)  timestampDelta
channelCount: (int)  channelCount 

Calculates a data length in bytes given a timestamp delta and channel count.

Parameters
timestampDeltaThe timestamp delta.
channelCountThe channel count.

◆ calculateDataLengthFromTimestampDelta:channelCount:bytesPerSample:

+ (int) calculateDataLengthFromTimestampDelta: (int)  timestampDelta
channelCount: (int)  channelCount
bytesPerSample: (int)  bytesPerSample 

Calculates a data length in bytes given a timestamp delta, channel count, and number of bytes per sample.

Parameters
timestampDeltaThe timestamp delta.
channelCountThe channel count.
bytesPerSampleThe number of bytes per sample.

◆ calculateDataLengthPreciseWithDuration:clockRate:channelCount:

+ (int) calculateDataLengthPreciseWithDuration: (double)  duration
clockRate: (int)  clockRate
channelCount: (int)  channelCount 

Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.

Parameters
durationThe duration in ms.
clockRateThe clock rate.
channelCountThe channel count.

◆ calculateDataLengthPreciseWithDuration:config:

+ (int) calculateDataLengthPreciseWithDuration: (double)  duration
config: (FMLiveSwitchAudioConfig *)  config 

Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.

Parameters
durationThe duration in ms.
configThe configuration.

◆ calculateDataLengthWithDuration:clockRate:channelCount:

+ (int) calculateDataLengthWithDuration: (int)  duration
clockRate: (int)  clockRate
channelCount: (int)  channelCount 

Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.

Parameters
durationThe duration in ms.
clockRateThe clock rate.
channelCountThe channel count.

◆ calculateDataLengthWithDuration:config:

+ (int) calculateDataLengthWithDuration: (int)  duration
config: (FMLiveSwitchAudioConfig *)  config 

Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count.

Parameters
durationThe duration in ms.
configThe configuration.

◆ calculateDurationFloatWithDataLength:clockRate:channelCount:

+ (int) calculateDurationFloatWithDataLength: (int)  dataLength
clockRate: (int)  clockRate
channelCount: (int)  channelCount 

Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count.

Parameters
dataLengthThe length of the audio chunk.
clockRateThe clock rate.
channelCountThe channel count.

◆ calculateDurationFloatWithDataLength:config:

+ (int) calculateDurationFloatWithDataLength: (int)  dataLength
config: (FMLiveSwitchAudioConfig *)  config 

Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count.

Parameters
dataLengthThe length of the audio chunk.
configThe configuration.

◆ calculateDurationFromSystemTimestampDelta:

+ (int) calculateDurationFromSystemTimestampDelta: (int)  systemTimestampDelta

Calculates a duration in milliseconds given a system timestamp delta in ticks.

Parameters
systemTimestampDeltaThe system timestamp delta.

◆ calculateDurationFromTimestampDelta:clockRate:

+ (int) calculateDurationFromTimestampDelta: (int)  timestampDelta
clockRate: (int)  clockRate 

Calculates a duration in milliseconds given a timestamp delta and its clock rate.

Parameters
timestampDeltaThe timestamp delta.
clockRateThe clock rate.

◆ calculateDurationWithDataLength:clockRate:channelCount:

+ (int) calculateDurationWithDataLength: (int)  dataLength
clockRate: (int)  clockRate
channelCount: (int)  channelCount 

Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count.

Parameters
dataLengthThe length of the audio chunk.
clockRateThe clock rate.
channelCountThe channel count.

◆ calculateDurationWithDataLength:config:

+ (int) calculateDurationWithDataLength: (int)  dataLength
config: (FMLiveSwitchAudioConfig *)  config 

Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count.

Parameters
dataLengthThe length of the audio chunk.
configThe configuration.

◆ calculateOutputLengthForChannelCountWithInputLength:inputChannelCount:outputChannelCount:

+ (int) calculateOutputLengthForChannelCountWithInputLength: (int)  inputLength
inputChannelCount: (int)  inputChannelCount
outputChannelCount: (int)  outputChannelCount 

Calculates the length of an output data buffer after conversion from an input to an output channel count.

Parameters
inputLengthThe input data buffer length.
inputChannelCountThe input channel count.
outputChannelCountThe output channel count.

◆ calculateSystemTimestampDeltaFromDuration:

+ (int) calculateSystemTimestampDeltaFromDuration: (int)  duration

Calculates a system timestamp delta in ticks given a duration in milliseconds.

Parameters
durationThe duration in milliseconds.

◆ calculateSystemTimestampDeltaFromTimestampDelta:clockRate:

+ (long long) calculateSystemTimestampDeltaFromTimestampDelta: (long long)  timestampDelta
clockRate: (int)  clockRate 

Calculates a system timestamp delta given a timestamp delta and its clock rate.

Parameters
timestampDeltaThe timestamp delta.
clockRateThe clock rate.

◆ calculateTimestampDeltaFromDataLength:channelCount:

+ (int) calculateTimestampDeltaFromDataLength: (int)  dataLength
channelCount: (int)  channelCount 

Calculates a timestamp delta given a data length and channel count.

Parameters
dataLengthThe data length in bytes.
channelCountThe channel count.

◆ calculateTimestampDeltaFromDataLength:channelCount:bytesPerSample:

+ (int) calculateTimestampDeltaFromDataLength: (int)  dataLength
channelCount: (int)  channelCount
bytesPerSample: (int)  bytesPerSample 

Calculates a timestamp delta given a data length in bytes, channel count, and number of bytes per sample.

Parameters
dataLengthThe data length in bytes.
channelCountThe channel count.
bytesPerSampleThe number of bytes per sample.

◆ calculateTimestampDeltaFromDuration:clockRate:

+ (int) calculateTimestampDeltaFromDuration: (int)  duration
clockRate: (int)  clockRate 

Calculates a timestamp delta given its clock rate and a duration in milliseconds.

Parameters
durationThe duration in milliseconds.
clockRateThe clock rate.

◆ calculateTimestampDeltaFromSystemTimestampDelta:clockRate:

+ (long long) calculateTimestampDeltaFromSystemTimestampDelta: (long long)  systemTimestampDelta
clockRate: (int)  clockRate 

Calculates a timestamp delta given its clock rate and a system timestamp delta.

Parameters
systemTimestampDeltaThe system timestamp delta.
clockRateThe clock rate.

◆ convertChannelCountWithInput:inputChannelCount:output:outputChannelCount:

+ (FMLiveSwitchDataBuffer*) convertChannelCountWithInput: (FMLiveSwitchDataBuffer *)  input
inputChannelCount: (int)  inputChannelCount
output: (FMLiveSwitchDataBuffer *)  output
outputChannelCount: (int)  outputChannelCount 

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.

Parameters
inputThe input data buffer.
inputChannelCountThe input channel count.
outputThe output data buffer.
outputChannelCountThe output channel count.

◆ floatFromShort:

+ (float) floatFromShort: (short)  value

Converts a short value to a floating-point value.

Parameters
valueThe short value.
Returns
The floating-point value.

◆ init

- (instancetype) init

◆ monoToStereoWithMono:stereo:

+ (FMLiveSwitchDataBuffer*) monoToStereoWithMono: (FMLiveSwitchDataBuffer *)  mono
stereo: (FMLiveSwitchDataBuffer *)  stereo 

Converts each sample into two identical samples.

Returns
A new FMLiveSwitchDataBufferPooled or null.

◆ readPcmShortWithInput:index:

+ (short) readPcmShortWithInput: (NSMutableData *)  input
index: (int)  index 

Reads a PCM short value from a byte array.

Parameters
inputThe source byte array.
indexThe source index in the byte array.
Returns
Short value. This is an int for performance reasons but can be safely cast to a short as needed.

◆ shortFromFloat:

+ (short) shortFromFloat: (float)  value

Converts a floating-point value to a short value.

Parameters
valueThe floating-point value.
Returns
The short value.

◆ soundUtility

+ (FMLiveSwitchSoundUtility*) soundUtility

◆ stereoToMonoWithStereo:mono:

+ (FMLiveSwitchDataBuffer*) stereoToMonoWithStereo: (FMLiveSwitchDataBuffer *)  stereo
mono: (FMLiveSwitchDataBuffer *)  mono 

Converts each pair of samples into one mixed sample.

Returns
A new FMLiveSwitchDataBufferPooled or null.

◆ writePcmShortWithInput:output:index:

+ (void) writePcmShortWithInput: (short)  input
output: (NSMutableData *)  output
index: (int)  index 

Writes a PCM short value to a byte array.

Parameters
inputThe short value to write.
outputThe target byte array.
indexThe target index in the byte array.