experiments with wave file

This is sort of 'episode 2' of the topic 'how to generate sounds of mixed waveforms' (http://www.cplusplus.com/forum/general/109119/)

I took xismn's code and just changed line 24 to
1
2
buffer[i] = sin((c++*deg)*pi/180)*amplitude;
buffer[i+(1*(channels-1))] = sin((c++*deg)*pi/180)*amplitude;

Shouldn't the wave have same frequency as the previous one?
If not, why?
If yes, I am having a problem.

If I use the original code and do
 
sineWave(buffer,200)

It generates a sine wave of frequency 200 Hz

But if I use the edited code and sineWave(buffer, 200) cretes a sine wave of frequency 400 Hz.

How is that possible ?

Also what is the difference between stereo and dual-mono ?
You're incrementing c twice. So one of your channels should have a phase shift from the other and both should be double the frequency. For buffer i, you are getting c = 0, 2, 4, 6, 8, 10, and for buffer i + 1 you are getting c = 1, 3, 5, 7, 9 ...

You want both to get c = 0, 1, 2, 3 ....

Also what is the point of multiplying 1 * (channels - 1)?
Last edited on
Topic archived. No new replies allowed.