Class PcmSoundSource

java.lang.Object
de.pottgames.tuningfork.SoundSource
de.pottgames.tuningfork.PcmSoundSource
All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable

public class PcmSoundSource extends SoundSource implements com.badlogic.gdx.utils.Disposable
A low level sound source class that can be fed with raw pcm data in a real-time fashion.
  • Constructor Details

    • PcmSoundSource

      public PcmSoundSource(int sampleRate, PcmFormat pcmFormat)
      Creates a new PcmSoundSource with the given specs.
      Parameters:
      sampleRate - the sample rate
      pcmFormat - the pcm format
  • Method Details

    • queueSamples

      public void queueSamples(byte[] pcm, int offset, int length)
      Adds pcm data to the queue of this sound source.

      8-bit data is expressed as an unsigned value over the range 0 to 255, 128 being an audio output level of zero .
      16-bit data is expressed as a signed value over the range -32768 to 32767, 0 being an audio output level of zero.
      Stereo data is expressed in an interleaved format, left channel sample followed by the right channel sample.

      Note: An underflow of pcm data will cause the source to stop playing. If you want it to keep playing, call play() after queueing samples.
      Parameters:
      pcm - the pcm data
      offset - the start index where to begin reading pcm data in the pcm byte array
      length - the length of the pcm data that should be read
    • queueSamples

      public void queueSamples(float[] pcm, int offset, int length)
      Adds pcm data to the queue of this sound source.

      float data is expressed as a signed value over the range -1 to +1, 0 is silence.

      Note: An underflow of pcm data will cause the source to stop playing. If you want it to keep playing, call play() after queueing samples.
      Parameters:
      pcm - the pcm data
      offset - the start index where to begin reading pcm data in the pcm byte array
      length - the length of the pcm data that should be read
    • queueSamples

      public void queueSamples(ByteBuffer pcm)
      Adds pcm data to the queue of this sound source.

      8-bit data is expressed as an unsigned value over the range 0 to 255, 128 being an audio output level of zero .
      16-bit data is expressed as a signed value over the range -32768 to 32767, 0 being an audio output level of zero.
      Stereo data is expressed in an interleaved format, left channel sample followed by the right channel sample.

      Note: An underflow of pcm data will cause the source to stop playing. If you want it to keep playing, call play() after queueing samples.
      Parameters:
      pcm - in native order
    • queueSamples

      public void queueSamples(ShortBuffer pcm)
      Adds pcm data to the queue of this sound source.

      8-bit data is expressed as an unsigned value over the range 0 to 255, 128 being an audio output level of zero .
      16-bit data is expressed as a signed value over the range -32768 to 32767, 0 being an audio output level of zero.
      Stereo data is expressed in an interleaved format, left channel sample followed by the right channel sample.

      Note: An underflow of pcm data will cause the source to stop playing. If you want it to keep playing, call play() after queueing samples.
      Parameters:
      pcm - in native order
    • queueSamples

      public void queueSamples(FloatBuffer pcm)
      Adds pcm data to the queue of this sound source.

      float data is expressed as a signed value over the range -1 to +1, 0 is silence.

      Note: An underflow of pcm data will cause the source to stop playing. If you want it to keep playing, call play() after queueing samples.
      Parameters:
      pcm - in native order
    • unqueueProcessedBuffers

      public void unqueueProcessedBuffers()
      Unqueues processed buffers. This is called automatically on each call to any of the queueSamples methods, so you never have to call it manually.
    • queuedBuffers

      public int queuedBuffers()
      Returns the number of queued buffers. This number is automatically decreased once a buffer is processed (finished playing). Each call to any of the queueSamples methods queues a buffer.
      Returns:
      the number of buffers queued
    • dispose

      public void dispose()
      Disposes the sound sources native resources. You should never use this sound source after disposing it.
      Specified by:
      dispose in interface com.badlogic.gdx.utils.Disposable
      Overrides:
      dispose in class SoundSource