void ofxFFTFile::update() {
    
	if(bFrameSync) {
        frameSyncCount += 1;
		float position = frameSyncCount / (float)frameSyncTotal;
		player->setPosition(position);
	}
    
    float * data = ofSoundGetSpectrum(bufferSize);
    ofxFFTBase::audioIn(data);
    
    ofxFFTBase::update();
}
Esempio n. 2
0
//--------------------------------------------------------------
void ofApp::update(){
    //新規フレームの取り込みをリセット
    bool bNewFrame = false;
    
#ifdef _USE_LIVE_VIDEO
    //カメラ使用の場合はカメラから新規フレーム取り込み
    vidGrabber.update();
    //新規にフレームが切り替わったか判定
    bNewFrame = vidGrabber.isFrameNew();
#else
    //カメラ不使用の場合は、ビデオプレーヤーから新規フレーム取り込み
    vidPlayer.idleMovie();
    //新規にフレームが切り替わったか判定
    bNewFrame = vidPlayer.isFrameNew();
#endif
    
    //フレームが切り替わった際のみ画像を解析
    if (bNewFrame){
#ifdef _USE_LIVE_VIDEO
        //取り込んだフレームを画像としてキャプチャ
        colorImg.setFromPixels(vidGrabber.getPixels(), 320,240);
        //左右反転
        colorImg.mirror(false, true);
#else
        //取り込んだフレームを画像としてキャプチャ
        colorImg.setFromPixels(vidPlayer.getPixels(), 320,240);
#endif
        //カラーのイメージをグレースケールに変換
        grayImage = colorImg;
        
        //まだ背景画像が記録されていなければ、現在のフレームを背景画像とする
        if (bLearnBakground == true){
            grayBg = grayImage;
            bLearnBakground = false;
        }
        
        //グレースケールのイメージと取り込んだ背景画像との差分を算出
        grayDiff.absDiff(grayBg, grayImage);
        //画像を2値化(白と黒だけに)する
        grayDiff.threshold(threshold);
        grayDiff.invert();
        //2値化した画像から輪郭を抽出する
        contourFinder.findContours(grayDiff, 25, grayDiff.width * grayDiff.height, 10, false, false);
        
    }
    
    //AudoVisualizer
    
    volume = ofSoundGetSpectrum(GetPrecision); //再生中のサウンドの音量を取得
    elapsedTime++;
}
//--------------------------------------------------------------
void testApp::update(){
	ofSoundUpdate();
    
    float * val = ofSoundGetSpectrum(nBandsToGet);		// request 128 values for fft
	for (int i = 0;i < nBandsToGet; i++){
		
		// let the smoothed calue sink to zero:
		fftSmoothed[i] *= 0.96f;
		
		// take the max, either the smoothed or the incoming:
		if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];
		
	}

    
    movie.update();
    
    
    
    
    
    if(movie.isFrameNew()){
        
        if(drawRuttEtra){
        
        vidPixels = movie.getPixelsRef();
        
        
        }
  
    }
    
	float p = movie.getPosition();
    
    
	//printf("%f\n",p);
	
	// Broadcast current position information of movie
	if ((!started || count % howOften == 0)) {
		ofxOscMessage m;
		m.setAddress( "/movie/position" );
		m.addFloatArg(p);
        m.addFloatArg(yStep);
        m.addFloatArg(xStep);
        m.addIntArg(drawRuttEtra);
		sender1.sendMessage(m);
		sender2.sendMessage(m);
		started = true;
	}
	count++;
}
Esempio n. 4
0
//--------------------------------------------------------------
void ofApp::update(){
	//Update sound engine
	ofSoundUpdate();

	//Get current spectrum with N bands
	float *val = ofSoundGetSpectrum( N );
	//We should not release memory of val,
	//because it is managed by sound engine

	//Update our smoothed spectrum,
	//by slowly decreasing its values and getting maximum with val
	//So we will have slowly falling peaks in spectrum
	for ( int i=0; i<N; i++ ) {
		spectrum[i] *= 0.97;	//Slow decreasing
		spectrum[i] = max( spectrum[i], val[i] );
	}

	//Update particles using spectrum values

	//Computing dt as a time between the last
	//and the current calling of update()
	float time = ofGetElapsedTimef();
	float dt = time - time0;
	dt = ofClamp( dt, 0.0, 0.1 );
	time0 = time; //Store the current time

	//Update Rad and Vel from spectrum
	//Note, the parameters in ofMap's were tuned for best result
	//just for current music track
	Rad = ofMap( spectrum[ bandRad ], 1, 3, 400, 800, true );
	Vel = ofMap( spectrum[ bandVel ], 0, 0.1, 0.05, 0.5 );

	//Update particles positions
	for (int j=0; j<n; j++) {
		tx[j] += Vel * dt;	//move offset
		ty[j] += Vel * dt;	//move offset
		//Calculate Perlin's noise in [-1, 1] and
		//multiply on Rad
		p[j].x = ofSignedNoise( tx[j] ) * Rad;
		p[j].y = ofSignedNoise( ty[j] ) * Rad;
	}

    if (bg_transparent > 0){
        bg_transparent = 255 - time * 3.5;
    }
    else{
        bg_transparent = 0;
    }

}
Esempio n. 5
0
void ofApp::update(){
    
    
    // particle collision detection
    for(std::size_t i = 0; i < numNodes; i++){
        particles[i].update();
        
        if(particles[i].position.x > cageSize || particles[i].position.x < 0) {
            particles[i].velocity.x *= -1.0;
        }
        
        if(particles[i].position.y > cageSize || particles[i].position.y < 0) {
            particles[i].velocity.y *= -1.0;
        }
        if(particles[i].position.z > cageSize || particles[i].position.z < 0) {
            particles[i].velocity.z *= -1.0;
        }
    }
    
    //attractor noise and collision detection
    
    t = ofGetFrameNum() * timeSpeed; // time value for noiseField
    
    ofPoint field = noiseField(attractorCenter);
    float speed = (1 + ofNoise(t, field.x, field.y)) / speedLim;
    
    attractorCenter.x += ofLerp(-speed, speed, field.x);
    attractorCenter.y += ofLerp(-speed, speed, field.y);
    
    if(attractorCenter.x > cageSize || attractorCenter.x < 0) {
        attractorCenter.x = ofGetWidth()/2;
    }
    
    if(attractorCenter.y > cageSize || attractorCenter.y < 0) {
        attractorCenter.y = ofGetHeight()/2;
    }
    
    // normalize volume input
    if(!soundP){
        scaledVol = ofMap(sqrt(smoothedVol), 0.0, 0.412, 0.0, 1.0, true);
    }
    
    // for SoundPlayer get levels
    if (soundP) {
        float * val = ofSoundGetSpectrum(1);
        scaledVol = val[0]*10;
    }
}
Esempio n. 6
0
void testApp::audioOut(float * output, int bufferSize, int nChannels) {
	
	float * fft = ofSoundGetSpectrum(512);
	
	for (int i = 0;i < 512; i++){
		
		// let the smoothed calue sink to zero:
		softMagnitude[i] *= 0.96f;
		

		// take the max, either the smoothed or the incoming:
		if (softMagnitude[i] < fft[i]) softMagnitude[i] = fft[i];
		
	}

}
Esempio n. 7
0
//--------------------------------------------------------------
void testApp::update(){
    
    for(int i = 0; i < points; i++){
        pos[i].x += fftSmoothed[1]*i;
        pos[i].y += fftSmoothed[1]*i;
    }
    
    float angle = fftSmoothed[1];
    degrees += radius * sin(angle);
    
	float * val = ofSoundGetSpectrum(points);
	for (int i = 0;i < points; i++){
		fftSmoothed[i] *= 0.96f;
		if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];
	}
}
//--------------------------------------------------------------
void ofApp::update(){	
	//Update sound engine
	ofSoundUpdate();	

	//Get current spectrum with N bands
	float *val = ofSoundGetSpectrum( N );
	//We should not release memory of val,
	//because it is managed by sound engine

	//Update our smoothed spectrum,
	//by slowly decreasing its values and getting maximum with val
	//So we will have slowly falling peaks in spectrum
	for ( int i=0; i<N; i++ ) {
		spectrum[i] *= 0.97;	//Slow decreasing
		spectrum[i] = max( spectrum[i], val[i] );
	}
}
Esempio n. 9
0
//--------------------------------------------------------------
void testApp::update()
{
	step += 0.0001;
	if (step > 1) {
        
		step -= 1;
	}
    
    ofSoundUpdate();
    float * val = ofSoundGetSpectrum(nBandsToGet);		// request 128 values for fft
	for (int i = 0;i < nBandsToGet; i++){
		
		// let the smoothed value sink to zero:
		fftSmoothed[i] *= 0.96f;
		
		// take the max, either the smoothed or the incoming:
		if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];
	}

}
Esempio n. 10
0
//--------------------------------------------------------------
void testApp::update(){
    
	ofSoundUpdate();
    
    string str = "";
    str += ofToString(sp.getPositionMS()) + ", " + ofToString(ofGetFrameNum()) + ", ";
    float* val = ofSoundGetSpectrum(nBandsToGet);
	for (int i = 0;i < nBandsToGet; i++){
		fftSmoothed[i] *= 0.96f;
		if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];
        str += ofToString(val[i]) + ((i == nBandsToGet - 1) ? "\n" : ", ");
	}
    
    
    file.open(ofToDataPath("soundData.text"), ofFile::Append);
    ofBuffer buff;
    buff = str;
    file.writeFromBuffer(buff);
    file.close();
}
Esempio n. 11
0
void Ball::update(){
    //Sound -------
    ofSoundUpdate();
    
    float * value = ofSoundGetSpectrum(bands);
    for (int i = 0; i < bands; i++){
        fftSmooth[i] *= 0.9f; //controls how fast dies down
        if (fftSmooth[i] < value[i]) {
            fftSmooth[i] = value[i];
        }
    }
    
    //Movement------
    
    sine = sin(ofGetElapsedTimef() * speed+5) * sinPar;
    cosine = cos(ofGetElapsedTimef() * speed+5) * cosPar;
    sine2 = sin(ofGetElapsedTimef() * speed) * sinPar2;
    cosine2 = cos(ofGetElapsedTimef() * speed) * cosPar2;
    
    
}
void audioVisualApp::update() {
    int nBandsToGet = fft->getBinSize();
    float * val = ofSoundGetSpectrum(nBandsToGet);		// request 128 values for fft
    for (int i = 0;i < nBandsToGet; i++){
        // let the smoothed value sink to zero:
        drawBins[i] *= 0.96f;
    }
    
    if (outputOn) {
        for (int i = 0;i < nBandsToGet; i++){
            // take the max, either the smoothed or the incoming:
            if (drawBins[i] < val[i]) drawBins[i] = val[i];
        }
    } else {
        soundMutex.lock();
        for (int i = 0;i < nBandsToGet; i++){
            // take the max, either the smoothed or the incoming:
            if (drawBins[i] < middleBins[i]) drawBins[i] = middleBins[i];
        }
        soundMutex.unlock();
    }
}
Esempio n. 13
0
//--------------------------------------------------------------
void ofApp::update(){
    
    
    float * fft = ofSoundGetSpectrum(nBandsToGet);
    
    for (int i = 0;i < nBandsToGet; i++){
        
        fftSmoothed[i] *= 0.9217f;
        
        if (fftSmoothed[i] < fft[i]) fftSmoothed[i] = fft[i];
        
    }
    
    if (playAnimation) {
        timer = ofGetElapsedTimef() - startTime;
        if (timer > duration){
            playAnimation = false;
        }
    }


}
Esempio n. 14
0
// The CD+G format takes advantage of the unused channels R thru W.  These unused
// six bits are used to store graphics information. Note that this is an extremely
// thin stream of information.  6 bits per byte * 16 bytes per packet * 4
// packets per sector * 75 sectors per second = 28800 bits per second, or 3.6 K per
// second.  By comparison, a typical 160 x 120 QuickTime movie uses 90K per second.
void KaraokePlayer::update() {
    // All visualizer code
    float* val = ofSoundGetSpectrum(nBandsToGet);
    avgSound = 0;
    
    // smooth fft and calc average volume
    for (int i = 0;i < nBandsToGet; i++){
        fftSmoothed[i] *= 0.96f;
        if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];
        avgSound += fftSmoothed[i];
    }
    
    // calculate average loudness of the music for "volume"
    avgSound /= nBandsToGet;
    // End visualizer code
    
    // Karaoke Code here
    // 24 bytes * 4 packets * 75 sectors = 7200 bytes per second
    long int bytesForPosition = mp3File.getPositionMS() * 7.2;
    while ( cdgFile.bytesRead() <= bytesForPosition )  //TODO: Fix this....it's hogging all CPU when music file ends.
        cdgFile.readNext();
}
Esempio n. 15
0
//--------------------------------------------------------------
void AudioPlayer::update(){
	// update the sound playing system:
	ofSoundUpdate();
	// (5) grab the fft, and put in into a "smoothed" array,
	//		by taking maximums, as peaks and then smoothing downward
	float * val = ofSoundGetSpectrum(nBandsToGet);		// request 128 values for fft
	for (int i = 0;i < nBandsToGet; i++){
		
		// let the smoothed calue sink to zero:
		fftSmoothed[i] *= 0.96f;
		
		// take the max, either the smoothed or the incoming:
		if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];
		
	}
  
	updateColor(BG_R_, BG_G_, BG_B_);
	float BG_R = BG_R_;
	float BG_G = BG_G_;
	float BG_B = BG_B_;
	amplifyColor(BG_R, BG_G, BG_B);
  
	ofBackground(BG_R,BG_G,BG_B);
}
Esempio n. 16
0
//--------------------------------------------------------------
void ofApp::update(){
    
    // update the sound playing system:
    ofSoundUpdate();
    
    // (5) grab the fft, and put in into a "smoothed" array,
    //		by taking maximums, as peaks and then smoothing downward
    float * val = ofSoundGetSpectrum(nBandsToGet);		// request 128 values for fft
    for (int i = 0;i < nBandsToGet; i++){
        
        // let the smoothed calue sink to zero
        fftSmoothed[i] *= 0.96f;
        
        // take the max, either the smoothed or the incoming:
        if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];
        
    }
    
   // ws.play();
    
    serialTest = serial.available();
    
    
    if (serialTest) {
        cout << "blahh" << endl;
    }
    
    //@add 2015/10/20 ########################################
    serialString = "";
    serialString = ofxGetSerialString(serial,'\n'); //read until end of line
    if (serialString.length() > 0) {
        readTime = ofGetElapsedTimef();
        ofLogVerbose() << "serialString = " << serialString << "\n";
    }

}
Esempio n. 17
0
//--------------------------------------------------------------
void Music::update(){
    
    
    //MARK- Video -------
    bigBangVid.update();
    ofSoundUpdate();
    bigBang.setVolume(volume);
    
    float * value = ofSoundGetSpectrum(bands);
    for (int i = 0; i < bands; i++){
        fftSmooth[i] *= 0.3f; //controls how fast dies down
        if (fftSmooth[i] < value[i]) {
            fftSmooth[i] = value[i];
        }
    }
    
    if (nunchukCButton == true) {
        
        //box behavior
        counter++;
        
        if (counter >= 1) {
            Box boxee;
            boxee.setup(wiiX, wiiY, -25, 2000);
            boxVector.push_back(boxee);
            counter = 0;
        }
        
        
        //on every loop update each element in box
        for (int i=0; i<boxVector.size(); i++) {
            boxVector[i].update();
        }
        
        //if more tahn 100 erase extra
        while (boxVector.size() > boxControl) {
            boxVector.erase(boxVector.begin());
            
        }
    }
    
    
    if (buttonB == true){
        width1 = roll *= ofGetWidth();
        height1 = yaw *= ofGetHeight();
        width2 = nunchukRoll *= ofGetWidth();
        height2 = nunchukYaw *= ofGetHeight();
    }
    
    if (buttonB == false) {
        width1 = ofGetWidth()/4;
        height1 = ofGetHeight()/4;
        width2 = ofGetWidth()/8;
        height2 = ofGetHeight()/8;
    }
    
   
    for (int i = 0; i<bands; i++) {
        if (nunchukZbutton == true) {
            ball.setup(ofGetWidth()/2, ofGetHeight()/2, -(fftSmooth[i]*300), 50);
        }
    }
    
    
    for (int i = 0; i < bands; i++){
    if (buttonA == true) {
        ball.setup(ofGetWidth()/2, ofGetHeight()/2, -(fftSmooth[i] * 200), 50);
}
        
    }
    
    
    
//    if (nunchukCButton == true) {
//        
//        //sphere behavior
//        counter1++;
//        
//        if (counter1 >= 1) {
//            Sphere sph;
//            sph.setup(ofGetWidth()/2, ofGetHeight()/2, -50, 500);
//            sphereVector.push_back(sph);
//            counter1 = 0;
//        }
//        
//        
//        //on every loop update each element in sphere
//        for (int j=0; j<sphereVector.size(); j++) {
//            sphereVector[j].update();
//        }
//        
//        //if more than Sphere Control Parameter
//        while (sphereVector.size() > sphereControl) {
//            sphereVector.erase(sphereVector.begin());
//            
//        }
//
//    }
    

    
    
    
       
    //MARK - Wii REMOTE SETUP-----------------------------------
    //MARK - Update Wii OSC - Get the Devices
    //Wii Remote Updating
    // check for waiting messages
    while( receiver.hasWaitingMessages() )
    {
        if(w == 0 || h == 0){
            w = ofGetWidth();
            h = ofGetHeight();
        }
        // get the next message
        ofxOscMessage m;
        float x,y;
        receiver.getNextMessage( &m );
        
        
        //Nunchuk Joystick
        
        if ( m.getAddress() == "/wii/2/nunchuk/joy/0" )
        {
            x = m.getArgAsFloat( 0 );
            wiiX = x * w;
            cout << "x: " << wiiX << " y: " << wiiY << "\n";
        }
        else if ( m.getAddress() == "/wii/2/nunchuk/joy/1" )
        {
            y = 1 - m.getArgAsFloat( 0 );
            wiiY = y * h;
            cout << "x: " << wiiX << " y: " << wiiY << "\n";
        }
        
        //Nunchuk Buttons
        
        else if (m.getAddress() == "/wii/2/nunchuk/button/C") {
            nunchukCButton = m.getArgAsBool(false);
        }
        
        else if (m.getAddress() == "/wii/2/nunchuk/button/Z") {
            nunchukZbutton = m.getArgAsBool(false);
        }
        
        //Nunchuk Orientation
        else if (m.getAddress() == "/wii/2/nunchuk/accel/pry/0") {
            nunchukRoll = m.getArgAsFloat(0);
        }
        
        else if (m.getAddress() == "/wii/2/nunchuk/accel/pry/1") {
            nunchukYaw = m.getArgAsFloat(0);
        }
        
        else if (m.getAddress() == "/wii/2/nunchuk/accel/pry/2") {
            nunchukPitch = m.getArgAsFloat(0);
        }
        
        else if (m.getAddress() == "/wii/2/nunchuk/accel/pry/3") {
            nunchukAccel = m.getArgAsFloat(0);
        }
        
        
        //Wii Remote Orientation & Acceleration
        else if (m.getAddress() == "/wii/2/accel/pry/1") {
            roll = m.getArgAsFloat(0);
            
        } else if (m.getAddress() == "/wii/2/accel/pry/2") {
            yaw = m.getArgAsFloat(0);
        }
        else if (m.getAddress() == "/wii/2/accel/pry/0") {
            pitch = m.getArgAsFloat(0);
            
        } else if (m.getAddress() == "/wii/2/accel/pry/3") {
            accel = m.getArgAsFloat(0);
        }
        
        //Wii Remote Buttons
        
        else if (m.getAddress() == "/wii/2/button/1") {
            button1 = m.getArgAsBool(false);
        }
        
        else if (m.getAddress() == "/wii/2/button/2") {
            button2 = m.getArgAsBool(false);
        }
        
        else if (m.getAddress() == "/wii/2/button/A") {
            buttonA = m.getArgAsBool(false);
        }
        
        else if (m.getAddress() == "/wii/2/button/B") {
            buttonB = m.getArgAsBool(false);
        }
        
        else if (m.getAddress() == "/wii/2/button/Plus") {
            buttonPlus = m.getArgAsBool(false);
        }
        
        else if (m.getAddress() == "/wii/2/button/Minus") {
            buttonMinus = m.getArgAsBool(false);
        }
        
        else if (m.getAddress() == "/wii/2/button/Home") {
            buttonHome = m.getArgAsBool(false);
        }
        
        //Wii Directional Pad
        else if (m.getAddress() == "/wii/2/button/Down") {
            buttonDown = m.getArgAsBool(false);
        }
        else if (m.getAddress() == "/wii/2/button/Up") {
            buttonUp = m.getArgAsBool(false);
        }
        else if (m.getAddress() == "/wii/2/button/Left") {
            buttonLeft = m.getArgAsBool(false);
        }
        else if (m.getAddress() == "/wii/2/button/Right") {
            buttonRight = m.getArgAsBool(false);
        }
        
        else
        {
            cout << "unrecognized message: " << m.getAddress() << "\n";
        }
//------------------------------------------------------------------

    }
    
    //Use Wii to Play Music & Video
    
    if (button1 == true) {
        bigBang.play();
        bigBangVid.play();
    } else if (button2 == true) {
        bigBang.stop();
        bigBangVid.stop();
    }
    
    //Use Plus and Minus to Control Volume
    if (buttonPlus == true) {
        volume = volume + .01f;
    } else if (buttonMinus == true) {
        volume = volume - .01f;
    }
    
    //Use Right Left to Control Speed Multiplier
    if (buttonRight == true) {
        bands++ ;
    } else if (buttonLeft == true) {
        bands--;
    }
    
    //Box Control
    if (nunchukCButton == true && buttonUp == true) {
        boxControl++;
    } else if (nunchukCButton == true && buttonDown == true) {
        boxControl--;
    }
//    
//    //Sphere Control
//    if (nunchukCButton == true && buttonUp == true) {
//        sphereControl++;
//    } else if (nunchukCButton == true && buttonDown == true) {
//        sphereControl--;
//    }
//    
    
    
//    if (nunchukCButton == true && buttonA == true) {
//        boxControl++;
//    } else if (nunchukZbutton == true && buttonA == true) {
//        boxControl--;
//    }
    
    
    //Sphere Control
//    sine = sin(ofGetElapsedTimef() * speed+5) * sinPar;
//    cosine = cos(ofGetElapsedTimef() * speed+5) * cosPar;

    
    
}
//--------------------------------------------------------------
void ofApp::update(){
    
//==========SOUND GRABBER==============//
    //lets scale the vol up to a 0-1 range
    scaledVol = ofMap(smoothedVol, 0.0, 0.17, 0.0, 1.0, true);
    
    //lets record the volume into an array
    volHistory.push_back( scaledVol );
    
    //if we are bigger the the size we want to record - lets drop the oldest value
    if( volHistory.size() >= 400 ){
        volHistory.erase(volHistory.begin(), volHistory.begin()+1);
    }

   
    

    
//==========visuals===========================//
    ofSoundUpdate();
    
    //get current spectrum with N bands
    float *val = ofSoundGetSpectrum(N);
    for (int i =0; i < N; i++) {
        spectrum[i] *=0.97;
        spectrum[i] = max(spectrum[i],val[i]);
    }
    
    //update particles using spectrum values
    //computing dt as a time between the last and the current calling of update()
    float time = ofGetElapsedTimef();
    float dt = time - time0;
    dt = ofClamp(dt, 0.0, 0.1);
    time0 = time; //store the current time
    
    //update rad and vel from spectrum
    //note the parameters in ofMap's were tuned for best result
//    //just for current music track
//    Rad2 = ofMap(spectrum[bandRad], 1, 3, 400, 800, true);
//    
//    Vel = ofMap(spectrum[bandVel], 0 , 0.1, 0.05, 0.5);
//    //update particles positions
//    for (int j=0; j < n; j++) {
//        x[j] += Vel * dt; // move offset
//        y[j] += Vel *dt; //move offset
//        //calculate Perlin's noise in [-1,1] and
//        //multiply on Rad
//        p[j].x = ofSignedNoise( x[j]) * Rad2;
//        p[j].y = ofSignedNoise( y[j]) * Rad2;
//        

    Rad2 = ofMap(spectrum[bandRad], 1, 3, 400, 800, true);
    
    Vel = ofMap(spectrum[bandVel], 0 , 0.1, 0.05, 0.5);
    //update particles positions
    for (int j=0; j < n; j++) {
        x[j] += dt * scaledVol; // move offset
        y[j] += dt * scaledVol; //move offset
        //calculate Perlin's noise in [-1,1] and
        //multiply on Rad
        p[j].x = ofSignedNoise( x[j]) * Rad2;
        p[j].y = ofSignedNoise( y[j]) * Rad2;

}
    
    //==============VIDEO=================//
    
    myMovie.update();



}
Esempio n. 19
0
//--------------------------------------------------------------
void testApp::update(){
    
    /* get the spectral data */
    float * val = ofSoundGetSpectrum(nBandsToGet);
	for (int i = 0; i < nBandsToGet; i++){
		
		// let the smoothed calue sink to zero:
		fftSmoothed[i] *= 0.96f;
		
		// take the max, either the smoothed or the incoming:
		if (fftSmoothed[i] < val[i])
            fftSmoothed[i] = val[i];
        
        if (fftSmoothed[i] > fftmax) {
            fftmax = fftSmoothed[i];
        }
	}
    
    /* update our bark map'd frequency bins */
    memset(bins, 0x00, sizeof(bins));
    for (int i = 0; i < SPECTRAL_BANDS; i++) {
        int idx = barkmap[i];
        bins[idx] += fftSmoothed[i] * 20;
    }
    
    /* put the eq vals into a path to turn them into a curve */
    int line_len = fbo_res;
    float ppseg = line_len /(float)(BARK_MAX+1);
    eq_path.clear();
    eq_path.curveTo(0, -bins[0]);
    for (int i = 0; i < BARK_MAX; i++) {
        //        bins[i] = max(5.0f, bins[i]); //set a lower bound on the bin val
        eq_path.curveTo(i * ppseg, -bins[i]);
    }
    
    //    eq_path.curveTo(BARK_MAX * ppseg, -bins[0]);
    //    eq_path.curveTo(BARK_MAX * ppseg, -bins[0]);
    
    //smooth this out a little at the end so the eq texture wraps, 25 = BARK_MAX
    eq_path.curveTo(25 * ppseg, -(bins[0] + bins[24] + bins[23] + bins[22])/4.0f);
    eq_path.curveTo(26 * ppseg, -bins[0]);
    eq_path.curveTo(26 * ppseg, -bins[0]);
    
    ofMesh eq_m = eq_path.getTessellation();
    
    //load up the eq curve into a texture
    eq_tex.loadData((float *)eq_m.getVerticesPointer(), fbo_res, 1, GL_RGB);
    
    //update where on the axis we will apply the latest eq data
    axis_loc--;
    
    if (axis_loc < 0)
        axis_loc = fbo_res;
    
    //use fbo to work out displacement coeffcients
    posbuf.dst->begin();
    ofClear(0);
    pos_shader.begin();
    pos_shader.setUniformTexture("u_prevDisp", posbuf.src->getTextureReference(), 0);
    pos_shader.setUniformTexture("u_newDisp", eq_tex, 1); //pass the new displacement data
    pos_shader.setUniform1f("u_axisloc", axis_loc);
    pos_shader.setUniform1f("u_decayRate", posdecayrate);
    
    ofSetColor(255, 255, 255, 255);
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
    glTexCoord2f(fbo_res, 0); glVertex3f(fbo_res, 0, 0);
    glTexCoord2f(fbo_res, fbo_res); glVertex3f(fbo_res, fbo_res, 0);
    glTexCoord2f(0, fbo_res); glVertex3f(0, fbo_res, 0);
    glEnd();
    
    pos_shader.end();
    posbuf.dst->end();
    posbuf.swap();
    
}
Esempio n. 20
0
//--------------------------------------------------------------
void ofApp::update(){
    
    //ofSetWindowTitle(ofToString(ofGetFrameRate()));
    
    // OSC
    // hide old messages
	for(int i = 0; i < NUM_MSG_STRINGS; i++){
		if(timers[i] < ofGetElapsedTimef()){
			msg_strings[i] = "";
		}
	}
    
	// check for waiting messages
	while(receiver.hasWaitingMessages()){
		// get the next message
		ofxOscMessage m;
		receiver.getNextMessage(&m);
        
		// check for mouse moved message
		if(m.getAddress() == "/camPosition"){
			// both the arguments are int32's
			camZ = m.getArgAsFloat(0);
			camX = m.getArgAsFloat(1);
		}
        
	}
    
    
    cam.setPosition(camX, 0, camZ);
    cam.lookAt(ofVec3f(0, 0, 0));
    
    
    // KINECT
    kinect.update();
    
    // SOUND
    ofSoundUpdate();   //Get current spectrum with N bands
    float *val = ofSoundGetSpectrum(N);
    planetCounter = 0;
    int step = 5;
    for(int y = 157; y < kinect.height - 158; y += step) {
        for(int x = 265; x < kinect.width - 265; x += step) {
            int iSpectrum = planetCounter / 16;
            spectrum[iSpectrum] *= 0.99;    //Slow decreasing
            spectrum[iSpectrum] = max(spectrum[iSpectrum], val[iSpectrum]);
            if (kinect.getDistanceAt(x, y) > 500 && kinect.getDistanceAt(x, y) <= 800) {
                myPlanet[planetCounter]->update(planetCounter, kinect.getDistanceAt(x, y), spectrum[iSpectrum]);
            } else {
                myPlanet[planetCounter]->update(planetCounter, 800, spectrum[iSpectrum]);
            }
            planetCounter++;
        }
    }
    
    for (int i = 0; i < nStars; i++) {
        spectrum[i] *= 0.99;
        spectrum[i] = max(spectrum[i], val[i]);
        myStar[i]->update(i, spectrum[i]);
    }
    
}
Esempio n. 21
0
//-------------------------------------------------------------------------
void ShapeSpectrum::update(){
  this->mFFTList = ofSoundGetSpectrum(mBands);
}
Esempio n. 22
0
//--------------------------------------------------------------
void testApp::update(){


    //    ofBackgroundGradient(ofColor::purple, ofColor::black);

	// update the sound playing system:
	ofSoundUpdate();

	// (1) we increase px and py by adding vx and vy
	px += vx;
	py += vy;

	// (2) check for collision, and trigger sounds:
	// horizontal collisions:
	if (px < 0){
		px = 0;
		vx *= -1;
		//dog.play();
	} else if (px > ofGetWidth()){
		px = ofGetWidth();
		vx *= -1;
		//ow.play();
	}
	// vertical collisions:
	if (py < 0 ){
		py = 0;
		vy *= -1;
		//rooster.play();
	} else if (py > ofGetHeight()){
		py = ofGetHeight();
		vy *= -1;
		//beat4.play();
	}
	// (3) slow down velocity:
	vx 	*= 0.996f;
	vy 	*= 0.996f;

	// (4) we use velocity for volume of the samples:
	float vel = sqrt(vx*vx + vy*vy);
	ow.setVolume(MIN(vel/5.0f, 1));
	beat.setVolume(MIN(vel/5.0f, 1));
	dog.setVolume(MIN(vel/5.0f, 1));
	rooster.setVolume(MIN(vel/5.0f, 1));
	/*beat4.setVolume(MIN(vel/5.0f, 1));
	something.setVolume(MIN(vel/5.0f, 1));
	beat5.setVolume(MIN(vel/5.0f, 1));
	daftpunk.setVolume(MIN(vel/5.0f, 1));*/

	// (5) grab the fft, and put in into a "smoothed" array,
	//		by taking maximums, as peaks and then smoothing downward
	float * val = ofSoundGetSpectrum(nBandsToGet);		// request 128 values for fft
	for (int i = 0;i < nBandsToGet; i++){

		// let the smoothed calue sink to zero:
		fftSmoothed[i] *= 0.96f;

		// take the max, either the smoothed or the incoming:
		if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];

	}


}
Esempio n. 23
0
//--------------------------------------------------------------
void ofApp::update(){
    
    pointLight.setPosition((ofGetWidth()*.8)+ cos(ofGetElapsedTimef()*.5)*(ofGetWidth()*.8), ofGetHeight()/2, 500);
    pointLight2.setPosition((ofGetWidth()*.8)+ cos(ofGetElapsedTimef()*.5)*(ofGetWidth()*.8), -ofGetHeight()/2, -500);
    heart_vertices[100].set(1400,1400,1400);
    int cnt =0;
    for(int i=0; i < 3;i++){
        for(int j=0; j < heart[i].getNumVertices(); j+=10){
            for(int k=0; k < nearest[cnt].size();k++){
                heart[i].setVertex(nearest[cnt][k],heart_[i].getVertex(nearest[cnt][k])*(ofNoise(ofGetFrameNum()/100.0f,j)*fftSmoothed[0]*0.4+1));
            }
            cnt++;
        }
    }
    
    float * val = ofSoundGetSpectrum(nBandsToGet);		// request 128 values for fft
    for (int i = 0;i < nBandsToGet; i++){
        
        // let the smoothed calue sink to zero:
        fftSmoothed[i] *= 0.96f;
        
        // take the max, either the smoothed or the incoming:
        if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];
        
    }
    if(!beat.isPlaying())beat.play();
    
    
    myFbo.begin();
    ofClear(0,0,0,255);
    
    


    cam.begin();

    ofPushMatrix();
    ofTranslate(0, 0,-400);
    ofEnableAlphaBlending();
    for(int key=0; key<IMG_SIZE; key++){
        float n = ofNoise(key,ofGetFrameNum()/80.0f);
        if(n>0.9) {
            ofSetColor(255,255,255,255);
            images[key].draw(-ofGetWidth()/2, -ofGetHeight()/2, ofGetWidth(), ofGetHeight());
            cout<<key<<endl;
        }
    }
    ofDisableAlphaBlending();
    //mizukusa.draw(ofPoint(-ofGetWidth()/2, -ofGetHeight()/2,1500) ,ofGetWidth(), ofGetHeight());
    ofPopMatrix();
    ofEnableDepthTest();
    
    ofEnableLighting();
    pointLight.enable();
    pointLight2.enable();
    
    ofPushMatrix();
    {
        
        
        ofPushMatrix();
        {
            
            ofScale(0.3,0.3);
            ofTranslate(ofGetWidth()/2*0.8,ofGetHeight()/2*0.8);
            ofRotateY(ofGetFrameNum()/3.0f);
            
            for(int i=0; i < 3; i++){
                //heart[i].draw();
            }
        }ofPopMatrix();
        material.end();
        ofScale(2.6,2.6);
        ofRotateY(ofGetFrameNum()/3.0f);
        ofRotateX(ofGetFrameNum()/1.8f);
        material.begin();
        for(int i=0; i < 3; i++){
            heart[i].draw();
        }
        
    }
    ofPopMatrix();
    ofDisableLighting();
    cam.end();

    myFbo.end();
    
    for(int i=0; i < 6; i++){
        noises[i] = ofNoise(i+1,ofGetFrameNum()/100.0f);
    }
    
    for(int key=0; key<6; key++){
        if(noises[key]>0.9 && key == 0) myGlitch.setFx(OFXPOSTGLITCH_GLOW	, true); else if(key==0) myGlitch.setFx(OFXPOSTGLITCH_GLOW	, false);
        if(noises[key]>0.8 && key == 1) myGlitch.setFx(OFXPOSTGLITCH_CUTSLIDER	, true); else  if(key==1)  myGlitch.setFx(OFXPOSTGLITCH_CUTSLIDER	, false);
        if(noises[key]>0.8 && key == 2) myGlitch.setFx(OFXPOSTGLITCH_CONVERGENCE	, true); else  if(key==2)  myGlitch.setFx(OFXPOSTGLITCH_CONVERGENCE	, false);
        if(noises[key]>0.8 && key == 3) myGlitch.setFx(OFXPOSTGLITCH_SLITSCAN	, true); else  if(key==3)  myGlitch.setFx(OFXPOSTGLITCH_SLITSCAN	, false);
        if(noises[key]>0.8 && key == 4) myGlitch.setFx(OFXPOSTGLITCH_NOISE	, true); else  if(key==4)  myGlitch.setFx(OFXPOSTGLITCH_NOISE	, false);
        if(noises[key]>0.8 && key == 5) myGlitch.setFx(OFXPOSTGLITCH_TWIST	, true); else  if(key==5)  myGlitch.setFx(OFXPOSTGLITCH_TWIST	, false);
        
    }
    
}
//--------------------------------------------------------------
void ofApp::update(){
	/********************
	********************/
	// sound.setVolume(volume);
	ofSoundUpdate();	

	//Get current spectrum with N bands
	float *val = ofSoundGetSpectrum( N );
	//We should not release memory of val,
	//because it is managed by sound engine

	/********************
	********************/
	float val_ave[N];
	
	/* */
	static float LastINT_sec = 0;
	float now = ofGetElapsedTimef();
	float dt = ofClamp(now - LastINT_sec, 0, 0.1);
	LastINT_sec = now;
	
	/* */
	// const double SmoothFilterThreshTime = 0.05; // 小さくする程Responceが良くなる.
	const double SmoothFilterThreshTime = 0.03;
	double tangent = 1 / SmoothFilterThreshTime;
	
	double SmoothFilterAlpha;
	if(dt < SmoothFilterThreshTime)	SmoothFilterAlpha = tangent * dt;
	else							SmoothFilterAlpha = 1;
	
	/* */
	// const double NonLinearFilter_ThreshLev = 0.02;
	const double NonLinearFilter_ThreshLev = 0.08;
	const double NonLinearFilter_k = 1/NonLinearFilter_ThreshLev;
	
	/* */
	const float Down_per_ms = 0.05 / 16.6;
	float DownRatio = Down_per_ms * dt * 1000;
	
	/* */
	for ( int i=0; i<N; i++ ) {
		/* */
		val_ave[i] = SmoothFilterAlpha * val[i] + (1 - SmoothFilterAlpha) * spectrum[i];
		
		/* */
		double diff = val_ave[i] - spectrum[i];
		if( (0 <= diff) && (diff < NonLinearFilter_ThreshLev) ){
			diff = NonLinearFilter_k * pow(diff, 2);
		}else if( (-NonLinearFilter_ThreshLev < diff) && (diff < 0) ){
			diff = -NonLinearFilter_k * pow(diff, 2);
		}else{
			diff = diff;
		}
		float val_NonLinearFilter_out = spectrum[i] + diff;
		
		/* */
		spectrum[i] *= (1 - DownRatio);
		spectrum[i] = max( spectrum[i], val_NonLinearFilter_out );
	}
	

	/********************
	********************/
	if(BootMode == BOOT_MODE__COLOR_CHANGE){
		int ColorThemeId = ColorThemeTable.IsColorThemeChange( sound.getPositionMS() );
		if(ColorThemeId != -1){
			switch(ColorThemeId){
				case 0:
					printf("\nAqua\n");
					break;
				case 1:
					printf("\nMagma\n");
					break;
				case 2:
					printf("\nDigital\n");
					break;
				case 3:
					printf("\nsexy\n");
					break;
				case 4:
					printf("\nTrip\n");
					break;
				case 5:
					printf("\nReggae\n");
					break;
				case 6:
					printf("\nSamba\n");
					break;
				case 7:
					printf("\nSweets\n");
					break;
			}
			
			/********************
			********************/
			SpectrumIndicator.load_ColorTheme_setting(ColorThemeId);
			ParticleSet.load_ColorTheme_setting(ColorThemeId);
			
			/********************
			********************/
			if(TimingAdjust_SpectrumIndicator.get__b_Adjust()){
				SpectrumIndicator.change_IndicatorType(TimingAdjust_SpectrumIndicator.get__NextValue());
			}
			if(TimingAdjust_SpectrumIndicator_point.get__b_Adjust()){
				TimingAdjust_SpectrumIndicator_point.get__NextValue(); // clear.
				
				SpectrumIndicator.toggle_PointIndicator();
			}
			if(TimingAdjust_Particle.get__b_Adjust()){
				TimingAdjust_Particle.get__NextValue(); // clear.
				
				b_Particle = !b_Particle;
				printf("\nparticle = %d\n", b_Particle);
			}

		}
	}
	
	/********************
	********************/
	SpectrumIndicator.update();
	
	/* 無効時もupdateし、減速させておく */
	// if(b_Particle) ParticleSet.update(mouseX, mouseY);
	ParticleSet.update(mouseX, mouseY);
	
	/********************
	********************/
	video.update();
}