Flutter/Java Plot Mp3 Frequency intensity

1,677

The Discrete Fourier Transform (for which FFT is the most commonly used algorithm) is exactly what you need since it will map your time domain samples to the frequency domain. Assuming you have the sound samples over a period of time and the frequency those were sampled with, you will be able to achieve your goal, it doesn't really matters if it is real time or not.

The second step would be to process the results from your FFT, which would produce the amplitudes of the frequencies present in your sample.

Try Github for Java based FFT implementations https://github.com/search?q=java+fft and you are likely to find also some examples there.

Share:
1,677
Fabrizio
Author by

Fabrizio

Updated on December 06, 2022

Comments

  • Fabrizio
    Fabrizio over 1 year

    I don't really properly know how to explain the exact thing I'm achieving. I need to track down the intensity of certain frequencies from an mp3 file for a certain number of times on android (Java) (or if it's possible on Dart (Flutter)). This is an image explaining what I mean:

    I made this screenshot in Blender using Bake Sound to f-Curve Modifier, which is exactly what I'm trying to achieve, but it's written in C++, so the first thing I did was trying to get some hints from the source code but I couldn't manage to find anything.

    As You can see it's not real-time but it's the value of a certain frequency (frequency Range in this case: 80-255Hz) over time.

    zoomed Version As you can see it's just a graph of the intensity of that frequency over time. and the "divions" on X axis in this case are of about 180s/600 frames.

    For what concerns the file format: The input files are mp3s or wav.

    For What Concerns the Language:

    My main goal is to achieve this in java, but if it's possible, it would be nice to be done in Flutter (so Dart). I'm asking one of the two. If Flutter is impossible or too difficult, a java implementation is good anyway, I'm using a platform channel already on the application so isn't that much of a problem.

    I've looked up online but the only tutorials I could find were real time examples that used FFT.

    Better Explanation Of what I need: I have a number of frames: Let's Say 300. I need a function that is something like this:

    List<Integer> calculateFrequencies(int number_of_frames, double freq_low, 
    freq_high, String FilePath){
    List<Integer> result = new ArrayList<>();
    double length = //Here I need to obtain the length of the song in units as small as possible, for example, milliseconds or nanoseconds
    
    for(int v = 0, v < number_of_frames; v++){
    
        double currFrame = lenght/300 * v;
        double intensity = get_intensity(currFrame, freq_low, freq_high) //How Could I do this?? 
    
    
        result.add(intensity);
     }
    
    return result;
    
    }
    

    How could I do this?

    Is that possible? And if it is, is it possible in android too?