FFT within a Object

I’m working on a project and i have my audio files being put into an audio object in order for it to be played and created but when I try to analyze the frequency using FFT it doesn’t pick anything up here’s the code for the sketch and object. I’m wondering if there’s any way I can pick up the frequency from this audio object.

//Sketch

"use strict"; //catch some common coding errors
let audios = [];
let menus;
let l
let fft;
let test
let song;
/**
 * setup :
 */
function preload()
{
     song = loadSound("abba.mp3") 
     l =  new audio("abba.mp3");
}
function setup() {
    createCanvas(500, 500);
    
    fft = new p5.FFT(0,16);
   
    audios.push(l)
    //song.play();
    
}

/**
 * draw :
 */
function draw() {
    l.testing()

}
function keyPressed()
{
    for(audio of audios){
        audio.switch()
    }
    
}

class audio{
    constructor(file,x,y){
        this.file = createAudio(file);
        this.x = x;
        this.y = y;
        this.pauses=true
        //this.sel = createSelect();
        this.ffst = new p5.FFT(0,16);
        this.testt;
    }
    player(){
        //this.sel.position(10,10)
        //this.sel.option('pear');
        this.file.loop();
    }
    switch()
    {
        this.pauses = !this.pauses
        if (this.pauses)
        {
            this.file.stop()
        }
        else{
            this.file.play()
        }
        
        
        console.log(this.pauses)
    }
    testing()
    {   this.file.play()
        this.testt = this.ffst.analyze(16);
    console.log(this.testt)
    }


}
1 Like

Were you able to resolve this issue?

It seems like you are trying to create a new p5.FFT (ffts) when you create an audio object, and then from testing() you are calling ffts.analyze(16) on that FFT. However, other than creating and calling analyze, do you give it any information – for example, should it be connected to file in some way? I’m not seeing that in your code – perhaps check the p5.FFT basic examples for usage…

For example, from: https://p5js.org/reference/#/p5.FFT

setInput() Set the input source for the FFT analysis. If no source is provided, FFT will analyze all sound in the sketch.

1 Like