ddf.minim
Class MAudioBuffer

java.lang.Object
  extended byddf.minim.MAudioBuffer
All Implemented Interfaces:
AudioBuffer

public class MAudioBuffer
extends java.lang.Object
implements AudioBuffer

MAudioBuffer encapsulates a sample buffer of floats. All Minim classes that give you access to audio samples do so with an MAudioBuffer. The underlying array is not immutable and this class has a number of methods for reading and writing to that array. It is even possible to be given a direct handle on the array to process it as you wish.

Author:
Damien Di Fede

Constructor Summary
MAudioBuffer(int bufferSize)
          Constructs and MAudioBuffer that is bufferSize samples long.
 
Method Summary
 void clear()
          Sets all of the values in this buffer to zero.
 float get(int i)
          Gets the ith sample in the buffer.
 float level()
          Gets the current level of the buffer.
 void mix(float[] b1, float[] b2)
          Mixes the two float arrays and puts the result in this buffer.
 void mix(MAudioBuffer b1, MAudioBuffer b2)
          Mixes the two AudioBuffers and puts the result in this buffer.
 void set(float[] buffer)
          Copies the values in buffer into this buffer.
 void set(int i, float v)
          Sets the ith sample to v.
 void set(MAudioBuffer buffer)
          Copies the values in buffer into this buffer.
 int size()
          Returns the length of the buffer.
 float[] toArray()
          Returns the samples in the buffer in a new float array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MAudioBuffer

public MAudioBuffer(int bufferSize)
Constructs and MAudioBuffer that is bufferSize samples long.

Parameters:
bufferSize - the size of the buffer
Method Detail

size

public int size()
Description copied from interface: AudioBuffer
Returns the length of the buffer.

Specified by:
size in interface AudioBuffer
Returns:
the length of the underlying float array

get

public float get(int i)
Description copied from interface: AudioBuffer
Gets the ith sample in the buffer. This method does not do bounds checking, so it may throw an exception.

Specified by:
get in interface AudioBuffer
Parameters:
i - the index of the sample you want to get
Returns:
the ith sample

set

public void set(int i,
                float v)
Sets the ith sample to v.

Parameters:
i - the index of the value you want to set
v - the value to set it to

set

public void set(float[] buffer)
Copies the values in buffer into this buffer. If buffer is not the same length as the float array an error will be reported and nothing will be copied.

Parameters:
buffer - the float array to copy

set

public void set(MAudioBuffer buffer)
Copies the values in buffer into this buffer. If buffer is not the same length as the float array an error will be reported and nothing will be copied.

Parameters:
buffer - the MAudioBuffer to copy

mix

public void mix(float[] b1,
                float[] b2)
Mixes the two float arrays and puts the result in this buffer. The passed arrays must be the same length as this buffer. If they are not, an error will be reported and nothing will be done. The mixing function is:

samples[i] = (b1[i] + b2[i]) / 2

Parameters:
b1 - the first buffer
b2 - the second buffer

mix

public void mix(MAudioBuffer b1,
                MAudioBuffer b2)
Mixes the two AudioBuffers and puts the result in this buffer. The passed buffers must be the same length as the underlying float array. If they are not, an error will be reported and nothing will be done. The mixing function is:

samples[i] = (b1[i] + b2[i]) / 2

Parameters:
b1 - the first buffer
b2 - the second buffer

clear

public void clear()
Sets all of the values in this buffer to zero.


level

public float level()
Description copied from interface: AudioBuffer
Gets the current level of the buffer. It is calculated as the root-mean-squared of all the samples in the buffer.

Specified by:
level in interface AudioBuffer
Returns:
the RMS amplitude of the buffer

toArray

public float[] toArray()
Description copied from interface: AudioBuffer
Returns the samples in the buffer in a new float array.

Specified by:
toArray in interface AudioBuffer
Returns:
a new float array containing the buffer's samples