Hello!
I'm having a very difficult time with this problem. What I'm trying to do is generate a sine wave for a specific frequency and output it as raw pcm data to a file.
The sine wave is generated as follows:
samples[i]=static_cast<int>(32767 * amplitude * sin(static_cast<double>(i)*scale) );
where scale = 2*PI/sample_rate.
And to write a specific sample in raw format, I'm first converting it to an array of char in little endian byte order, like this:
void writeInt(std::ofstream& out, int integer, int num_bytes)
{
int y = (integer);
for(int i=0; i<num_bytes; i++)
{
int x = y&255;
out.put(x);
y = y>>8;
}
}
Now, this is fine in Linux (using gcc). I am able to play a smooth frequency. The problem is when I try to run the same code under Windows (compiled with mingw or bcc32), I get a very distorted sounding wave. Clearly, the data is not being written or converted properly. So to get right down to it, what is causing this difference between Linux and Windows? And, if at all possible, how do I do this the right way in Windows?
Thanks for your consideration!