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
Diff: LUTs/LUTS.cpp
- Revision:
- 9:f6ba53e355a0
- Parent:
- 7:33cb5f2db1ee
- Child:
- 10:258a1eca02cc
diff -r f305ea78b2b1 -r f6ba53e355a0 LUTs/LUTS.cpp
--- a/LUTs/LUTS.cpp Tue May 05 16:46:01 2020 +0000
+++ b/LUTs/LUTS.cpp Wed May 06 14:37:34 2020 +0000
@@ -7,14 +7,56 @@
LUTs::~LUTs()
{
}
-
+ volatile uint16_t sin_wavtable[1024];
void LUTs::sin_wavetable()
{
printf("Generating Wavetable \n");
- for (int i=0; i<4096; i++) {
- sin_d[i] = 0.5f*sin(2.0f*PI*(i/4096.0f));
- wavtable[i]= sin_d[i]+0.5; //generates wave table 0<1 in double
- //printf("wav[i]= %f \n", wavtable[i]); // Used for Debug
+ for (int i=0; i<1024; i++) {
+ sin_d= 65535*(0.5*sin(2.0*PI*(i/1024.0))+0.5);
+ //calculates remainder for rounding
+ rem= fmod(sin_d,1);
+ //printf("preround= %g -", sin_d); //DEBUG
+ if (rem>=0.5) {
+ sin_d=ceil(sin_d); //round UP
+ } else {
+ sin_d= floor(sin_d-rem); //round DOWN
+ }
+ // printf("Postround= %g -",sin_d); //DEBUG
+ sin_u=((uint16_t)sin_d);
+ //printf("sin_u= %u \n", sin_u);
+ sin_wavtable[i]=sin_u;
+ //sin_wavtable[i]=get_sin(i);
+ }
+ /*//DEBUG
+ for (int i=0; i<1024; i=i+128) {
+ printf("sin_wav[%d]= %u \n", i, sin_wavtable);
}
-}
\ No newline at end of file
+ */
+}
+
+
+
+
+
+/*
+uint16_t get_sin(int i)
+{
+ //calculates sin val as double (0->65535)
+
+ sin_d= 65535*(0.5*sin(2.0*PI*(i/1024.0))+0.5);
+ //calculates remainder for rounding
+ rem= fmod(sin_d,1);
+ //printf("preround= %g -", sin_d[i]); //DEBUG
+ if (rem>=0.5) {
+ sin_d=ceil(sin_d); //round UP
+ } else {
+ sin_d= floor(sin_d-rem); //round DOWN
+ }
+ //printf("Postround= %g -",sin_d[i]); //DEBUG
+ return((uint16_t)sin_d);
+
+ //summed into one function
+ return((uint16_t)floor(65535*(0.5*sin(2.0*PI*(i/1024.0))+0.5)));
+}
+*/
\ No newline at end of file