Class BasicIndexGranularSource
java.lang.Object
net.paulhertz.pixelaudio.granular.BasicIndexGranularSource
- All Implemented Interfaces:
PAFloatSource,PASource
BasicIndexGranularSource
A simple granular source that:
- reads from a mono float[] source buffer,
- uses a list of grain start indices (sample positions),
- plays grains in order with fixed hop and fixed grain length,
- applies a window (Minim WindowFunction) per grain,
- sums all active grains into outL/outR.
Timing:
- Grains are scheduled relative to a "note start" time.
- At note-on, call seekTo(noteStartAbsoluteSample) to define when this
grain train begins.
- Grain k starts at: noteStart + k * hopSamples, lasts grainLengthSamples.
This class ignores per-grain pan for now; it writes mono into both outL and outR.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final int[]private final intprivate booleanprivate longprivate final intprivate final float[]private final WindowCacheprivate final float[]private final ddf.minim.analysis.WindowFunction -
Constructor Summary
ConstructorsConstructorDescriptionBasicIndexGranularSource(float[] source, int[] grainStarts, int grainLengthSamples, int hopSamples, ddf.minim.analysis.WindowFunction windowFunction) -
Method Summary
Modifier and TypeMethodDescriptionintint[]intfloat[]ddf.minim.analysis.WindowFunctionlongDuration in samples, or Long.MAX_VALUE if effectively infinite/streaming.Pitch policy hint for the instrument: should the instrument apply its pitch (playback rate) on top of this source?voidrenderBlock(long blockStart, int blockSize, float[] outL, float[] outR) Render audio into the given block buffers.voidseekTo(long absoluteSample) Call this at note-on to define when the grain train starts in absolute sample time.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.paulhertz.pixelaudio.granular.PASource
getMultiChannelBuffer, setGrainWindow
-
Field Details
-
source
private final float[] source -
grainStarts
private final int[] grainStarts -
grainLengthSamples
private final int grainLengthSamples -
hopSamples
private final int hopSamples -
windowFunction
private final ddf.minim.analysis.WindowFunction windowFunction -
windowCache
-
windowCurve
private final float[] windowCurve -
numGrains
private final int numGrains -
noteStartSample
private long noteStartSample -
noteStarted
private boolean noteStarted
-
-
Constructor Details
-
BasicIndexGranularSource
public BasicIndexGranularSource(float[] source, int[] grainStarts, int grainLengthSamples, int hopSamples, ddf.minim.analysis.WindowFunction windowFunction) - Parameters:
source- mono audio buffer (float[])grainStarts- list of sample indices into 'source' where each grain is anchoredgrainLengthSamples- fixed grain length (in samples)hopSamples- fixed time between grain starts (in samples)windowFunction- Minim window function (Hann, Hamming, Blackman, ...)
-
-
Method Details
-
seekTo
public void seekTo(long absoluteSample) Call this at note-on to define when the grain train starts in absolute sample time. Typically: scheduler or voice will call source.seekTo(nowAbsoluteSamples). -
renderBlock
public void renderBlock(long blockStart, int blockSize, float[] outL, float[] outR) Description copied from interface:PAFloatSourceRender audio into the given block buffers. Implementations should: - Assume outL/outR length >= blockSize. - Mix into outL/outR (add), not clear them. - Avoid allocation on the audio thread.- Specified by:
renderBlockin interfacePAFloatSource- Parameters:
blockStart- the absolute sample index in the source’s own sample domain (e.g., buffer index space).blockSize- number of samples in this block.outL- left channel buffer to mix into.outR- right channel buffer to mix into (may be same as outL for mono).
-
lengthSamples
public long lengthSamples()Description copied from interface:PAFloatSourceDuration in samples, or Long.MAX_VALUE if effectively infinite/streaming.- Specified by:
lengthSamplesin interfacePAFloatSource
-
pitchPolicy
Description copied from interface:PASourcePitch policy hint for the instrument: should the instrument apply its pitch (playback rate) on top of this source?- Specified by:
pitchPolicyin interfacePASource
-
getSource
public float[] getSource() -
getGrainStarts
public int[] getGrainStarts() -
getGrainLengthSamples
public int getGrainLengthSamples() -
getHopSamples
public int getHopSamples() -
getWindowFunction
public ddf.minim.analysis.WindowFunction getWindowFunction()
-