The main thing I’d suggest is to avoid summing every squared sample value in the window every time. Instead use a sliding window (i.e. subtract the least recent value and add the most recent).
If your feedback loop doesn’t have to be that tight, you could also calculate the RMS’s root function every N samples and average that every sample, instead of performing the root every sample. But if you’re relying on this for critical level control then you probably need to do the root every sample.
If you’re not short of memory, you could implement the root function as a lookup / interpolate.
By calculating RMS average i was able to draw ok waveform.
how can i draw the waveform of low frequencies only, like 100 Hz?
I remember reading somewhere that the data doesn’t directly tell this, it had something to do with length of waves.
If it’s a waveform you’re after, use the direct representation of the signal itself with no processing. The RMS is probably unsuitable for what you want. If you want to see the components around a frequency, you need a bandpass filter or alternatively you can do a fourier transform. It’s impossible, in practical terms, to find exactly what the signal is at 100Hz, but by applying a bandpass digital filter you can approximate it.
As this is getting out of the bounds of support, and into general DSP, I strongly suggest you have a look at some background reading, for example:
Try googling for ‘Butterworth bandpass’ or ‘Chebychev bandpass’
Stephen Bernsee’s DSP dimension has some good tutorials on the DFT/FFT
Or get your hands on a good book about signal processing e.g. Digital Signal Processing by John G. Proakis, Dimitris K Manolakis
Thanks for your reply.
Hmm.. FFT seems a bit too hard for me.
I’m using System_GetSpectrum with nosound_nrt to get the data.
Or at least trying to.
I first use the PlaySound function.
Then in a loop:
1) Increase position (Channel_SetPosition) by 10 ms.
2) Call System_Update
3) Call System_GetSpectrum
Each time i get the same spectrum values!
The song position seems to change because in a thread i check the position with Channel_GetPosition and it does increase.
Does System_Update update the spectrum too?
Please login first to submit.