Class TutorialOne_06_WindowBuffer

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

public class TutorialOne_06_WindowBuffer extends processing.core.PApplet
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    (package private) int
     
    int
     
    ArrayList<processing.core.PVector>
     
     
    (package private) int
     
    (package private) ddf.minim.MultiChannelBuffer
    buffer for complete file
    (package private) float[]
    A source for streaming audio from a file
    (package private) float
     
    (package private) File
     
    (package private) int
     
    (package private) String
     
    (package private) String
     
    (package private) String
     
    (package private) int
     
    (package private) ddf.minim.AudioOutput
     
    (package private) float[]
     
    (package private) float
     
     
     
    (package private) int[]
     
    (package private) int
     
    processing.core.PVector
     
     
     
    (package private) String
     
    (package private) float
     
    (package private) ADSRParams
     
    (package private) float
     
    (package private) float
     
    int
     
    int
     
    float
     
    float
     
    ArrayList<processing.core.PVector>
     
    ListIterator<processing.core.PVector>
     
    (package private) int
     
    (package private) float
     
    (package private) int
    keep track of the frame we should be rendering
    (package private) float
     
    (package private) int
     
    (package private) int
     
    (package private) int
     
    int
     
    (package private) ADSRParams
     
    (package private) float
     
    (package private) File
     
    (package private) int
     
    (package private) String
     
    (package private) String
     
    (package private) String
     
    (package private) int
     
    (package private) boolean
     
    (package private) boolean
     
    (package private) boolean
     
    boolean
     
    (package private) boolean
    boolean to flag fixed length capture
    (package private) boolean
     
    (package private) boolean
     
    (package private) boolean
    boolean to flag audio capture
    (package private) boolean
     
    (package private) boolean
     
    (package private) boolean
     
    (package private) boolean
     
    (package private) boolean
     
    (package private) float
     
    (package private) processing.core.PImage
     
    (package private) PixelAudioMapper
     
    (package private) int
     
    (package private) float
     
    (package private) ddf.minim.Minim
    Minim audio library
    (package private) MultiGen
     
    (package private) int
     
    (package private) int
     
    (package private) boolean
     
    (package private) boolean
    save isListening state
    (package private) int
     
    (package private) float
     
    (package private) PixelAudio
     
    (package private) ddf.minim.MultiChannelBuffer
     
    (package private) int
     
    int
     
    (package private) PASamplerInstrumentPool
     
    (package private) int
     
    (package private) int
     
    (package private) float
     
    (package private) int
     
    (package private) int
     
    (package private) int
     
    (package private) float
     
    (package private) int
     
    (package private) int
     
    (package private) int
     
    int
     
    (package private) int
     
    (package private) float
     
    (package private) ArrayList<TimedLocation>
     
    (package private) int
     
    (package private) int
     
    (package private) com.hamoid.VideoExport
     
    A windowed buffer for anthem
    (package private) int
    how far to step the window on each frame

    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
    addPoint(int x, int y)
    While user is dragging the mouses and isDrawMode == true, accumulates new points to allPoints and event times to allTimes.
    void
     
    int[]
    applyColor(int[] colorSource, int[] graySource, int[] lut)
    Utility method for applying hue and saturation values from a source array of RGB values to the brightness values in a target array of RGB values, using a lookup table to redirect indexing.
    void
    applyImageColor(processing.core.PImage colorImage, processing.core.PImage targetImage)
    Apply the hue and saturation channels of one image to another image, leaving its brightness channel unchanged.
    void
     
    void
     
    void
    audioMousePressed(int x, int y)
    Typically called from mousePressed with mouseX and mouseY, generates audio events.
    static void
    blendInto(ddf.minim.MultiChannelBuffer dest, ddf.minim.MultiChannelBuffer src, float weight, boolean normalize, float targetDB)
    Blends audio data from buffer "src" into buffer "dest" in place.
    int
     
    void
    Call to initiate process of opening an image file to get its color data.
    void
    Wrapper method for Processing's selectInput command
    void
    colorFileSelected(File selectedFile)
    callback method for chooseColorImage()
    void
    Draws shapes stored in curveMaker, a PACurveMaker instance that stores the most recent drawing data.
    void
     
    void
    Iterates over brushShapesList and draws the brushstrokes stored in each PACurveMaker in the list.
    void
    drawCircle(int x, int y)
    Draws a circle at the location of an audio trigger (mouseDown event).
    void
    drawCircle(int x, int y, float d, int c)
    Draws a circle at the location of an audio trigger (mouseDown event).
    void
    Transcode directly from audioSignal to mapImage.pixels, the display image.
    void
    fileSelected(File selectedFile)
    callback method for chooseFile(), handles standard audio and image formats for Processing.
    int[]
    getColors(int size)
    Generates an array of rainbow colors using the HSB color space.
    int
    getSamplePos(int x, int y)
    Calculates the index of the image pixel within the signal path, taking the current window position and animated shifting of pixels and audioSignal into account.
    void
    Handles user's drawing actions, draws previously recorded brushstrokes, tracks and generates animation and audio events.
    void
    handleMousePressed(int x, int y)
    Responds to mousePressed events associated with drawing.
    hilbertRowOrtho(int cols, int rows, int genW, int genH)
    This method creates rows of HilbertGens, starting each row from the left and adding gens.
    void
     
    void
    Initializes allPoints and adds the current mouse location to it.
    void
    CALL THIS METHOD IN SETUP() Initializes Minim audio library and audio variables.
    void
    Initializes a PACurveMaker instance with allPoints as an argument to the factory method PACurveMaker.buildCurveMaker() and then fills in PACurveMaker instance variables from global variables in the host class.
    void
    Initializes the line, curve, and brushstroke drawing variables.
    void
    Initializes mapImage with the colors array.
    void
    built-in keyPressed handler, forwards events to parseKey.
    boolean
    listenToAnthem(boolean isStartListening)
    TODO update for buffer animation
    float
    loadAnthem(File audFile)
     
    void
    LoadAudioFile attempts to load audio data from a selected file into playBuffer and anthemBuffer.
    void
    Processes the eventPoints list to create TimedLocation events and stores them in curveTLEvents.
    void
    loadEventPoints(int startTime)
    Processes the eventPoints list to create TimedLocation events and stores them in curveTLEvents.
    void
    Attempts to load image data from a selected file into mapImage, then calls writeImageToAudio() to transcode HSB brightness channel to audio and writes it to playBuffer and audioSignal.
    static void
    main(String[] args)
    Entry point for pure Java implementation (in Eclipse).
    void
    Used for interactively setting the amount of pixel array shift when animating.
    boolean
    mouseInPoly(ArrayList<processing.core.PVector> poly)
    Detects if the mouse is within a selected polygon.
    void
    The built-in mousePressed handler for Processing, but note that it forwards mouse coords to handleMousePressed().
    void
     
    void
    moveAudioWindow(int howFar)
    Moves WindowedBuffer instance windowBuff's window to the index howFar.
    static void
    normalize(float[] signal, float targetDB)
    Normalizes a single-channel signal array to a target RMS level in dBFS.
    void
    parseKey(char key, int keyCode)
    Handles key press events passed on by the built-in keyPressed method.
    void
    playBrushstrokes(int offset)
    Plays all audio events controlled by PACurveMaker curves in brushShapesList, spaced out by offset milliseconds.
    int
    playSample(int samplePos, int samplelen, float amplitude)
    Plays an audio sample with the default envelope.
    int
    playSample(int samplePos, int samplelen, float amplitude, float pan)
    Plays an audio sample with default envelope and stereo pan.
    int
    playSample(int samplePos, int samplelen, float amplitude, ADSRParams env)
    Plays an audio sample with a custom envelope.
    int
    playSample(int samplePos, int samplelen, float amplitude, ADSRParams env, float pan)
    Plays an audio sample with a custom envelope and stereo pan.
    int
    playSample(int samplePos, int samplelen, float amplitude, ADSRParams env, float pitch, float pan)
    Plays an audio sample with with a custom envelope, pitch and stereo pan.
    void
     
    void
     
    void
    Removes the current active PACurveMaker instance, flagged by a highlighted brush stroke, from brushShapesList, if there is one.
    void
    Removes the newest PACurveMaker instance, shown as a brush stroke in the display, from brushShapesList.
    void
    Removes the oldest brush in brushShapesList.
    void
    renderFrame(int step)
    Renders a frame of animation: moving along the signal path, copies mapImage pixels into rgbSignal, rotates them shift elements left, writes them back to mapImage along the signal path.
    void
    Prepares audioSignal before it is used as an instrument source.
    void
    reset(boolean isClearCurves)
    Reinitializes audio and clears event lists.
    void
    Rewinds WindowedBuffer instance windowBuff to the beginning of the audio buffer.
    void
    Tracks and runs TimedLocation events in the curveTLEvents list.
    void
    Tracks and runs TimedLocation events in the timeLocsArray list.
    void
    saveAudioToFile(float[] samples, float sampleRate, String fileName)
    Saves audio data to 16-bit integer PCM format, which Processing can also open.
    void
    saveImageToFile(processing.core.PImage img, String fileName)
     
    void
    Calls Processing's selectOutput method to start the process of saving the current audio signal to a .wav file.
    void
    Calls Processing's selectOutput method to start the process of saving the mapImage (the offscreen copy of the display image) to a .png file.
    static int
    setAlpha(int argb, int alpha)
     
    int
    setAlphaWithBlack(int argb, int alpha)
     
    void
    setAudioGain(float g)
    Sets audioOut.gain.
    int
    setSampleVars(int x, int y)
    Sets variables sampleX, sampleY and samplePos.
    void
     
    void
     
    void
    to generate help output, run RegEx search/replace on parseKey case lines with: // case ('.'): // (.+) // println(" * Press $1 to $2.");
    void
    Step through the animation, called by the draw() method.
    void
     
    void
    storeCurveTL(ListIterator<processing.core.PVector> iter, int startTime)
     
    void
    storeGranularCurveTL(ListIterator<processing.core.PVector> iter, int startTime, int grainSize)
     
    void
    Updates global variable audioSignal, either by rotating array or getting a new window of values from the audio buffer.
    void
    writeAudioToImage(float[] sig, PixelAudioMapper mapper, processing.core.PImage img, PixelAudioMapper.ChannelNames chan)
    Transcodes audio data in sig[] and writes it to color channel chan of mapImage using the lookup tables in mapper to redirect indexing.
    void
    writeImageToAudio(processing.core.PImage img, PixelAudioMapper mapper, float[] sig, PixelAudioMapper.ChannelNames chan)
    This method writes a color channel from the an image to playBuffer, fulfilling a central concept of the PixelAudio library: image is sound.
    void
    writeToScreen(String msg, int x, int y, int weight, boolean isWhite)
    Displays a line of text to the screen, usually in the draw loop.

    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, mouseClicked, mouseDragged, mouseEntered, mouseEntered, mouseExited, mouseExited, mouseMoved, mouseMoved, mousePressed, 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
    • multigen

      MultiGen multigen
    • genWidth

      int genWidth
    • genHeight

      int genHeight
    • rows

      int rows
    • cols

      int cols
    • mapper

    • mapSize

      int mapSize
    • mapImage

      processing.core.PImage mapImage
    • chan

    • colors

      int[] colors
    • audioFile

      File audioFile
    • audioFilePath

      String audioFilePath
    • audioFileName

      String audioFileName
    • audioFileTag

      String audioFileTag
    • audioFileLength

      int audioFileLength
    • imageFile

      File imageFile
    • imageFilePath

      String imageFilePath
    • imageFileName

      String imageFileName
    • imageFileTag

      String imageFileTag
    • imageFileWidth

      int imageFileWidth
    • imageFileHeight

      int imageFileHeight
    • daPath

      String daPath
    • minim

      ddf.minim.Minim minim
      Minim audio library
    • audioOut

      ddf.minim.AudioOutput audioOut
    • isBufferStale

      boolean isBufferStale
    • sampleRate

      float sampleRate
    • fileSampleRate

      float fileSampleRate
    • audioSignal

      float[] audioSignal
    • playBuffer

      ddf.minim.MultiChannelBuffer playBuffer
    • samplePos

      int samplePos
    • audioLength

      int audioLength
    • noteDuration

      int noteDuration
    • samplelen

      int samplelen
    • defaultGain

      float defaultGain
    • gain

      float gain
    • pool

    • poolSize

      int poolSize
    • perInstrumentVoices

      int perInstrumentVoices
    • defaultEnv

      ADSRParams defaultEnv
    • granularEnv

      ADSRParams granularEnv
    • maxAmplitude

      float maxAmplitude
    • attackTime

      float attackTime
    • decayTime

      float decayTime
    • sustainLevel

      float sustainLevel
    • releaseTime

      float releaseTime
    • pitchScaling

      float pitchScaling
    • defaultPitchScaling

      float defaultPitchScaling
    • lowPitchScaling

      float lowPitchScaling
    • highPitchScaling

      float highPitchScaling
    • isMuted

      boolean isMuted
    • sampleX

      int sampleX
    • sampleY

      int sampleY
    • isIgnoreOutsideBounds

      boolean isIgnoreOutsideBounds
    • timeLocsArray

      ArrayList<TimedLocation> timeLocsArray
    • isLoadToBoth

      boolean isLoadToBoth
    • isGranular

      boolean isGranular
    • grainDuration

      int grainDuration
    • shift

      int shift
    • totalShift

      int totalShift
    • isAnimating

      boolean isAnimating
    • oldIsAnimating

      boolean oldIsAnimating
    • isTrackMouse

      boolean isTrackMouse
    • animSteps

      int animSteps
    • isRecordingVideo

      boolean isRecordingVideo
    • videoFrameRate

      int videoFrameRate
    • step

      int step
    • videx

      com.hamoid.VideoExport videx
    • isDrawMode

      public boolean isDrawMode
    • epsilon

      public float epsilon
    • allPoints

      public ArrayList<processing.core.PVector> allPoints
    • dragColor

      public int dragColor
    • dragWeight

      public float dragWeight
    • startTime

      public int startTime
    • allTimes

      public ArrayList<Integer> allTimes
    • currentPoint

      public processing.core.PVector currentPoint
    • polySteps

      public int polySteps
    • defaultPolySteps

      public int defaultPolySteps
    • granPolySteps

      public int granPolySteps
    • curveMaker

      public PACurveMaker curveMaker
    • eventPoints

      public ArrayList<processing.core.PVector> eventPoints
    • eventPointsIter

      public ListIterator<processing.core.PVector> eventPointsIter
    • eventStep

      int eventStep
    • curveTLEvents

      public ArrayList<TimedLocation> curveTLEvents
    • brushShapesList

      public ArrayList<PACurveMaker> brushShapesList
    • activeBrush

      public PACurveMaker activeBrush
    • activeIndex

      public int activeIndex
    • newBrushColor

      int newBrushColor
    • polyPointsColor

      int polyPointsColor
    • activeBrushColor

      int activeBrushColor
    • readyBrushColor

      int readyBrushColor
    • blend

      float blend
    • isBlending

      boolean isBlending
    • frame

      int frame
      keep track of the frame we should be rendering
    • windowBuff

      A windowed buffer for anthem
    • windowHopSize

      int windowHopSize
      how far to step the window on each frame
    • anthemBuffer

      ddf.minim.MultiChannelBuffer anthemBuffer
      buffer for complete file
    • anthemSignal

      float[] anthemSignal
      A source for streaming audio from a file
    • isListening

      boolean isListening
      boolean to flag audio capture
    • oldIsListening

      boolean oldIsListening
      save isListening state
    • isFixedLength

      boolean isFixedLength
      boolean to flag fixed length capture
    • isRaining

      boolean isRaining
  • Constructor Details

    • TutorialOne_06_WindowBuffer

      public TutorialOne_06_WindowBuffer()
  • Method Details

    • main

      public static void main(String[] args)
      Entry point for pure Java implementation (in Eclipse). Omit in Processsing.
      Parameters:
      args - not used
    • 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()
      Overrides:
      stop in class processing.core.PApplet
    • getColors

      public int[] getColors(int size)
      Generates an array of rainbow colors using the HSB color space.
      Parameters:
      size - the number of entries in the colors array
      Returns:
      an array of RGB colors ordered by hue
    • hilbertRowOrtho

      public MultiGen hilbertRowOrtho(int cols, int rows, int genW, int genH)
      This method creates rows of HilbertGens, starting each row from the left and adding gens. The odd rows are flipped vertically and the even rows are unchanged. The unchanged HilbertGen starts at upper left corner and ends at upper right corner, so this provides some possibilities of symmetry between rows. The path is not continuous.
      Parameters:
      cols - number of columns of gens wide
      rows - number of rows of gens high
      genW - width of each gen (same as genH and a power of 2)
      genH - height of each gen
      Returns:
      a MultiGen composed of cols * rows PixelMapGens
    • initImages

      public void initImages()
      Initializes mapImage with the colors array. MapImage will handle the color data for mapper and also serve as our display image.
    • initDrawing

      public void initDrawing()
      Initializes the line, curve, and brushstroke drawing variables. Note that timeLocsArray has been initialized by initAudio(), though it will be used for point events in the drawing code, too.
    • preloadFiles

      public void preloadFiles(String path)
    • draw

      public void draw()
      Overrides:
      draw in class processing.core.PApplet
    • animate

      public void animate()
    • stepAnimation

      public void stepAnimation()
      Step through the animation, called by the draw() method. Will also record a frame of video, if we're recording.
    • renderFrame

      public void renderFrame(int step)
      Renders a frame of animation: moving along the signal path, copies mapImage pixels into rgbSignal, rotates them shift elements left, writes them back to mapImage along the signal path.
      Parameters:
      step - current animation step
    • drawSignal

      public void drawSignal()
      Transcode directly from audioSignal to mapImage.pixels, the display image. When we are stepping through an audio buffer with BufferedWindow, audioSignal contains the most recent window, which is exactly the same size as mapImage.pixels. By default, we transcode audio to the Brightness channel of HSB, preserving Hue and Saturation in the mapImage.
    • updateAudio

      public void updateAudio()
      Updates global variable audioSignal, either by rotating array or getting a new window of values from the audio buffer.
    • handleDrawing

      public void handleDrawing()
      Handles user's drawing actions, draws previously recorded brushstrokes, tracks and generates animation and audio events.
    • writeToScreen

      public void writeToScreen(String msg, int x, int y, int weight, boolean isWhite)
      Displays a line of text to the screen, usually in the draw loop. Handy for debugging. typical call: writeToScreen("When does the mind stop and the world begin?", 64, 1000, 24, true);
      Parameters:
      msg - message to write
      x - x coordinate
      y - y coordinate
      weight - font weight
      isWhite - if true, white text, otherwise, black text
    • mousePressed

      public void mousePressed()
      The built-in mousePressed handler for Processing, but note that it forwards mouse coords to handleMousePressed(). If isDrawMode is true, we start accumulating points to allPoints: initAllPoints() adds the current mouseX and mouseY. After that, the draw loop calls handleDrawing() to add points. Drawing ends on mouseReleased().
      Overrides:
      mousePressed in class processing.core.PApplet
    • mouseDragged

      public void mouseDragged()
      Used for interactively setting the amount of pixel array shift when animating. TODO, since this app is a demo for WindowedBuffer, we can probably do without setting shift interactively.
      Overrides:
      mouseDragged in class processing.core.PApplet
    • mouseReleased

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

      public void keyPressed()
      built-in keyPressed handler, forwards events to parseKey.
      Overrides:
      keyPressed in class processing.core.PApplet
    • parseKey

      public void parseKey(char key, int keyCode)
      Handles key press events passed on by the built-in keyPressed method. By moving key event handling outside the built-in keyPressed method, we make it possible to post key commands without an actual key event. Methods and interfaces and even other threads can call parseKey(). This opens up many possibilities and a some dangers, too.
      Parameters:
      key -
      keyCode -
      See Also:
      • (Eclipse) or TutorialOne_05_UDP (Processing) for an example of external calls to parseKey().
    • resetAudioWindow

      public void resetAudioWindow()
      Rewinds WindowedBuffer instance windowBuff to the beginning of the audio buffer.
    • moveAudioWindow

      public void moveAudioWindow(int howFar)
      Moves WindowedBuffer instance windowBuff's window to the index howFar.
    • setAudioGain

      public void setAudioGain(float g)
      Sets audioOut.gain.
      Parameters:
      g - gain value for audioOut, in decibels
    • showHelp

      public void showHelp()
      to generate help output, run RegEx search/replace on parseKey case lines with: // case ('.'): // (.+) // println(" * Press $1 to $2.");
    • applyColor

      public int[] applyColor(int[] colorSource, int[] graySource, int[] lut)
      Utility method for applying hue and saturation values from a source array of RGB values to the brightness values in a target array of RGB values, using a lookup table to redirect indexing. Available as a static method in PixelAudio class PixelAudioMapper.
      Parameters:
      colorSource - a source array of RGB data from which to obtain hue and saturation values
      graySource - an target array of RGB data from which to obtain brightness values
      lut - a lookup table, must be the same size as colorSource and graySource
      Returns:
      the graySource array of RGB values, with hue and saturation values changed
      Throws:
      IllegalArgumentException - if array arguments are null or if they are not the same length
    • chooseColorImage

      public void chooseColorImage()
      Call to initiate process of opening an image file to get its color data.
    • colorFileSelected

      public void colorFileSelected(File selectedFile)
      callback method for chooseColorImage()
      Parameters:
      selectedFile - the File the user selected
    • applyImageColor

      public void applyImageColor(processing.core.PImage colorImage, processing.core.PImage targetImage)
      Apply the hue and saturation channels of one image to another image, leaving its brightness channel unchanged.
      Parameters:
      colorImage - image that is the source of hue and saturation values
      targetImage - target image where brightness will remain unchanged
    • applyImageColorToMapImage

      public void applyImageColorToMapImage(File imgFile)
    • chooseFile

      public void chooseFile()
      Wrapper method for Processing's selectInput command
    • fileSelected

      public void fileSelected(File selectedFile)
      callback method for chooseFile(), handles standard audio and image formats for Processing. If a file has been successfully selected, continues with a call to loadAudioFile() or loadImageFile().
      Parameters:
      selectedFile - the File the user selected
    • loadAudioFile

      public void loadAudioFile(File audFile)
      LoadAudioFile attempts to load audio data from a selected file into playBuffer and anthemBuffer. If audio loads, resizes playBuffer to mapSize and loads the entire file into anthemBuffer, which is passed to the PASamplerInstrumentPool audio sampling instrument "pool". In the context of a windowed buffer as audio source, as in TutorialOneWindowBuffer, blending is not applied to the WindowedBuffer instance, but only to playBuffer. I have ignored it in this example code. It might make sense to use it to blend images during a performance, but I leave that to future development by others or by myself.
      Parameters:
      audFile - an audio file
    • loadAnthem

      public float loadAnthem(File audFile)
    • blendInto

      public static void blendInto(ddf.minim.MultiChannelBuffer dest, ddf.minim.MultiChannelBuffer src, float weight, boolean normalize, float targetDB)
      Blends audio data from buffer "src" into buffer "dest" in place. The formula per sample is: dest[i] = weight * src[i] + (1 - weight) * dest[i]
      Parameters:
      dest - Destination buffer (will be modified)
      src - Source buffer to blend into dest
      weight - Blend ratio (0.0 = keep dest, 1.0 = replace with src)
    • normalize

      public static void normalize(float[] signal, float targetDB)
      Normalizes a single-channel signal array to a target RMS level in dBFS.
      Parameters:
      signal - The audio samples to normalize (modified in place)
      targetDB - The target RMS level in decibels relative to full scale (e.g. -3.0f for moderately loud, -12.0f for safe headroom)
    • writeAudioToImage

      public void writeAudioToImage(float[] sig, PixelAudioMapper mapper, processing.core.PImage img, PixelAudioMapper.ChannelNames chan)
      Transcodes audio data in sig[] and writes it to color channel chan of mapImage using the lookup tables in mapper to redirect indexing. Calls PixelAudioMapper method mapSigToImg(), which will throw an IllegalArgumentException if sig.length != img.pixels.length or sig.length != mapper.getSize().
      Parameters:
      sig - an array of float, should be audio data in the range [-1.0, 1.0]
      mapper - a PixelAudioMapper
      img - a PImage
      chan - a color channel
    • loadImageFile

      public void loadImageFile(File imgFile)
      Attempts to load image data from a selected file into mapImage, then calls writeImageToAudio() to transcode HSB brightness channel to audio and writes it to playBuffer and audioSignal. If you want to load the image file and audio file separately, comment out writeImageToAudio().
      Parameters:
      imgFile - an image file
    • setAlphaWithBlack

      public int setAlphaWithBlack(int argb, int alpha)
    • setAlpha

      public static int setAlpha(int argb, int alpha)
    • writeImageToAudio

      public void writeImageToAudio(processing.core.PImage img, PixelAudioMapper mapper, float[] sig, PixelAudioMapper.ChannelNames chan)
      This method writes a color channel from the an image to playBuffer, fulfilling a central concept of the PixelAudio library: image is sound. Calls mapper.mapImgToSig(), which will throw an IllegalArgumentException if img.pixels.length != sig.length or img.width * img.height != mapper.getWidth() * mapper.getHeight().
      Parameters:
      img - a PImage, a source of data
      mapper - a PixelAudioMapper, handles mapping between image and audio signal
      sig - an target array of float in audio format
      chan - a color channel
    • saveToAudio

      public void saveToAudio()
      Calls Processing's selectOutput method to start the process of saving the current audio signal to a .wav file.
    • audioFileSelectedWrite

      public void audioFileSelectedWrite(File selection)
    • saveAudioToFile

      public 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. This same method can be called as a static method in PixelAudio.
      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')
    • saveToImage

      public void saveToImage()
      Calls Processing's selectOutput method to start the process of saving the mapImage (the offscreen copy of the display image) to a .png file.
    • imageFileSelectedWrite

      public void imageFileSelectedWrite(File selection)
    • saveImageToFile

      public void saveImageToFile(processing.core.PImage img, String fileName)
    • initAudio

      public void initAudio()
      CALL THIS METHOD IN SETUP() Initializes Minim audio library and audio variables.
    • renderSignals

      public void renderSignals()
      Prepares audioSignal before it is used as an instrument source. Modify as needed to prepare your audio signal data. TODO Of limited use. Discard?
    • audioMousePressed

      public void audioMousePressed(int x, int y)
      Typically called from mousePressed with mouseX and mouseY, generates audio events.
      Parameters:
      x - x-coordinate within a PixelAudioMapper's width
      y - y-coordinate within a PixelAudioMapper's height
    • setSampleVars

      public int setSampleVars(int x, int y)
      Sets variables sampleX, sampleY and samplePos. Arguments x and y may be outside the window bounds, sampleX and sampleY will be constrained to window bounds. As a result, samplePos will be within the bounds of audioSignal.
      Parameters:
      x - x coordinate, typically from a mouse event
      y - y coordinate, typically from a mouse event
      Returns:
      samplePos, the index of of (x, y) along the signal path
    • getSamplePos

      public int getSamplePos(int x, int y)
      Calculates the index of the image pixel within the signal path, taking the current window position and animated shifting of pixels and audioSignal into account.
      Parameters:
      x - an x coordinate within mapImage and display bounds
      y - a y coordinate within mapImage and display bounds
      Returns:
      the index of the sample corresponding to (x,y) on the signal path
    • 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
    • drawCircle

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

      public void raindrops()
    • listenToAnthem

      public boolean listenToAnthem(boolean isStartListening)
      TODO update for buffer animation
      Parameters:
      isStartListening - true if audio stream capture should be initiated, false if it should be ended
      Returns:
      current value of isStartListening
    • playSample

      public int playSample(int samplePos, int samplelen, float amplitude)
      Plays an audio sample with the default envelope.
      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
    • playSample

      public int playSample(int samplePos, int samplelen, float amplitude, ADSRParams env)
      Plays an audio sample with a custom envelope.
      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, float pan)
      Plays an audio sample with default envelope and stereo pan.
      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
    • playSample

      public int playSample(int samplePos, int samplelen, float amplitude, ADSRParams env, float pan)
      Plays an audio sample with a custom envelope and stereo pan.
      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
      pan - position of sound in the stereo audio field (-1.0 = left, 0.0 = center, 1.0 = right)
      Returns:
      the calculated sample length in samples
    • playSample

      public int playSample(int samplePos, int samplelen, float amplitude, ADSRParams env, float pitch, float pan)
      Plays an audio sample with with a custom envelope, pitch and stereo pan.
      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
      pitch - pitch scaling as deviation from default (1.0), where 0.5 = octave lower, 2.0 = oactave higher
      pan - position of sound in the stereo audio field (-1.0 = left, 0.0 = center, 1.0 = right)
      Returns:
    • calcSampleLen

      public int calcSampleLen()
      Returns:
      a length in samples with some Gaussian variation
    • initAllPoints

      public void initAllPoints()
      Initializes allPoints and adds the current mouse location to it.
    • handleMousePressed

      public void handleMousePressed(int x, int y)
      Responds to mousePressed events associated with drawing.
    • addPoint

      public void addPoint(int x, int y)
      While user is dragging the mouses and isDrawMode == true, accumulates new points to allPoints and event times to allTimes. Sets sampleX, sampleY and samplePos variables. We constrain points outside the bounds of the display window. An alternative approach is be to ignore them (isIgnoreOutsideBounds == true), which may give a more "natural" appearance for fast drawing.
    • loadEventPoints

      public void loadEventPoints()
      Processes the eventPoints list to create TimedLocation events and stores them in curveTLEvents.
    • loadEventPoints

      public void loadEventPoints(int startTime)
      Processes the eventPoints list to create TimedLocation events and stores them in curveTLEvents.
      Parameters:
      startTime - time in millis (in the future!) when event should begin
    • storeGranularCurveTL

      public void storeGranularCurveTL(ListIterator<processing.core.PVector> iter, int startTime, int grainSize)
      Parameters:
      iter - a ListIterator over eventPoints
      startTime - a time in millis
      grainSize - a duration in milliseconds
    • storeCurveTL

      public void storeCurveTL(ListIterator<processing.core.PVector> iter, int startTime)
      Parameters:
      iter - a ListIterator over eventPoints
      startTime - a time in millis
    • initCurveMaker

      public void initCurveMaker()
      Initializes a PACurveMaker instance with allPoints as an argument to the factory method PACurveMaker.buildCurveMaker() and then fills in PACurveMaker instance variables from global variables in the host class.
    • drawBrushShapes

      public void drawBrushShapes()
      Iterates over brushShapesList and draws the brushstrokes stored in each PACurveMaker in the list. Detects if mouse is over a brush and points activeBrush to it if that is the case.
    • curveMakerDraw

      public void curveMakerDraw()
      Draws shapes stored in curveMaker, a PACurveMaker instance that stores the most recent drawing data.
    • runCurveEvents

      public void runCurveEvents()
      Tracks and runs TimedLocation events in the curveTLEvents list. This method is synchronized with a view to future development where it may be called from different threads.
    • runPointEvents

      public void runPointEvents()
      Tracks and runs TimedLocation events in the timeLocsArray list. This method is synchronized with a view to future development where it may be called from different threads.
    • mouseInPoly

      public boolean mouseInPoly(ArrayList<processing.core.PVector> poly)
      Detects if the mouse is within a selected polygon.
      Parameters:
      poly - a polygon as an ArrayList of PVectors
      Returns:
      true if mouse is within poly, false otherwise
    • reset

      public void reset(boolean isClearCurves)
      Reinitializes audio and clears event lists. If isClearCurves is true, clears brushShapesList and curveTLEvents.
      Parameters:
      isClearCurves -
    • playBrushstrokes

      public void playBrushstrokes(int offset)
      Plays all audio events controlled by PACurveMaker curves in brushShapesList, spaced out by offset milliseconds.
      Parameters:
      offset -
    • removeActiveBrush

      public void removeActiveBrush()
      Removes the current active PACurveMaker instance, flagged by a highlighted brush stroke, from brushShapesList, if there is one.
    • removeNewestBrush

      public void removeNewestBrush()
      Removes the newest PACurveMaker instance, shown as a brush stroke in the display, from brushShapesList.
    • removeOldestBrush

      public void removeOldestBrush()
      Removes the oldest brush in brushShapesList.