I am working on an application that applies filters on sound files, the filters are applied in frequency domain so I get the samples from the .wav file using NAudio library with this code :
audio = new AudioFileReader(wav_file);
samples = new float[wave.Length];
audio.Read(samples, 0, samples.Length);
after applying the previous code, now I have the samples as an array of float, then I apply the short-time Fourier transform on the samples getting the frequency domain data, and then the filters are applied on the frequency domain data.
and then the inverse short-time Fourier transform is applied on the frequency domain data to convert it back to time domain which should be similar to the initial samples but with the filters applied.
the steps again:
now the problem is in the last step, I have the float array of samples (time domain data), how do I convert it into a .wav file and play it?
To save samples as a .wav file, the following code is used:
WaveFormat waveFormat = new WaveFormat(sampleRate, bitDepth, channels);
using (WaveFileWriter writer = new WaveFileWriter("C:\\track1.wav", waveFormat))
{
writer.WriteSamples(floatOutput, 0, floatOutput.Length);
}
the sampleRate
, bitDepth
, and channels
are extracted from the input file like this:
sampleRate = wave.WaveFormat.SampleRate;
bitDepth = wave.WaveFormat.BitsPerSample;
channels = wave.WaveFormat.Channels;