FM synthesis fuzzy sound I'm trying to reproduce this !!!WARNING LOUDNESS!!! sound in C. In the website, it says to use Carrier: 500 Hz, modulator frequency: 1 Hz, modulator index: 500, however I'm getting lots of clicks and fuzzing (along with the right sound) with this code:

#include &lt;stdio.h&gt;
#include &lt;math.h&gt;
#include &lt;string.h&gt;

#define DURATION    20
#define RATE        44100
#define NUMCHANS 1

#define NUMSAMPLES  (DURATION*RATE)
#define NUMSAMPLESC (NUMSAMPLES*NUMCHANS)

#define BYTES_IN_HEADER (11*sizeof(int))
#define BYTES_IN_BUFFER (NUMSAMPLESC*sizeof(short) + BYTES_IN_HEADER)

#define DELTAT (1.0/RATE)

#define M_PI 3.14159265359

static const int wavHeader[] = {
0x46464952, 
NUMSAMPLESC*2+36, 
0x45564157, 
0x20746D66, 
16, 
1|(NUMCHANS&lt;&lt;16), 
RATE, 
RATE*NUMCHANS*sizeof(short), 
(NUMCHANS*sizeof(short))|((8*sizeof(short))&lt;&lt;16),
0x61746164, 
NUMSAMPLES*sizeof(short)
};

static short buffer[BYTES_IN_BUFFER/sizeof(short)];

int main(void) {

 unsigned int i;
 double t = 0.0;
 FILE *fp;

 memcpy(buffer, wavHeader, BYTES_IN_HEADER);

for(i = BYTES_IN_HEADER/sizeof(short); i &lt; BYTES_IN_BUFFER/sizeof(short); i++, t += DELTAT) {
    buffer[i] = 100 * sin(2*M_PI*500*t + 500*sin(t*2*M_PI*1));
}

 fp = fopen("test.wav", "w");
 fwrite(buffer, 1, BYTES_IN_BUFFER, fp);

fclose(fp);

return 0;
}


I have tried using single precision floats, reversing endianness, but with the same result. The only thing that seems to remove the clicks and fuzzing to a certain extent (but they're still there) is if i copy the lower 8 bits of each sample into the upper 8 bits.

My sound card is integrated from a P43DE3 motherboard and can handle audio CDs well, and my OS is Windows 8.

How do I reproduce that sound without noise?

EDIT

It seems to produce the correct output when I run it on a Mac. Perhaps and endianness error? Will investigate further.
OK, I figured out what the problem was using a hex editor. The compiler on Windows was seemingly introducing random 0x0D throughout the file. That's because of the mode I was opening the file with, "w". fwrite converted every instance of '\n' into "\r\n". All I had to do was change the file opening mode to "wb+", and it sounds exactly like the linked audio file, after changing the carrier amplitude to 2e5.