Class BigWaveSynthAudio
- All Implemented Interfaces:
processing.core.PConstants
WaveSynth is a class that combines an additive synthesis audio generator with a digital "color organ," an image generator that maps audio signals to colors. MultiGen is child class of PixelMapGen that allows you to combine individual PixelMapGens into a composite PixelMapGen instance with one signal path traversing all the pixels of the corresponding image. This example sketch also allows you to load JSON data files stored in the example sketches' data folder to reconfigure the WaveSynth. On startup, we call initWaveDataList() to create a WaveData array with two operators.
Note the role that sampleRate plays in generating images and audio signals from a WaveSynth. Three sample rate values influence the audio output and image display: the audio output frequency, usually set just once, the audio instrument playback frequency, which can vary, and the WaveSynth's local sampling rate, which can also vary. The global sampleRate variable sets the frequency of audio output. In initAudio() it also sets the playback frequency of the PASamplerInstrument:
this.audioOut = minim.getLineOut(Minim.STEREO, 1024, sampleRate);
synth = new PASamplerInstrumentPool(audioBuffer, audioOut.sampleRate(), maxVoices, 1, audioOut, shortAdsr);
The local sample rate of a WvaeSynth affects the pattern in the display image and may affect playback of the audio signal generated by the WaveSynth. WaveSynth.sampleRate is set in the initWaveSynth() method and can be changed with key commands '1' through '7'.
synth.setSampleRate(genWidth * genHeight);The audio sampler instrument that plays the audio signals generated by a WaveSynth, the PASamplerInstrumentPool object "synth", uses the audioOut sampleRate for its playback sample rate. It ignores the local sample rate of the WaveSynth. When you change the sampling rate of the WaveSynth, the frequency of playback will change, because the synth is set up to step through its buffer at the audio sampling rate. Frequencies will be accurate only when the WaveSynth sample rate, the synth playback sample rate, and the output rate are all the same. This happens when you press the '7' key, which sets the WaveSynth rate to the audio output sampling rate (which we'll say is 44100 Hz). The WaveSynth then squeezes its sine wave operator output into 44100 audio samples or pixels, on the screen and in its audio signal. For the WaveSyth that shows on startup, with frequencies of 768 and 192 Hz, the output frequency of a note will then be 768 Hz, right around G5 (G above middle C) on a piano keyboard.
At sampleRate = genWidth * genHeight, one cycle of a sine wave set in the WaveSynth would fill an entire HilbertGen. A frequency of 768 will place 768 copies of a sine wave along the signal path over the entire bitmap of a single HilbertGen. The MultiGen which is displayed in this sketch is composed of six Hilbert curves (HilbertGen objects). 768 was used as a frequency because it shares factors with the HilbertGen's dimensions. This results in symmetrical patterns.
The audio signals and images generated by the WaveSyth data files in the JSON folder demonstrate a wide range of possibilities. Some produce low frequencies that create large areas of shifting colors when animation is on. You may not be able to hear the audio these example produce, except as a click from the envelope. Some JSON files produce high frequencies that appear as fine-grained images but can't be heard because the audio frequency is too high. The medium frequencies can produce many different timbres. The audio signal they produce tends to be very repetitive. Multiple instruments playing together can result in interesting phase interference effects. The raindrops() method can be called ('d') to produce random audio events that demonstrate these effects. Combine the raindrops() method with detuning ('t' command) to get a wide range of animation and audio drone effects.
For more information and sample code about the WaveSyth class, see the WaveSynthEditor and WaveSynthSequencer example sketches.
Press ' ' to turn animation on and off. Press 'd' to turn raindrops on and off. Press 't' to detune instruments by a small amount. Press 'T' to restore tuning to instruments. Press 'l' or 'L' to select long or short notes for audio events. Press 'o' or 'O' to open a WaveSynth settings JSON file. Press 'j' or 'J' to save current WaveSynth to a JSON file. Press 'f' to print the current frame rate to the console. Press '1' to set the current WaveSynth's sample rate to genWidth * genHeight. Press '2' to set the current WaveSynth's sample rate to genWidth * genHeight / 2. Press '3' to set the current WaveSynth's sample rate to genWidth * genHeight / 3. Press '4' to set the current WaveSynth's sample rate to genWidth * genHeight / 4. Press '5' to set the current WaveSynth's sample rate to genWidth * genHeight / 5. Press '6' to set the current WaveSynth's sample rate to genWidth * genHeight / 6. Press '7' to set the current WaveSynth's sample rate to the audio sample rate. Press 'h' to show help message in console.See also: BigWaveSynth, WaveSynthEditor, WaveSynthSequencer, and MultiGenLookupTables. For a wealth of methods to create MultiGens, see ArgosyMixer.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) int(package private) int(package private) ddf.minim.MultiChannelBuffer(package private) int(package private) ddf.minim.AudioOutput(package private) float[](package private) int(package private) int(package private) String(package private) int(package private) File(package private) String(package private) float(package private) float(package private) int(package private) int(package private) boolean(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) ADSRParams(package private) int(package private) PixelAudioMapper(package private) int(package private) ddf.minim.MinimMinim audio library(package private) MultiGen(package private) float(package private) boolean(package private) PixelAudio(package private) int(package private) int[](package private) int(package private) int(package private) int(package private) float(package private) int(package private) int(package private) ADSRParams(package private) int(package private) int(package private) PASamplerInstrumentPool(package private) processing.core.PImage(package private) ArrayList<TimedLocation>(package private) WaveSynthFields 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, windowYFields 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 -
Method Summary
Modifier and TypeMethodDescriptionintcalcSampleLen(float timeInSecs) voidDetunes each instrument in the polyphonic synth by a small amount.voiddraw()voiddrawCircle(int x, int y) Draws a circle at the location of an audio trigger (mouseDown event).voidfileSelectedOpen(File selection) voidfileSelectedWrite(File selection) hilbertLoop3x2(int genW, int genH) Generates a looping fractal signal path consisting of 6 HilbertGens, arranged 3 wide and 2 tall, to fit a 3 * genW by 2 * genH image.voidinitWaveSynth(WaveSynth synth) Sets gain, gamma, isScaleHisto, animSteps, and sampleRate instance variables of a WaveSynth object and generates its first frame of animation.voidvoidstatic voidvoidvoidplayLongNote(float panning) Triggers an audio event with a 3-second initial duration followed by a 5-second long release.intplaySample(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.voidplayShortNote(float panning) Triggers an audio event with a 3-second initial duration followed by a 5-second long release.voidprintWaveData(WaveSynth synth) Outputs fields from current waveAnimal and it waveDataListvoidTrigger a WaveSynth sample at a random location.floatrandomShift(float val, float shift) voidCalls WaveSynth to render a audio sample array derived from the same math that creates the image.voidRestores the tuning of individual instruments in the polyphonic synth.voidRun the animation for audio events.voidvoidsettings()voidsetup()voidsetWaveSynthFromJSON(processing.data.JSONObject json, WaveSynth synth) voidshowHelp()voidMethods 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, 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
-
Field Details
-
pixelaudio
PixelAudio pixelaudio -
multigen
MultiGen multigen -
rows
int rows -
columns
int columns -
genWidth
int genWidth -
genHeight
int genHeight -
mapper
PixelAudioMapper 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 minimMinim audio library -
audioOut
ddf.minim.AudioOutput audioOut -
audioBuffer
ddf.minim.MultiChannelBuffer audioBuffer -
isBufferStale
boolean isBufferStale -
sampleRate
float sampleRate -
audioSignal
float[] audioSignal -
rgbSignal
int[] rgbSignal -
audioLength
int audioLength -
shortDuration
int shortDuration -
longDuration
int longDuration -
isPlayLongNote
boolean isPlayLongNote -
samplelen
int samplelen -
defaultGain
float defaultGain -
gain
float gain -
synth
PASamplerInstrumentPool synth -
poolSize
int poolSize -
isUseSynth
boolean isUseSynth -
shortAdsr
ADSRParams shortAdsr -
longAdsr
ADSRParams longAdsr -
jsonFolder
String jsonFolder -
currentDataFile
File currentDataFile -
currentFileName
String currentFileName -
json
processing.data.JSONObject json -
isAnimating
boolean isAnimating -
oldIsAnimating
boolean oldIsAnimating -
isLooping
boolean isLooping -
circleColor
int circleColor -
isRaining
boolean isRaining -
sampleX
int sampleX -
sampleY
int sampleY -
samplePos
int samplePos -
timeLocsArray
ArrayList<TimedLocation> timeLocsArray -
count
int count
-
-
Constructor Details
-
BigWaveSynthAudio
public BigWaveSynthAudio()
-
-
Method Details
-
main
-
settings
public void settings()- Overrides:
settingsin classprocessing.core.PApplet
-
setup
public void setup()- Overrides:
setupin classprocessing.core.PApplet
-
hilbertLoop3x2
Generates a looping fractal signal path consisting of 6 HilbertGens, arranged 3 wide and 2 tall, to fit a 3 * genW by 2 * genH image. This particular MultiGen configuration is used so extensively in my sample code that I've given it a factory method in the HilbertGen class. It's written out here so you can see how it works. Note that genH must equal genW and both must be powers of 2. For the image size we're using in this example, genW = image width / 3 and genH = image height / 2.- Parameters:
genW- width of each HilbertGengenH- height of each HilbertGen- Returns:
- a 3 x 2 array of Hilbert curves, connected in a loop (3 * genWidth by 2 * genHeight pixels)
-
initWaveDataList
-
initWaveSynth
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
-
initAudio
public void initAudio() -
draw
public void draw()- Overrides:
drawin classprocessing.core.PApplet
-
runTimeArray
public void runTimeArray()Run the animation for audio events. -
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 circley- y coordinate of circle
-
raindrops
public void raindrops()Trigger a WaveSynth sample at a random location. -
detuneInstruments
public void detuneInstruments()Detunes each instrument in the polyphonic synth by a small amount. Demonstrates how to access individual PASamplerInstrument instances in PASamplerInstrumentPool's list of instruments. -
retuneInstruments
public void retuneInstruments()Restores the tuning of individual instruments in the polyphonic synth. -
randomShift
public float randomShift(float val, float shift) -
keyPressed
public void keyPressed()- Overrides:
keyPressedin classprocessing.core.PApplet
-
showHelp
public void showHelp() -
stepAnimation
public void stepAnimation() -
mouseClicked
public void mouseClicked()- Overrides:
mouseClickedin classprocessing.core.PApplet
-
playLongNote
public void playLongNote(float panning) Triggers an audio event with a 3-second initial duration followed by a 5-second long release. -
playShortNote
public void playShortNote(float panning) Triggers an audio event with a 3-second initial duration followed by a 5-second long release. -
renderSignal
public void renderSignal()Calls WaveSynth to render a audio sample array derived from the same math that creates the image. -
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 buffersamplelen- length of the sample (will be adjusted)amplitude- amplitude of the sample on playbackenv- an ADSR envelope for the samplepitch- pitch scaling as deviation from default (1.0), where 0.5 = octave lower, 2.0 = oactave higherpan- position of sound in the stereo audio field (-1.0 = left, 0.0 = center, 1.0 = right)- Returns:
-
calcSampleLen
public int calcSampleLen(float timeInSecs) - Returns:
- a length in samples with some Gaussian variation
-
loadWaveData
public void loadWaveData() -
fileSelectedOpen
-
setWaveSynthFromJSON
-
printWaveData
Outputs fields from current waveAnimal and it waveDataList -
saveWaveData
public void saveWaveData() -
fileSelectedWrite
-