Class PAGranularSampler
java.lang.Object
ddf.minim.UGen
net.paulhertz.pixelaudio.granular.PAGranularSampler
public class PAGranularSampler
extends ddf.minim.UGen
PAGranularSampler
UGen-based multi-voice granular sampler.
Features:
- Voice pooling (PAGranularVoice instances)
- Per-voice ADSR, gain, and pan
- Optional looping of the grain path
- Thread-safe play() method
- Per-sample mixing (like PASharedBufferSampler)
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class ddf.minim.UGen
ddf.minim.UGen.InputType, ddf.minim.UGen.UGenInput -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate floatprivate intprivate floatprivate final ddf.minim.AudioOutputprivate longprivate final AudioScheduler<PAGranularSampler.ScheduledPlay>private booleanprivate final float[]private final List<PAGranularVoice> -
Constructor Summary
ConstructorsConstructorDescriptionPAGranularSampler(ddf.minim.AudioOutput out) PAGranularSampler(ddf.minim.AudioOutput out, int maxVoices) Initializes this PAGranularSampler, which extends UGen and gets patched to an AudioOutput, with the result that its uGenerate method is called on each audio block. -
Method Summary
Modifier and TypeMethodDescriptionddf.minim.AudioOutputprivate PAGranularVoicegetAvailableVoice(PASource src, ADSRParams env, float gain, float pan, boolean looping) private PAGranularVoicegetAvailableVoice(PASource src, ADSRParams env, float gain, float pan, boolean looping, ddf.minim.analysis.WindowFunction grainWindow, int grainLenSamples) Allocate a PAGranularVoice instance.longExpose the current absolute sample cursor (for higher-level scheduling).intbooleanlongplay(PASource src, float gain, float pan, ADSRParams defaultEnv, boolean looping) longplay(PASource src, ADSRParams env, float gain, float pan) longplay(PASource src, ADSRParams env, float gain, float pan, boolean looping) Play a granular source as a voice.voidsetMaxVoices(int maxVoices) voidsetSmoothSteal(boolean smoothSteal) private static floatsoftClipSoftsign(float x, float drive) voidstartAfterDelaySamples(PASource src, ADSRParams env, float gain, float pan, boolean looping, long delaySamples) Schedule a new voice to start after a given delay in samples.voidstartAtSampleTime(PASource src, ADSRParams env, float gain, float pan, boolean looping, long startSample) Schedule a new voice to start at an absolute sample time.voidstartAtSampleTime(PASource src, ADSRParams env, float gain, float pan, boolean looping, long startSample, ddf.minim.analysis.WindowFunction grainWindow, int grainLenSamples) Called by PAGranularInstrument.startAtSampleTime(...), creates a ScheduledPlay instance with PASource src and other arguments, then passes it to AudioScheduler scheduler, which will be handled through Minim's uGenerate call to this instance of PAGranularSampler.voidstopAll()protected voiduGenerate(float[] channels) Provides per-sample frame processing with AudioScheduler, called through Minim.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, unpatch
-
Field Details
-
out
private final ddf.minim.AudioOutput out -
voices
-
maxVoices
private int maxVoices -
blockSize
private int blockSize -
smoothSteal
private boolean smoothSteal -
scheduler
-
sampleCursor
private long sampleCursor -
tmpStereo
private final float[] tmpStereo -
mixNorm
private float mixNorm -
globalMakeUpGain
private float globalMakeUpGain
-
-
Constructor Details
-
PAGranularSampler
public PAGranularSampler(ddf.minim.AudioOutput out, int maxVoices) Initializes this PAGranularSampler, which extends UGen and gets patched to an AudioOutput, with the result that its uGenerate method is called on each audio block.- Parameters:
out- a Minim AudioOutput that this PAGranularSampler will patch tomaxVoices- maximum number of voices to allocate
-
PAGranularSampler
public PAGranularSampler(ddf.minim.AudioOutput out)
-
-
Method Details
-
getAvailableVoice
private PAGranularVoice getAvailableVoice(PASource src, ADSRParams env, float gain, float pan, boolean looping, ddf.minim.analysis.WindowFunction grainWindow, int grainLenSamples) Allocate a PAGranularVoice instance. Called from play() and uGenerate() methods.- Parameters:
src- A PASourceenv- ADSRParams envelope, could be nullgain- gain as a decimal value scaling amplitudepan- pan in stereo space, but grains can set individuallylooping- looping flag, best be falsegrainWindow- a Minim WindowFunctiongrainLenSamples- number of samples in one grain- Returns:
-
getAvailableVoice
private PAGranularVoice getAvailableVoice(PASource src, ADSRParams env, float gain, float pan, boolean looping) -
play
Play a granular source as a voice.- Parameters:
src- PASource (PathGranularSource or BasicIndexGranularSource)env- ADSR for the macro envelopegain- amplitudepan- -1..+1looping- loop granular path- Returns:
- voiceId or -1
-
play
-
play
-
startAtSampleTime
public void startAtSampleTime(PASource src, ADSRParams env, float gain, float pan, boolean looping, long startSample) Schedule a new voice to start at an absolute sample time.- Parameters:
src- PASourceenv- ADSR (already resolved: either custom or default)gain- final gainpan- final panlooping- loop flagstartSample- absolute sample index at which to start the voice
-
startAtSampleTime
public void startAtSampleTime(PASource src, ADSRParams env, float gain, float pan, boolean looping, long startSample, ddf.minim.analysis.WindowFunction grainWindow, int grainLenSamples) Called by PAGranularInstrument.startAtSampleTime(...), creates a ScheduledPlay instance with PASource src and other arguments, then passes it to AudioScheduler scheduler, which will be handled through Minim's uGenerate call to this instance of PAGranularSampler.- Parameters:
src- PASourceenv- ADSR (already resolved: either custom or default)gain- final gainpan- final panlooping- loop flagstartSample- absolute sample index at which to start the voicegrainWindow- a window function for shaping grain amplitudegrainLenSamples- number of samples in one grain
-
startAfterDelaySamples
public void startAfterDelaySamples(PASource src, ADSRParams env, float gain, float pan, boolean looping, long delaySamples) Schedule a new voice to start after a given delay in samples.- Parameters:
src- PASourceenv- ADSRgain- final gainpan- final panlooping- loop flagdelaySamples- how many samples from "now" to start
-
getCurrentSampleTime
public long getCurrentSampleTime()Expose the current absolute sample cursor (for higher-level scheduling). -
uGenerate
protected void uGenerate(float[] channels) Provides per-sample frame processing with AudioScheduler, called through Minim.- Specified by:
uGeneratein classddf.minim.UGen
-
softClipSoftsign
private static float softClipSoftsign(float x, float drive) -
stopAll
public void stopAll() -
setMaxVoices
public void setMaxVoices(int maxVoices) -
getMaxVoices
public int getMaxVoices() -
setSmoothSteal
public void setSmoothSteal(boolean smoothSteal) -
isSmoothSteal
public boolean isSmoothSteal() -
getVoices
-
getAudioOutput
public ddf.minim.AudioOutput getAudioOutput()
-