simple explanation please
pilot0315
Posts: 910
in Propeller 2
QSIN(length, angle, twopi) : y Rotate (length,0) by (angle / twopi) * 2Pi and return y. Use 0 for twopi = $1_0000_0000. Twopi is unsigned.
QCOS(length, angle, twopi) : x Rotate (length,0) by (angle / twopi) * 2Pi and return x. Use 0 for twopi = $1_0000_0000. Twopi is unsigned.
I was looking at this code so as to attempt to out put three different pulsed sounds that increase and decrease in loudness. Need three different frequencies. Found this code but do not understand the twopi. Can any one reference me to some simple explanations please.
Thank you in advance.
Plus some relatively simple example code with good comments.
Thanks
Comments
Twopi is just the value that represents an entire circumference. If it is 4, then angles 0..3 would be 0, 90, 180, and 270 degrees.
Chip: Its actually a (badly named) function in this case instead of a value (per that PDF). The twopi function uses two sins 90 degrees out of phase in cartesian space to create a circle upon which the graph data is imposed. I think.
Oh, okay. I was just thinking about the QSIN and QCOS methods in Spin2, and their third argument called 'twopi'. I hadn't even looked at the pdf because I didn't think it was necessary.
Here is an example in Spin2 to generate an audio sine frequency:
https://forums.parallax.com/discussion/comment/1496551/#Comment_1496551
You can do this 3 times in the loop to generate 3 frequencies. To modulate the amplitude make the $7FFF a variable and change it from 0 to $7FFF and back to 0 to increase / decrease the loudness.
Andy
The example modified for two frequencies and the amplitude modulated by a triangle waveform:
Andy
Just for clarity: the "twopi" variable mentioned in the QSIN and QCOS documentation has nothing at all to do with the "twopi" function described in your linked PDF file. They just happen to share a name.
Thanks to all.
@ersmith
Thanks for the explanation.
@Ariba
I will try your code.
Thanks