Beispiel #1
0
    void update() {
#ifdef USE_AUDIO
        //Speaker sampling code
        speakerFbo.begin();
        renderScene(shader, speakerXyzMap, speakerConfidenceMap);
        speakerFbo.end();
        
        //Read back the fbo, and average it on the CPU
        speakerFbo.readToPixels(speakerPixels);
        speakerPixels.setImageType(OF_IMAGE_GRAYSCALE);
        
        ofxOscMessage brightnessMsg;
        brightnessMsg.setAddress("/audio/brightness");
        float* pix = speakerPixels.getData();
        for(int i = 0; i < n_speakers; i++){
            float avg = 0;
            for(int j = 0; j < n_samples; j++){
                avg += *pix++;
            }
            avg /= n_samples;
            brightnessMsg.addFloatArg(avg);
        }
        oscSender.sendMessage(brightnessMsg);
        
        float elapsedTime = ofGetElapsedTimef();
        // copied from shader --- 8< ---
        float t = elapsedTime / 30.; // duration of each stage
        float stage = floor(t); // index of current stage
        float i = t - stage; // progress in current stage
        // copied from shader --- 8< ---
        
        if(stage != previousStage) {
            ofxOscMessage msg;
            msg.setAddress("/audio/scene_change_event");
            msg.addIntArg(stage == 0 ? 0 : 2);
            oscSender.sendMessage(msg);
        }
        previousStage = stage;
        
        if(stage == 0) {
            float lighthouseAngle = ofGetElapsedTimef() / TWO_PI;
            lighthouseAngle += 0; // set offset here
            ofxOscMessage msg;
            msg.setAddress("/audio/lighthouse_angle");
            msg.addFloatArg(fmodf(lighthouseAngle, 1));
            oscSender.sendMessage(msg);
        }
        
#endif
    }
Beispiel #2
0
 void keyPressed(int key) {
     server->keyPressed(key);
     
     if(key > '0' && key < '9') {
         ofxOscMessage msg;
         msg.setAddress("/audio/scene_change_event");
         msg.addIntArg(key - '0');
         oscSender.sendMessage(msg);
     }
 }
Beispiel #3
0
 void sendOsc() {
     ofxOscMessage msg;
     msg.setAddress("/motors");
     msg.addFloatArg(local.nwLength);
     msg.addFloatArg(local.nwSpeed);
     msg.addFloatArg(local.neLength);
     msg.addFloatArg(local.neSpeed);
     msg.addFloatArg(local.seLength);
     msg.addFloatArg(local.seSpeed);
     msg.addFloatArg(local.swLength);
     msg.addFloatArg(local.swSpeed);
     oscSend.sendMessage(msg);
 }
Beispiel #4
0
    void updateMotion() {
        // get overall motion
//        motion.update(graySmall);
//        motionValue = motion.getMean();
        
        motionRunning.setLearningTime(motionLearningTime);
        motionRunning.update(graySmall, thresholdedRunning);
        motionValue = motionRunning.getPresence();
        
        ofxOscMessage msg;
        msg.setAddress("/motion");
        float t = ofGetElapsedTimef();
        msg.addFloatArg(motionValue);
        osc.sendMessage(msg);
        if(motionValue > smoothedMotionValue) {
            smoothedMotionValue = ofLerp(motionValue, smoothedMotionValue, motionSmoothingUp);
        } else {
            smoothedMotionValue = ofLerp(motionValue, smoothedMotionValue, motionSmoothingDown);
        }
    }