Code Monkey home page Code Monkey logo

Comments (3)

alnitak avatar alnitak commented on May 25, 2024

Hi,
you can only get FFT and wave data while the audio is playing. See getFft(), getWave(), getAudioTexture() in the doc.
They return a convenient Pointer<Float> for performance instead of copying it ie in a Float32List every time.

Getting a whole audio frequency domain at once is not yet planned

from flutter_soloud.

BigGitWorld avatar BigGitWorld commented on May 25, 2024

Hi, you can only get FFT and wave data while the audio is playing. See getFft(), getWave(), getAudioTexture() in the doc. They return a convenient Pointer<Float> for performance instead of copying it ie in a Float32List every time.

Getting a whole audio frequency domain at once is not yet planned

Thanks for your answer.

  1. But I didn't understand how can I get value of frequencies to Hz from FFT data. Do you mean ffi.Pointer<ffi.Float> audioData represents amplitude of each sine wave or frequency of sine wave? I want to have both of them (a Map with key=frequency and value=amplitude of that sine waves that create our signal). How can I find it?
    could you give me source code of this example where x-axis shows frequencies and y-axis shows amplitude of them to decibel?

  2. In fact, I have a reference wav file and want to compare other wav files with it to check if they are similar or not.
    can you suggest me a solution please?

from flutter_soloud.

alnitak avatar alnitak commented on May 25, 2024

I notice now that I didn't exposed getAudioTexture(), it's not available on Flutter side. So you will need to use getAudioTexture2D().

Using getAudioTexture2D() you will get back a matrix with 256 rows of 512 floats. You could consider only the 1st row as it represents the latest data. So this first row is composed by:

  • The first 256 floats represent the FFT frequencies data in the 0.0~1.0 range.
  • The other 256 floats represent the wave data in -1.0~1.0 range (amplitude).
    So, the first 256 floats in this array, I think are the values you are looking for:
final ffi.Pointer<ffi.Float> audioData = SoLoud().getAudioTexture2D(playerData);

You can access these floats with double n = audioData[i]. The i index is the frequency in Hz and its value is the amplitude (volume) of that frequency.
Since the engine is set to 44100 samples/s and the amount of data given to compute FFT is 1024, below a function to know which frequency is represented in the array index i.

double Index2Freq(int i, double samples, int nFFT) {
  return  (samples / nFFT / 2.0) * i;
}

and you can use it with something like this:

void getFreqs() {
  for (final int i=0; i<256; i++) print('index: $i  is  ${Index2Freq(i, 44100, 1024)} Hz');
}

Here you can see the widget used in the Visualizer example to show the FFT data, but the correct image is this. The one you linked is made using Audacity app and it's a bit different with the one generated by this plugin and I don't know yet why 😄

I didn't tested and I don't know much about audio processing, but hope this helps!

  1. I think this could be more complicated than it might seems. To compare audio you should use fingerprints, basically you should generate these fingerprint of samples and then compare each other. There are some libraries around by I never tried.

I move this issue to Discussion, it maybe be useful to others!

from flutter_soloud.

Related Issues (20)

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.