Philips Philips
/
microphonetospeaker
Read samples from analog input ADC and outputs to DAC,outputs to speaker, like a karaoke machine lol
Diff: main.cpp
- Revision:
- 0:32b3a9352bd2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat May 28 01:08:01 2011 +0000 @@ -0,0 +1,22 @@ +#include "mbed.h" + +/* ADC for the microphone/input, DAC for the speaker/output */ +AnalogIn mic(p19); +AnalogOut speaker(p18); + +#define NUM_SAMPLES 15000 +unsigned short buffer[NUM_SAMPLES]; + +int main() +{ + int i; + for (i = 0; ; ) // infinite loop + { + /* read mike */ + buffer[i] = mic.read_u16(); + /* Write to speaker */ + speaker.write_u16(buffer[i]); + /* Increment index and wrap around */ + i = (i+1) % NUM_SAMPLES; + } +} \ No newline at end of file