Class PAGranularInstrument
PASource playback.
PAGranularInstrument is the instrument-level control surface in the granular
synthesis chain. It applies global pan, global gain, and default envelope settings, then
delegates voice allocation and sample-accurate scheduling to PAGranularSampler.
Most gesture-driven granular synthesis code should enter the chain through
PAGranularInstrumentDirector, which creates the PABurstGranularSource
instances and calls this class. Direct use of PAGranularInstrument is useful when
callers already have a PASource and want immediate or scheduled playback.
This class does not manage Minim MultiChannelBuffer data. A PASource
encapsulates its own audio data or rendering behavior.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ADSRParamsprivate floatprivate floatprivate booleanprivate final ddf.minim.AudioOutputprivate final PAGranularSampler -
Constructor Summary
ConstructorsConstructorDescriptionPAGranularInstrument(ddf.minim.AudioOutput out) Creates a granular instrument with a default envelope and 16 voices.PAGranularInstrument(ddf.minim.AudioOutput out, ADSRParams defaultEnv, int maxVoices) Creates a granular instrument. -
Method Summary
Modifier and TypeMethodDescriptionintCounts active or releasing granular voices.voidClears pending scheduled events and releases all active voices through their envelopes.voidClears pending scheduled events and immediately stops all active voices.private static floatclampPan(float p) voidClears playback events that have been scheduled but have not started yet.voidclose()Closes this instrument and stops all voices.floatfloatfloatlongfloatlongConvenience overload that uses unity gain, global pan, and the default envelope.longConvenience overload that uses center pan and the default envelope.longConvenience overload that uses the default envelope and disables looping.longplay(PASource src, float amp, float pan, ADSRParams env, boolean looping) Plays a granular source immediately.longplayLooping(PASource src, float amp, float pan) Convenience overload that enables looping with the default envelope.voidReleases all active or already-releasing voices through their envelopes.voidvoidsetGlobalGain(float gLinear) voidsetGlobalGainDb(float gDb) voidsetGlobalPan(float pan) voidstartAfterDelaySamples(PASource src, float amp, float pan, ADSRParams env, boolean looping, long delaySamples) Schedules playback after a delay in samples relative to the current sampler time.voidstartAtSampleTime(PASource src, float amp, float pan, ADSRParams env, boolean looping, long startSample) Schedules playback of a source at an absolute sample time.voidstartAtSampleTime(PASource src, float amp, float pan, ADSRParams env, boolean looping, long startSample, ddf.minim.analysis.WindowFunction grainWindow, int grainLenSamples) Schedules playback of a source at an absolute sample time with grain-window settings.voidstartNow(PASource src, float amp, float pan, ADSRParams env, boolean looping) Schedules playback at the current instrument cursor.voidstopAll()
-
Field Details
-
sampler
-
out
private final ddf.minim.AudioOutput out -
defaultEnv
-
globalPan
private float globalPan -
globalGain
private float globalGain -
isClosed
private boolean isClosed
-
-
Constructor Details
-
PAGranularInstrument
Creates a granular instrument.- Parameters:
out- Minim audio output used by the samplerdefaultEnv- default macro envelope for voices when a playback call supplies nullmaxVoices- maximum number of simultaneous granular voices
-
PAGranularInstrument
public PAGranularInstrument(ddf.minim.AudioOutput out) Creates a granular instrument with a default envelope and 16 voices.- Parameters:
out- Minim audio output used by the sampler
-
-
Method Details
-
play
Plays a granular source immediately.The current gesture-driven granular engine normally supplies a
PABurstGranularSourcecreated byPAGranularInstrumentDirector. OtherPASourceimplementations can be played directly if they satisfy the source rendering contract.- Parameters:
src- source to renderamp- linear amplitude multiplier before global gain is appliedpan- stereo pan offset in the range [-1, 1]env- envelope to use, or null to use the instrument defaultlooping- true to loop the source path where supported- Returns:
- voice id, or -1 if playback could not start
-
play
Convenience overload that uses the default envelope and disables looping. -
play
Convenience overload that uses center pan and the default envelope. -
play
Convenience overload that uses unity gain, global pan, and the default envelope. -
playLooping
Convenience overload that enables looping with the default envelope. -
startAtSampleTime
public void startAtSampleTime(PASource src, float amp, float pan, ADSRParams env, boolean looping, long startSample) Schedules playback of a source at an absolute sample time.- Parameters:
src- source to renderamp- linear amplitude multiplier before global gain is appliedpan- stereo pan offset in the range [-1, 1]env- envelope to use, or null to use the instrument defaultlooping- true to loop the source path where supportedstartSample- absolute sample index at which playback should start
-
startAtSampleTime
public void startAtSampleTime(PASource src, float amp, float pan, ADSRParams env, boolean looping, long startSample, ddf.minim.analysis.WindowFunction grainWindow, int grainLenSamples) Schedules playback of a source at an absolute sample time with grain-window settings.This overload is used by
PAGranularInstrumentDirectorso the resolved grain window and grain length can travel with a scheduled event into the sampler and voice.- Parameters:
src- source to renderamp- linear amplitude multiplier before global gain is appliedpan- stereo pan offset in the range [-1, 1]env- envelope to use, or null to use the instrument defaultlooping- true to loop the source path where supportedstartSample- absolute sample index at which playback should startgrainWindow- window function for shaping grain amplitude, or null for source defaultgrainLenSamples- number of samples in one grain
-
startAfterDelaySamples
public void startAfterDelaySamples(PASource src, float amp, float pan, ADSRParams env, boolean looping, long delaySamples) Schedules playback after a delay in samples relative to the current sampler time.- Parameters:
src- source to renderamp- linear amplitude multiplier before global gain is appliedpan- stereo pan offset in the range [-1, 1]env- envelope to use, or null to use the instrument defaultlooping- true to loop the source path where supporteddelaySamples- delay from the current sample time
-
startNow
Schedules playback at the current instrument cursor.- Parameters:
src- source to renderamp- linear amplitude multiplier before global gain is appliedpan- stereo pan offset in the range [-1, 1]env- envelope to use, or null to use the instrument defaultlooping- true to loop the source path where supported
-
stopAll
public void stopAll() -
setDefaultEnvelope
-
getDefaultEnvelope
-
setGlobalPan
public void setGlobalPan(float pan) -
getGlobalPan
public float getGlobalPan() -
setGlobalGain
public void setGlobalGain(float gLinear) -
getGlobalGain
public float getGlobalGain() -
setGlobalGainDb
public void setGlobalGainDb(float gDb) -
getGlobalGainDb
public float getGlobalGainDb() -
getSampleRate
public float getSampleRate() -
getSampler
-
getSampleCursor
public long getSampleCursor() -
close
public void close()Closes this instrument and stops all voices. -
clearScheduled
public void clearScheduled()Clears playback events that have been scheduled but have not started yet.Voices that are already active continue playing. For a musical stop, call this first and then call
releaseAll(). -
releaseAll
public void releaseAll()Releases all active or already-releasing voices through their envelopes.A release is generally less abrupt than a stop, because each active voice is allowed to pass through its envelope release stage. Scheduled events are not cleared by this method.
-
cancelAndStopAll
public void cancelAndStopAll()Clears pending scheduled events and immediately stops all active voices.A stop halts voice processing directly and is therefore more abrupt than a release.
-
cancelAndReleaseAll
public void cancelAndReleaseAll()Clears pending scheduled events and releases all active voices through their envelopes.This is the less abrupt counterpart to
cancelAndStopAll()and is generally better suited to musical fade-outs. -
activeOrReleasingVoiceCount
public int activeOrReleasingVoiceCount()Counts active or releasing granular voices.- Returns:
- active or releasing voice count
-
clampPan
private static float clampPan(float p)
-