Package net.paulhertz.pixelaudio
Class WaveSynthBuilder
java.lang.Object
net.paulhertz.pixelaudio.WaveSynthBuilder
Utilities for generating WaveSynth "instruments" and working with WaveSynth data.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcapturePhaseValues(WaveSynth wavesynth) Applies the current phase values to the initial values of the WaveSynth, so that the current state of the image display will appear as the first frame of animation.static booleancheckJSONHeader(processing.data.JSONObject json, String key, String val) static float[]chromaticScale(float funda) static intcolorShift(int c, float shift) Moves an RGB color into the HSB color space and shifts it by a decimal fraction in the range (0.0,1.0) that represents a portion of the circle of hue values.static floatfrequencyPianoKey(float freq) static booleangetJSONFromFile(File selection, processing.data.JSONObject json, WaveSynth synth) static booleangetJSONFromFile(File selection, processing.data.JSONObject json, WaveSynth synth, boolean isStrict) static processing.data.JSONObjectstatic voidmuteWaveData(WaveSynth wavesynth, int elem) static floatpianoKeyFrequency(float keyNumber) static voidprintWDStates(ArrayList<WaveData> waveDataList) Prints mute/active status of WaveData operators in supplied waveDataList.static voidsaveWaveSynthJSON(processing.core.PApplet app, File selection, WaveSynth synth) static voidScales the amplitude of an ArrayList of WaveData objects.static voidscaleFreqs(ArrayList<WaveData> waveDataList, float scale, boolean isVerbose) Scales the frequencies of an ArrayList of WaveData objects.static voidsetWaveSynthFromJSON(processing.data.JSONObject json, WaveSynth synth) Sets the fields of a WaveSynth using values stored in a JSON object.static voidshiftColors(ArrayList<WaveData> waveDataList, float shift, boolean isVerbose) Shifts the colors of an ArrayList of WaveData objects.static voidshiftPhases(ArrayList<WaveData> waveDataList, float shift, boolean isVerbose) Shifts the phase of an ArrayList of WaveData objects.static voidshowPhaseValues(WaveSynth wavesynth) Outputs the phase values of a WaveSynth's array of WaveData objects to the console.synthDoubleStop(float funda1, float funda2, float pianoKey1, float pianoKey2, int animSteps) Generates an ArrayList of WaveData objects to be used by a WaveSynth to generate RGB pixel values and (on request) audio signal values.synthTrumpet(float fundamental, int howManyPartials, float pianoKey, int animSteps) Generates an ArrayList of WaveData objects to be used by a WaveSynth to generate RGB pixel values and (on request) audio signal values.static voidtoggleWDMute(WaveSynth wavesynth, int elem) Mutes or unmutes a WaveData operator (view in the control panel).static voidtoggleWDSolo(WaveSynth wavesynth, int elem, boolean isSolo) Sets a specified WaveData element in the waveDataList of a supplied WaveSynth to WaveData.WaveState.SOLO if isSolo is true, otherwise sets it to WaveData.WaveState.ACTIVE.static voidunmuteAllWD(ArrayList<WaveData> waveDataList) Unmutes all the operators in supplied waveDataList.static voidunmuteWaveData(WaveSynth wavesynth, int elem) static StringwaveSynthAsString(WaveSynth synth) Returns supplied WaveSynth settings and WaveData list as a formated String.
-
Field Details
-
semitoneFac
public static final double semitoneFac -
animSteps
public static int animSteps
-
-
Constructor Details
-
WaveSynthBuilder
public WaveSynthBuilder()
-
-
Method Details
-
synthTrumpet
public static ArrayList<WaveData> synthTrumpet(float fundamental, int howManyPartials, float pianoKey, int animSteps) Generates an ArrayList of WaveData objects to be used by a WaveSynth to generate RGB pixel values and (on request) audio signal values.- Returns:
- an ArrayList of WaveData objects
-
synthDoubleStop
public static ArrayList<WaveData> synthDoubleStop(float funda1, float funda2, float pianoKey1, float pianoKey2, int animSteps) Generates an ArrayList of WaveData objects to be used by a WaveSynth to generate RGB pixel values and (on request) audio signal values.- Returns:
- an ArrayList of WaveData objects
-
chromaticScale
public static float[] chromaticScale(float funda) -
pianoKeyFrequency
public static float pianoKeyFrequency(float keyNumber) -
frequencyPianoKey
public static float frequencyPianoKey(float freq) -
colorShift
public static int colorShift(int c, float shift) Moves an RGB color into the HSB color space and shifts it by a decimal fraction in the range (0.0,1.0) that represents a portion of the circle of hue values. For example, 1.0f/24 is 15 degrees around the 360-degree HSB color circle.- Parameters:
c- an RGB colorshift- the shift [0..1] of the hue in the HSB representation of color c- Returns:
- the RGB representation of the shifted color
-
scaleAmps
Scales the amplitude of an ArrayList of WaveData objects.- Parameters:
waveDataList- an ArrayList of WaveData objectsscale- the amount to scale the amplitude of each WaveData objectisVerbose- if true, output changes to data to the console
-
shiftColors
Shifts the colors of an ArrayList of WaveData objects.- Parameters:
waveDataList- an ArrayList of WaveData objectsshift- the amount shift each colorisVerbose- if true, output changes to data to the console
-
scaleFreqs
Scales the frequencies of an ArrayList of WaveData objects.- Parameters:
waveDataList- an ArrayList of WaveData objectsscale- the amount to scale the frequency of each WaveData objectisVerbose- if true, output changes to data to the console
-
shiftPhases
Shifts the phase of an ArrayList of WaveData objects.- Parameters:
waveDataList- an ArrayList of WaveData objectsshift- amount to shift the phase of each WaveData objectisVerbose- if true, output changes to data to the console
-
showPhaseValues
Outputs the phase values of a WaveSynth's array of WaveData objects to the console.- Parameters:
wavesynth- a WaveSynth whose waveDataList's phase values will be output
-
capturePhaseValues
Applies the current phase values to the initial values of the WaveSynth, so that the current state of the image display will appear as the first frame of animation. Save the WaveSynth to a JSON file to keep the new phase values.- Parameters:
wavesynth- an WaveSynth whose current WaveData phase values will be captured
-
toggleWDMute
Mutes or unmutes a WaveData operator (view in the control panel).- Parameters:
wavesynth- a WaveSynthelem- the index number of a WaveData object stored in a WaveSynth's waveDataList field
-
muteWaveData
-
unmuteWaveData
-
unmuteAllWD
Unmutes all the operators in supplied waveDataList.- Parameters:
waveDataList- an ArrayList of WaveData objects
-
toggleWDSolo
Sets a specified WaveData element in the waveDataList of a supplied WaveSynth to WaveData.WaveState.SOLO if isSolo is true, otherwise sets it to WaveData.WaveState.ACTIVE. If isSolo is true, all other WaveData elements taht are ACTIVE will be set to SUSPENDED. Any elements that are currently muted will remain muted, any elements whose waveState is SOLO will remain unchanged. Call unmuteAllWD() to set all elements to ACTIVE. TODO improve on the logic for WaveState changes.- Parameters:
wavesynth- a WaveSynth whose waveDataList will be affectedelem- index of an element in the waveDataListisSolo- if true, set WaveData element to WaveData.WaveState.SOLO otherwise, set it to WaveData.WaveState.ACTIVE
-
printWDStates
Prints mute/active status of WaveData operators in supplied waveDataList.- Parameters:
waveDataList- an ArrayList of WaveData objects
-
getJSONFromFile
public static boolean getJSONFromFile(File selection, processing.data.JSONObject json, WaveSynth synth, boolean isStrict) - Parameters:
selection- a file containing JSON datajson- a JSONObject that will be initialized with data from the filesynth- a WaveSynth object whose fields will be filled out from the JSON dataisStrict- if true, return false if no WaveSynth header is found in the JSON file- Returns:
- true if the File
-
getJSONFromFile
-
checkJSONHeader
-
setWaveSynthFromJSON
Sets the fields of a WaveSynth using values stored in a JSON object.- Parameters:
json- a JSON object, typically read in from a filesynth- a WaveSynth
-
waveSynthAsString
Returns supplied WaveSynth settings and WaveData list as a formated String. -
saveWaveSynthJSON
-
getWaveSynthJSONHeader
public static processing.data.JSONObject getWaveSynthJSONHeader()
-