Package net.paulhertz.pixelaudio.voices

# Class PASamplerVoice

java.lang.Object
net.paulhertz.pixelaudio.voices.PASamplerVoice

public class PASamplerVoice extends Object
PASamplerVoice — a single playback "voice" reading from a shared mono buffer. Each voice handles: - playback position and pitch - per-voice amplitude and pan - one independent SimpleADSR envelope (sample-accurate) - optional zero-crossing start and micro-fade-in Voices can be smoothly released and are recycled once the envelope finishes.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `private boolean`
  `active`
  `private float[]`
  `buffer`
  `private static final boolean`
  `DEBUG`
  `private int`
  `end`
  `private SimpleADSR`
  `envelope`
  `private boolean`
  `finished`
  `private int`
  `frameCounter`
  `private float`
  `gain`
  `private boolean`
  `isFindZeroCrossing`
  `private boolean`
  `isMicroFadeIn`
  `private boolean`
  `looping`
  `private static long`
  `NEXT_VOICE_ID`
  `private float`
  `pan`
  `private float`
  `playbackSampleRate`
  `private float`
  `position`
  `private float`
  `rate`
  `private boolean`
  `released`
  `private int`
  `start`
  `private long`
  `voiceId`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PASamplerVoice(float[] buffer, float sampleRate)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `activate(int start, int length, float gain, ADSRParams envParams, float pitch, float pan, boolean looping)`
  `private void`
  `applyMicroFadeIn()`
  `private int`
  `findZeroCrossing(int index, int direction)`
  `float`
  `getPan()`
  `long`
  `getVoiceId()`
  `boolean`
  `isActive()`
  `boolean`
  `isFindZeroCrossing()`
  `boolean`
  `isFinished()`
  `boolean`
  `isLooping()`
  `boolean`
  `isMicroFadeIn()`
  `boolean`
  `isReleasing()`
  `float`
  `nextSample()`
  `void`
  `release()`
  `void`
  `resetPosition()`
  `void`
  `setBuffer(float[] buffer)`
  `void`
  `setBuffer(float[] buffer, float playbackSampleRate)`
  `void`
  `setFindZeroCrossing(boolean val)`
  `void`
  `setLooping(boolean looping)`
  `void`
  `setMicroFadeIn(boolean val)`
  `void`
  `setPlaybackSampleRate(float newRate)`
  `void`
  `stop()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### NEXT_VOICE_ID

    private static long NEXT_VOICE_ID

  - ### buffer

    private float[] buffer

  - ### playbackSampleRate

    private float playbackSampleRate

  - ### voiceId

    private long voiceId

  - ### active

    private boolean active

  - ### released

    private boolean released

  - ### finished

    private boolean finished

  - ### looping

    private boolean looping

  - ### start

    private int start

  - ### end

    private int end

  - ### position

    private float position

  - ### rate

    private float rate

  - ### gain

    private float gain

  - ### pan

    private float pan

  - ### envelope

    private SimpleADSR envelope

  - ### isFindZeroCrossing

    private boolean isFindZeroCrossing

  - ### isMicroFadeIn

    private boolean isMicroFadeIn

  - ### DEBUG

    private static final boolean DEBUG
    See Also:
      - Constant Field Values

  - ### frameCounter

    private int frameCounter

- ## Constructor Details

  - ### PASamplerVoice

    public PASamplerVoice(float[] buffer, float sampleRate)

- ## Method Details

  - ### activate

    public void activate(int start, int length, float gain, ADSRParams envParams, float pitch, float pan, boolean looping)

  - ### nextSample

    public float nextSample()

  - ### release

    public void release()

  - ### stop

    public void stop()

  - ### resetPosition

    public void resetPosition()

  - ### setBuffer

    public void setBuffer(float[] buffer)

  - ### setBuffer

    public void setBuffer(float[] buffer, float playbackSampleRate)

  - ### isActive

    public boolean isActive()

  - ### isReleasing

    public boolean isReleasing()

  - ### isFinished

    public boolean isFinished()

  - ### isLooping

    public boolean isLooping()

  - ### setLooping

    public void setLooping(boolean looping)

  - ### getPan

    public float getPan()

  - ### getVoiceId

    public long getVoiceId()

  - ### applyMicroFadeIn

    private void applyMicroFadeIn()

  - ### findZeroCrossing

    private int findZeroCrossing(int index, int direction)

  - ### isFindZeroCrossing

    public boolean isFindZeroCrossing()

  - ### setFindZeroCrossing

    public void setFindZeroCrossing(boolean val)

  - ### isMicroFadeIn

    public boolean isMicroFadeIn()

  - ### setMicroFadeIn

    public void setMicroFadeIn(boolean val)

  - ### setPlaybackSampleRate

    public void setPlaybackSampleRate(float newRate)