Needing help mapping a pre-loaded supercollider buffer, to an ofxsupercollider sketch; fixing issues in the same sketch with OpenCV


#1

greetings

i have created the following piece of code, using openframeworks addons examples.

#include <iostream>
#include <stdlib.h>
#include "ofMain.h"
#include "ofxPd.h"
#include "ofxSuperCollider.h"
#include "ofxSCexit.h"
#include "ofxGui.h"
#include "ofxOpenCv.h"
#include "ofxOsc.h"
#include "ofxOscParameterSync.h"

class ofApp : public ofBaseApp{
public:
    void setup();
    void update();
    void draw();
    void exit();
    void keyPressed(int key);
    void keyReleased(int key);
    void mouseMoved(int x, int y );
    void mouseDragged(int x, int y, int button);
    void mousePressed(int x, int y, int button);
    void mouseReleased(int x, int y, int button);
    void windowResized(int w, int h);
    void dragEvent(ofDragInfo dragInfo);
    void gotMessage(ofMessage msg);
    ofxSCSynth *synth;
    ofxSCexit sc;
    ofVideoGrabber vidGrabber;
    ofxCvColorImage colorImg;
    ofxCvGrayscaleImage grayImage;
    ofxCvGrayscaleImage grayBg;
    ofxCvGrayscaleImage grayDiff;
    ofxCvContourFinder contourFinder;
    int threshold;
    bool bLearnBakground;
    ofxOscParameterSync sync;
    ofParameter<float> size;
    ofParameter<int> number;
    ofParameter<bool> check;
    ofParameterGroup parameters;
    ofParameter<ofColor> color;
    ofxPanel gui;
};

void ofApp::setup(){
    system("/Applications/of_v0.9.8_osx_release/apps/myApps/appGiovaniDemo/bin/run.sh");
    ofSetLogLevel(OF_LOG_VERBOSE);
    int num =1;
    float notes[] = {1.0, 5.0/4.0, 4.0/3.0, 3.0/2.0};
    float base[] = {1.0, 2.0, 4.0, 6.0, 8.0, 16.0};
    float radius;
    float soundSpeed;
    float lfo;
    float phase;
    float movedDim;
    soundSpeed = notes[num%4] * base[num%6] * pow(1.5, 1.0+int(num/16.0));
    synth = new ofxSCSynth("simple_sine");
    synth->set("freq", soundSpeed * 50);
    synth->set("lfoFreq", lfo);
    synth->set("amp", 0);
    synth->create();
    vidGrabber.setVerbose(true);
    vidGrabber.setup(320,240);
    colorImg.allocate(320,240);
    grayImage.allocate(320,240);
    grayBg.allocate(320,240);
    grayDiff.allocate(320,240);
    bLearnBakground = true;
    threshold = 80;
    parameters.setName("parameters");
    parameters.add(size.set("number of blobs",contourFinder.nBlobs,0,100));
    parameters.add(number.set("FPS",ofGetFrameRate(),0,100));
    gui.setup(parameters);
    ofSetVerticalSync(true);
}

//--------------------------------------------------------------
void ofApp::update(){
    ofBackground(100,100,100);
    bool bNewFrame = false;
    vidGrabber.update();
	   bNewFrame = vidGrabber.isFrameNew();
    if (bNewFrame){
        colorImg.setFromPixels(vidGrabber.getPixels());
        grayImage = colorImg;
        if (bLearnBakground == true){
            grayBg = grayImage;
            bLearnBakground = false;
        }
        grayDiff.absDiff(grayBg, grayImage);
        grayDiff.threshold(threshold);
        contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true);	// find holes
    }
    gui.getParameter();
    parameters.add(size.set("number of blobs",contourFinder.nBlobs,0,100));
    parameters.add(number.set("FPS",ofGetFrameRate(),0,100));

    
    int mod, index;
    mod = ofMap(contourFinder.blobs[1].boundingRect.getCenter().x + 360, 0, ofGetWidth(), 20, 8000);
    index = ofMap(contourFinder.blobs[1].boundingRect.getCenter().y + 540, 0, ofGetHeight(), 1000, 0);
    synth->set("mod", mod);
    synth->set("index", index);
    
}

//--------------------------------------------------------------
void ofApp::draw(){
    ofSetHexColor(0xffffff);
    colorImg.draw(20,20);
    grayImage.draw(360,20);
    grayBg.draw(20,280);
    grayDiff.draw(360,280);
    ofFill();
    ofSetHexColor(0x333333);
    ofDrawRectangle(360,540,320,240);
    ofSetHexColor(0xffffff);
    for (int i = 0; i < contourFinder.nBlobs; i++){
        contourFinder.blobs[i].draw(360,540);
        ofSetColor(255);
        if(contourFinder.blobs[i].hole){
            ofDrawBitmapString("hole",
                               contourFinder.blobs[i].boundingRect.getCenter().x + 360,
                               contourFinder.blobs[i].boundingRect.getCenter().y + 540);
        }
    }
    ofSetHexColor(0xffffff);
    stringstream reportStr;
    reportStr << "bg subtraction and blob detection" << endl
    << "press ' ' to capture bg" << endl
    << "threshold " << threshold << " (press: +/-)" << endl
    << "num blobs found " << contourFinder.nBlobs << ", fps: " << ofGetFrameRate();
    ofDrawBitmapString(reportStr.str(), 20, 600);
    gui.draw();
    
    

}

//--------------------------------------------------------------
void ofApp::exit(){
    synth->free();
    sc.SCexit();
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    switch (key){
        case ' ':
            bLearnBakground = true;
            break;
        case '+':
            threshold ++;
            if (threshold > 255) threshold = 255;
            break;
        case '-':
            threshold --;
            if (threshold < 0) threshold = 0;
            break;
    }
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){
    
}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
    
}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
    
}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
    
}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
    
}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){ 
    
}

//========================================================================
int main( ){
	ofSetupOpenGL(320,720,OF_WINDOW);
	ofRunApp(new ofApp());

}

I need to know:

how can I map the following piece of code to the first blob, as the whole thing turns out to crash when I point to something like:

int mod, index;
mod = ofMap(contourFinder.blobs[1].boundingRect.getCenter().x + 360, 0, ofGetWidth(), 20, 8000);


int mod, index;
mod = ofMap(, 0, ofGetWidth(), 20, 8000);
index = ofMap(, 0, ofGetHeight(), 1000, 0);
synth->set("mod", mod);
synth->set("index", index);

also, what is wrong with the supercollider thing, as it doesn’t turn out to generate any sound. shall I add a synthdef to the boot.scd file in the ofxsupercollider-boot example. also, the examples of supercollider synthdefs seem to have disappeared in the GitHub repositories. hope you guys can fix that (or maybe should I address this in each of them)


#2

the blob business was easily fixed with this:

    if(contourFinder.nBlobs >= 1){
    mod = ofMap(contourFinder.blobs[1].boundingRect.getCenter().x, 0, ofGetWidth(), 20, 8000);
    index = ofMap(contourFinder.blobs[1].boundingRect.getCenter().y, 0, ofGetHeight(), 1000, 0);
    synth->set("mod", mod);
    synth->set("index", index);
    }

#3

I got rid of the ofxsupercolliderboot library as it was only creating mess in the project.

i am running this

#include <iostream>
#include <stdlib.h>
#include "ofMain.h"
#include "ofxPd.h"
#include "ofxSuperCollider.h"
#include "ofxSCexit.h"
#include "ofxGui.h"
#include "ofxOpenCv.h"
#include "ofxOsc.h"
#include "ofxOscParameterSync.h"

class ofApp : public ofBaseApp{
public:
    void setup();
    void update();
    void draw();
    void exit();
    void keyPressed(int key);
    void keyReleased(int key);
    void mouseMoved(int x, int y );
    void mouseDragged(int x, int y, int button);
    void mousePressed(int x, int y, int button);
    void mouseReleased(int x, int y, int button);
    void windowResized(int w, int h);
    void dragEvent(ofDragInfo dragInfo);
    void gotMessage(ofMessage msg);
    ofxSCSynth	*synth;
    ofxSCSynth	*playbuf;
    ofxSCBus	*bus;
    ofxSCSynth	*delay;
    ofxSCBuffer	*buffer;
    ofVideoGrabber vidGrabber;
    ofxCvColorImage colorImg;
    ofxCvGrayscaleImage grayImage;
    ofxCvGrayscaleImage grayBg;
    ofxCvGrayscaleImage grayDiff;
    ofxCvContourFinder contourFinder;
    int threshold;
    bool bLearnBakground;
    ofxOscParameterSync sync;
    ofParameter<float> size;
    ofParameter<int> number;
    ofParameter<bool> check;
    ofParameterGroup parameters;
    ofParameter<ofColor> color;
    ofxPanel gui;
};

void ofApp::setup(){
    synth = new ofxSCSynth("sine_harmonic");
    synth->create();
    buffer = new ofxSCBuffer();
    buffer->read(ofToDataPath("bell.aif", true));
    bus = new ofxSCBus(2);
    playbuf = new ofxSCSynth("playbuf_1");
    playbuf->set("bufnum", buffer->index);
    playbuf->set("outbus", bus->index);
    delay = new ofxSCSynth("fx_delay");
    delay->set("wet", 0.4);
    delay->set("delaytime", 0.4);
    delay->set("decaytime", 4);
    delay->set("inbus", bus->index);
    delay->set("outbus", 0);
    delay->addToTail();
    vidGrabber.setVerbose(true);
    vidGrabber.setup(320,240);
    colorImg.allocate(320,240);
    grayImage.allocate(320,240);
    grayBg.allocate(320,240);
    grayDiff.allocate(320,240);
    bLearnBakground = true;
    threshold = 80;
    parameters.setName("parameters");
    parameters.add(size.set("number of blobs",contourFinder.nBlobs,0,100));
    parameters.add(number.set("FPS",ofGetFrameRate(),0,100));
    gui.setup(parameters);
    ofSetVerticalSync(true);
}

//--------------------------------------------------------------
void ofApp::update(){
    ofBackground(100,100,100);
    bool bNewFrame = false;
    vidGrabber.update();
	   bNewFrame = vidGrabber.isFrameNew();
    if (bNewFrame){
        colorImg.setFromPixels(vidGrabber.getPixels());
        grayImage = colorImg;
        if (bLearnBakground == true){
            grayBg = grayImage;
            bLearnBakground = false;
        }
        grayDiff.absDiff(grayBg, grayImage);
        grayDiff.threshold(threshold);
        contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true);	// find holes
    }
    gui.getParameter();
    parameters.add(size.set("number of blobs",contourFinder.nBlobs,0,100));
    parameters.add(number.set("FPS",ofGetFrameRate(),0,100));

    
    float synthX, synthY;
    if(contourFinder.nBlobs >= 1){
    synthX = ofMap(contourFinder.blobs[1].boundingRect.getCenter().x, 0, ofGetWidth(), 0, 1);
    synthY = ofMap(contourFinder.blobs[1].boundingRect.getCenter().y, 0, ofGetHeight(), 0, 1);
    playbuf->set("x", synthX);
    playbuf->set("y", synthY);
    playbuf->set("rate", 2.0f * synthX / ofGetWidth());
    playbuf->grain();
    synth->set("amp", 0.8f);
    synth->set("amp", 0.8f);
    }
}

//--------------------------------------------------------------
void ofApp::draw(){
    ofSetHexColor(0xffffff);
    colorImg.draw(20,20);
    grayImage.draw(360,20);
    grayBg.draw(20,280);
    grayDiff.draw(360,280);
    ofFill();
    ofSetHexColor(0x333333);
    ofDrawRectangle(360,540,320,240);
    ofSetHexColor(0xffffff);
    for (int i = 0; i < contourFinder.nBlobs; i++){
        contourFinder.blobs[i].draw(360,540);
        ofSetColor(255);
        if(contourFinder.blobs[i].hole){
            ofDrawBitmapString("hole",
                               contourFinder.blobs[i].boundingRect.getCenter().x + 360,
                               contourFinder.blobs[i].boundingRect.getCenter().y + 540);
        }
    }
    ofSetHexColor(0xffffff);
    stringstream reportStr;
    reportStr << "bg subtraction and blob detection" << endl
    << "press ' ' to capture bg" << endl
    << "threshold " << threshold << " (press: +/-)" << endl
    << "num blobs found " << contourFinder.nBlobs << ", fps: " << ofGetFrameRate();
    ofDrawBitmapString(reportStr.str(), 20, 600);
    gui.draw();
}

//--------------------------------------------------------------
void ofApp::exit(){
    synth->free();
    delay->free();
    buffer->free();
    bus->free();
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    switch (key){
        case ' ':
            bLearnBakground = true;
            break;
        case '+':
            threshold ++;
            if (threshold > 255) threshold = 255;
            break;
        case '-':
            threshold --;
            if (threshold < 0) threshold = 0;
            break;
    }
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){
    
}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
    
}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
    
}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
    
}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
    
}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){ 
    
}

//========================================================================
int main( ){
	ofSetupOpenGL(320,720,OF_WINDOW);
	ofRunApp(new ofApp());

}

plus this

(
	SynthDef(\fx_comb, { |inbus = 0, outbus = 0, wet = 0.5, delaytime = 0.1, decaytime = 1.0, fade = 0.5|
		var in, out;
		
		in = In.ar(inbus, 2);
		out = CombN.ar(in, 2.0, delaytime, decaytime);
		
		out = (wet * out) + ((1 - wet) * in);
		Out.ar(outbus, out);
	}).store;
)
(
 SynthDef(\sine_harmonic, { |outbus = 0, freq = 200, amp = 0.1, gate = 1, pan = 0|
	var data, env;
 
	amp = Lag.kr(amp, 0.4);
 
	// generate, degrade, filter, echo
	data = SinOsc.ar(freq, 0, amp);
	data = Latch.ar(data, Impulse.ar(Rand(1000, 35000)));
	data = LPF.ar(data, 1000);
	data = Pan2.ar(data, pan);
	data = data + CombN.ar(data, 0.5, 0.3, 15.0, 0.3);
 
	// envelope
	env = EnvGen.kr(Env.asr(0.5, 1.0, 1.0), gate: gate, doneAction: 2);
	data = data * env;
 
	data = [ data[0], data[1] * Select.kr(IRand(0, 3), [ 1, 1, -1 ]) ];
 
	Out.ar(outbus, data);
 }).store;
)
(
 SynthDef(\playbuf_1, { |bufnum = 0, outbus = 0, amp = 0.5, loop = 0, pan = 0, rate = 1.0|
	var data;
	data = PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum) * rate, 0, 0, loop);
	FreeSelfWhenDone.kr(data);
	Out.ar(outbus, Pan2.ar(data, pan, amp));
 }).store;
)

but server crashes sometimes because something in opencv and I can get no sound at the moment. which is silly but yeah

if someone can help me to fix this I would be quite thankful


#4

in mean time I got the code to run and I got a change to do some sound with it. however cpu I exploding at points. here is what I am doing:

openframeworks

#include <iostream>
#include <stdlib.h>
#include "ofMain.h"
#include "ofxPd.h"
#include "ofxSuperCollider.h"
#include "ofxSCexit.h"
#include "ofxGui.h"
#include "ofxOpenCv.h"
#include "ofxOsc.h"
#include "ofxOscParameterSync.h"

class ofApp : public ofBaseApp{
public:
    void setup();
    void update();
    void draw();
    void exit();
    void keyPressed(int key);
    void keyReleased(int key);
    void mouseMoved(int x, int y );
    void mouseDragged(int x, int y, int button);
    void mousePressed(int x, int y, int button);
    void mouseReleased(int x, int y, int button);
    void windowResized(int w, int h);
    void dragEvent(ofDragInfo dragInfo);
    void gotMessage(ofMessage msg);
    ofxSCSynth	*synth;
    ofxSCSynth	*playbuf;
    ofxSCBus	*bus;
    ofxSCSynth	*delay;
    ofxSCBuffer	*buffer;
    ofVideoGrabber vidGrabber;
    ofxCvColorImage colorImg;
    ofxCvGrayscaleImage grayImage;
    ofxCvGrayscaleImage grayBg;
    ofxCvGrayscaleImage grayDiff;
    ofxCvContourFinder contourFinder;
    int threshold;
    bool bLearnBakground;
    ofxOscParameterSync sync;
    ofParameter<float> size;
    ofParameter<int> number;
    ofParameter<bool> check;
    ofParameterGroup parameters;
    ofParameter<ofColor> color;
    ofxPanel gui;
};

void ofApp::setup(){
    synth = new ofxSCSynth("sine_harmonic");
    synth->create();
    buffer = new ofxSCBuffer();
    buffer->read(ofToDataPath("bell.aif", true));
    bus = new ofxSCBus(2);
    playbuf = new ofxSCSynth("playbuf_1");
    playbuf->set("bufnum", buffer->index);
    playbuf->set("outbus", bus->index);
    delay = new ofxSCSynth("fx_delay");
    delay->set("wet", 0.4);
    delay->set("delaytime", 0.4);
    delay->set("decaytime", 4);
    delay->set("inbus", bus->index);
    delay->set("outbus", 0);
    delay->addToTail();
    vidGrabber.setVerbose(true);
    vidGrabber.setup(320,240);
    colorImg.allocate(320,240);
    grayImage.allocate(320,240);
    grayBg.allocate(320,240);
    grayDiff.allocate(320,240);
    bLearnBakground = true;
    threshold = 80;
    parameters.setName("parameters");
    parameters.add(size.set("number of blobs",contourFinder.nBlobs,0,100));
    parameters.add(number.set("FPS",ofGetFrameRate(),0,100));
    gui.setup(parameters);
    ofSetVerticalSync(true);
}

//--------------------------------------------------------------
void ofApp::update(){
    ofBackground(100,100,100);
    bool bNewFrame = false;
    vidGrabber.update();
	   bNewFrame = vidGrabber.isFrameNew();
    if (bNewFrame){
        colorImg.setFromPixels(vidGrabber.getPixels());
        grayImage = colorImg;
        if (bLearnBakground == true){
            grayBg = grayImage;
            bLearnBakground = false;
        }
        grayDiff.absDiff(grayBg, grayImage);
        grayDiff.threshold(threshold);
        contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true);	// find holes
    }
    gui.getParameter();
    parameters.add(size.set("number of blobs",contourFinder.nBlobs,0,100));
    parameters.add(number.set("FPS",ofGetFrameRate(),0,100));

    
    float synthX, synthY;
    if(contourFinder.nBlobs >= 1){
    synthX = ofMap(contourFinder.blobs[1].boundingRect.getCenter().x, 0, ofGetWidth(), 0, 1);
    synthY = ofMap(contourFinder.blobs[1].boundingRect.getCenter().y, 0, ofGetHeight(), 0, 1);
    playbuf->set("rate", 2.0f * synthX / ofGetWidth());
    playbuf->grain();
    synth->set("amp", 0.8f);
    synth->set("freq", synthX + 40);
    synth->set("amp", 1.0f - (float) synthY / ofGetHeight());
    synth->set("pan", (float) synthX / ofGetHeight() - 0.5f);
    }
    else {
    synth->set("amp", 0.1f);
    }
}

//--------------------------------------------------------------
void ofApp::draw(){
    ofSetHexColor(0xffffff);
    colorImg.draw(20,20);
    grayImage.draw(360,20);
    grayBg.draw(20,280);
    grayDiff.draw(360,280);
    ofFill();
    ofSetHexColor(0x333333);
    ofDrawRectangle(360,540,320,240);
    ofSetHexColor(0xffffff);
    for (int i = 0; i < contourFinder.nBlobs; i++){
        contourFinder.blobs[i].draw(360,540);
        ofSetColor(255);
        if(contourFinder.blobs[i].hole){
            ofDrawBitmapString("hole",
                               contourFinder.blobs[i].boundingRect.getCenter().x + 360,
                               contourFinder.blobs[i].boundingRect.getCenter().y + 540);
        }
    }
    ofSetHexColor(0xffffff);
    stringstream reportStr;
    reportStr << "bg subtraction and blob detection" << endl
    << "press ' ' to capture bg" << endl
    << "threshold " << threshold << " (press: +/-)" << endl
    << "num blobs found " << contourFinder.nBlobs << ", fps: " << ofGetFrameRate();
    ofDrawBitmapString(reportStr.str(), 20, 600);
    gui.draw();
}

//--------------------------------------------------------------
void ofApp::exit(){
    synth->free();
    delay->free();
    buffer->free();
    bus->free();
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    switch (key){
        case ' ':
            bLearnBakground = true;
            break;
        case '+':
            threshold ++;
            if (threshold > 255) threshold = 255;
            break;
        case '-':
            threshold --;
            if (threshold < 0) threshold = 0;
            break;
    }
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){
    
}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
    
}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
    
}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
    
}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
    
}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){ 
    
}

//========================================================================
int main( ){
	ofSetupOpenGL(1200,1200,OF_WINDOW);
	ofRunApp(new ofApp());

}

supercollider

s = Server.default;
s.boot;

(
	SynthDef(\fx_comb, { |inbus = 0, outbus = 0, wet = 0.5, delaytime = 0.1, decaytime = 1.0, fade = 0.5|
		var in, out;
		
		in = In.ar(inbus, 2);
		out = CombN.ar(in, 2.0, delaytime, decaytime);
		
		out = (wet * out) + ((1 - wet) * in);
		Out.ar(outbus, out);
	}).store;
)
(
 SynthDef(\sine_harmonic, { |outbus = 0, freq = 200, amp = 0.1, gate = 1, pan = 0|
	var data, env;
 
	amp = Lag.kr(amp, 0.4);
 
	// generate, degrade, filter, echo
	data = SinOsc.ar(freq, 0, amp);
	data = Latch.ar(data, Impulse.ar(Rand(1000, 35000)));
	data = LPF.ar(data, 1000);
	data = Pan2.ar(data, pan);
	data = data + CombN.ar(data, 0.5, 0.3, 15.0, 0.3);
 
	// envelope
	env = EnvGen.kr(Env.asr(0.5, 1.0, 1.0), gate: gate, doneAction: 2);
	data = data * env;
 
	data = [ data[0], data[1] * Select.kr(IRand(0, 3), [ 1, 1, -1 ]) ];
 
	Out.ar(outbus, data);
 }).store;
)
(
 SynthDef(\playbuf_1, { |bufnum = 0, outbus = 0, amp = 0.5, loop = 0, pan = 0, rate = 1.0|
	var data;
	data = PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum) * rate, 0, 0, loop);
	FreeSelfWhenDone.kr(data);
	Out.ar(outbus, Pan2.ar(data, pan, amp));
 }).store;
)

#5

if someone can help me to fix this I would be quite thankful


#6

i fixed the predeceasing bug by removing
playbuf->grain();


#7

now, I want to read a one hour buffer into a warp 1. I did the following but I get no sound. if someone can Help I would be thankful

#include <iostream>
#include <stdlib.h>
#include "ofMain.h"
#include "ofxPd.h"
#include "ofxSuperCollider.h"
#include "ofxSCexit.h"
#include "ofxGui.h"
#include "ofxOpenCv.h"
#include "ofxOsc.h"
#include "ofxOscParameterSync.h"

class ofApp : public ofBaseApp{
public:
    void setup();
    void update();
    void draw();
    void exit();
    void keyPressed(int key);
    void keyReleased(int key);
    void mouseMoved(int x, int y );
    void mouseDragged(int x, int y, int button);
    void mousePressed(int x, int y, int button);
    void mouseReleased(int x, int y, int button);
    void windowResized(int w, int h);
    void dragEvent(ofDragInfo dragInfo);
    void gotMessage(ofMessage msg);
    ofxSCSynth	*synth;
    ofxSCSynth	*playbuf;
    ofxSCBus	*bus;
    ofxSCSynth	*delay;
    ofxSCBuffer	*buffer;
    ofVideoGrabber vidGrabber;
    ofxCvColorImage colorImg;
    ofxCvGrayscaleImage grayImage;
    ofxCvGrayscaleImage grayBg;
    ofxCvGrayscaleImage grayDiff;
    ofxCvContourFinder contourFinder;
    int threshold;
    bool bLearnBakground;
    ofxOscParameterSync sync;
    ofParameter<float> size;
    ofParameter<int> number;
    ofParameter<bool> check;
    ofParameterGroup parameters;
    ofParameter<ofColor> color;
    ofxPanel gui;
};

void ofApp::setup(){
    buffer = new ofxSCBuffer();
    buffer->read(ofToDataPath("master.wav", true));
    bus = new ofxSCBus(2);
    playbuf = new ofxSCSynth("playbuf_1");
    playbuf->set("bufnum", buffer->index);
    playbuf->set("outbus", bus->index);
    vidGrabber.setVerbose(true);
    vidGrabber.setup(320,240);
    colorImg.allocate(320,240);
    grayImage.allocate(320,240);
    grayBg.allocate(320,240);
    grayDiff.allocate(320,240);
    bLearnBakground = true;
    threshold = 80;
    parameters.setName("parameters");
    parameters.add(size.set("number of blobs",contourFinder.nBlobs,0,100));
    parameters.add(number.set("FPS",ofGetFrameRate(),0,100));
    gui.setup(parameters);
    ofSetVerticalSync(true);
}

//--------------------------------------------------------------
void ofApp::update(){
    ofBackground(100,100,100);
    bool bNewFrame = false;
    vidGrabber.update();
	   bNewFrame = vidGrabber.isFrameNew();
    if (bNewFrame){
        colorImg.setFromPixels(vidGrabber.getPixels());
        grayImage = colorImg;
        if (bLearnBakground == true){
            grayBg = grayImage;
            bLearnBakground = false;
        }
        grayDiff.absDiff(grayBg, grayImage);
        grayDiff.threshold(threshold);
        contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true);	// find holes
    }
    gui.getParameter();
    parameters.add(size.set("number of blobs",contourFinder.nBlobs,0,100));
    parameters.add(number.set("FPS",ofGetFrameRate(),0,100));

    
    float synthX, synthY;
    if(contourFinder.nBlobs >= 1){
    synthX = ofMap(contourFinder.blobs[1].boundingRect.getCenter().x, 0, ofGetWidth(), 0, 1);
    synthY = ofMap(contourFinder.blobs[1].boundingRect.getCenter().y, 0, ofGetHeight(), 0, 1);
    playbuf->set("x", synthX);
    playbuf->set("amp", synthY);

    }
    else {
    playbuf->set("amp", 0.0f);
    }
}

//--------------------------------------------------------------
void ofApp::draw(){
    ofSetHexColor(0xffffff);
    colorImg.draw(20,20);
    grayImage.draw(360,20);
    grayBg.draw(20,280);
    grayDiff.draw(360,280);
    ofFill();
    ofSetHexColor(0x333333);
    ofDrawRectangle(360,540,320,240);
    ofSetHexColor(0xffffff);
    for (int i = 0; i < contourFinder.nBlobs; i++){
        contourFinder.blobs[i].draw(360,540);
        ofSetColor(255);
        if(contourFinder.blobs[i].hole){
            ofDrawBitmapString("hole",
                               contourFinder.blobs[i].boundingRect.getCenter().x + 360,
                               contourFinder.blobs[i].boundingRect.getCenter().y + 540);
        }
    }
    ofSetHexColor(0xffffff);
    stringstream reportStr;
    reportStr << "bg subtraction and blob detection" << endl
    << "press ' ' to capture bg" << endl
    << "threshold " << threshold << " (press: +/-)" << endl
    << "num blobs found " << contourFinder.nBlobs << ", fps: " << ofGetFrameRate();
    ofDrawBitmapString(reportStr.str(), 20, 600);
    gui.draw();
}

//--------------------------------------------------------------
void ofApp::exit(){
    synth->free();
    delay->free();
    buffer->free();
    bus->free();
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    switch (key){
        case ' ':
            bLearnBakground = true;
            break;
        case '+':
            threshold ++;
            if (threshold > 255) threshold = 255;
            break;
        case '-':
            threshold --;
            if (threshold < 0) threshold = 0;
            break;
    }
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){
    
}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
    
}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
    
}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
    
}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
    
}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){ 
    
}

//========================================================================
int main( ){
	ofSetupOpenGL(1200,1200,OF_WINDOW);
	ofRunApp(new ofApp());

}

furthermore, I have this piece of supercollider code:

(
 SynthDef(\playbuf_1, { |bufnum = 0, outbus = 0, amp = 0.5, loop = 0, pan = 0, rate = 1.0, x|
	var data;
	data = Warp1.ar(2, bufnum, x + (TRand.kr(0, 0.01, Impulse.kr(40)) * 0.1), 1, 2, -1, 8, 1, 4, 1);
	FreeSelfWhenDone.kr(data);
	Out.ar(outbus, Pan2.ar(data, pan, amp));
 }).store;
)

if you guys can help fixing this I would be quite thankful. cheers


#8

I don’t get any sound and the blob detection does eventually make it crash sometimes


#9

anyone?


#10

I really need help. if someone could provide insight I would be highly thankful. problem: open frameworks crashes (blob and memory allocation related issues); supercollider doesn’t play sound (buffer loading related problem)


#11

anyone?


#12

I already sort that out. playbuf and delay were missing:

playbuf->create();
delay->create()


#13

Hi. I’m in no position to help with your questions right now as I am just getting started with OF (0.9.8_osx) and SC (3.8.0). I’ve cloned Gene Kogan’s ofxSuperCollider repo on github and see that you have contributed a couple of commits. I also see from the lack of contributions on this forum to this thread that this isn’t something folks are working on here. Are you posting in a different forum where I can see more of a discussion? Thanks for moving this forward!