tomparkin:
Sorry, I realised you linked to another forum with a more fulsome description.
So, if I understand you correctly, you want to take incoming ("live/on-the-fly"?) .wav data, and then perform a DFT on it?
If that's true, I'm not sure wav2sketch.c is entirely what you want, unless I'm missing something. The C code is reading a .wav file, encoding it as G.711 (by default), and then auto-generating C/C++ code containing the data in a form that the Teensy Audio Library likes (apparently, last bit from the comments in the file).
When I've done fourier transform stuff in the past it has always been with plain old PCM data.
So I think what you want/need is:
- Access a .wav file from "somewhere" (SD card? How is it arriving?)
- Crib the wav2sketch code to read/handle the wav file header
- Crib the wav2sketch code to read (chunks of) the wav file as arrays of PCM data
- Poke the PCM data into your DFT code
IOW, unless I have completely the wrong end of the stick (not unusual!) wav2sketch is mostly going to be useful as a reference rather than a direct source of working code for your usecase.
Thanks a lot for your answer tomparkin.
Finally someone trys to understand the kind of problems i'm going to have to think of before getting the job done. To clarify what exactly i want to achieve in the end, i can just summarize as follows:
I want a real time frequency analysis with numerical data of a signal which is being sent to my microcontroller. It could be one of my synthesizers, a microphone, anything really. So the input is not stored anywhere, it is recorded LIVE. That's why i need to sample it and store the samples (preferably on a SDcard). These discrete numbers / samples, created by the PCM, are then the values i'm going to send into a DFT / FFT function, which will result a discrete signal in frequency domain. Going further i then want to examine the peaks in the spectrum or defined more accurately the loudness of the discrete frequencies, but that is not a target right now. First i need to get control over the samples and transformations.
Like you said it would be an idea to not use the wav2sketch code and try to use another kind of file format (most reasonably PCM / .WAV). However there's a 1024-point FFT program written for the teensy / teensyduino library and it actually provides pretty accurate results ... and it is using the u-law encoded, hexadecimal data which is being generated by the wav2sketch.c file, so that is where this is coming from ...
But thinking about it again actually you're so right: why not try to write my own code and to use the .WAV files / PCM data directly ... hmmm maybe because i just hate coding if it's not a 2 liner lol ... way better to steal everything from someone else :o
The formula for a discrete fourier transformation is not too complicated - i already programmed one using eulers formula. You're absolutely right if you say the standard procedure would make more sense. Remove the first 96 + 192 bits (12 + 24 bytes) from the .WAV and send the remaining PCM data into my DFT function. But I'm still having big problems with 2 things:
- what is one of the 32bit integers of the PCM data telling me? Meaning how can i translate those numbers to loudness / decibel values?
- same with the resulting spectrum. If I'm transforming a vector of digital integer values what is the resulting spectrum telling me in forms of loudness? If you look at existing equalizers they all have a spectrum analyzer with dB values for the frequency bands
Thank you so much guys for all the help! Cheers
Henning