added fxecho, moved settings() into setup() so this now runs in Processing 4, yeah

This commit is contained in:
2022-07-07 07:38:42 +02:00
parent 13315ff922
commit c837c9fe92
5 changed files with 125 additions and 15 deletions

View File

@@ -1,2 +1,2 @@
//globals
uptime = 116641803
uptime = 116657675

View File

@@ -1232,14 +1232,14 @@ class WAHWAH extends Shader {
class PHASER extends Shader {
float samplerate = 92230.0; // try setting this to 44100.0 or 2048.5 for kicks
//float samplerate = 92230.0; // try setting this to 44100.0 or 2048.5 for kicks
float samplerate = 44100; // try setting this to 44100.0 or 2048.5 for kicks
int mode;
PHASER() {
name ="fxPhaser";
params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
params.add(new Param ("frequency", FLOATVAL, 0.4, 4.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param ("dry/wet", INTVAL, 0, 255, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param ("depth", INTVAL, 0, 255, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param ("frequency", FLOATVAL, 0.1, 40.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param ("depth", INTVAL, 1, 255, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param ("feedback", INTVAL, -100, 100, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param ("phase", FLOATVAL, 0, TWO_PI, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param ("stages", INTVAL, 1, 24, new int[]{TRIANG, SINE, RAMPUPDOWN }));
@@ -1261,10 +1261,13 @@ class PHASER extends Shader {
void apply() {
mode = (int)params.get(0).value;
float mFreq = params.get(1).value;
int mDryWet = (int)params.get(2).value;
int mDepth = (int)params.get(3).value;
int mFeedback = (int)params.get(4).value;
float mPhase = params.get(5).value;
int mDryWet = 255;
int mDepth = (int)params.get(2).value;
int mFeedback = (int)params.get(3).value;
float mPhase = params.get(4).value;
//these two are only changed if mode = 1
int mStages = 2;
@@ -1294,8 +1297,8 @@ class PHASER extends Shader {
*/
// enable these for some more fun :)
if (mode == 1) {
mStages = (int)params.get(6).value;
mSampleRate = params.get(7).value;
mStages = (int)params.get(5).value;
mSampleRate = params.get(6).value;
}
//init
float gain = 0, fbout = 0;
@@ -1345,6 +1348,112 @@ class PHASER extends Shader {
}
/*
ECHO
*/
class ECHO extends Shader{
int mode = 0;
PImage result;
ECHO() {
name = "fxEcho";
params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
params.add(new Param ("xp", INTVAL, 0, 100, new int[]{TRIANG, SINE, RAMPUPDOWN }));
params.add(new Param ("yp", INTVAL, 0, 100, new int[]{TRIANG, SINE, RAMPUPDOWN }));
result = createImage(renderer.width, renderer.height, RGB);
}
void apply() {
mode = (int)params.get(0).value;
int xp = (int)params.get(1).value;
int yp = (int)params.get(2).value;
renderer.beginDraw();
renderer.colorMode(RGB);
colorMode(RGB);
if (mode == 0) {
renderer.image(auEcho(renderer, xp, yp), 0, 0);
} else if (mode == 1) {
renderer.image(auEchoWTF(renderer, xp, yp), 0, 0);
}
renderer.endDraw();
}
PImage auEcho(PImage img, int xp, int yp) {
result.resize(img.width, img.height);
float _delay = map(xp, 0, 100, 0.001, 1.0);
float decay = map(yp, 0, 100, 0.0, 1.0);
int delay = (int)(img.pixels.length * _delay);
color[] history = new color[img.pixels.length];
int blendMode = BLEND;
img.loadPixels();
result.loadPixels();
for ( int i = 0, l = img.pixels.length; i<l; i++) {
history[i] = img.pixels[i];
}
for ( int i = 0, l = img.pixels.length; i<l; i++) {
int fromPos = i-delay < 0 ? l-abs(i-delay) : i-delay;
color fromColor = history[fromPos];
float r = red(fromColor) * decay;
float g = green(fromColor) * decay;
float b = blue(fromColor) * decay;
color origColor = history[i];
color toColor = color(
r + red(origColor),
g + green(origColor),
b + blue(origColor) );
result.pixels[i] = history[i] = blendColor(origColor, toColor, blendMode);
}
return result;
}
PImage auEchoWTF(PImage img, int xp, int yp) {
result.resize(img.width, img.height);
float delay = map(xp, 0, 100, 0.001, 5);
float decay = map(yp, 0, 100, 0.0, 5.0);
int histPos = 0;
int histLen = img.pixels.length*3;
float[] history = new float[histLen*3];
img.loadPixels();
result.loadPixels();
float ibuf = 0.0, obuf = 0.0;
float[] rgb = new float[3];
for ( int i = 0, l = img.pixels.length; i<l; i++, histPos++) {
color c = img.pixels[i];
rgb[0] = map(red(c), 0, 255, 0, 1);
rgb[1] = map(green(c), 0, 255, 0, 1);
rgb[2] = map(blue(c), 0, 255, 0, 1);
history[i] = rgb[0];
history[i+1] = rgb[1];
history[i+2] = rgb[2];
}
for ( int i = 0, l = img.pixels.length; i<l; i++, histPos++) {
color c = img.pixels[i];
rgb[0] = map(red(c), 0, 255, 0, 1);
rgb[1] = map(green(c), 0, 255, 0, 1);
rgb[2] = map(blue(c), 0, 255, 0, 1);
if ( histPos == histLen ) histPos = 0;
for ( int ri = 0; ri < 3; ri++ ) {
history[histPos+ri] = rgb[ri] = rgb[ri] + history[histPos+ri] * decay;
}
color out = color(
(int)map(rgb[0], 0, 1, 0, 255),
(int)map(rgb[1], 0, 1, 0, 255),
(int)map(rgb[2], 0, 1, 0, 255));
result.pixels[i] = out;
}
return result;
}
}

View File

@@ -35,13 +35,10 @@ void dropEvent(DropEvent theDropEvent) {
sourceManager.importURI(theDropEvent.filePath());
}
void settings() {
size(800, 600);
}
SecondApplet gui;
void setup() {
size(800, 600);
w = width;
h = height;
frameRate(60);

View File

@@ -481,6 +481,9 @@ public class SecondApplet extends PApplet {
case(7):
shaderManager.addShader(new PHASER());
break;
case(8):
shaderManager.addShader(new ECHO());
break;
/*
case(4):
shaderManager.addShader(new AUECHO());

View File

@@ -49,6 +49,7 @@ String availableFx[] = {
"fxSlitscan",
"fxWahWah",
"fxPhaser",
"fxEcho",
"fxDarker",
"fxBrighter",
"fxMove",