Package net.paulhertz.pixelaudio.sampler
Class PASamplerInstrumentPoolMulti
java.lang.Object
net.paulhertz.pixelaudio.sampler.PASamplerInstrumentPoolMulti
- All Implemented Interfaces:
PAPlayable,PASamplerPlayable
PASamplerInstrumentPoolMulti
Manages multiple PASamplerInstrumentPool instances, each keyed by name.
Each sub-pool may represent a distinct sample source or timbral layer.
TODO example sketches.
Features:
- Dynamic add/remove of sub-pools.
- Shared AudioOutput.
- Optional active-key routing, where only one pool plays at a time.
- Global stop, buffer, and sample-rate propagation.
- Graceful resizing using
PASamplerInstrumentPoolgentle reinitialization.
TODO example sketches.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Stringprivate booleanprivate floatprivate final ddf.minim.AudioOutputprivate final Map<String,PASamplerInstrumentPool> -
Constructor Summary
ConstructorsConstructorDescriptionPASamplerInstrumentPoolMulti(ddf.minim.AudioOutput out) Constructs an empty multi-pool manager.PASamplerInstrumentPoolMulti(String key, ddf.minim.MultiChannelBuffer buffer, float sampleRate, int poolSize, int perInstrumentVoices, ddf.minim.AudioOutput out, ADSRParams adsr) Convenience constructor for single-pool initialization. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPool(String key, ddf.minim.MultiChannelBuffer buffer, float bufferSampleRate, int poolSize, int perInstrumentVoices, ddf.minim.AudioOutput out, ADSRParams env) Adds a named sampler pool.voidclose()Close all sub-pools and release shared resources.private PASamplerInstrumentPoolcurrent()Returns the currently active sub-pool (may be null).voidPrints current pool state to standard output.getPoolByTag(String tag) Returns a named pool.intgetPools()booleanReports whether a named pool exists.booleanisClosed()booleanintplay(float amplitude, float pitch, float pan) Plays the instrument's entire buffer, from PAPlayable interface.intplay(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan) PASamplerPlayable's play method, all six standard parameters in standard order, called by other methods.intplaySample(int samplePos, int sampleLen, float amplitude) Play subrange with amplitude only.intplaySample(int samplePos, int sampleLen, float amplitude, float pitch) Play subrange with amplitude and pitch (no envelope).intplaySample(int samplePos, int sampleLen, float amplitude, float pitch, float pan) Plays a sample range with pitch and pan on the active pool.intplaySample(int samplePos, int sampleLen, float amplitude, ADSRParams env) intplaySample(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch) Plays a sample range with envelope and pitch on the active pool.intplaySample(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan) Play a subrange of the buffer with full parameters.intplaySample(ddf.minim.MultiChannelBuffer buffer, int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch) Plays a range from a temporary buffer on the active pool.intplaySample(ddf.minim.MultiChannelBuffer buffer, int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan) Plays a range from a temporary buffer on the active pool.intplaySample(String tag, int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan) Plays a sample range on a named pool.voidremovePool(String key) Remove a pool by key and close it safely.voidresizeAllPools(int newPoolSize, int newVoicesPerInstrument) Adjust size or polyphony of all sub-pools gracefully.voidActivate the given pool key for subsequent play() calls.voidsetBuffer(float[] newBuffer, float newSampleRate) Propagate float[] buffer to all sub-pools (mono assumption).voidsetBuffer(ddf.minim.MultiChannelBuffer newBuffer) Propagate new buffer to all sub-pools, keeping sample rates intact.voidsetBuffer(ddf.minim.MultiChannelBuffer newBuffer, float newSampleRate) Propagate new buffer and sample rate to all sub-pools.voidsetMasterGain(float linear) Sets master gain on every sub-pool.voidstop()Stop playback immediately (implementation-defined).voidstopAll()Stops all voices in every sub-pool.voidUpdate sample rates of all sub-pools from AudioOutput.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.paulhertz.pixelaudio.sampler.PAPlayable
play, play, play, play, playMethods inherited from interface net.paulhertz.pixelaudio.sampler.PASamplerPlayable
playSample, playSample, playSample, playSample, playSample
-
Field Details
-
out
private final ddf.minim.AudioOutput out -
pools
-
activeKey
-
isClosed
private boolean isClosed -
masterGain
private volatile float masterGain
-
-
Constructor Details
-
PASamplerInstrumentPoolMulti
public PASamplerInstrumentPoolMulti(ddf.minim.AudioOutput out) Constructs an empty multi-pool manager.- Parameters:
out- shared AudioOutput for sub-pools
-
PASamplerInstrumentPoolMulti
public PASamplerInstrumentPoolMulti(String key, ddf.minim.MultiChannelBuffer buffer, float sampleRate, int poolSize, int perInstrumentVoices, ddf.minim.AudioOutput out, ADSRParams adsr) Convenience constructor for single-pool initialization.- Parameters:
key- key for the initial poolbuffer- source buffer for the initial poolsampleRate- sample rate of the source buffer in HzpoolSize- number of instruments in the initial poolperInstrumentVoices- voices per instrumentout- shared AudioOutputadsr- default ADSR envelope
-
-
Method Details
-
addPool
public void addPool(String key, ddf.minim.MultiChannelBuffer buffer, float bufferSampleRate, int poolSize, int perInstrumentVoices, ddf.minim.AudioOutput out, ADSRParams env) Adds a named sampler pool.- Parameters:
key- pool keybuffer- source buffer for the poolbufferSampleRate- sample rate of the source buffer in HzpoolSize- number of instruments in the poolperInstrumentVoices- voices per instrumentout- AudioOutput for the poolenv- default ADSR envelope
-
removePool
Remove a pool by key and close it safely.- Parameters:
key- pool key to remove
-
current
Returns the currently active sub-pool (may be null). -
setActive
Activate the given pool key for subsequent play() calls.- Parameters:
key- pool key to activate
-
getActiveKey
- Returns:
- currently active pool key
-
play
public int play(float amplitude, float pitch, float pan) Plays the instrument's entire buffer, from PAPlayable interface.- Specified by:
playin interfacePAPlayable- Parameters:
amplitude- gain multiplier (0..1+)pitch- playback rate or pitch factor (implementation-defined)pan- stereo pan (-1 left .. +1 right)- Returns:
- non-zero if a voice/event was triggered
-
stop
public void stop()Description copied from interface:PAPlayableStop playback immediately (implementation-defined).- Specified by:
stopin interfacePAPlayable
-
play
public int play(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan) PASamplerPlayable's play method, all six standard parameters in standard order, called by other methods.- Specified by:
playin interfacePASamplerPlayable- Parameters:
samplePos- buffer index to start playbacksampleLen- requested duration in samplesamplitude- gain multiplierenv- optional ADSR envelopepitch- pitch or playback-rate multiplierpan- stereo pan- Returns:
- actual event duration in samples
-
isLooping
public boolean isLooping()- Returns:
- true if any sub-pool has looping voices
-
stopAll
public void stopAll()Stops all voices in every sub-pool. -
playSample
public int playSample(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan) Play a subrange of the buffer with full parameters.- Specified by:
playSamplein interfacePASamplerPlayable- Parameters:
samplePos- buffer index to start playbacksampleLen- requested duration in samplesamplitude- gain multiplierenv- optional ADSR envelopepitch- pitch or playback-rate multiplierpan- stereo pan- Returns:
- actual event duration in samples
-
playSample
Plays a sample range with envelope and pitch on the active pool.- Parameters:
samplePos- buffer index to start playbacksampleLen- requested duration in samplesamplitude- gain multiplierenv- optional ADSR envelopepitch- pitch or playback-rate multiplier- Returns:
- actual event duration in samples
-
playSample
public int playSample(int samplePos, int sampleLen, float amplitude, float pitch, float pan) Plays a sample range with pitch and pan on the active pool.- Parameters:
samplePos- buffer index to start playbacksampleLen- requested duration in samplesamplitude- gain multiplierpitch- pitch or playback-rate multiplierpan- stereo pan- Returns:
- actual event duration in samples
-
playSample
public int playSample(int samplePos, int sampleLen, float amplitude) Play subrange with amplitude only.- Specified by:
playSamplein interfacePASamplerPlayable- Parameters:
samplePos- buffer index to start playbacksampleLen- requested duration in samplesamplitude- gain multiplier- Returns:
- actual event duration in samples
-
playSample
public int playSample(int samplePos, int sampleLen, float amplitude, float pitch) Play subrange with amplitude and pitch (no envelope).- Specified by:
playSamplein interfacePASamplerPlayable- Parameters:
samplePos- buffer index to start playbacksampleLen- requested duration in samplesamplitude- gain multiplierpitch- pitch or playback-rate multiplier- Returns:
- actual event duration in samples
-
playSample
-
playSample
public int playSample(ddf.minim.MultiChannelBuffer buffer, int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan) Plays a range from a temporary buffer on the active pool.- Parameters:
buffer- source buffer for playbacksamplePos- buffer index to start playbacksampleLen- requested duration in samplesamplitude- gain multiplierenv- optional ADSR envelopepitch- pitch or playback-rate multiplierpan- stereo pan- Returns:
- actual event duration in samples
-
playSample
public int playSample(ddf.minim.MultiChannelBuffer buffer, int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch) Plays a range from a temporary buffer on the active pool.- Parameters:
buffer- source buffer for playbacksamplePos- buffer index to start playbacksampleLen- requested duration in samplesamplitude- gain multiplierenv- optional ADSR envelopepitch- pitch or playback-rate multiplier- Returns:
- actual event duration in samples
-
playSample
public int playSample(String tag, int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan) Plays a sample range on a named pool.- Parameters:
tag- pool keysamplePos- buffer index to start playbacksampleLen- requested duration in samplesamplitude- gain multiplierenv- optional ADSR envelopepitch- pitch or playback-rate multiplierpan- stereo pan- Returns:
- actual event duration in samples
-
hasPool
Reports whether a named pool exists.- Parameters:
tag- pool key- Returns:
- true when the pool exists
-
getPoolByTag
Returns a named pool.- Parameters:
tag- pool key- Returns:
- matching pool, or null
-
setBuffer
public void setBuffer(ddf.minim.MultiChannelBuffer newBuffer) Propagate new buffer to all sub-pools, keeping sample rates intact.- Parameters:
newBuffer- replacement source buffer
-
setBuffer
public void setBuffer(ddf.minim.MultiChannelBuffer newBuffer, float newSampleRate) Propagate new buffer and sample rate to all sub-pools.- Parameters:
newBuffer- replacement source buffernewSampleRate- sample rate of the replacement buffer in Hz
-
setBuffer
public void setBuffer(float[] newBuffer, float newSampleRate) Propagate float[] buffer to all sub-pools (mono assumption).- Parameters:
newBuffer- replacement mono source buffernewSampleRate- sample rate of the replacement buffer in Hz
-
updateRateFromOutput
public void updateRateFromOutput()Update sample rates of all sub-pools from AudioOutput. -
setMasterGain
public void setMasterGain(float linear) Sets master gain on every sub-pool.- Parameters:
linear- linear gain value
-
resizeAllPools
public void resizeAllPools(int newPoolSize, int newVoicesPerInstrument) Adjust size or polyphony of all sub-pools gracefully.- Parameters:
newPoolSize- number of instruments per poolnewVoicesPerInstrument- voices per instrument
-
close
public void close()Close all sub-pools and release shared resources. -
isClosed
public boolean isClosed()- Returns:
- true after this multi-pool manager has been closed
-
getPoolCount
public int getPoolCount()- Returns:
- number of managed pools
-
getPools
- Returns:
- map of pool keys to pools
-
debugPrintState
public void debugPrintState()Prints current pool state to standard output.
-