fm.liveswitch.SoundUtility Class Reference

Sound utility methods. More...

Public Member Functions

 SoundUtility ()
 

Static Public Member Functions

static int calculateDataLength (int duration, int clockRate, int channelCount)
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
static int calculateDataLength (int duration, fm.liveswitch.AudioConfig config)
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
static int calculateDataLengthFloat (int duration, int clockRate, int channelCount)
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
static int calculateDataLengthFloat (int duration, fm.liveswitch.AudioConfig config)
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
static int calculateDataLengthFloatPrecise (double duration, int clockRate, int channelCount)
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
static int calculateDataLengthFloatPrecise (double duration, fm.liveswitch.AudioConfig config)
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
static int calculateDataLengthFromTimestampDelta (int timestampDelta, int channelCount)
 Calculates a data length in bytes given a timestamp delta and channel count. More...
 
static int calculateDataLengthFromTimestampDelta (int timestampDelta, int channelCount, int bytesPerSample)
 Calculates a data length in bytes given a timestamp delta, channel count, and number of bytes per sample. More...
 
static int calculateDataLengthPrecise (double duration, int clockRate, int channelCount)
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
static int calculateDataLengthPrecise (double duration, fm.liveswitch.AudioConfig config)
 Calculates the number of bytes in a given audio chunk given its duration (ms), clock rate, and channel count. More...
 
static int calculateDuration (int dataLength, int clockRate, int channelCount)
 Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count. More...
 
static int calculateDuration (int dataLength, fm.liveswitch.AudioConfig config)
 Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count. More...
 
static int calculateDurationFloat (int dataLength, int clockRate, int channelCount)
 Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count. More...
 
static int calculateDurationFloat (int dataLength, fm.liveswitch.AudioConfig config)
 Calculates the duration of an audio chunk given its data length (the number of bytes), clock rate, and channel count. More...
 
static int calculateDurationFromSystemTimestampDelta (int systemTimestampDelta)
 Calculates a duration in milliseconds given a system timestamp delta in ticks. More...
 
static int calculateDurationFromTimestampDelta (int timestampDelta, int clockRate)
 Calculates a duration in milliseconds given a timestamp delta and its clock rate. More...
 
static int calculateOutputLengthForChannelCount (int inputLength, int inputChannelCount, int outputChannelCount)
 Calculates the length of an output data buffer after conversion from an input to an output channel count. More...
 
static int calculateSystemTimestampDeltaFromDuration (int duration)
 Calculates a system timestamp delta in ticks given a duration in milliseconds. More...
 
static long calculateSystemTimestampDeltaFromTimestampDelta (long timestampDelta, int clockRate)
 Calculates a system timestamp delta given a timestamp delta and its clock rate. More...
 
static int calculateTimestampDeltaFromDataLength (int dataLength, int channelCount)
 Calculates a timestamp delta given a data length and channel count. More...
 
static int calculateTimestampDeltaFromDataLength (int dataLength, int channelCount, int bytesPerSample)
 Calculates a timestamp delta given a data length in bytes, channel count, and number of bytes per sample. More...
 
static int calculateTimestampDeltaFromDuration (int duration, int clockRate)
 Calculates a timestamp delta given its clock rate and a duration in milliseconds. More...
 
static long calculateTimestampDeltaFromSystemTimestampDelta (long systemTimestampDelta, int clockRate)
 Calculates a timestamp delta given its clock rate and a system timestamp delta. More...
 
static fm.liveswitch.DataBuffer convertChannelCount (fm.liveswitch.DataBuffer input, int inputChannelCount, fm.liveswitch.DataBuffer output, int outputChannelCount)
 Converts a data buffer to a new channel count. More...
 
static float floatFromShort (short value)
 Converts a short value to a floating-point value. More...
 
static fm.liveswitch.DataBuffer monoToStereo (fm.liveswitch.DataBuffer mono, fm.liveswitch.DataBuffer stereo)
 Converts each sample into two identical samples. More...
 
static short readPcmShort (byte[] input, int index)
 Reads a PCM short value from a byte array. More...
 
static short shortFromFloat (float value)
 Converts a floating-point value to a short value. More...
 
static fm.liveswitch.DataBuffer stereoToMono (fm.liveswitch.DataBuffer stereo, fm.liveswitch.DataBuffer mono)
 Converts each pair of samples into one mixed sample. More...
 
static void writePcmShort (short input, byte[] output, int index)
 Writes a PCM short value to a byte array. More...
 

Detailed Description

Sound utility methods.

Constructor & Destructor Documentation

◆ SoundUtility()

fm.liveswitch.SoundUtility.SoundUtility ( )

Member Function Documentation

◆ calculateDataLength() [1/2]

static int fm.liveswitch.SoundUtility.calculateDataLength ( int  duration,
fm.liveswitch.AudioConfig  config 
)
static

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.

◆ calculateDataLength() [2/2]

static int fm.liveswitch.SoundUtility.calculateDataLength ( int  duration,
int  clockRate,
int  channelCount 
)
static

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.

◆ calculateDataLengthFloat() [1/2]

static int fm.liveswitch.SoundUtility.calculateDataLengthFloat ( int  duration,
fm.liveswitch.AudioConfig  config 
)
static

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.

◆ calculateDataLengthFloat() [2/2]

static int fm.liveswitch.SoundUtility.calculateDataLengthFloat ( int  duration,
int  clockRate,
int  channelCount 
)
static

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.

◆ calculateDataLengthFloatPrecise() [1/2]

static int fm.liveswitch.SoundUtility.calculateDataLengthFloatPrecise ( double  duration,
fm.liveswitch.AudioConfig  config 
)
static

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.

◆ calculateDataLengthFloatPrecise() [2/2]

static int fm.liveswitch.SoundUtility.calculateDataLengthFloatPrecise ( double  duration,
int  clockRate,
int  channelCount 
)
static

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.

◆ calculateDataLengthFromTimestampDelta() [1/2]

static int fm.liveswitch.SoundUtility.calculateDataLengthFromTimestampDelta ( int  timestampDelta,
int  channelCount 
)
static

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

Parameters
timestampDeltaThe timestamp delta.
channelCountThe channel count.

◆ calculateDataLengthFromTimestampDelta() [2/2]

static int fm.liveswitch.SoundUtility.calculateDataLengthFromTimestampDelta ( int  timestampDelta,
int  channelCount,
int  bytesPerSample 
)
static

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.

◆ calculateDataLengthPrecise() [1/2]

static int fm.liveswitch.SoundUtility.calculateDataLengthPrecise ( double  duration,
fm.liveswitch.AudioConfig  config 
)
static

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.

◆ calculateDataLengthPrecise() [2/2]

static int fm.liveswitch.SoundUtility.calculateDataLengthPrecise ( double  duration,
int  clockRate,
int  channelCount 
)
static

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.

◆ calculateDuration() [1/2]

static int fm.liveswitch.SoundUtility.calculateDuration ( int  dataLength,
fm.liveswitch.AudioConfig  config 
)
static

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.

◆ calculateDuration() [2/2]

static int fm.liveswitch.SoundUtility.calculateDuration ( int  dataLength,
int  clockRate,
int  channelCount 
)
static

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.

◆ calculateDurationFloat() [1/2]

static int fm.liveswitch.SoundUtility.calculateDurationFloat ( int  dataLength,
fm.liveswitch.AudioConfig  config 
)
static

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.

◆ calculateDurationFloat() [2/2]

static int fm.liveswitch.SoundUtility.calculateDurationFloat ( int  dataLength,
int  clockRate,
int  channelCount 
)
static

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.

◆ calculateDurationFromSystemTimestampDelta()

static int fm.liveswitch.SoundUtility.calculateDurationFromSystemTimestampDelta ( int  systemTimestampDelta)
static

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

Parameters
systemTimestampDeltaThe system timestamp delta.

◆ calculateDurationFromTimestampDelta()

static int fm.liveswitch.SoundUtility.calculateDurationFromTimestampDelta ( int  timestampDelta,
int  clockRate 
)
static

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

Parameters
timestampDeltaThe timestamp delta.
clockRateThe clock rate.

◆ calculateOutputLengthForChannelCount()

static int fm.liveswitch.SoundUtility.calculateOutputLengthForChannelCount ( int  inputLength,
int  inputChannelCount,
int  outputChannelCount 
)
static

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()

static int fm.liveswitch.SoundUtility.calculateSystemTimestampDeltaFromDuration ( int  duration)
static

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

Parameters
durationThe duration in milliseconds.

◆ calculateSystemTimestampDeltaFromTimestampDelta()

static long fm.liveswitch.SoundUtility.calculateSystemTimestampDeltaFromTimestampDelta ( long  timestampDelta,
int  clockRate 
)
static

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

Parameters
timestampDeltaThe timestamp delta.
clockRateThe clock rate.

◆ calculateTimestampDeltaFromDataLength() [1/2]

static int fm.liveswitch.SoundUtility.calculateTimestampDeltaFromDataLength ( int  dataLength,
int  channelCount 
)
static

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

Parameters
dataLengthThe data length in bytes.
channelCountThe channel count.

◆ calculateTimestampDeltaFromDataLength() [2/2]

static int fm.liveswitch.SoundUtility.calculateTimestampDeltaFromDataLength ( int  dataLength,
int  channelCount,
int  bytesPerSample 
)
static

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()

static int fm.liveswitch.SoundUtility.calculateTimestampDeltaFromDuration ( int  duration,
int  clockRate 
)
static

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

Parameters
durationThe duration in milliseconds.
clockRateThe clock rate.

◆ calculateTimestampDeltaFromSystemTimestampDelta()

static long fm.liveswitch.SoundUtility.calculateTimestampDeltaFromSystemTimestampDelta ( long  systemTimestampDelta,
int  clockRate 
)
static

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

Parameters
systemTimestampDeltaThe system timestamp delta.
clockRateThe clock rate.

◆ convertChannelCount()

static fm.liveswitch.DataBuffer fm.liveswitch.SoundUtility.convertChannelCount ( fm.liveswitch.DataBuffer  input,
int  inputChannelCount,
fm.liveswitch.DataBuffer  output,
int  outputChannelCount 
)
static

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()

static float fm.liveswitch.SoundUtility.floatFromShort ( short  value)
static

Converts a short value to a floating-point value.

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

◆ monoToStereo()

static fm.liveswitch.DataBuffer fm.liveswitch.SoundUtility.monoToStereo ( fm.liveswitch.DataBuffer  mono,
fm.liveswitch.DataBuffer  stereo 
)
static

Converts each sample into two identical samples.

Returns
A new fm.liveswitch.DataBufferPooled or
null
.

◆ readPcmShort()

static short fm.liveswitch.SoundUtility.readPcmShort ( byte[]  input,
int  index 
)
static

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()

static short fm.liveswitch.SoundUtility.shortFromFloat ( float  value)
static

Converts a floating-point value to a short value.

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

◆ stereoToMono()

static fm.liveswitch.DataBuffer fm.liveswitch.SoundUtility.stereoToMono ( fm.liveswitch.DataBuffer  stereo,
fm.liveswitch.DataBuffer  mono 
)
static

Converts each pair of samples into one mixed sample.

Returns
A new fm.liveswitch.DataBufferPooled or
null
.

◆ writePcmShort()

static void fm.liveswitch.SoundUtility.writePcmShort ( short  input,
byte[]  output,
int  index 
)
static

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.