Class PcmSoundSource
java.lang.Object
de.pottgames.tuningfork.SoundSource
de.pottgames.tuningfork.PcmSoundSource
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
A low level sound source class that can be fed with raw pcm data in a real-time fashion.
-
Field Summary
Fields inherited from class SoundSource
sourceId -
Constructor Summary
ConstructorsConstructorDescriptionPcmSoundSource(int sampleRate, PcmFormat pcmFormat) Creates a newPcmSoundSourcewith the given specs. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Disposes the sound sources native resources.intReturns the number of queued buffers.voidqueueSamples(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.voidqueueSamples(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.voidqueueSamples(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.voidqueueSamples(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.voidqueueSamples(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.voidUnqueues processed buffers.Methods inherited from class SoundSource
attachEffect, attachEffect, detachAllEffects, detachEffect, disableAttenuation, enableAttenuation, getAttenuationFactor, getAttenuationMaxDistance, getAttenuationMinDistance, getPitch, getPosition, getRadius, getResampler, getSpatialization, getVirtualization, getVolume, hasFilter, isDirectional, isPaused, isPlaying, isRelative, makeDirectional, makeOmniDirectional, pause, play, setAttenuationFactor, setAttenuationMaxDistance, setAttenuationMinDistance, setDirection, setFilter, setLooping, setPitch, setPosition, setPosition, setRadius, setRelative, setResampler, setResamplerByIndex, setSpatialization, setSpeed, setSpeed, setVirtualization, setVolume, stop
-
Constructor Details
-
PcmSoundSource
Creates a newPcmSoundSourcewith the given specs.- Parameters:
sampleRate- the sample ratepcmFormat- 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, callplay()after queueing samples.- Parameters:
pcm- the pcm dataoffset- the start index where to begin reading pcm data in the pcm byte arraylength- 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, callplay()after queueing samples.- Parameters:
pcm- the pcm dataoffset- the start index where to begin reading pcm data in the pcm byte arraylength- the length of the pcm data that should be read
-
queueSamples
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, callplay()after queueing samples.- Parameters:
pcm- in native order
-
queueSamples
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, callplay()after queueing samples.- Parameters:
pcm- in native order
-
queueSamples
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, callplay()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:
disposein interfacecom.badlogic.gdx.utils.Disposable- Overrides:
disposein classSoundSource
-