0

I have an array of integers (int_16) that contains all audio data of a Wav file. Now i would like to obtain its "frequency domain" representation and add a 1000Hz noise.

I have read a lot of math but i haven't found a real implementation of this problem in C.

I would only like to discover:

  • which is the appropriate library (FFTW?)

  • how to apply the FFT to my array (Which function i can use)

  • what kind of data i obtain and what they represent

  • how to add a 1000Hz noise and rebuild the new Wav

Thank you!!

Luca P.
  • 89
  • 1
  • 7
  • I suppose you mean a 1000Hz tone? – meaning-matters Jun 12 '13 at 09:42
  • 2
    If your goal is just to add a 1000Hz tone, working in the frequency domain is overkill. Just add a sinusoid to your samples. Have a look at this code: http://stackoverflow.com/questions/2457482/processing-an-audio-wav-file-with-c –  Jun 12 '13 at 09:46
  • Thank you Yves, perhaps it would be better if I specified that I need to do this for educational purpose! – Luca P. Jun 12 '13 at 10:06

1 Answers1

4

You don't need to convert your signal to the frequency domain and back again to do this - you can just add a 1 kHz sine wave in the time domain, e.g.

#include <stdint.h>
#include <limits.h>
#include <math.h>

const float kA = 0.1f;         // amplitude = 10% of full scale (-20 dB)
const float kF = 1000.0f;      // frequency = 1 kHz
const float kFS = 44100.0f;    // sample rate = 44.1 kHz

for (int i = 0; i < N; ++i)    // for each sample
{
    samples[i] += (int16_t)(SHRT_MAX * kA * sinf(2.0f * M_PI * kF * i / kFS));
}                              // add sine wave to signal
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • Thank you Paul, perhaps it would be better if I specified that I need to do this for educational purpose, and because it could open the way for many other applications! – Luca P. Jun 12 '13 at 10:08
  • 1
    In that case, just a suggestion: it might be more rewarding to pick a task that actually benefits from processing in the frequency domain in some way, e.g. more efficient, easier to accomplish. – Paul R Jun 12 '13 at 12:30