added minim poc

This commit is contained in:
Jakob 2023-06-24 10:24:49 +02:00
parent d4190333c4
commit 4c1761a6b9
4 changed files with 107 additions and 12 deletions

View File

@ -1 +1,2 @@
video.mp4
gits.mp4

View File

@ -1,3 +1,6 @@
test:
glslViewer main.frag video.mp4 -w 960 -h 540 --nocursor --fps30
glslViewer main.frag video.mp4 -w 960 -h 540 -p 8881 --nocursor --fps30
test-gits:
glslViewer main.frag gits.mp4 -w 960 -h 540 -p 8881 --nocursor --fps30

View File

@ -9,15 +9,43 @@ uniform float u_time; // in seconds
uniform float u_delta; // delta time between frames (in seconds)
varying vec2 v_texcoord;
// video in
// video in - actually, this is just the first texture in. can be anything and is set from commandline.
uniform sampler2D u_tex0;
uniform vec2 u_tex0Resolution;
// lygia effects
// osc messages in, add `-p 8000 -l` to receive them.
// their path just needs to match the name
uniform float osc_val_1;
uniform float osc_val_2;
uniform float osc_val_3;
// lygia effects import and setup
// for some reason the -I flag doesn't do the right thing here
// common imports:
#include "../../lib/lygia/math/lerp.glsl"
// effect: chromatic aberration
#define CHROMAAB_TYPE vec4
#include "../../lib/lygia/distort/chromaAB.glsl"
//#include "sample/nearest.glsl"
// effect: brightness-contrast
#include "../../lib/lygia/color/exposure.glsl"
// effect: dither
#define FIND_CLOSER(new) (old = mix(new, old, step(length(old-ref), length(new-ref))));
vec3 ditherBayerLut(vec3 ref) {
vec3 old = vec3(1.0);
FIND_CLOSER(vec3(0.74));
FIND_CLOSER(vec3(0.47));
FIND_CLOSER(vec3(0.13));
FIND_CLOSER(vec3(0.05));
return old;
}
#include "../../lib/lygia/sample/dither.glsl"
void main() {
// common setup
@ -26,17 +54,22 @@ void main() {
vec2 st = gl_FragCoord.xy * pixel; // 0-1
vec2 uv = v_texcoord;
// set video
// read input texture
color = texture2D(u_tex0, st, 1.0);
// chromatic aberration
color = chromaAB(u_tex0, uv);
//color.rgb = mix(texture2D(u_tex0, uv).rgb,
// sampleNearest(u_tex0, uv, u_tex0Resolution).rgb,
// step(0.5, st.x));
// effect: dither
vec4 fx_dither = vec4(sampleDither(u_tex0, uv, u_resolution * 1.0), 1.0);
float fx_dither_amount = .0;
color = lerp(color, fx_dither, fx_dither_amount);
// effect: chromatic aberration
vec4 fx_chroma = chromaAB(u_tex0, uv);
float fx_chroma_amount = .0;
color = lerp(color, fx_chroma, fx_chroma_amount);
// effect: exposure
float exposure = osc_val_1;
color = exposure(color,exposure);
// actually set color
gl_FragColor = color;

View File

@ -0,0 +1,58 @@
/**
* This sketch demonstrates how to use the BeatDetect object song SOUND_ENERGY mode.<br />
* You must call <code>detect</code> every frame and then you can use <code>isOnset</code>
* to track the beat of the music.
* <p>
* This sketch plays an entire song, so it may be a little slow to load.
* <p>
* For more information about Minim and additional features,
* visit http://code.compartmental.net/minim/
*/
import ddf.minim.*;
import ddf.minim.analysis.*;
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress remoteLoc;
Minim minim;
AudioInput audioIn;
BeatDetect beat;
float eRadius;
void setup()
{
size(200, 200, P3D);
minim = new Minim(this);
audioIn = minim.getLineIn();
// a beat detection object song SOUND_ENERGY mode with a sensitivity of 10 milliseconds
beat = new BeatDetect();
ellipseMode(RADIUS);
eRadius = 20;
oscP5 = new OscP5(this, 12000);
remoteLoc = new NetAddress("127.0.0.1",8881);
}
void draw()
{
background(0);
beat.detect(audioIn.mix);
float a = map(eRadius, 20, 80, 60, 255);
fill(60, 255, 0, a);
if ( beat.isOnset() ) eRadius = 80;
ellipse(width/2, height/2, eRadius, eRadius);
eRadius *= 0.95;
if ( eRadius < 20 ) eRadius = 20;
if(frameCount % 5 == 0) {
OscMessage msg = new OscMessage("/osc_val_1");
float x = map(eRadius,20,80,0.2,1.2);
msg.add(x); //<>//
oscP5.send(msg, remoteLoc);
}
}