Package net.paulhertz.pixelaudio

# Class WaveData

java.lang.Object
net.paulhertz.pixelaudio.WaveData

public class WaveData extends Object
Data storage for WaveSynth operator data. NEW (as of

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `WaveData.WaveState`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `float`
  `amp`
  amplitude
  `int`
  `animSteps`
  TODO animSteps is an external value from a WaveSynth and application context -- is there a better way to handle it?
  `private float`
  `c`
  `private float`
  `cs`
  `float`
  `dc`
  DC offset/bias to add to generated amplitude values, a new setting, default 0
  `static int`
  `defaultAnimSteps`
  convenience variable, 30 seconds of animation at 24 frames per second, also context dependent
  `private boolean`
  `framePrepared`
  `float`
  `freq`
  frequency
  `boolean`
  `isMuted`
  runtime variable for muting
  `float`
  `phase`
  fraction of TWO_PI in the range 0..1,
  `float`
  `phaseCycles`
  number of times to cycle through TWO_PI over the duration of the animation
  `float`
  `phaseInc`
  increment to the phase for each step of animation = (cycles * TWO_PI)/(animation steps) Should be set when animation begins, otherwise is set to 0, unchanging.
  `static final boolean`
  `phaseScalesTwoPI`
  support for old JSON format where phase was already scaled by TWO_PI in the new format phase ranges over the open interval (0, 1), so we scale it by TWO_PI and store the result in phaseTwoPi, which tracks phase information.
  `float`
  `phaseTwoPi`
  TWO_PI * phase, used internally to calculate wave value
  `private int`
  `preparedFrame`
  `private static final int`
  `RENORM_PERIOD`
  `private float`
  `s`
  `private float`
  `sn`
  `private int`
  `stepsSinceRenorm`
  `int`
  `waveColor`
  color associated with the wave
  `WaveData.WaveState`
  `waveState`
  tracking variable for mute, solo, etc.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `WaveData()`
  `WaveData(float f, float a, float p, float dc, float cycles, int c)`
  Constructor for WaveData when animation steps are not known
  `WaveData(float f, float a, float p, float dc, float cycles, int c, int steps)`
  Preferred constructor for WaveData
  `WaveData(float f, float a, float p, float dc, float cycles, int c, int animSteps, boolean phaseScalesTwoPi)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `WaveData`
  `clone()`
  `void`
  `invalidateFrameState()`
  If you ever need to force this oscillator to be rebuilt next frame.
  `static float`
  `mapToPositivePhase(float value, float a, float b)`
  Maps a value to a specified range (of a cyclic function) Explanation: 1.
  `float`
  `nextValue()`
  Get the next value along the path, using oscillator recurrence.
  `float`
  `phaseAtFrame(int frame)`
  `void`
  `prepareFrame(int frame, float mapInc)`
  Prepare oscillator state for this frame, assuming a constant freq and a constant mapInc for pos stepping.
  `void`
  `prepareFrame(int frame, float mapInc, float freqShift)`
  Variant that includes a per-frame freqShift.
  `float`
  `rawPhaseAtFrame(int frame)`
  `float`
  `scaledPhaseAtFrame(int frame)`
  `void`
  `setAmp(float a)`
  `void`
  `setAnimationSteps(int newSteps)`
  `void`
  `setCycles(float cycles)`
  `void`
  `setCycles(float cycles, int steps)`
  `void`
  `setDc(float newDc)`
  `void`
  `setFreq(float f)`
  `void`
  `setPhase(float p)`
  `void`
  `setPhase(float p, boolean phaseScalesTwoPi)`
  `void`
  `setWaveColor(int c)`
  `void`
  `setWaveState(WaveData.WaveState newWaveState)`
  `String`
  `toString()`
  `void`
  `updateWaveData(float f, float a, float p, float cycles, int c, int steps)`
  `static ArrayList<WaveData>`
  `waveDataListCopy(ArrayList<WaveData> wdList)`
  `float`
  `waveValue(int frame, int pos, float mapInc)`
  `float`
  `waveValue(int frame, int pos, float freqShift, float mapInc)`
  Experimenting with noise to change the wave forms.

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

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

- ## Field Details

  - ### freq

    public float freq
    frequency

  - ### amp

    public float amp
    amplitude

  - ### phase

    public float phase
    fraction of TWO_PI in the range 0..1,

  - ### phaseTwoPi

    public float phaseTwoPi
    TWO_PI * phase, used internally to calculate wave value

  - ### phaseCycles

    public float phaseCycles
    number of times to cycle through TWO_PI over the duration of the animation

  - ### phaseInc

    public float phaseInc
    increment to the phase for each step of animation = (cycles * TWO_PI)/(animation steps) Should be set when animation begins, otherwise is set to 0, unchanging.

  - ### dc

    public float dc
    DC offset/bias to add to generated amplitude values, a new setting, default 0

  - ### waveColor

    public int waveColor
    color associated with the wave

  - ### isMuted

    public boolean isMuted
    runtime variable for muting

  - ### waveState

    public WaveData.WaveState waveState
    tracking variable for mute, solo, etc.

  - ### animSteps

    public int animSteps
    TODO animSteps is an external value from a WaveSynth and application context -- is there a better way to handle it?

  - ### defaultAnimSteps

    public static int defaultAnimSteps
    convenience variable, 30 seconds of animation at 24 frames per second, also context dependent

  - ### phaseScalesTwoPI

    public static final boolean phaseScalesTwoPI
    support for old JSON format where phase was already scaled by TWO_PI in the new format phase ranges over the open interval (0, 1), so we scale it by TWO_PI and store the result in phaseTwoPi, which tracks phase information.
    See Also:
      - Constant Field Values

  - ### s

    private float s

  - ### c

    private float c

  - ### cs

    private float cs

  - ### sn

    private float sn

  - ### preparedFrame

    private int preparedFrame

  - ### framePrepared

    private boolean framePrepared

  - ### stepsSinceRenorm

    private int stepsSinceRenorm

  - ### RENORM_PERIOD

    private static final int RENORM_PERIOD
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### WaveData

    public WaveData(float f, float a, float p, float dc, float cycles, int c, int animSteps, boolean phaseScalesTwoPi)

  - ### WaveData

    public WaveData(float f, float a, float p, float dc, float cycles, int c, int steps)
    Preferred constructor for WaveData
    Parameters:
      `f` - frequency
      `a` - amplitude
      `p` - phase, decimal fraction of TWO_PI, typically in the range [0..1]
      `dc` - DC component added to wave values
      `cycles` - number of cyles over one animation period
      `c` - color associated with this WaveData object
      `steps` - number of frames for animation

  - ### WaveData

    public WaveData(float f, float a, float p, float dc, float cycles, int c)
    Constructor for WaveData when animation steps are not known
    Parameters:
      `f` - frequency
      `a` - amplitude
      `p` - phase, decimal fraction of TWO_PI, typically in the range [0..1]
      `dc` - DC component added to wave values
      `cycles` - number of cyles over one animation period
      `c` - color associated with this WaveData object

  - ### WaveData

    public WaveData()

- ## Method Details

  - ### updateWaveData

    public void updateWaveData(float f, float a, float p, float cycles, int c, int steps)

  - ### setFreq

    public void setFreq(float f)

  - ### setAmp

    public void setAmp(float a)

  - ### setPhase

    public void setPhase(float p, boolean phaseScalesTwoPi)

  - ### setPhase

    public void setPhase(float p)

  - ### setCycles

    public void setCycles(float cycles, int steps)

  - ### setCycles

    public void setCycles(float cycles)

  - ### setAnimationSteps

    public void setAnimationSteps(int newSteps)

  - ### setDc

    public void setDc(float newDc)

  - ### setWaveColor

    public void setWaveColor(int c)

  - ### setWaveState

    public void setWaveState(WaveData.WaveState newWaveState)

  - ### waveValue

    public float waveValue(int frame, int pos, float freqShift, float mapInc)
    Experimenting with noise to change the wave forms.
    Parameters:
      `frame` - current frame
      `pos` - pixel/audio sample index on signal path
      `freqShift` - experiment with shifting frequency
      `mapInc` - the increment in phase over the image pixels, typically TWO_PI / image size
    Returns:
      amplitude value of wave for frame and pos

  - ### waveValue

    public float waveValue(int frame, int pos, float mapInc)
    Parameters:
      `frame` - current frame
      `pos` - pixel/audio sample index on signal path
      `mapInc` - the increment in phase over the image pixels, typically TWO_PI / image size
    Returns:
      amplitude value of wave for frame and pos

  - ### prepareFrame

    public void prepareFrame(int frame, float mapInc)
    Prepare oscillator state for this frame, assuming a constant freq and a constant mapInc for pos stepping. Call once per frame (per WaveData) before stepping pos with nextValue().

  - ### prepareFrame

    public void prepareFrame(int frame, float mapInc, float freqShift)
    Variant that includes a per-frame freqShift. Use when you want global detune / modulation per frame, not per pixel.

  - ### nextValue

    public float nextValue()
    Get the next value along the path, using oscillator recurrence. Must be called AFTER prepareFrame(...), and then repeatedly for pos = 0,1,2,... in order.

  - ### invalidateFrameState

    public void invalidateFrameState()
    If you ever need to force this oscillator to be rebuilt next frame.

  - ### rawPhaseAtFrame

    public float rawPhaseAtFrame(int frame)

  - ### phaseAtFrame

    public float phaseAtFrame(int frame)

  - ### scaledPhaseAtFrame

    public float scaledPhaseAtFrame(int frame)

  - ### mapToPositivePhase

    public static float mapToPositivePhase(float value, float a, float b)
    Maps a value to a specified range (of a cyclic function) Explanation: 1. Subtract a: Translates the interval to [0,b−a)[0,b−a). 2. value % range: Reduces the value to (−range,range). 3. Adding range: Ensures the result is positive. 4. Final % range: Maps the result to [0,range)[0,range). 5. Adding a: Shifts the result back to the original interval [a,b).
    Parameters:
      `value` - float value to be mapped
      `a` - lower bound
      `b` - upper bound
    Returns:
      value mapped to interval [a,b)

  - ### waveDataListCopy

    public static ArrayList<WaveData> waveDataListCopy(ArrayList<WaveData> wdList)

  - ### clone

    public WaveData clone()
    Overrides:
      `clone` in class `Object`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`