Package net.paulhertz.pixelaudio.voices
Class PASharedBufferSampler
java.lang.Object
ddf.minim.UGen
net.paulhertz.pixelaudio.voices.PASharedBufferSampler
- All Implemented Interfaces:
PASampler
UGen-based sampler that plays multiple PASamplerVoice instances
from a single shared mono buffer (channel 0 of a MultiChannelBuffer)
which is an array of floating point samples over (-1.0..1.0).
Features:
- Shared buffer (no duplication)
- Polyphony with voice pooling
- Looping (global default + per-voice)
- ADSR per voice via ADSRParams
- Oldest-first voice recycling, optional smooth stealing
- Thread-safe triggering
Automatically patches to the provided AudioOutput.
-
Nested Class Summary
Nested classes/interfaces inherited from class ddf.minim.UGen
ddf.minim.UGen.InputType, ddf.minim.UGen.UGenInput -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate float[]private intprotected booleanprivate booleanprivate intprivate final ddf.minim.AudioOutputprivate floatprivate booleanprivate final List<PASamplerVoice> -
Constructor Summary
ConstructorsConstructorDescriptionPASharedBufferSampler(ddf.minim.MultiChannelBuffer multiBuffer, float sampleRate, ddf.minim.AudioOutput out) Construct a sampler over a shared MultiChannelBuffer.PASharedBufferSampler(ddf.minim.MultiChannelBuffer multiBuffer, float playbackSampleRate, ddf.minim.AudioOutput out, int maxVoices) PASharedBufferSampler(ddf.minim.MultiChannelBuffer multiBuffer, ddf.minim.AudioOutput out) -
Method Summary
Modifier and TypeMethodDescriptionintddf.minim.AudioOutputprivate PASamplerVoiceGet a free voice, or recycle the oldest active one if at the polyphony limit.intintfloatReturns the current sample rate of this sampler.Read-only list of voices for GUI or debugging.booleanbooleanReturns true if any currently active voice is looping.booleanintplay(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan) Play command with all the useful arguments in standard order, overrides PASampler.play().voidsetBuffer(float[] buffer) voidsetBuffer(float[] buffer, float playbackSampleRate) voidsetGlobalLooping(boolean looping) Default looping for newly triggered voices.voidsetMaxVoices(int maxVoices) Change maximum polyphony at runtime.voidsetPlaybackSampleRate(float newRate) Updates the playback sample rate used for reading from the buffer.voidsetSmoothSteal(boolean smoothSteal) Enable/disable smooth stealing (release envelope) on voice recycle.voidstopAll()Stops all voices immediately.protected voiduGenerate(float[] channels) voidConvenience: synchronize playback rate with AudioOutput's sample rate.Methods inherited from class ddf.minim.UGen
addAudio, addControl, addControl, addInput, channelCount, channelCountChanged, getLastValues, patch, patch, patch, printInputs, removeInput, sampleRate, sampleRateChanged, setChannelCount, setSampleRate, tick, unpatch, unpatchMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.paulhertz.pixelaudio.voices.PASampler
setSampleRate
-
Field Details
-
buffer
private float[] buffer -
bufferLen
private int bufferLen -
playbackSampleRate
private float playbackSampleRate -
out
private final ddf.minim.AudioOutput out -
voices
-
maxVoices
private int maxVoices -
globalLooping
private boolean globalLooping -
smoothSteal
private boolean smoothSteal -
DEBUG
protected boolean DEBUG
-
-
Constructor Details
-
PASharedBufferSampler
public PASharedBufferSampler(ddf.minim.MultiChannelBuffer multiBuffer, float sampleRate, ddf.minim.AudioOutput out) Construct a sampler over a shared MultiChannelBuffer. Automatically patches to the provided AudioOutput.- Parameters:
multiBuffer- shared source buffer (mono or stereo)sampleRate- sample rate of the bufferout- target AudioOutput for playback
-
PASharedBufferSampler
public PASharedBufferSampler(ddf.minim.MultiChannelBuffer multiBuffer, float playbackSampleRate, ddf.minim.AudioOutput out, int maxVoices) -
PASharedBufferSampler
public PASharedBufferSampler(ddf.minim.MultiChannelBuffer multiBuffer, ddf.minim.AudioOutput out)
-
-
Method Details
-
play
public int play(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan) Play command with all the useful arguments in standard order, overrides PASampler.play(). TODO We plan to make this the only play() method PASharedBufferSampler.- Specified by:
playin interfacePASampler- Parameters:
samplePos- index into the buffer to start samplingsampleLen- expected duration of the audio event, which is expected to return its actual durationamplitude- maximum amplitude of signal generated by the samplerenv- ADSR style envelope for the entire eventpitch- pitch multiplier, where 1.0f implies pitch is unchanged and all samples are readpan- location of audio event in stereo field, -1.0f = left, 0.0f = center, 1.0f = right- Returns:
- actual duration of event in samples, typically sampleLen + envelope release time
-
getAvailableVoice
Get a free voice, or recycle the oldest active one if at the polyphony limit. -
uGenerate
protected void uGenerate(float[] channels) - Specified by:
uGeneratein classddf.minim.UGen
-
stopAll
public void stopAll()Description copied from interface:PASamplerStops all voices immediately. -
isLooping
public boolean isLooping()Description copied from interface:PASamplerReturns true if any currently active voice is looping. -
setGlobalLooping
public void setGlobalLooping(boolean looping) Default looping for newly triggered voices. -
isGlobalLooping
public boolean isGlobalLooping() -
setSmoothSteal
public void setSmoothSteal(boolean smoothSteal) Enable/disable smooth stealing (release envelope) on voice recycle. -
isSmoothSteal
public boolean isSmoothSteal() -
setMaxVoices
public void setMaxVoices(int maxVoices) Change maximum polyphony at runtime. -
getMaxVoices
public int getMaxVoices() -
getVoices
Read-only list of voices for GUI or debugging. -
setBuffer
public void setBuffer(float[] buffer) -
setBuffer
public void setBuffer(float[] buffer, float playbackSampleRate) -
countAvailableVoices
public int countAvailableVoices() -
getPlaybackSampleRate
public float getPlaybackSampleRate()Returns the current sample rate of this sampler. -
setPlaybackSampleRate
public void setPlaybackSampleRate(float newRate) Updates the playback sample rate used for reading from the buffer. Does not affect Minim's UGen sample rate. -
updatePlaybackRateFromOutput
public void updatePlaybackRateFromOutput()Convenience: synchronize playback rate with AudioOutput's sample rate. Useful if you want playback speed tied to system rate. -
getBufferLength
public int getBufferLength() -
getAudioOutput
public ddf.minim.AudioOutput getAudioOutput()
-