How to do logarithmic resampling on audio buffer with ofxFft?

#1

Following the “example-basic” from ofxFFT i get the binned frequencies for an audio signal.

I am now wondering how I can do logarithmic resampling for this audio buffer.

@roymacdonald has an example on how to draw it as a graph to screen.
But thats not the same as making a new resampled buffer; I guess?
Since I need a new buffer of the same bufferSize with each integer array index filled with the correct log() frequency. But it not just a matter of changing the value at each index, but also moving it to a different index. Like changing x and y.

thx.

#2

I’m not DSP specialist but I assume we can do it like following way.

  1. get fft
  2. Prepare new bins with logged freq
  3. Fill each bin, sum if freq range is overwrapped
  4. calc inverse fft

If it’s ok to get log of amplitude, then you can use same bin arrangement.

#3

Thanks for your input. It much appreciated.

I came up with this little function

    void resampleToLog(vector<vector<float>>& data){
        
        for(int chan = 0; chan < data.size(); chan++){
            ofPolyline logLine;
            ofVec3f v;
            int temp_size = data[chan].size();
            
            for(int i=0; i<temp_size; i++){
                v.x = log10(i+1); //ofMap(log10(i+1), 0, log10(n), 0, temp_size);
                v.y = log10(data[chan][i]+1); //ofMap(log10(data[chan][i]+1), 0, log10(2), offset, r.y);
                logLine.addVertex(v);
            }
            
            for(int i=0; i<temp_size; i++){
                
                v = logLine.getPointAtPercent(ofMap(i, 0, temp_size, 0, 1));
                data[chan][i] = v.y;
            }
        }   
        
    }
#4

Hi @stephanschulz, I just saw this post. sorry. Did you figure it out?

I wrote this some time ago, you might find it useful.
best

1 Like
#5

Thanks looks interesting. I think for the log problem I am good now.

But still I’m currently trying to get ofxConstantQ working on OF 10.1 so see how it looks. But so far only the GUI appears and the console prints out stuff.
But maybe the processing just takes super long.

Will keep trying.

#6

HI, dont bother trying ofxConstantQ. It is a kinda outdated algorithm and addon. You can get much better results with a filterbank (like ofxFilterbank)

1 Like