multithreading example

Dependencies:   FastAnalogIn

Revision:
110:037667235b6d
Parent:
109:1d95a4596fb5
Child:
111:f6bf8ca71128
--- a/main.cpp	Mon Nov 25 02:56:01 2019 +0000
+++ b/main.cpp	Mon Nov 25 06:05:31 2019 +0000
@@ -15,20 +15,36 @@
 
 #define SLEEP_TIME                  500 // (msec)
 #define PRINT_AFTER_N_LOOPS         20
+#define BUFFSIZE                    1760 // size of buffer = sampling_time * sampling_rate * size(float)
 
-#include "mbed.h"
+//define defaults for mfcc
+#define DEF_NUMCEPSTRA      12
+#define DEF_NUMFILTERS      40
+#define DEF_SAMPLINGRATE    16000
+#define DEF_WINLENGTH       25
+#define DEF_FRAMESHIFT      10
+#define DEF_LOWFREQ         50
+#define DEF_HIGHFREQ        DEF_SAMPLINGRATE/2
+#define WINDOW_SIZE         DEF_WINLENGTH - DEF_FRAMESHIFT
+#define ARRAY_SIZE          800
  
 //DigitalOut led1(LED1);
 //DigitalOut led2(LED2);
 Thread thread_adc;
+Thread thread_mfcc;
 
-Thread thread_mfcc;
+// PIN DEFINITIONS
+DigitalOut vcc(GPIO0);
+AnalogIn mic(PB_0);
+CircularBuff<uint16_t> buff(BUFFSIZE);
+
+int num_readings = 0;
  
 void adc_thread() {
     while (true) {
-        printf("Top of ADC sampling thread");
-        
-        wait(0.6);
+        // printf("Top of ADC sampling thread");
+        buff.push(mic.read_u16());
+        num_readings++;
     }
 }
 
@@ -37,13 +53,20 @@
 */
 void mfcc_thread() {
     while (true) {
-        printf("Top of MFCC thread");
-        
+        //printf("Top of MFCC thread");
         wait(2);
+        num_readings /= 2;
+        printf("Readings / second: %i", num_readings);
+        num_readings = 0;
     }
 }
 
 int main() {
+    printf("Creating buff of size %d\n", BUFFSIZE);
+    
+    /* clear the buffer */
+    buff.clear();
+    
     thread_adc.start(adc_thread);
     thread_mfcc.start(mfcc_thread);
 }
\ No newline at end of file