liamappelbe / fftea

A simple and efficient FFT implementation for Dart
Apache License 2.0
67 stars 1 forks source link

How do I convert the raw data obtained by the microphone into the data required for the spectrogram? #51

Open tang158152 opened 2 months ago

tang158152 commented 2 months ago
截屏2024-08-21 14 16 40
tang158152 commented 2 months ago

How do I convert the raw data obtained by the microphone into the data required for the spectrogram? I don't know much about audio, please forgive me

liamappelbe commented 2 months ago

Need some details about what the raw data looks like. What is the Dart type? How is it encoded?

Assuming it's just, say, an Int16List, you just need to convert it to a List<double> or Float64List by mapping the int16 range (-32768 to 32767) to the usual range for float audio sample (-1 to 1). Ie, just divide each element by 32768.

Also, my experience with microphone libraries in flutter has been pretty bad. I'd recommend verifying the data you're getting from the microphone by saving it to a file and listening back to it, before you try to run it through a spectrogram. See this comment.

tang158152 commented 2 months ago

Need some details about what the raw data looks like. What is the Dart type? How is it encoded?

Assuming it's just, say, an Int16List, you just need to convert it to a List<double> or Float64List by mapping the int16 range (-32768 to 32767) to the usual range for float audio sample (-1 to 1). Ie, just divide each element by 32768.

Also, my experience with microphone libraries in flutter has been pretty bad. I'd recommend verifying the data you're getting from the microphone by saving it to a file and listening back to it, before you try to run it through a spectrogram. See this comment.

Mine is a audio_streamer plug-in, I see that the data is sent every 0.5, 19200 data is delivered at a time, this is the data issued every 0.5 seconds, can you see the details of these raw data [Uploading data.txt…]()

tang158152 commented 2 months ago

And I pay attention to the big, in this 19,200 data, the previous data is always large

liamappelbe commented 2 months ago

You upload hasn't worked, so I can't actually see the data. It looks like the audio_streamer plugin already gives you a List<double>, so you probably don't actually need to do any conversions.

Since you want to stream the data, use STFT.stream, and it should all just work.

I still recommend saving a few of the chunks you get from audio_streamer to a WAV file, and listening to the WAV to make sure there are no audio artifacts that would mess up the STFT.

tang158152 commented 2 months ago

data.txt

tang158152 commented 2 months ago

数据.txt

This is data acquired every 0.5 seconds

liamappelbe commented 2 months ago

yep, looks like it's already in the correct format. Have you tried running it through STFT.stream?

tang158152 commented 2 months ago

STFT.stream

Is there a suitable plugin library for STFT.stream, I don't know much about audio

liamappelbe commented 2 months ago

Is there a suitable plugin library for STFT.stream, I don't know much about audio

Not sure what you mean. You can use this package anywhere you'd want to use a plugin. package:fftea is pure Dart, so it's fully compatible with all Flutter platforms. No plugin needed.