libgdx API

com.badlogic.gdx.audio.analysis
Class AudioTools

java.lang.Object
  extended by com.badlogic.gdx.audio.analysis.AudioTools

public class AudioTools
extends java.lang.Object

Class holding various static native methods for processing audio data.

Author:
mzechner

Constructor Summary
AudioTools()
           
 
Method Summary
static java.nio.FloatBuffer allocateFloatBuffer(int numSamples, int numChannels)
          Allcoates a direct buffer for the given number of samples and channels.
static java.nio.ShortBuffer allocateShortBuffer(int numSamples, int numChannels)
          Allcoates a direct buffer for the given number of samples and channels.
static void convertToFloat(java.nio.ShortBuffer source, java.nio.FloatBuffer target, int numSamples)
          Converts the 16-bit signed PCM data given in source to 32-bit float PCM in the range [-1,1].
static void convertToMono(java.nio.FloatBuffer source, java.nio.FloatBuffer target, int numSamples)
          Converts the samples in source which are assumed to be interleaved left/right stereo samples to mono, writting the converted samples to target.
static void convertToMono(java.nio.ShortBuffer source, java.nio.ShortBuffer target, int numSamples)
          Converts the samples in source which are assumed to be interleaved left/right stereo samples to mono, writting the converted samples to target.
static void convertToShort(java.nio.FloatBuffer source, java.nio.ShortBuffer target, int numSamples)
          Converts the 32-bit float PCM data given in source to 16-bit signed PCM in the range [-1,1].
static float spectralFlux(java.nio.FloatBuffer spectrumA, java.nio.FloatBuffer spectrumB, int numSamples)
          Calculates the spectral flux between the two given spectra.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AudioTools

public AudioTools()
Method Detail

convertToFloat

public static void convertToFloat(java.nio.ShortBuffer source,
                                  java.nio.FloatBuffer target,
                                  int numSamples)
Converts the 16-bit signed PCM data given in source to 32-bit float PCM in the range [-1,1]. It is assumed that there's numSamples elements available in both buffers. Source and target get read and written to from offset 0. All buffers must be direct.

Parameters:
source - the source buffer
target - the target buffer
numSamples - the number of samples

convertToShort

public static void convertToShort(java.nio.FloatBuffer source,
                                  java.nio.ShortBuffer target,
                                  int numSamples)
Converts the 32-bit float PCM data given in source to 16-bit signed PCM in the range [-1,1]. It is assumed that there's numSamples elements available in both buffers. Source and target get read and written to from offset 0. All buffers must be direct.

Parameters:
source - the source buffer
target - the target buffer
numSamples - the number of samples

convertToMono

public static void convertToMono(java.nio.ShortBuffer source,
                                 java.nio.ShortBuffer target,
                                 int numSamples)
Converts the samples in source which are assumed to be interleaved left/right stereo samples to mono, writting the converted samples to target. Source is assumed to hold numSamples samples, target should hold numSamples / 2. Samples are read and written from position 0 up to numSamples. All buffers must be direct.

Parameters:
source - the source buffer
target - the target buffer
numSamples - the number of samples to convert (target will have numSamples /2 filled after a call to this)

convertToMono

public static void convertToMono(java.nio.FloatBuffer source,
                                 java.nio.FloatBuffer target,
                                 int numSamples)
Converts the samples in source which are assumed to be interleaved left/right stereo samples to mono, writting the converted samples to target. Source is assumed to hold numSamples samples, target should hold numSamples / 2. Samples are read and written from position 0 up to numSamples. All buffers must be direct.

Parameters:
source - the source buffer
target - the target buffer
numSamples - the number of samples to convert (target will have numSamples /2 filled after a call to this)

spectralFlux

public static float spectralFlux(java.nio.FloatBuffer spectrumA,
                                 java.nio.FloatBuffer spectrumB,
                                 int numSamples)
Calculates the spectral flux between the two given spectra. Both buffers are assumed to hold numSamples elements. Spectrum B is the current spectrum spectrum A the last spectrum. All buffers must be direct.

Parameters:
spectrumA - the first spectrum
spectrumB - the second spectrum
numSamples - the number of elements
Returns:
the spectral flux

allocateFloatBuffer

public static java.nio.FloatBuffer allocateFloatBuffer(int numSamples,
                                                       int numChannels)
Allcoates a direct buffer for the given number of samples and channels. The final numer of samples is numSamples * numChannels.

Parameters:
numSamples - the number of samples
numChannels - the number of channels
Returns:
the direct buffer

allocateShortBuffer

public static java.nio.ShortBuffer allocateShortBuffer(int numSamples,
                                                       int numChannels)
Allcoates a direct buffer for the given number of samples and channels. The final numer of samples is numSamples * numChannels.

Parameters:
numSamples - the number of samples
numChannels - the number of channels
Returns:
the direct buffer

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)