Package net.paulhertz.pixelaudio

# Class PixelAudio

java.lang.Object
net.paulhertz.pixelaudio.PixelAudio

public class PixelAudio extends Object

Author:
  Paul Hertz PixelAudio library for Processing. Typical usage in Processing is to declare a global: PixelAudio pixelaudio; and then initialize it in the setup method: public void setup() { // ... pixelaudio = new PixelAudio(this); // ... more setup code } The host PApplet can be obtained from PixelAudio by other classes. A number of useful static variables and methods are also included.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static processing.core.PApplet`
  `myParent`
  myParent is a reference to the parent sketch, we make it static so it's available to other classes
  `private static Random`
  `rando`
  Java Random
  `static final int`
  `SR_1024x1024`
  `static final int`
  `SR_256x256`
  `static final int`
  `SR_44dot1k`
  `static final int`
  `SR_48k`
  `static final int`
  `SR_512x512`
  `static final int`
  `SR_96k`
  `static final String`
  `VERSION`
  SHould be set by Ant script (?), but that is not happening

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PixelAudio(processing.core.PApplet theParent)`
  a Constructor, usually called in the setup() method in your sketch to initialize and start the Library.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static final float`
  `constrain(float amt, float low, float high)`
  Processing's PApplet.constrain method, copied for convenience.
  `static final int`
  `constrain(int amt, int low, int high)`
  Processing's PApplet.constrain method, copied for convenience.
  `static double`
  `gauss(double mean, double variance)`
  Returns a Gaussian variable using a Java library call to `Random.nextGaussian`.
  `static final float`
  `lerp(float a, float b, float f)`
  Good old lerp.
  `static final float`
  `map(float value, float start1, float stop1, float start2, float stop2)`
  Processing's map method, but with no error checking
  `static Random`
  `rando()`
  `static Random`
  `rando(long seed)`
  `static void`
  `saveAudioTo32BitPCMFile(float[] samples, float sampleRate, String fileName)`
  Saves audio data to a 32-bit floating point format that has higher resolution than 16-bit integer PCM.
  `static void`
  `saveAudioToFile(float[] samples, float sampleRate, String fileName)`
  Saves audio data to 16-bit integer PCM format, which Processing can also open.
  `static void`
  `saveStereoAudioTo32BitPCMFile(float[] leftChannel, float[] rightChannel, float sampleRate, String fileName)`
  Saves stereo audio data to a 32-bit floating point format that has higher resolution than 16-bit integer PCM.
  `static void`
  `saveStereoAudioToFile(float[] leftChannel, float[] rightChannel, float sampleRate, String fileName)`
  Saves stereo audio data to 16-bit integer PCM format, which Processing can also open.
  `String`
  `sayHello()`
  `static String`
  `version()`
  return the version of the Library.
  `private void`
  `welcome()`

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

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

- ## Field Details

  - ### myParent

    public static processing.core.PApplet myParent
    myParent is a reference to the parent sketch, we make it static so it's available to other classes

  - ### rando

    private static Random rando
    Java Random

  - ### VERSION

    public static final String VERSION
    SHould be set by Ant script (?), but that is not happening
    See Also:
      - Constant Field Values

  - ### SR_96k

    public static final int SR_96k
    See Also:
      - Constant Field Values

  - ### SR_48k

    public static final int SR_48k
    See Also:
      - Constant Field Values

  - ### SR_44dot1k

    public static final int SR_44dot1k
    See Also:
      - Constant Field Values

  - ### SR_256x256

    public static final int SR_256x256
    See Also:
      - Constant Field Values

  - ### SR_512x512

    public static final int SR_512x512
    See Also:
      - Constant Field Values

  - ### SR_1024x1024

    public static final int SR_1024x1024
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### PixelAudio

    public PixelAudio(processing.core.PApplet theParent)
    a Constructor, usually called in the setup() method in your sketch to initialize and start the Library.
    Parameters:
      `theParent` - the parent PApplet

- ## Method Details

  - ### welcome

    private void welcome()

  - ### sayHello

    public String sayHello()

  - ### version

    public static String version()
    return the version of the Library.
    Returns:
      String

  - ### constrain

    public static final float constrain(float amt, float low, float high)
    Processing's PApplet.constrain method, copied for convenience.
    Parameters:
      `amt` -
      `low` -
      `high` -
    Returns:
      amt clipped to low and high, closed interval

  - ### constrain

    public static final int constrain(int amt, int low, int high)
    Processing's PApplet.constrain method, copied for convenience.
    Parameters:
      `amt` -
      `low` -
      `high` -
    Returns:
      amt clipped to low and high, closed interval

  - ### map

    public static final float map(float value, float start1, float stop1, float start2, float stop2)
    Processing's map method, but with no error checking
    Parameters:
      `value` -
      `start1` -
      `stop1` -
      `start2` -
      `stop2` -
    Returns:

  - ### lerp

    public static final float lerp(float a, float b, float f)
    Good old lerp.
    Parameters:
      `a` - first bound, typically a minimum value
      `b` - second bound, typically a maximum value
      `f` - scaling value, from 0..1 to interpolate between a and b, but can go over or under
    Returns:
      a value between a and b, scaled by f (if 0 <= f >= 1).

  - ### gauss

    public static double gauss(double mean, double variance)
    Returns a Gaussian variable using a Java library call to `Random.nextGaussian`.
    Parameters:
      `mean` -
      `variance` -
    Returns:
      a Gaussian-distributed random number with mean `mean` and variance `variance`

  - ### rando

    public static Random rando()

  - ### rando

    public static Random rando(long seed)

  - ### saveAudioToFile

    public static void saveAudioToFile(float[] samples, float sampleRate, String fileName) throws IOException, UnsupportedAudioFileException
    Saves audio data to 16-bit integer PCM format, which Processing can also open.
    Parameters:
      `samples` - an array of floats in the audio range (-1.0f, 1.0f)
      `sampleRate` - audio sample rate for the file
      `fileName` - name of the file to save to
    Throws:
      `IOException` - an Exception you'll need to handle to call this method (see keyPressed entry for 's')
      `UnsupportedAudioFileException` - another Exception (see keyPressed entry for 's')

  - ### saveAudioTo32BitPCMFile

    public static void saveAudioTo32BitPCMFile(float[] samples, float sampleRate, String fileName) throws IOException
    Saves audio data to a 32-bit floating point format that has higher resolution than 16-bit integer PCM. The format can't be opened by Processing but can be opened by audio applications.
    Parameters:
      `samples` - an array of floats in the audio range (-1.0f, 1.0f)
      `sampleRate` - the sample rate for the file
      `fileName` - name of the file
    Throws:
      `IOException` - an Exception you'll need to catch to call this method (see keyPressed entry for 's')

  - ### saveStereoAudioToFile

    public static void saveStereoAudioToFile(float[] leftChannel, float[] rightChannel, float sampleRate, String fileName) throws IOException, UnsupportedAudioFileException
    Saves stereo audio data to 16-bit integer PCM format, which Processing can also open.
    Parameters:
      `leftChannel` - an array of floats in the audio range (-1.0f, 1.0f)
      `rightChannel` - an array of floats in the audio range (-1.0f, 1.0f)
      `sampleRate` - audio sample rate for the file
      `fileName` - name of the file to save to
    Throws:
      `IOException` - an Exception you'll need to handle to call this method (see keyPressed entry for 's')
      `UnsupportedAudioFileException` - another Exception (see keyPressed entry for 's')

  - ### saveStereoAudioTo32BitPCMFile

    public static void saveStereoAudioTo32BitPCMFile(float[] leftChannel, float[] rightChannel, float sampleRate, String fileName) throws IOException
    Saves stereo audio data to a 32-bit floating point format that has higher resolution than 16-bit integer PCM. The format can't be opened by Processing but can be opened by audio applications.
    Parameters:
      `leftChannel` - an array of floats in the audio range (-1.0f, 1.0f)
      `rightChannel` - an array of floats in the audio range (-1.0f, 1.0f)
      `sampleRate` - the sample rate for the file
      `fileName` - name of the file
    Throws:
      `IOException` - an Exception you'll need to handle when calling this method