From a2fe68dfed91e362404ea1171cc8f0b313956cc3 Mon Sep 17 00:00:00 2001 From: Comment Date: Wed, 26 Feb 2014 17:01:43 +0000 Subject: thank fuk --- glitcher/src/ofApp.cpp | 125 +++++++++---------------------------------------- 1 file changed, 23 insertions(+), 102 deletions(-) (limited to 'glitcher/src/ofApp.cpp') diff --git a/glitcher/src/ofApp.cpp b/glitcher/src/ofApp.cpp index dee1e2b..ec97933 100644 --- a/glitcher/src/ofApp.cpp +++ b/glitcher/src/ofApp.cpp @@ -6,128 +6,46 @@ void ofApp::setup() { ofSetLogLevel(OF_LOG_WARNING); ofSetFrameRate(60); - - buffer.allocate(ofGetWidth(),ofGetHeight()); - renderFBO.allocate(ofGetWidth(),ofGetHeight(),GL_RGB); - //buffer.clear(); int bufferSize= ofGetWidth(); //should be based on the size of glitch buffer soundStream.listDevices(); - soundStream.setup(this, 0, 2, 44100, bufferSize, 4); + //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(ofGetWidth(),ofGetHeight(),&samples); + glitch.set_interp(ofRandom(30)+2,ofRandom(22)+2); + + frame=0; } //-------------------------------------------------------------- void ofApp::update() { ofSetWindowTitle(ofToString(ofGetFrameRate())); + + glitch.update(); } //-------------------------------------------------------------- void ofApp::draw() { - - //rough out how it could be possible to perform an avs style glitch transform - //within a drawing - //drawing- to an fbo - //distorting- from an opencv texture - //how to get from an fbo to an opencv texture - ofSetColor(255, 255, 255); - - renderFBO.begin(); - buffer.draw(0,0); - - - ofNoFill(); - ofPushMatrix(); - ofTranslate(ofGetWidth()/2,ofGetHeight()/2); - ofRect(-20,-20,40,40); - ofPopMatrix(); - renderFBO.end(); - renderFBO.readToPixels(buffer.getPixelsRef()); - buffer.flagImageChanged(); - - //create low res remap target - - cv::Mat dstX(16,12,CV_32FC1); - cv::Mat dstY(16,12,CV_32FC1); - cv::Mat srcX(16,12,CV_32FC1); - cv::Mat srcY(16,12,CV_32FC1); - - float xFactor=ofGetWidth()/srcX.cols; - float yFactor=ofGetHeight()/srcX.rows; - for (int i=0;i(j,i)=i*xFactor; - srcY.at(j,i)=j*yFactor; - } - } - - //transform the low res matrix - float tX=-.05; //fraction of image - float tY=-.04; //fraction of image - float oX=0.5; //fraction of image - float oY=0.5; //fraction of image - float s=0.99; - float r=0.0; - - 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); + frame++; + if (frame=1000){ + //glitch.set_interp(ofRandom(30)+2,ofRandom(22)+2); + frame=0; } + - 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(ofGetWidth(),ofGetHeight()), 0, 0, cv::INTER_LINEAR); - cv::resize(dstY,scaledstY, cv::Size(ofGetWidth(),ofGetHeight()), 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; + glitch.draw(0,0); //eventually textured into a viewport - renderFBO.draw(0,0); //eventually textured into a viewport - //buffer.draw(0,0); } -void audioIn(float * input, int bufferSize, int nChannels){ - +void ofApp::audioIn(float * input, int bufferSize, int nChannels){ + for (int i=0;i