Giter VIP home page Giter VIP logo

ofxfft's Introduction

ofxFft

ofxFft is a Fast-Fourier Transform addon for openFrameworks

ofxFft wraps two libraries with the same interface: FFTW and KISS FFT. KISS FFT is included with OF, MIT licensed, and enabled by default. FFTW is GPL and must be manually enabled using the OFX_FFT_USE_FFTW compiler define.

Installation & Usage

To install ofxFft, move the ofxFft folder to your of/addons/ folder.

Search paths required when using ofxFFt:

  • of/addons/ofxFft/src
  • of/addons/ofxFft/libs/kiss

Basic usage is demonstrated by example-eq and example-basic.

With OF version 0.9.0, the OF Project Generator will add the compiler search paths for the project automatically if configured to include ofxFft.

Project files for the examples are not included so you will need to generate the project files for your operating system and development environment using the OF ProjectGenerator which is included with the OpenFrameworks distribution.

Point the ProjectGenerator to addons/ofxFft, change the project name to the exact name of the example you want to generate (ie example-basic), and make sure to choose ofxFft from the addons. Hitting "Generate" will populate that example with the project files you will need to build it.

Using FFTW

To use ofxFft with FFTW instead of KISS FFT, make sure you download the precompiled libraries.

Next, you'll need to add OFX_FFT_USE_FFTW to your compiler flags for each project using ofxFFT:

  • Xcode:

    • Select the Project -> Build Settings -> Other C++ Flags
    • add the following:
    -DOFX_FFT_USE_FFTW
    
  • Linux (Makefiles & Codeblocks):

    • edit config.make in your project folder and add the following to the USER_CFLAGS line:
    -DOFX_FFT_USE_FFTW
    
  • Codeblocks (Win):

    • right-click on your project in the project tree
    • select "Build options..."
    • make sure the project name is selected in the tree (not release or debug)
    • select the "Compiler settings" tab and add the following to the "#defines" tab:
    OFX_FFT_USE_FFTW
    
  • Visual Studio:

    • right click on the project in the project tree and select Properties
    • set the Configuration to All Configurations
    • add the defines and search paths:
    • add the following to Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions:
    OFX_FFT_USE_FFTW
    
  1. If you're using FFTW on Windows, you'll also need to add:
  `of/addons/ofxFft/libs/fftw/include`
  

And link with:

  `of/addons/ofxFft/libs/fftw/lib/win32/libfftw3f-3.dll`
  

Using FFTW in the examples

If you're using FFTW with the example projects, in ofApp.cpp, comment the line:

fft = ofxFft::create(bufferSize, OF_FFT_WINDOW_HAMMING);

and uncomment out the line:

//fft = ofxFft::create(bufferSize, OF_FFT_WINDOW_HAMMING, OF_FFT_FFTW);

FFTW compilation notes

FFTW was compiled with:

./configure --disable-shared --enable-static --enable-float --enable-threads
make
sudo make install

which puts the static libraries in .libs

Note that the library is compiled in 32-bit mode on both Windows and OS X.

ofxfft's People

Contributors

cibomahto avatar danomatika avatar fx-lange avatar kylemcdonald avatar laserpilot avatar xiaowp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ofxfft's Issues

run audioReceived() outside testapp

Hi there!

I'm trying to create a class just for sound analysis but i can't run the audioReceived() function outside testApp.
I'm tying to adapt visualizer example to do it so far i have the following code.
Maybe you can help me?

thanks in advance
João

testApp.h

#pragma once

#include "ofMain.h"
#include "audioGuiController.h"
#include "audioAnalysis.h"


class testApp : public ofBaseApp{
    public:
        void setup();
        void update();
        void draw();

    audioAnalysis audio;
};

testApp.cpp

#include "testApp.h"


void testApp::setup(){

    audio.setup();



}

void testApp::update(){

    audio.update();



}

void testApp::draw(){

    audio.draw();
}

audioAnalysis.h


#pragma once
#include "ofMain.h"
#include "ofxFft.h"

#define MIC 0
#define NOISE 1
#define SINE 2

class audioAnalysis :  public ofBaseSoundInput{

public:

    //audioAnalysis();

    void setup();
    void update();
    void draw();

    //

    void plot(float* array, int length, float scale, float offset);
    void audioReceived(float* input, int bufferSize, int nChannels);
    int plotHeight, bufferSize;

    ofxFft* fft;

    float* audioInput;
    float* fftOutput;
    float* eqFunction;
    float* eqOutput;
    float* ifftOutput;
    float appWidth;
    float appHeight;

    int mode;
    //


    //void audioIn(float * input, int bufferSize, int nChannels);

    vector <float> left;
    vector <float> right;
    vector <float> volHistory;

    int bufferCounter;
    int drawCounter;

    float smoothedVol;
    float scaledVol;

    ofSoundStream soundStream;

    float * fftSmoothed;


};

audioAnalysis.cpp

#include "audioAnalysis.h"

void audioAnalysis::setup(){


    plotHeight = 128;
    bufferSize = 512;

    fft = ofxFft::create(bufferSize, OF_FFT_WINDOW_BARTLETT);
    // To use with FFTW, try:
    // fft = ofxFft::create(bufferSize, OF_FFT_WINDOW_BARTLETT, OF_FFT_FFTW);

    audioInput = new float[bufferSize];
    fftOutput = new float[fft->getBinSize()];
    eqFunction = new float[fft->getBinSize()];
    eqOutput = new float[fft->getBinSize()];
    ifftOutput = new float[bufferSize];

    // 0 output channels,
    // 1 input channel
    // 44100 samples per second
    // [bins] samples per buffer
    // 4 num buffers (latency)

    // this describes a linear low pass filter
    for(int i = 0; i < fft->getBinSize(); i++)
        eqFunction[i] = (float) (fft->getBinSize() - i) / (float) fft->getBinSize();

    mode = MIC;
    appWidth = ofGetWidth();
    appHeight = ofGetHeight();

    ofSoundStreamSetup(0, 1, 44100, bufferSize, 4); //  ofSoundStreamSetup(0, 1, this, 44100, bufferSize, 4);
    soundStream.setInput(this); //

    ofBackground(0, 0, 0);

}


void audioAnalysis::draw(){
    ofSetHexColor(0xffffff);
    ofPushMatrix();

    glTranslatef(16, 16, 0);
    ofDrawBitmapString("Audio Input", 0, 0);
    plot(audioInput, bufferSize, plotHeight / 2, 0);

    glTranslatef(0, plotHeight + 16, 0);
    ofDrawBitmapString("FFT Output", 0, 0);
    plot(fftOutput, fft->getBinSize(), -plotHeight, plotHeight / 2);

    ofPushMatrix();
    glTranslatef(fft->getBinSize(), 0, 0);
    ofDrawBitmapString("EQd FFT Output", 0, 0);
    plot(eqOutput, fft->getBinSize(), -plotHeight, plotHeight / 2);
    ofPopMatrix();


    glTranslatef(0, plotHeight + 16, 0);
    ofDrawBitmapString("IFFT Output", 0, 0);
    plot(ifftOutput, fft->getSignalSize(), plotHeight / 2, 0);

    ofPopMatrix();
    string msg = ofToString((int) ofGetFrameRate()) + " fps";
    ofDrawBitmapString(msg, appWidth - 80, appHeight - 20);
}


void audioAnalysis::plot(float* array, int length, float scale, float offset) {

    ofNoFill();
    ofRect(0, 0, length, plotHeight);
    glPushMatrix();
    glTranslatef(0, plotHeight / 2 + offset, 0);
    ofBeginShape();
    for (int i = 0; i < length; i++)
        ofVertex(i, array[i] * scale);
    ofEndShape();
    glPopMatrix();
}

void audioAnalysis::audioReceived(float* input, int bufferSize, int nChannels) {
          //cout<<"qwerty"<<endl;
    if (mode == MIC) {
        // store input in audioInput buffer
        memcpy(audioInput, input, sizeof(float) * bufferSize);
    } else if (mode == NOISE) {
        for (int i = 0; i < bufferSize; i++)
            audioInput[i] = ofRandom(-1, 1);
    } else if (mode == SINE) {
        for (int i = 0; i < bufferSize; i++)
            audioInput[i] = sinf(PI * i *200 / appWidth);
    }

    fft->setSignal(audioInput);
    memcpy(fftOutput, fft->getAmplitude(), sizeof(float) * fft->getBinSize());

    for(int i = 0; i < fft->getBinSize(); i++)
        eqOutput[i] = fftOutput[i] * eqFunction[i];

    fft->setPolar(eqOutput, fft->getPhase());

    fft->clampSignal();
    memcpy(ifftOutput, fft->getSignal(), sizeof(float) * fft->getSignalSize());
}

expected constant expression error

when i use it in vs2012,there is a error like this
error C2057: expected constant expression
so i change
float avgCol[numFFTbins]; to
float *avgCol= new float[numFFTbins];

it's ok.

Is it bug?

ffts integration?

This library https://github.com/anthonix/ffts seems to outperform all other FFT implementations out there, with a permissive BSD license. It could be a better replacement for FFTW, and is works very well with iOS/Android too.

Check out FFTS. It has a permissive BSD license, and it is faster than FFTW, IPP, KissFFT, Apple vDSP etc on ARM and x86.

precompiled binaries for OS X aren't 64bit

Last pull request lets ofxFFT work properly with OF 0.9.0 but the precompiled libraries for OSX are dated and seem to only work if you build in 32bit - throws these errors on 64bit - might need to just make updates to those libraries and hope it doesn't break much? http://www.fftw.org

ld: warning: ignoring file ../../../addons/ofxFft/libs/fftw/lib/osx/fftw3f.a, file was built for archive which is not the architecture being linked (x86_64): ../../../addons/ofxFft/libs/fftw/lib/osx/fftw3f.a Undefined symbols for architecture x86_64: "_fftwf_destroy_plan", referenced from: ofxFftw::~ofxFftw() in ofxFftw.o "_fftwf_plan_r2r_1d", referenced from: ofxFftw::setup(int, fftWindowType) in ofxFftw.o "_fftwf_cleanup", referenced from: ofxFftw::~ofxFftw() in ofxFftw.o "_fftwf_malloc", referenced from: ofxFftw::setup(int, fftWindowType) in ofxFftw.o "_fftwf_free", referenced from: ofxFftw::~ofxFftw() in ofxFftw.o "_fftwf_execute", referenced from: ofxFftw::executeFft() in ofxFftw.o ofxFftw::executeIfft() in ofxFftw.o ld: symbol(s) not found for architecture x86_64

Calling ofxEasyFft.setup() stops all other audio running in other applications

When I make a new ofxEasyFft instance and call .setup() then all other audio running on my pc stop working.

Code:
shProcessFFT = new ProcessFFT();
shProcessFFT->setup();

When taking a closer look in the source code I find that it happens specifically on this line:
audio ->openStream( (nOutputChannels>0)?&outputParameters:NULL, (nInputChannels>0)?&inputParameters:NULL, RTAUDIO_FLOAT32,
sampleRate, &bufferFrames, &rtAudioCallback, this, &options);

Line 128, ofRtAudioSoundStream.cpp

I need audio to work in other applications while running my code. Does anyone know why this is happening and/or how to stop it from happening?

Consider using KISS as default library in examples

The examples are all configured to use FFTW by default, which means that they won't compile of the of the box. Configuring them to work as KISS FFT would make the experience smoother.

This would be pretty non-invasive and just involves changing which implementation is commented out by default. If it sounds good, I'm happy to make the changes.

I can't setup fftw according the readme.md in vs2012

So I setup fftw folow the fftw website .
lib /machine:x64 /def:libfftw3-3.def
lib /machine:x64 /def:libfftw3f-3.def
lib /machine:x64 /def:libfftw3l-3.def

then set the include library,lib library ,and add
linker input libfftw3-3.liblibfftw3f-3.liblibfftw3l-3.lib
copy the libfftw3f-3.dll libfftw3-3.dll libfftw3l-3.dll to system path

it's trouble.

Is there a easy way?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.