Exemple #1
0
void svvimApp::getAlpha () {
  
  // Sound buffer for FFT
  mPcmBuffer = mInput.getPcmBuffer();
  
  //
  if (mPcmBuffer) {
    mFftDataRef = audio::calculateFft(mPcmBuffer->getChannelData( audio::CHANNEL_FRONT_LEFT ), 512);
  }
  
	uint16_t bandCount = 64;
	
	if( ! mPcmBuffer )
    return;
	
	//use the most recent Pcm data to calculate t`he Fft
	std::shared_ptr <float> fftRef = audio::calculateFft( mPcmBuffer->getChannelData( audio::CHANNEL_FRONT_LEFT ), bandCount );
  
	if( ! fftRef ) {
		return;
	}
	
	float * fftBuffer = fftRef.get();
	 
  //mAlpha = max(2, mAlpha);
	//draw the bands
	for( int i = 0; i < ( bandCount/32 ); i++ ) {
		 mAlpha += fftBuffer[i] / bandCount / 4;
	}
  
  mAlpha /= 6.5;
}
void TouchAudioTestApp::update()
{
	mPcmBuffer = mInput.getPcmBuffer();
	if( ! mPcmBuffer ) {
		return;
	}
}
void shader02vertexApp::update() {
    
    //--audio input
    mPcmBuffer= mInput.getPcmBuffer();
    if(mPcmBuffer) {
        mBufferSize= mPcmBuffer->getSampleCount();
        //std::cout<<"mBufferSize: "<<mBufferSize<<std::endl;
        mBufferLeft= mPcmBuffer->getChannelData(audio::CHANNEL_FRONT_LEFT);
        mFftLeft= audio::calculateFft(mPcmBuffer->getChannelData(audio::CHANNEL_FRONT_LEFT), mBufferSize/2);
        mAmplitude= 0.0f;
        for(uint32_t i= 0; i<mBufferSize; i++) {
            mAmplitude += abs(mBufferLeft->mData[i]);
        }
        mAmplitude /= float(mBufferSize);   //average amplitude
        
        Surface32f mSurfaceSnd(mBufferSize, 1, true);
        Surface32f::Iter sndIter(mSurfaceSnd.getIter());
        uint32_t i= 0;
        while(sndIter.line()) {
            while(sndIter.pixel()) {
                sndIter.r()= mBufferLeft->mData[i];
                i++;
            }
        }
        mTextureSnd= gl::Texture(mSurfaceSnd);
        
        Surface32f mSurfaceFft(mBufferSize/2, 1, true);
        Surface32f::Iter fftIter(mSurfaceFft.getIter());
        uint32_t j= 0;
        float *fftBuffer= mFftLeft.get();
        while(fftIter.line()) {
            while(fftIter.pixel()) {
                fftIter.r()= fftBuffer[j];
                j++;
            }
        }
        mTextureFft= gl::Texture(mSurfaceFft);
    }
    
    //--shaders
    if((fs::last_write_time(mPathFrag)>mTimeFrag) || (fs::last_write_time(mPathVert)>mTimeVert)) {
        loadShader();   //hot-loading shader
    }
}
Exemple #4
0
void redEyeApp::update() {
    
    //--osc input
    while(mListener.hasWaitingMessages()) {
		osc::Message msg;
		mListener.getNextMessage(&msg);
        mOsc= msg.getAddress();
        for(uint32_t i= 0; i<msg.getNumArgs(); i++) {
            mOsc= mOsc+" "+msg.getArgAsString(i, true);
        }
        if(msg.getAddress()=="/numSamples") {
            mNumSamples= math<int32_t>::clamp(msg.getArgAsInt32(0, true), 1, 2048);
        } else if(msg.getAddress()=="/downSample") {
            mDownSample= math<int32_t>::clamp(msg.getArgAsInt32(0, true), 0, 2047);
        } else if(msg.getAddress()=="/amplitude") {
            mAmplitude= msg.getArgAsFloat(0, true);
        } else if(msg.getAddress()=="/width") {
            mWidth= math<float>::clamp(msg.getArgAsFloat(0, true), 0, 1000);
        } else if(msg.getAddress()=="/colorBack") {
            ColorA col= ColorA(0, 0, 0, 1);
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 4); i++) {
                col[i]= msg.getArgAsFloat(i, true);
            }
            mColorBack.set(col.r, col.g, col.b, col.a);
        
        } else if(msg.getAddress()=="/scale0") {
            Vec3f sca= Vec3f(1.0f, 1.0f, 1.0f);
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 3); i++) {
                msg.getArgAsFloat(i, true);
            }
            mScale0.set(sca.x, sca.y, sca.z);
        } else if(msg.getAddress()=="/scale1") {
            Vec3f sca= Vec3f(1.0f, 1.0f, 1.0f);
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 3); i++) {
                msg.getArgAsFloat(i, true);
            }
            mScale1.set(sca.x, sca.y, sca.z);
        } else if(msg.getAddress()=="/rotate0") {
            Vec3f rot= Vec3f::zero();
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 3); i++) {
                rot[i]= msg.getArgAsFloat(i, true);
            }
            mRotate0.set(rot.x, rot.y, rot.z);
        } else if(msg.getAddress()=="/rotate1") {
            Vec3f rot= Vec3f::zero();
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 3); i++) {
                rot[i]= msg.getArgAsFloat(i, true);
            }
            mRotate1.set(rot.x, rot.y, rot.z);
        } else if(msg.getAddress()=="/translate0") {
            Vec3f tra= Vec3f::zero();
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 3); i++) {
                tra[i]= msg.getArgAsFloat(i, true);
            }
            mTranslate0.set(tra.x, tra.y, tra.z);
        } else if(msg.getAddress()=="/translate1") {
            Vec3f tra= Vec3f::zero();
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 3); i++) {
                tra[i]= msg.getArgAsFloat(i, true);
            }
            mTranslate1.set(tra.x, tra.y, tra.z);
        } else if(msg.getAddress()=="/color0") {
            ColorA col= ColorA(0, 0, 0, 1);
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 4); i++) {
                col[i]= msg.getArgAsFloat(i, true);
            }
            mColor0.set(col.r, col.g, col.b, col.a);
        } else if(msg.getAddress()=="/color1") {
            ColorA col= ColorA(0, 0, 0, 1);
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 4); i++) {
                col[i]= msg.getArgAsFloat(i, true);
            }
            mColor1.set(col.r, col.g, col.b, col.a);
        }
	}
    
    //--audio input
    mPcmBuffer= mInput.getPcmBuffer();
    if(mPcmBuffer) {
        mBufferSize= mPcmBuffer->getSampleCount();
        //std::cout<<"mBufferSize: "<<mBufferSize<<std::endl;
        mBufferLeft= mPcmBuffer->getChannelData(audio::CHANNEL_FRONT_LEFT);
        //mBufferRight= mPcmBuffer->getChannelData(audio::CHANNEL_FRONT_RIGHT);
        mFftLeft= audio::calculateFft(mPcmBuffer->getChannelData(audio::CHANNEL_FRONT_LEFT), mBufferSize/2);
        //mFftRight= audio::calculateFft(mPcmBuffer->getChannelData(audio::CHANNEL_FRONT_LEFT), mBufferSize/2);
        mAmplitude= 0.0f;
        for(uint32_t i= 0; i<mBufferSize; i++) {
            mAmplitude += abs(mBufferLeft->mData[i]);
        }
        mAmplitude /= float(mBufferSize);   //average amplitude
        
        Surface32f mSurfaceSnd(mBufferSize, 1, true);
        Surface32f::Iter sndIter(mSurfaceSnd.getIter());
        uint32_t i= 0;
        while(sndIter.line()) {
            while(sndIter.pixel()) {
                sndIter.r()= mBufferLeft->mData[i];
                i++;
            }
        }
        mTextureSnd= gl::Texture(mSurfaceSnd);
        
        Surface32f mSurfaceFft(mBufferSize/2, 1, true);
        Surface32f::Iter fftIter(mSurfaceFft.getIter());
        uint32_t j= 0;
        float *fftBuffer= mFftLeft.get();
        while(fftIter.line()) {
            while(fftIter.pixel()) {
                fftIter.r()= fftBuffer[j];
                j++;
            }
        }
        mTextureFft= gl::Texture(mSurfaceFft);
    }
    
    //--shaders
    if(mShader!=NULL) {
        if((fs::last_write_time(mPathFrag)>mTimeFrag) || (fs::last_write_time(mPathVert)>mTimeVert)) {
            loadShader();   //hot-loading shader
        }
    }
    
    mFps= getAverageFps();
}