tone: Exploit sine-wave symmetry to save space.
authorsjlongland <sjlongland@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 25 Sep 2015 13:13:54 +0000 (13:13 +0000)
committersjlongland <sjlongland@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 25 Sep 2015 13:13:54 +0000 (13:13 +0000)
commit6b97d8bc503b5218918333e5455e4aa77e3104d4
tree03539039addaf484dfce6a47959be1bc44f742f4
parent11b5197cb23511201602a7ee7bf7feccfa832a40
tone: Exploit sine-wave symmetry to save space.

The sine wave basically can be divided into four quadrants, 0→0.5pi,
0.5pi→pi, pi→1.5pi and 1.5pi→2pi.  If we call these Q1, Q2, Q3 and Q4,
we can see:

- Q2 is basically Q1 in reverse
- Q3 is Q1 negated
- Q4 is Q2 negated

We can therefore exploit this to store ¼ of the waveform.  We do some if
statement trickery to stitch the partial waveforms together.  End result
is we've now quadrupled the definition of our sine wave at minimal
code-size cost.

CPU wise is a wee bit more expensive, but still a lot better than
actually calculating sine with a math library!

git-svn-id: https://svn.code.sf.net/p/freetel/code@2381 01035d8c-6547-0410-b346-abe4f91aad63
codec2-dev/stm32/src/tone.c