summaryrefslogtreecommitdiff
path: root/basedProject/src
diff options
context:
space:
mode:
Diffstat (limited to 'basedProject/src')
-rw-r--r--basedProject/src/audioGlitcher.h179
-rw-r--r--basedProject/src/main.cpp4
-rw-r--r--basedProject/src/ofApp.cpp47
-rw-r--r--basedProject/src/ofApp.h9
4 files changed, 230 insertions, 9 deletions
diff --git a/basedProject/src/audioGlitcher.h b/basedProject/src/audioGlitcher.h
new file mode 100644
index 0000000..8f48288
--- /dev/null
+++ b/basedProject/src/audioGlitcher.h
@@ -0,0 +1,179 @@
+#pragma once
+
+#include "ofMain.h"
+#include "ofxOpenCv.h"
+
+class audioGlitcher {
+ public:
+
+ ofxCvColorImage buffer;
+ ofFbo renderFBO;
+ IplImage tmp;
+ vector<float> *samples;
+ int interp_x,interp_y;
+ float trans_x,trans_y;
+ float scale;
+ float rotation;
+ float origin_x,origin_y;
+
+ void setup(int w,int h,vector<float> *s){
+ buffer.allocate(w,h);
+ renderFBO.allocate(w,h,GL_RGB);
+ samples=s;
+ origin_x=origin_y=0.5f;
+ trans_x=trans_y=0.0f;
+ scale=1.0f;
+ rotation=0.0f;
+ interp_x=16;
+ interp_y=12;
+ }
+ void set_interp(int ix,int iy){
+ interp_x=ix;
+ interp_y=iy;
+ }
+ void set_trans(float x,float y){
+ trans_x=x;
+ trans_y=y;
+ }
+ void set_scale(float s){
+ scale=s;
+ }
+ void set_origin(float x,float y){
+ origin_x=x;
+ origin_y=y;
+ }
+ void draw(int x,int y){
+ renderFBO.draw(x,y);
+ }
+ void update(){
+
+ renderFBO.readToPixels(buffer.getPixelsRef());
+ buffer.flagImageChanged();
+
+ //create low res remap target
+
+ cv::Mat dstX(interp_x,interp_y,CV_32FC1);
+ cv::Mat dstY(interp_x,interp_y,CV_32FC1);
+ cv::Mat srcX(interp_x,interp_y,CV_32FC1);
+ cv::Mat srcY(interp_x,interp_y,CV_32FC1);
+
+ float xFactor=renderFBO.getWidth()/srcX.cols;
+ float yFactor=renderFBO.getHeight()/srcX.rows;
+ for (int i=0;i<srcX.cols;i++){
+ for (int j=0;j<srcX.rows;j++){
+ srcX.at<float>(j,i)=i*xFactor;
+ srcY.at<float>(j,i)=j*yFactor;
+ }
+ }
+
+ //transform the low res matrix
+ float tX=trans_x-.05; //fraction of image
+ float tY=trans_y-.04; //fraction of image
+ float oX=origin_x; //fraction of image
+ float oY=origin_y; //fraction of image
+ float s=scale;
+ float r=rotation;
+
+ cv::Point2f srcTri[3], dstTri[3];
+
+ // Compute matrix by creating triangle and transforming
+ srcTri[0].x=0;
+ srcTri[0].y=0;
+ srcTri[1].x=dstX.rows-1;
+ srcTri[1].y=0;
+ srcTri[2].x=0;
+ srcTri[2].y=dstX.cols-1;
+
+ for (int i=0;i<3;i++){
+
+ dstTri[i].x=srcTri[i].x+(tX*dstX.cols);
+ dstTri[i].y=srcTri[i].y+(tY*dstX.cols); //use cols for equiv coords
+ //rotate and scale around centre
+ //transform to centre
+ dstTri[i].x-=(oX*dstX.cols);
+ dstTri[i].y-=(oY*dstX.cols);
+
+ dstTri[i].x*=s;
+ dstTri[i].y*=s;
+
+ double dx=(dstTri[i].x*cos(r))-(dstTri[i].y*sin(r));
+ double dy=(dstTri[i].x*sin(r))+(dstTri[i].y*cos(r));
+
+ dstTri[i].x=dx;
+ dstTri[i].y=dy;
+
+ //transform back
+ dstTri[i].x+=(oX*dstX.cols);
+ dstTri[i].y+=(oY*dstX.cols);
+ }
+
+ cv::Mat trans_mat=getAffineTransform(srcTri,dstTri);
+ warpAffine(srcX,dstX,trans_mat, srcX.size(), cv::INTER_LINEAR, cv::BORDER_WRAP);
+ warpAffine(srcY,dstY,trans_mat, srcY.size(), cv::INTER_LINEAR, cv::BORDER_WRAP);
+
+ cv::Mat scaledstX;
+ cv::Mat scaledstY;
+
+ cv::resize(dstX,scaledstX, cv::Size(renderFBO.getWidth(),renderFBO.getHeight()), 0, 0, cv::INTER_LINEAR);
+ cv::resize(dstY,scaledstY, cv::Size(renderFBO.getWidth(),renderFBO.getHeight()), 0, 0, cv::INTER_LINEAR);
+
+ cv::Mat buf = buffer.getCvImage();
+ cv::Mat dstbuf;
+
+ cv::remap(buf,dstbuf,scaledstX,scaledstY, cv::INTER_NEAREST, cv::BORDER_WRAP); //, cv::Scalar(0,0, 0) );
+ tmp = IplImage(dstbuf);
+
+ //buffer=tmp;
+ //buffer.remap(scaledstX,scaledstY);
+ buffer=&tmp;
+
+ renderFBO.begin();
+
+ //
+ ofSetColor(255,255,255);
+
+ buffer-=1;
+ buffer.draw(0,0);
+ //
+
+ //ofEnableAlphaBlending();
+ //ofSetColor(0,0,0,128);
+ //ofRect(0,0,ofGetWidth(),ofGetHeight());
+ //ofDisableAlphaBlending();
+
+ if (false){
+ ofNoFill();
+ ofPushMatrix();
+ ofTranslate(renderFBO.getWidth()/2,renderFBO.getHeight()/2);
+ ofRect(-20,-20,40,40);
+ ofPopMatrix();
+ }
+
+ if (true) {
+ ofPushMatrix();
+ ofTranslate(0,renderFBO.getHeight()/2);
+
+
+ ofSetColor(0,0,0);
+ ofFill();
+ ofBeginShape();
+ for (int i=0;i<samples->size();i++){
+ ofVertex(i,(*samples)[i]*renderFBO.getHeight());
+ }
+ ofEndShape();
+
+ ofSetColor(255,255,255);
+ ofNoFill();
+ ofBeginShape();
+ for (int i=0;i<samples->size();i++){
+ ofVertex(i,(*samples)[i]*renderFBO.getHeight());
+ }
+ ofEndShape();
+
+ ofPopMatrix();
+ }
+
+ renderFBO.end();
+ //renderFBO.flagImageChanged();
+ }
+}; \ No newline at end of file
diff --git a/basedProject/src/main.cpp b/basedProject/src/main.cpp
index 6fe0e3d..a543dc4 100644
--- a/basedProject/src/main.cpp
+++ b/basedProject/src/main.cpp
@@ -1,7 +1,7 @@
#include "ofApp.h"
int main() {
- ofSetupOpenGL(4080,768, OF_WINDOW);
- //ofSetupOpenGL(1536,288, OF_WINDOW);
+ //ofSetupOpenGL(4080,768, OF_WINDOW);
+ ofSetupOpenGL(1536,288, OF_WINDOW);
ofRunApp(new ofApp());
}
diff --git a/basedProject/src/ofApp.cpp b/basedProject/src/ofApp.cpp
index 0dc6b46..1b2a074 100644
--- a/basedProject/src/ofApp.cpp
+++ b/basedProject/src/ofApp.cpp
@@ -13,27 +13,49 @@ void ofApp::setup() {
///ofSetVerticalSync(true);
//some model / light stuff
+ /*
glEnable (GL_DEPTH_TEST);
glShadeModel (GL_SMOOTH);
glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable (GL_COLOR_MATERIAL);
ofDisableLighting();
- ofSetGlobalAmbientColor(ofColor(255,255,255));
+ //ofSetGlobalAmbientColor(ofColor(255,255,255));
+ */
fullscreen=false;
activeView=0;
xhair.loadImage("crosshairs.png");
+
+ int bufferSize= 512; //should be based on the size of glitch buffer
+
+ soundStream.listDevices();
+ //nb all you have to do to make audio work is to turn off pulseaudio in configuration
+ soundStream.setup(this, 0, 1, 44100, bufferSize, 1);
+ samples.resize(bufferSize);
+
+ glitch.setup(512,384,&samples);
+ glitch.set_interp(ofRandom(30)+2,ofRandom(22)+2);
}
//--------------------------------------------------------------
void ofApp::update() {
ofSetWindowTitle(ofToString(ofGetFrameRate()));
+
+ glitch.update();
+}
+
+void ofApp::audioIn(float * input, int bufferSize, int nChannels){
+ for (int i=0;i<bufferSize/nChannels;i+=nChannels){
+ samples[i]=input[i*nChannels];
+ }
}
//--------------------------------------------------------------
void ofApp::draw() {
+ //ofSetColor(255,255, 255);
+ //glitch.draw(0,0);
for (int i=0;i<views.size();i++) {
views[i].setLight();
@@ -41,20 +63,31 @@ void ofApp::draw() {
for (int i=0;i<views.size();i++) {
//views[i].begin2d();
views[i].begin();
- //ofFill();
+
+
+ ofFill();
+ //glitch.renderFBO.
+ //xhair.getTextureReference().bind();
+ bindTexture(glitch.renderFBO);
//ofEnableAlphaBlending();
- ofSetColor(0, 0, 255, 255);
+ //ofSetColor(0, 0, 255, 255);
ofDrawSphere(0,0,0,145);
- ofSetColor(0, 255, 0, 255);
+ //ofSpherePrimitive s=ofSpherePrimitive(145,50);
+ //s.enableTextures();
+ //s.draw();
+ //ofSetColor(0, 255, 0, 255);
ofDrawSphere(200,0,230,75);
- ofSetColor(255, 0,0, 255);
+ //ofSetColor(255, 0,0, 255);
ofDrawSphere(-60,-190,280,47.5);
- ofSetColor(255, 255,255, 255);
+ //ofSetColor(255, 255,255, 255);
//xhair.draw(0,0,views[i].getWidth(),views[i].getHeight());
-
+ //glitch.renderFBO.
+ //xhair.getTextureReference().unbind();
+ unbindTexture(glitch.renderFBO);
//views[i].end2d();
views[i].end();
}
+
}
//--------------------------------------------------------------
diff --git a/basedProject/src/ofApp.h b/basedProject/src/ofApp.h
index 7090ab6..3e45838 100644
--- a/basedProject/src/ofApp.h
+++ b/basedProject/src/ofApp.h
@@ -34,6 +34,8 @@ have to track how many frames each key has been pressed for
#include "mapUtils.h"
#include "viewpoint.h"
+#include "audioGlitcher.h"
+
class ofApp : public ofBaseApp{
@@ -57,4 +59,11 @@ class ofApp : public ofBaseApp{
ofImage xhair;
+ void audioIn(float * input, int bufferSize, int nChannels);
+
+ audioGlitcher glitch;
+
+ ofSoundStream soundStream;
+ vector<float> samples;
+
};