Package net.paulhertz.pixelaudio.example

# Class LookupTables

java.lang.Object
processing.core.PApplet
net.paulhertz.pixelaudio.example.LookupTables

All Implemented Interfaces:
  `processing.core.PConstants`

public class LookupTables extends processing.core.PApplet
PixelAudio Core Concept: Mapping The LookupTables example shows how to map a 1D audio signal onto a 2D bitmap, using lookup tables (LUTs) to create a one-to-one correspondence between audio samples and RGB pixels. Imagine the audio signal as path that visits every pixel in a bitmap: the signal's lookup table for pixels is a list of the array indices of the pixels it visits, in the order it visits them. By convention, pixel array coordinates start at (0,0) in the upper left corner of a bitmap, and proceed in "row major" order, left to right, top to bottom. The bitmap has a corresponding lookup table, where the array indices of the audio signal are stored in the order of the pixel coordinates. The signal and bitmap lookup tables are inverses of each other, so that the signal can be mapped to the bitmap and the bitmap can be mapped to the signal. PixelAudio classes that implement the abstract PixelMapGen class just have to provide the coordinates of the signal path, then PixelMapGen will generate the lookup tables for the signal and the image. The coordinates may be generated by mathematical functions, but they only need to be calculated once. In PixelAudio, I call a subclass of PixelMapGen a "gen" object. Gen objects plug in to PixelAudioMapper. PixelAudioMapper handles mapping back and forth between audio and images and can transcode audio and image data. It has methods for handling arrays of audio samples and RGB pixels and working with the RGB and HSB color spaces. This example also shows 1) basic affine transforms of PixelMapGen objects, such as rotation and reflection, 2) how to change the PixelMapGen instance a PixelAudioMapper object is using, and 3) basic animation using array rotation. Signal path index numbers are small white numbers. Bitmap index numbers are big black numbers. Read the signalToImageLUT values by following the white signal numbers and reading the black numbers. Read the imageToSignalLUT values by following the black pixel numbers and reading the white numbers. KEY COMMANDS Press 'a' to advance animation by one step. Press 'A' to rewind animation by one step. Press 'd' to print the current PixelMapGen's description String. Press 'g' to swap in a new PixelMapGen. Press 'n' to hide the numbers overlay. Press 'l' to hide the lines overlay. Press 'k' to print the imageToSignalLUT and the signalToImageLUT to the console. Press 't' to print affine maps to the console. Press 'f' to rotate current gen 90 degrees clockwise. Press 'b' to rotate current gen 90 degrees counterclockwise. Press 'r' to rotate current gen 180 degrees. Press 'x' to flip x-coordinates (reflect on y-axis). Press 'y' to flip y-coordinates (reflect on x-axis). Press '1' to mirror current gen on the primary diagonal, upper left to lower right. Press '2' to mirror current gen on the secondary diagonal, upper right to lower left. Press 'h' to show this help text in the console.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `(package private) BoustropheGen`
  `bGen`
  `(package private) int`
  `bigTextSize`
  `(package private) ArrayList<int[]>`
  `coords`
  `(package private) int`
  `drawingScale`
  `(package private) PixelMapGen`
  `gen`
  `(package private) int`
  `genH`
  `(package private) int`
  `genW`
  `(package private) HilbertGen`
  `hGen`
  `(package private) int`
  `imageHeight`
  `(package private) int[]`
  `imageLUT`
  `(package private) int`
  `imageWidth`
  `(package private) boolean`
  `isHideLines`
  `(package private) boolean`
  `isHideNumbers`
  `(package private) PixelAudioMapper`
  `mapper`
  `(package private) MooreGen`
  `mGen`
  `(package private) int`
  `offset`
  `(package private) PixelAudio`
  `pixelaudio`
  `(package private) int[]`
  `signalLUT`
  `(package private) int`
  `smallTextSize`
  `(package private) int[]`
  `spectrum`
  `(package private) DiagonalZigzagGen`
  `zGen`

  ### 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
  `LookupTables()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `draw()`
  `void`
  `drawLines()`
  Draw lines to the display.
  `void`
  `drawNumbers()`
  Draw numbers to the display.
  `void`
  `drawSquares()`
  Draw color squares to the display.
  `int[]`
  `getColors(int size)`
  Creates an array of colors in rainbow (spectrum) order.
  `void`
  `initGens()`
  Initialize a HilbertGen, a DiagonalZigzagGen, a MooreGen, and a BoustropheGen that fit the width and height of this sketch.
  `void`
  `initMapper(PixelMapGen gen)`
  Initialize a PixelAudioMapper, mapper, with a supplied gen, and request some useful data structures from it.
  `void`
  `keyPressed()`
  `static void`
  `main(String[] args)`
  `void`
  `printLUTs()`
  Print the LUTs and gen coordinates to the console.
  `void`
  `settings()`
  `void`
  `setup()`
  `void`
  `showHelp()`
  `void`
  `stepAnimation(int step)`
  `void`
  `testAffineMap(int w, int h)`
  A test of the affine transforms in the BitmapTransform class, which uses indexing to perform bitmap rotation and reflection.
  `void`
  `updateMapper(PixelMapGen gen)`
  Swaps in a new gen to a previously created PixelAudioMapper instance, and reloads relevant data structures.

  ### 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, 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, stop, 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

    HilbertGen hGen

  - ### mGen

    MooreGen mGen

  - ### zGen

    DiagonalZigzagGen zGen

  - ### bGen

    BoustropheGen bGen

  - ### gen

    PixelMapGen gen

  - ### mapper

    PixelAudioMapper mapper

  - ### spectrum

    int[] spectrum

  - ### coords

    ArrayList<int[]> coords

  - ### imageLUT

    int[] imageLUT

  - ### signalLUT

    int[] signalLUT

  - ### imageWidth

    int imageWidth

  - ### imageHeight

    int imageHeight

  - ### genW

    int genW

  - ### genH

    int genH

  - ### drawingScale

    int drawingScale

  - ### offset

    int offset

  - ### bigTextSize

    int bigTextSize

  - ### smallTextSize

    int smallTextSize

  - ### isHideNumbers

    boolean isHideNumbers

  - ### isHideLines

    boolean isHideLines

- ## Constructor Details

  - ### LookupTables

    public LookupTables()

- ## 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`

  - ### initGens

    public void initGens()
    Initialize a HilbertGen, a DiagonalZigzagGen, a MooreGen, and a BoustropheGen that fit the width and height of this sketch.

  - ### initMapper

    public void initMapper(PixelMapGen gen)
    Initialize a PixelAudioMapper, mapper, with a supplied gen, and request some useful data structures from it.
    Parameters:
      `gen` - a PixelMapGen instance

  - ### updateMapper

    public void updateMapper(PixelMapGen gen)
    Swaps in a new gen to a previously created PixelAudioMapper instance, and reloads relevant data structures.
    Parameters:
      `gen` - a PixelMapGen instance

  - ### draw

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

  - ### keyPressed

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

  - ### showHelp

    public void showHelp()

  - ### getColors

    public int[] getColors(int size)
    Creates an array of colors in rainbow (spectrum) order.
    Parameters:
      `size` - size of the desired array
    Returns:
      an array of colors in rainbow (spectrum) order

  - ### printLUTs

    public void printLUTs()
    Print the LUTs and gen coordinates to the console.

  - ### testAffineMap

    public void testAffineMap(int w, int h)
    A test of the affine transforms in the BitmapTransform class, which uses indexing to perform bitmap rotation and reflection.
    Parameters:
      `w` - width of a hypothetical bitmap
      `h` - height of a hypothetical bitmap

  - ### drawSquares

    public void drawSquares()
    Draw color squares to the display.

  - ### drawLines

    public void drawLines()
    Draw lines to the display.

  - ### drawNumbers

    public void drawNumbers()
    Draw numbers to the display.

  - ### stepAnimation

    public void stepAnimation(int step)