net.beadsproject.beads.core
Class AudioUtils

java.lang.Object
  extended by net.beadsproject.beads.core.AudioUtils

public final class AudioUtils
extends java.lang.Object

AudioUtils provides basic conversion of buffers of audio data between different formats, interleaving, and some other miscellaneous audio functions.

Author:
ollie

Field Summary
static java.util.Random rng
          A handy random number generator.
 
Constructor Summary
AudioUtils()
           
 
Method Summary
static void byteToFloat(float[] out, byte[] in, boolean bigEndian)
          Converts a buffer of bytes to a buffer of floats with a given byte order.
static void deinterleave(float[] source, int nChannels, int nFrames, float[][] result)
          De-interleave an interleaved buffer of floats to form a 2D array of floats of size nChannels x nFrames.
static double fastPow(double a, double b)
          Does a freaky shortcut for calculating pow, faster but less accurate than regular Math.pow().
static void floatToByte(byte[] out, float[] in, boolean bigEndian)
          Converts a buffer of floats to a buffer of bytes with a given byte order.
static void floatToShort(short[] out, float[] in)
          Converts a buffer of floats to a buffer of shorts.
static void interleave(float[][] source, int nChannels, int nFrames, float[] result)
          Interleave a 2D array of floats of size nChannels x nFrames to form a single interleaved buffer of floats.
static void shortToFloat(float[] out, short[] in)
          Converts a buffer of shorts to a buffer of floats.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rng

public static java.util.Random rng
A handy random number generator.

Constructor Detail

AudioUtils

public AudioUtils()
Method Detail

shortToFloat

public static final void shortToFloat(float[] out,
                                      short[] in)
Converts a buffer of shorts to a buffer of floats.

Parameters:
out - buffer of floats.
in - buffer of shorts.

floatToShort

public static final void floatToShort(short[] out,
                                      float[] in)
Converts a buffer of floats to a buffer of shorts.

Parameters:
out - buffer of shorts.
in - buffer of floats.

floatToByte

public static final void floatToByte(byte[] out,
                                     float[] in,
                                     boolean bigEndian)
Converts a buffer of floats to a buffer of bytes with a given byte order.

Parameters:
out - buffer of bytes.
in - buffer of floats.
bigEndian - true for big endian byte order, false otherwise.

byteToFloat

public static final void byteToFloat(float[] out,
                                     byte[] in,
                                     boolean bigEndian)
Converts a buffer of bytes to a buffer of floats with a given byte order.

Parameters:
out - buffer of floats.
in - buffer of bytes.
bigEndian - true for big endian byte order, false otherwise.

deinterleave

public static final void deinterleave(float[] source,
                                      int nChannels,
                                      int nFrames,
                                      float[][] result)
De-interleave an interleaved buffer of floats to form a 2D array of floats of size nChannels x nFrames.

Parameters:
source - interleaved buffer of floats.
nChannels - first dimension of resulting 2D array.
nFrames - second dimension of resulting 2D array.
result - the result

interleave

public static final void interleave(float[][] source,
                                    int nChannels,
                                    int nFrames,
                                    float[] result)
Interleave a 2D array of floats of size nChannels x nFrames to form a single interleaved buffer of floats.

Parameters:
source - 2D array of floats.
nChannels - first dimension of input 2D array.
nFrames - second dimension of input 2D array.
result - the result

fastPow

public static double fastPow(double a,
                             double b)
Does a freaky shortcut for calculating pow, faster but less accurate than regular Math.pow().

CREDIT: this method is copied directly from http://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/

Parameters:
a - the base.
b - the exponent.
Returns:
the result