Kiyoteru Hayama
/
VoiceRecorder
simple voice recorder. Pwoer up or reset, record voice for 5 sec. Press botton then voice out.
main.cpp@0:00a8ac955304, 2014-08-14 (annotated)
- Committer:
- hayama
- Date:
- Thu Aug 14 09:45:57 2014 +0000
- Revision:
- 0:00a8ac955304
simple voice recorder
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hayama | 0:00a8ac955304 | 1 | #include "mbed.h" |
hayama | 0:00a8ac955304 | 2 | #define NUMDAT 15000 |
hayama | 0:00a8ac955304 | 3 | #define DLY 250 |
hayama | 0:00a8ac955304 | 4 | |
hayama | 0:00a8ac955304 | 5 | float micCB; |
hayama | 0:00a8ac955304 | 6 | short dat[NUMDAT]; |
hayama | 0:00a8ac955304 | 7 | int i; |
hayama | 0:00a8ac955304 | 8 | |
hayama | 0:00a8ac955304 | 9 | DigitalIn sw(p5); |
hayama | 0:00a8ac955304 | 10 | AnalogIn micC(p16); |
hayama | 0:00a8ac955304 | 11 | AnalogOut spOut(p18); |
hayama | 0:00a8ac955304 | 12 | BusOut leds( LED4, LED3, LED2, LED1 ); |
hayama | 0:00a8ac955304 | 13 | |
hayama | 0:00a8ac955304 | 14 | void voiceOut(){ |
hayama | 0:00a8ac955304 | 15 | leds=2; |
hayama | 0:00a8ac955304 | 16 | for(i=0;i<NUMDAT; i++){ |
hayama | 0:00a8ac955304 | 17 | spOut=((float)dat[i])/32768*10+0.5; |
hayama | 0:00a8ac955304 | 18 | wait_us(DLY); |
hayama | 0:00a8ac955304 | 19 | } |
hayama | 0:00a8ac955304 | 20 | } |
hayama | 0:00a8ac955304 | 21 | |
hayama | 0:00a8ac955304 | 22 | int main() { |
hayama | 0:00a8ac955304 | 23 | leds=0; |
hayama | 0:00a8ac955304 | 24 | wait(1); |
hayama | 0:00a8ac955304 | 25 | micCB=0; |
hayama | 0:00a8ac955304 | 26 | for(i=0;i<100;i++){ micCB+=micC; } |
hayama | 0:00a8ac955304 | 27 | micCB/=100; |
hayama | 0:00a8ac955304 | 28 | leds=1; |
hayama | 0:00a8ac955304 | 29 | |
hayama | 0:00a8ac955304 | 30 | // record voice |
hayama | 0:00a8ac955304 | 31 | for(i=0;i<NUMDAT; i++){ |
hayama | 0:00a8ac955304 | 32 | dat[i]=(int)((micC-micCB)*32768); |
hayama | 0:00a8ac955304 | 33 | wait_us(DLY); |
hayama | 0:00a8ac955304 | 34 | } |
hayama | 0:00a8ac955304 | 35 | |
hayama | 0:00a8ac955304 | 36 | while(1){ |
hayama | 0:00a8ac955304 | 37 | leds=0; |
hayama | 0:00a8ac955304 | 38 | if (sw==0) voiceOut(); |
hayama | 0:00a8ac955304 | 39 | } |
hayama | 0:00a8ac955304 | 40 | } |
hayama | 0:00a8ac955304 | 41 | |
hayama | 0:00a8ac955304 | 42 | |
hayama | 0:00a8ac955304 | 43 |