Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of STM32FMSynth by
Diff: main.cpp
- Revision:
- 5:ac5c4bd3ef4b
- Parent:
- 4:1d2a699c95c7
- Child:
- 6:9f8c8c3c111d
--- a/main.cpp Wed Nov 29 02:34:59 2017 +0000
+++ b/main.cpp Wed Nov 29 21:47:56 2017 +0000
@@ -77,10 +77,28 @@
int carR;
int fastSin(const int phase){
- int i = phase >> 2;
+ int index = (phase & 0x3ffc) >> 2;
+ int subindex = phase & 0x3;
+ int quadrant = (phase & 0xc000) >> 14;
int sum = 0;
- sum += (phase & 0x3) * sintable[i+1];
- sum += (0x4 - (phase & 0x3)) * sintable[i];
+ switch (quadrant) {
+ case 0:
+ sum += (4 - subindex) * sintable[index];
+ sum += subindex * sintable[index+1];
+ break;
+ case 1:
+ sum += (4 - subindex) * sintable[1+4096-index];
+ sum += subindex * sintable[4096-index];
+ break;
+ case 2:
+ sum -= (4 - subindex) * sintable[index];
+ sum -= subindex * sintable[index+1];
+ break;
+ case 3:
+ sum -= (4 - subindex) * sintable[1+4096-index];
+ sum -= subindex * sintable[4096-index];
+ break;
+ }
sum = sum >> 2;
return sum;
