
Hi guys,
I've got a little problem with apllying transfer fuction. I need to take data from .wav file and make convolution with transfer function and play this sound in real time. Thank you for advices. I'm new to NAudio.



Hi, this is not a trivial task. For realtime processing you can´t process the data in the time domain, which would be simple coding (using the class "ImpulseResponseConvolution"). The only approach is complex and demands a lot of knowledge: you
need to transform the data in the frequency domain, process it and transform it back. For transformation the "FastFourierTransform" (FFT) or "ShortTermFourierTransform" (STFT) is commonly used. Unfortunately, there is no implementation
available in NAudio, but good luck (and pls provide if you can deploy it).


May 17 at 5:30 PM
Edited May 17 at 5:31 PM

Thanks,I thought, I could just fit my input data from wav file to transfer function...



I recommend to look at the FastFouriertransformation class and the sampleaggregator class for a start.



Hello, so I tried to do FFT with use of SampleAggregator.cs, but I'm not shure, if I realy understand class SampleAggregator  Is that instance, witch take samples from my wave file (or any input), and apply FFT algorythm for every single sample of my
wave file  this is the method Add in this class right? And length of FFT means, how large is step between couted frequencies in spectrum? For example if is frequency of my point[n] = 100Hz, frequency of point[n+1] is my sample rate/ FFT length, so if I've
got sample rate 44100 and FFT length 1024, point[n+1] = point[n]+(44100/1024), so if my point[n] is 100 my point[n+1]= 143,066.... ??? I'm right or absolutly dumb...?? :D
Thanks for answer.


May 24 at 7:43 PM
Edited May 24 at 7:47 PM

I´m not deep into the the maths, but what I know so far is:
Each bin of the FFT result is equally spaced in the frequency spectrum.
For example when SampleRate is 44100 Hz and FFT Size is 1024:
frequency[0]=0*44100/(1024*2) // First bin is always 0 Hz, called the DC offset
frequency[1]=1*44100/(1024*2) //Second bin, here at 22 Hz
frequency[2]=2*44100/(1024*2) //Third bin, here at 44 Hz
....
frequency[1024]=1024*44100/(1024*2) //Last bin is always half SampleRate, here 22050 Hz
So just loop over the FFT Result and calculate the frequency and amplitude.



So, I tried to do FFT of my wave file and than apply my poly transfer function:
void FftCalculated(object sender, FftEventArgs e)
{
//y[n] = A*x^3[n] + B^2[n] + C*x[n] + DI; // my transfer function
for (int i = 0; i < e.Result.Length; i++)
{
fftResultX[i] = e.Result[i].X; // result of fft for Complex.X
fftResultY[i] = e.Result[i].Y; // result of fft for Complex.Y
fftResultH[i].X = A * (e.Result[i].X) * (e.Result[i].X) * (e.Result[i].X) + B * (e.Result[i].X) * (e.Result[i].X) + C * (e.Result[i].X)+D; //distortion  fit my fft result to my transfer function
fftResultH[i].Y = A * (e.Result[i].Y) * (e.Result[i].Y) * (e.Result[i].Y) + B * (e.Result[i].Y) * (e.Result[i].Y) + C * (e.Result[i].Y) + D;
}
}
where fftResultH is spectrum with distortion effect of my transfer function. And now I want to playing my effected sound in real time / when I open my wave fine and press my play botton I want to hear effected sound, where I can changing parameters A,B,C,D
of my transfer function in realtime... Can I do it this way?
I'm using SampleAggregator.



Girl, you got no idea what you´re doing. Besides that and your load of spelling mistakes, as I said initially it is NOT a trivial task. I don´t even know myself exactly how to do it.



No need for FFT right?, Just convolve your signal with the transfer function.



My transfer function is not linear, so you can't convolve nonlinear system with signal. If you want convolve you have to do volterra series. What I have to do is FFT and the add harmonic in spectrum... So... I done it my program can add harmonic distortion
to my input signal... but I've got a little trouble with latency. I've go some handling noises like popping in my output signal... but my latency is 250... I think is becouse of counting of polynoms in worker thread...
PS: To Freefall... I'm sorry... I know my English is terrible, but I'm not native speaker and writer definitly not...



Two tips maybe,
1: Add a clipper so the signal does not go to digital 1 and 1. It could be out of bounds rather than latent. But with FFT I can see the point.
2: Lot's of things add harmonic distortion. Think tubes, It's not FFT level complex (nothing is ;) ), rather It's a transfer function.
Good luck!



Thanks but what I need is changing shape of transfer function i real time. Clipper is included in my project...



Not shure what the mission was, mbe i'm wrong. But i'd say the pieces are there..


Jun 5 at 10:51 PM
Edited Jun 5 at 10:58 PM

What I know so far if I remember correctly:
1) samples of realtime input > FFT > Complex output
2) samples of convolution input > FFT > Complex output (Can be stored and reused)
3) Multiply 1) and 2) for convolution > IFFT (=inverse FFT) > output realtime samples
I think this was the basic approach.

