Bluetooth Enabled Keyboard/Synthesizer for mbed

Dependencies:   mbed 4DGL-uLCD-SE SDFileSystem mbed-rtos

Revision:
18:24f56dcc5a59
Parent:
17:7dd298995c14
Child:
19:2f635d03467c
--- a/main.cpp	Fri Apr 29 22:43:06 2016 +0000
+++ b/main.cpp	Fri Apr 29 22:59:39 2016 +0000
@@ -29,7 +29,7 @@
 double *currentDecayTable;             // pointer to the correct decay coefficient table
 double *currentSustainTable;           // pointer to the correct sustain coefficient table
 double *currentReleaseTable;           // pointer to the correct release coefficient table
-vector<double> sampleBuffer;        // vector to hold samples of generated waveform
+vector<float> sampleBuffer;        // vector to hold samples of generated waveform
 int num_samples = 256;              // number of samples 
 volatile int noteFreq;              // the current frequency of the note being played
 double timeIncrement = (2/256);     // 2 seconds with 256 samples
@@ -394,7 +394,7 @@
     double t = 0;                           // Represents time, since we want each note to last 2 seconds and have 256 samples
     for(int i = 0; i < 256 ; i++)
     {
-        sampleBuffer.push_back(((sin(2*(PI)*frequency*t)) + 1)/2);  // scaled to be a % of maximum output voltage (3.3V)
+        sampleBuffer.push_back(((sin(2*(PI)*frequency*(float)t)) + 1)/2);  // scaled to be a % of maximum output voltage (3.3V)
         t = t + timeIncrement;                                       // increment t for calculation of next value in the waveform   
     }
 }
@@ -404,7 +404,7 @@
     double t = 0;                           // Represents time, since we want each note to last 2 seconds and have 256 samples
     for(int i = 0; i<256 ; i++)
     {
-        sampleBuffer.push_back((2*(t*frequency) - (.5 + (t*frequency)) + 1) / 2);
+        sampleBuffer.push_back((2*((float)t*frequency) - (.5 + (t*frequency)) + 1) / 2);
         t = t + timeIncrement;              // increment t for calculation of next value in the waveform   
     }
 }
@@ -416,9 +416,9 @@
     for(int i = 0; i < 256; i++)
     {
         if(((int)(t / width) % 2 ) == 0)     // Even, write a 1 for the square wave
-        sampleBuffer.push_back(1.0);
+        sampleBuffer.push_back((float)1.0);
         else                                // Odd, write a 0 for the square wave
-        sampleBuffer.push_back(0.0);
+        sampleBuffer.push_back((float)0.0);
         t = t + timeIncrement;              // increment t for calculation of next value in the waveform
     }
 }