Class WaveSynthSequencer

java.lang.Object
processing.core.PApplet
net.paulhertz.pixelaudio.example.WaveSynthSequencer
All Implemented Interfaces:
processing.core.PConstants

public class WaveSynthSequencer extends processing.core.PApplet
Example sketch shows how to create an audio synth sequencer with the WaveSynth. An early example of audio/image sequencing with the WaveSynth color organ, used for a performance at Experimental Sound Studio, Chicago.

INSTRUCTIONS FOR PERFORMANCE

 Launch and let the raindrops play. 
 The tempo for performance is quarter note = 88 bpm, flexible for humans, inflexible for computer.
 Percussion cues computer instrumentalist -- type '\' to start music, speak words. (Engineer: mic up)
 At end, escape key closes app and WorkFlowPerformance is uncovered.
 
 WaveSynthSequencer builds on BigWaveSynth, which shows how you can load
 WaveSynth pixel data into the pixel array of a MultiGen. WaveSynthSequencer 
 adds some useful features: 1. you can play the image as audio, and
 2. you can save the audio to a WAVE file.
 
 This example also allows you to load JSON files to reconfigure the WaveSynth. 
 Initially, we call buildWaveDataList() to create a WaveData array with eight operators. 
 This is passed to a WaveSynth which is further configured by initWaveSynth(). 
 To load JSON data, press the 'o' key and go to the data folder of this sketch.
 
 Note that the sampleRate value influences the appearance of the image, the duration
 of audio samples and the way data is written to an audio file. See the comments
 in setup() for details. 
 
 
 Press ' ' (spacebar) or click to play audio at the mouse location.
 Press TAB to start and stop WaveSynth animation.
 Press 'o' to open a JSON WaveSynth configuration file.
 Press 'O' to reload the most recent JSON WaveSynth configuration file.
 Press 'j' or 'J' to save current WaveSynth configuration to a JSON file.
 Press 's' to save the display to an image file named wavesynth_(wsIndex).png.
 Press 'S' to save WaveSynth audio to an audio file named wavesynth_(wsIndex).wave.
 Press 'f' to display the current frameRate. 
 Press 'w' to step the WaveSynth Sequencer without playing a musical note.
 Press 'W' to step the WaveSynth Sequencer and play the corresponding a musical note.
 Press 'd' to turn raindrops on or off (raindrops trigger audio events). 
 Press '\' to run the WaveSynth Sequencer 
 Press 'c' to reset the image and sound to the opening state. 
 Press 'h' to show this help message in the console. 
 
 See also: BigWaveSynth, BigWaveSynthAudio.
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) ADSRParams
     
    (package private) int
     
    (package private) int
     
    (package private) float
     
    (package private) ddf.minim.MultiChannelBuffer
     
    (package private) int
     
    (package private) ddf.minim.AudioOutput
     
    (package private) float[]
     
    (package private) float
     
    (package private) int
     
    (package private) int
     
    (package private) DecimalFormat
     
    (package private) String
     
    (package private) int
     
    (package private) File
     
    (package private) String
     
    (package private) float[]
    amplitude values
    (package private) int[]
     
    (package private) int[]
     
    (package private) float
     
    (package private) DecimalFormat
     
    (package private) DecimalFormat
     
    (package private) int
     
    (package private) int
     
    (package private) HilbertGen
     
     
    (package private) boolean
     
    (package private) boolean
     
    (package private) boolean
     
    (package private) boolean
     
    (package private) boolean
     
    (package private) processing.data.JSONObject
     
    (package private) String
     
    (package private) PixelAudioMapper
     
    (package private) int
     
    (package private) float
     
    (package private) ddf.minim.Minim
    Minim audio library
    (package private) MultiGen
     
    (package private) float
     
    (package private) DecimalFormat
     
    (package private) int
     
    (package private) boolean
     
    (package private) PixelAudio
     
    (package private) PASamplerInstrumentPool
     
    (package private) float
     
    (package private) int[]
     
    (package private) int
     
    (package private) int
     
    (package private) int
     
    (package private) int
     
    (package private) int
     
    (package private) int
     
    static final double
    for frequency calculations, numbers are piano keys
    (package private) int
     
    (package private) float
     
    (package private) processing.core.PImage
     
    (package private) int
     
    (package private) ArrayList<TimedLocation>
     
    (package private) DecimalFormat
     
    (package private) WaveSynth
     
    (package private) ArrayList<WaveSynth>
    for time calculations, 12 = one quarter note
    (package private) ArrayList<WaveData>
     
    (package private) int
     

    Fields inherited from class processing.core.PApplet

    args, ARGS_BGCOLOR, ARGS_DISABLE_AWT, ARGS_DISPLAY, ARGS_EDITOR_LOCATION, ARGS_EXTERNAL, ARGS_FULL_SCREEN, ARGS_HIDE_STOP, ARGS_LOCATION, ARGS_PRESENT, ARGS_SKETCH_FOLDER, ARGS_STOP_COLOR, ARGS_UI_SCALE, ARGS_WINDOW_COLOR, DEFAULT_HEIGHT, DEFAULT_WIDTH, disableAWT, displayHeight, displayWidth, dmouseX, dmouseY, emouseX, emouseY, exitCalled, EXTERNAL_MOVE, EXTERNAL_STOP, finished, firstMouse, focused, frameCount, frameRate, frameRateLastNanos, g, height, insideDraw, javaPlatform, javaVersion, javaVersionName, key, keyCode, keyEvent, keyPressed, keyRepeatEnabled, looping, matchPatterns, mouseButton, mouseEvent, mousePressed, mouseX, mouseY, pixelDensity, pixelHeight, pixels, pixelWidth, platform, pmouseX, pmouseY, ratioLeft, ratioScale, ratioTop, recorder, redraw, rheight, rmouseX, rmouseY, rwidth, surface, useNativeSelect, width, windowX, windowY

    Fields inherited from interface processing.core.PConstants

    ADD, ALPHA, ALT, AMBIENT, ARC, ARGB, ARROW, BACKSPACE, BASELINE, BEVEL, BEZIER_VERTEX, BLEND, BLUR, BOTTOM, BOX, BREAK, BURN, CENTER, CHATTER, CHORD, CLAMP, CLOSE, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CURVE_VERTEX, CUSTOM, DARKEST, DEG_TO_RAD, DELETE, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ASYNC_SAVEFRAME, DISABLE_BUFFER_READING, DISABLE_DEPTH_MASK, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_KEY_REPEAT, DISABLE_NATIVE_FONTS, DISABLE_OPENGL_ERRORS, DISABLE_OPTIMIZED_STROKE, DISABLE_STROKE_PERSPECTIVE, DISABLE_STROKE_PURE, DISABLE_TEXTURE_MIPMAPS, DODGE, DOWN, DXF, ELLIPSE, ENABLE_ASYNC_SAVEFRAME, ENABLE_BUFFER_READING, ENABLE_DEPTH_MASK, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_KEY_REPEAT, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_ERRORS, ENABLE_OPTIMIZED_STROKE, ENABLE_STROKE_PERSPECTIVE, ENABLE_STROKE_PURE, ENABLE_TEXTURE_MIPMAPS, ENTER, EPSILON, ERODE, ESC, EXCLUSION, FX2D, GIF, GRAY, GROUP, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LANDSCAPE, LEFT, LIGHTEST, LINE, LINE_LOOP, LINE_STRIP, LINES, LINUX, MACOS, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MODELVIEW, MOVE, MULTIPLY, NORMAL, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, PIE, platformNames, POINT, POINTS, POLYGON, PORTRAIT, POSTERIZE, PROBLEM, PROJECT, PROJECTION, QUAD, QUAD_BEZIER_VERTEX, QUAD_STRIP, QUADRATIC_VERTEX, QUADS, QUARTER_PI, RAD_TO_DEG, RADIUS, RECT, REPEAT, REPLACE, RETURN, RGB, RIGHT, ROUND, SCREEN, SHAPE, SHIFT, SOFT_LIGHT, SPAN, SPHERE, SPOT, SQUARE, SUBTRACT, SVG, TAB, TARGA, TAU, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, UP, VERTEX, WAIT, WHITESPACE, WINDOWS, X, Y, Z
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    audioMouseClick(int sampleX, int sampleY)
     
    buildWaveDataList(float fundamental, int howManyPartials, float pianoKey)
    Generates an ArrayList of WaveData objects to be used by a WaveSynth to generate RGB pixel values and (on request) audio signal values.
    int
     
    void
    checkBufferState(boolean isStale)
     
    float[]
    chromaticScale(float funda)
     
    int
    colorShift(int c, float shift)
     
    void
    The main loop for drawing to the screen.
    void
    drawCircle(int x, int y)
    Draws a circle at the location of an audio trigger (mouseDown event).
    void
     
    void
     
    void
    CALL IN SETUP()
    void
    Initializes number formatters, handy for display.
    Sets gain, gamma, isScaleHisto, animSteps, and sampleRate instance variables of a WaveSynth object and generates its first frame of animation.
    void
    Initializes a list of WaveSynth objects using pianoKey numbers in dbwfMusic array.
    void
     
    loadLoopGen(int loopGenW, int loopGenH)
    Adds PixelMapGen objects to the local variable genList, puts the coords of their upper left corner in offsetList.
    void
    Initializes the introMusic ArrayList of NoteTimedLocation objects, data for a simple audio sequencer.
    void
    Show an Open File dialog for JSON files
    static void
    main(String[] args)
     
    void
     
    float
    pianoKeyFrequency(int keyNumber)
     
    int
    playSample(int samplePos, int samplelen, float amplitude)
    Plays an audio sample with WFSamplerInstrument and default ADSR.
    int
    playSample(int samplePos, int samplelen, float amplitude, ADSRParams env)
    Plays an audio sample with WFSamplerInstrument and custom ADSR.
    void
    Outputs fields from a WaveSynth to the console
    void
    Trigger a WaveSynth sample at a random location.
    void
    Calls WaveSynth to render a audio sample array derived from the same math that creates the image, then loads the derived audio data to audioBuffer, ready to be played.
    void
    Run the WaveSynth Sequencer.
    void
    Run the animation for audio events.
    static void
    saveAudioTo32BitPCMFile(float[] samples, float sampleRate, String fileName)
    Saves 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.
    void
    Save audio buffer to a file called "wavesynth_(wsIndex).wav".
    void
    Show a Save File dialog
    void
     
    void
     
    void
     
    void
    Animates the WaveSynth referenced by variable wavesynth.
    void
    Advance the WaveSynth Sequencer to its next state.
    void
    turn off audio processing when we exit
    void
     

    Methods inherited from class processing.core.PApplet

    abs, abs, acos, alpha, ambient, ambient, ambient, ambientLight, ambientLight, append, append, append, append, append, append, applyMatrix, applyMatrix, applyMatrix, applyMatrix, applyMatrix, arc, arc, arraycopy, arraycopy, arraycopy, arrayCopy, arrayCopy, arrayCopy, asin, atan, atan2, attrib, attrib, attrib, attribColor, attribNormal, attribPosition, background, background, background, background, background, background, background, beginCamera, beginContour, beginPGL, beginRaw, beginRaw, beginRecord, beginRecord, beginShape, beginShape, bezier, bezier, bezierDetail, bezierPoint, bezierTangent, bezierVertex, bezierVertex, binary, binary, binary, binary, blend, blend, blendColor, blendMode, blue, box, box, brightness, calcSketchPath, camera, camera, ceil, checkAlpha, checkExtension, choice, choice, circle, clear, clip, color, color, color, color, color, color, color, color, colorMode, colorMode, colorMode, colorMode, concat, concat, concat, concat, concat, concat, concat, constrain, constrain, copy, copy, copy, cos, createFont, createFont, createFont, createGraphics, createGraphics, createGraphics, createImage, createInput, createInput, createInputRaw, createOutput, createOutput, createPath, createPath, createPrimaryGraphics, createReader, createReader, createReader, createShape, createShape, createShape, createWriter, createWriter, createWriter, cursor, cursor, cursor, cursor, curve, curve, curveDetail, curvePoint, curveTangent, curveTightness, curveVertex, curveVertex, dataFile, dataPath, day, debug, degrees, delay, dequeueEvents, desktopFile, desktopPath, die, die, directionalLight, displayDensity, displayDensity, dispose, dist, dist, edge, ellipse, ellipseMode, emissive, emissive, emissive, endCamera, endContour, endPGL, endRaw, endRecord, endShape, endShape, exec, exec, exit, exitActual, exitCalled, exp, expand, expand, expand, expand, expand, expand, expand, expand, expand, expand, expand, expand, expand, expand, expand, expand, expand, expand, fill, fill, fill, fill, fill, fill, filter, filter, filter, floor, flush, focusGained, focusLost, frameMoved, frameRate, frustum, fullScreen, fullScreen, fullScreen, fullScreen, get, get, get, getExtension, getGraphics, getMatrix, getMatrix, getMatrix, getSurface, green, handleDraw, handleKeyEvent, handleMethods, handleMouseEvent, hex, hex, hex, hex, hideMenuBar, hint, hour, hue, image, image, image, imageMode, initSurface, insertFrame, isLooping, join, join, keyPressed, keyReleased, keyReleased, keyTyped, keyTyped, launch, lerp, lerpColor, lerpColor, lightFalloff, lights, lightSpecular, line, line, link, listFiles, listFiles, listPaths, loadBytes, loadBytes, loadBytes, loadFont, loadImage, loadImage, loadJSONArray, loadJSONArray, loadJSONObject, loadJSONObject, loadPixels, loadShader, loadShader, loadShape, loadShape, loadStrings, loadStrings, loadStrings, loadStrings, loadTable, loadTable, loadXML, loadXML, log, loop, mag, mag, main, main, main, makeGraphics, map, mask, match, matchAll, max, max, max, max, max, max, method, millis, min, min, min, min, min, min, minute, modelX, modelY, modelZ, month, mouseClicked, mouseDragged, mouseDragged, mouseEntered, mouseEntered, mouseExited, mouseExited, mouseMoved, mouseMoved, mousePressed, mousePressed, mouseReleased, mouseReleased, mouseWheel, mouseWheel, nf, nf, nf, nf, nf, nf, nfc, nfc, nfc, nfc, nfp, nfp, nfp, nfp, nfs, nfs, nfs, nfs, noClip, noCursor, noFill, noise, noise, noise, noiseDetail, noiseDetail, noiseSeed, noLights, noLoop, norm, normal, noSmooth, noStroke, noTexture, noTint, orientation, ortho, ortho, ortho, parseBoolean, parseBoolean, parseBoolean, parseBoolean, parseByte, parseByte, parseByte, parseByte, parseByte, parseByte, parseByte, parseByte, parseChar, parseChar, parseChar, parseChar, parseFloat, parseFloat, parseFloat, parseFloat, parseFloat, parseFloat, parseFloat, parseInt, parseInt, parseInt, parseInt, parseInt, parseInt, parseInt, parseInt, parseInt, parseInt, parseInt, parseInt, parseJSONArray, parseJSONObject, parseXML, parseXML, pause, perspective, perspective, pixelDensity, point, point, pointLight, pop, popMatrix, popStyle, postEvent, postWindowMoved, postWindowResized, pow, print, print, print, print, print, print, print, print, print, printArray, printCamera, println, println, println, println, println, println, println, println, println, println, println, printMatrix, printProjection, printStackTrace, push, pushMatrix, pushStyle, quad, quadraticVertex, quadraticVertex, radians, random, random, randomGaussian, randomSeed, rect, rect, rect, rectMode, red, redraw, registerMethod, requestImage, requestImage, resetMatrix, resetShader, resetShader, resume, reverse, reverse, reverse, reverse, reverse, reverse, reverse, rotate, rotate, rotateX, rotateY, rotateZ, round, runSketch, runSketch, runSketch, saturation, save, saveBytes, saveBytes, saveBytes, saveFile, saveFrame, saveFrame, saveJSONArray, saveJSONArray, saveJSONObject, saveJSONObject, savePath, saveStream, saveStream, saveStream, saveStream, saveStream, saveStrings, saveStrings, saveStrings, saveTable, saveTable, saveXML, saveXML, scale, scale, scale, screenX, screenX, screenY, screenY, screenZ, second, selectCallback, selectFolder, selectFolder, selectFolder, selectInput, selectInput, selectInput, selectOutput, selectOutput, selectOutput, set, set, setMatrix, setMatrix, setMatrix, setSize, shader, shader, shape, shape, shape, shapeMode, shearX, shearY, shell, shininess, shorten, shorten, shorten, shorten, shorten, shorten, shorten, showDepthWarning, showDepthWarningXYZ, showMethodWarning, showMissingWarning, showSurface, showVariationWarning, sin, size, size, size, sketchDisplay, sketchFile, sketchFullScreen, sketchHeight, sketchOutputPath, sketchOutputStream, sketchPath, sketchPath, sketchPixelDensity, sketchRenderer, sketchSmooth, sketchWidth, sketchWindowColor, smooth, smooth, sort, sort, sort, sort, sort, sort, sort, sort, sort, sort, specular, specular, specular, sphere, sphereDetail, sphereDetail, splice, splice, splice, splice, splice, splice, splice, splice, splice, splice, splice, splice, splice, split, split, splitTokens, splitTokens, spotLight, sq, sqrt, square, start, startSurface, str, str, str, str, str, str, str, str, str, str, stroke, stroke, stroke, stroke, stroke, stroke, strokeCap, strokeJoin, strokeWeight, style, subset, subset, subset, subset, subset, subset, subset, subset, subset, subset, subset, subset, subset, subset, subset, subset, subset, subset, tan, text, text, text, text, text, text, text, text, text, text, text, textAlign, textAlign, textAscent, textDescent, textFont, textFont, textLeading, textMode, textSize, texture, textureMode, textureWrap, textWidth, textWidth, textWidth, thread, tint, tint, tint, tint, tint, tint, translate, translate, triangle, trim, trim, unbinary, unhex, unregisterMethod, updatePixels, updatePixels, urlDecode, urlEncode, vertex, vertex, vertex, vertex, vertex, windowMove, windowMoved, windowRatio, windowResizable, windowResize, windowResized, windowTitle, year

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • pixelaudio

      PixelAudio pixelaudio
    • hGen

    • multigen

      MultiGen multigen
    • rows

      int rows
    • columns

      int columns
    • genWidth

      int genWidth
    • genHeight

      int genHeight
    • mapper

    • mapSize

      int mapSize
    • wdList

    • wavesynth

      WaveSynth wavesynth
    • synthImage

      processing.core.PImage synthImage
    • myGamma

      float myGamma
    • animSteps

      int animSteps
    • animStop

      int animStop
    • step

      int step
    • comments

      String comments
    • minim

      ddf.minim.Minim minim
      Minim audio library
    • audioOut

      ddf.minim.AudioOutput audioOut
    • audioBuffer

      ddf.minim.MultiChannelBuffer audioBuffer
    • isBufferStale

      boolean isBufferStale
    • sampleRate

      int sampleRate
    • audioSignal

      float[] audioSignal
    • rgbSignal

      int[] rgbSignal
    • audioLength

      int audioLength
    • noteDuration

      int noteDuration
    • samplelen

      int samplelen
    • pool

    • adsr

    • maxAmplitude

      float maxAmplitude
    • attackTime

      float attackTime
    • decayTime

      float decayTime
    • sustainLevel

      float sustainLevel
    • releaseTime

      float releaseTime
    • jsonFolder

      String jsonFolder
    • currentDataFile

      File currentDataFile
    • currentFileName

      String currentFileName
    • json

      processing.data.JSONObject json
    • isWaveSynthAnimating

      boolean isWaveSynthAnimating
    • oldIsAnimating

      boolean oldIsAnimating
    • isLooping

      boolean isLooping
    • isRaining

      boolean isRaining
    • circleColor

      int circleColor
    • sampleX

      int sampleX
    • sampleY

      int sampleY
    • samplePos

      int samplePos
    • timeLocsArray

      ArrayList<TimedLocation> timeLocsArray
    • count

      int count
    • semitoneFac

      public static final double semitoneFac
      for frequency calculations, numbers are piano keys
    • dbwfMusic

      int[] dbwfMusic
    • waveSynthList

      ArrayList<WaveSynth> waveSynthList
      for time calculations, 12 = one quarter note
    • dbwfTimes

      int[] dbwfTimes
    • dbwfAmps

      float[] dbwfAmps
      amplitude values
    • ticks

      int ticks
    • beatSpan

      float beatSpan
    • wsIndex

      int wsIndex
    • introMusic

    • isPlayIntro

      boolean isPlayIntro
    • twoPlaces

      DecimalFormat twoPlaces
    • noPlaces

      DecimalFormat noPlaces
    • fourFrontPlaces

      DecimalFormat fourFrontPlaces
    • commaTwoPlaces

      DecimalFormat commaTwoPlaces
    • eightPlaces

      DecimalFormat eightPlaces
  • Constructor Details

    • WaveSynthSequencer

      public WaveSynthSequencer()
  • Method Details

    • main

      public static void main(String[] args)
    • settings

      public void settings()
      Overrides:
      settings in class processing.core.PApplet
    • setup

      public void setup()
      Overrides:
      setup in class processing.core.PApplet
    • stop

      public void stop()
      turn off audio processing when we exit
      Overrides:
      stop in class processing.core.PApplet
    • loadLoopGen

      public MultiGen loadLoopGen(int loopGenW, int loopGenH)
      Adds PixelMapGen objects to the local variable genList, puts the coords of their upper left corner in offsetList. The two lists are used to initialize a MultiGen, which can be used to map audio and pixel data. This method provides a big looping fractal consisting of 6 Hilbert curves. This method was an early effort at creating continuous paths over multiple PixelMapGens. It is now available as a static method in the PixelAudio library, HilbertGen. hilbertLoop3x2(int genW, int genH).
    • initDecimalFormats

      public void initDecimalFormats()
      Initializes number formatters, handy for display. Processing's nf() method will also do.
    • draw

      public void draw()
      The main loop for drawing to the screen.
      Overrides:
      draw in class processing.core.PApplet
    • stepAnimation

      public void stepAnimation()
      Animates the WaveSynth referenced by variable wavesynth. The animation is controlled by the WaveSynth phase and cycle attributes.
    • keyPressed

      public void keyPressed()
      Overrides:
      keyPressed in class processing.core.PApplet
    • stepWaveSynth

      public void stepWaveSynth()
      Advance the WaveSynth Sequencer to its next state.
    • showHelp

      public void showHelp()
    • saveToAudio

      public void saveToAudio()
      Save audio buffer to a file called "wavesynth_(wsIndex).wav".
    • mouseClicked

      public void mouseClicked()
      Overrides:
      mouseClicked in class processing.core.PApplet
    • initAudio

      public void initAudio()
      CALL IN SETUP()
    • audioMouseClick

      public void audioMouseClick(int sampleX, int sampleY)
    • renderSignal

      public void renderSignal()
      Calls WaveSynth to render a audio sample array derived from the same math that creates the image, then loads the derived audio data to audioBuffer, ready to be played.
    • checkBufferState

      public void checkBufferState(boolean isStale)
    • playSample

      public int playSample(int samplePos, int samplelen, float amplitude, ADSRParams env)
      Plays an audio sample with WFSamplerInstrument and custom ADSR.
      Parameters:
      samplePos - position of the sample in the audio buffer
      samplelen - length of the sample (will be adjusted)
      amplitude - amplitude of the sample on playback
      env - an ADSR envelope for the sample
      Returns:
      the calculated sample length in samples
    • playSample

      public int playSample(int samplePos, int samplelen, float amplitude)
      Plays an audio sample with WFSamplerInstrument and default ADSR.
      Parameters:
      samplePos - position of the sample in the audio buffer
      samplelen - length of the sample (will be adjusted)
      amplitude - amplitude of the sample on playback
      Returns:
      the calculated sample length in samples
    • calcSampleLen

      public int calcSampleLen()
    • runTimeArray

      public void runTimeArray()
      Run the animation for audio events.
    • runMusicArray

      public void runMusicArray()
      Run the WaveSynth Sequencer.
    • raindrops

      public void raindrops()
      Trigger a WaveSynth sample at a random location.
    • drawCircle

      public void drawCircle(int x, int y)
      Draws a circle at the location of an audio trigger (mouseDown event).
      Parameters:
      x - x coordinate of circle
      y - y coordinate of circle
    • buildWaveDataList

      public ArrayList<WaveData> buildWaveDataList(float fundamental, int howManyPartials, float pianoKey)
      Generates an ArrayList of WaveData objects to be used by a WaveSynth to generate RGB pixel values and (on request) audio signal values. A version of this code is included in the WaveSynthBuilder class in the PixelAudio library, wrapped in a static method called synthTrumpet(float fundamental, int howManyPartials, float pianoKey, int animSteps).
      Returns:
      an ArrayList of WaveData objects
    • colorShift

      public int colorShift(int c, float shift)
      Parameters:
      c - an RGB color
      shift - the shift [0..1] of the hue in the HSB representation of color c
      Returns:
      the RGB representation of the shifted color
    • initWaveSynth

      public WaveSynth initWaveSynth(WaveSynth synth)
      Sets gain, gamma, isScaleHisto, animSteps, and sampleRate instance variables of a WaveSynth object and generates its first frame of animation.
      Parameters:
      synth - a WaveSynth object whose attributes will be set
      Returns:
      the WaveSynth object with attributes set
    • pianoKeyFrequency

      public float pianoKeyFrequency(int keyNumber)
      Parameters:
      keyNumber - key number on a piano, where A is key 49
      Returns:
      frequency of the key (A = 440)
    • chromaticScale

      public float[] chromaticScale(float funda)
      Parameters:
      funda - the starting frequency
      Returns:
      a chromatic scale starting with funda
    • initWaveSynthList

      public void initWaveSynthList()
      Initializes a list of WaveSynth objects using pianoKey numbers in dbwfMusic array.
    • loadMusic

      public void loadMusic()
      Initializes the introMusic ArrayList of NoteTimedLocation objects, data for a simple audio sequencer. Uses the dbwfTimes array to set durations, dbwfMusic to set frequencies, and dbwfAmps to set amplitudes.
    • loadWaveData

      public void loadWaveData()
      Show an Open File dialog for JSON files
    • fileSelectedOpen

      public void fileSelectedOpen(File selection)
      Parameters:
      selection - a file selected from an Open File dialog
    • syncAfterWaveSynthLoad

      public void syncAfterWaveSynthLoad()
    • printWaveData

      public void printWaveData(WaveSynth synth)
      Outputs fields from a WaveSynth to the console
    • saveWaveData

      public void saveWaveData()
      Show a Save File dialog
    • fileSelectedWrite

      public void fileSelectedWrite(File selection)
    • saveAudioTo32BitPCMFile

      public static void saveAudioTo32BitPCMFile(float[] samples, float sampleRate, String fileName) throws IOException
      Saves 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')
    • 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 catch to call this method (see keyPressed entry for 's')
      UnsupportedAudioFileException - another Exception (see keyPressed entry for 's')