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.
Fork of flash_audio_playerI2S by
Diff: main.cpp
- Revision:
- 0:e4f991474a45
- Child:
- 1:8fda76e11be8
diff -r 000000000000 -r e4f991474a45 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Oct 21 20:53:36 2017 +0000
@@ -0,0 +1,37 @@
+#include "mbed.h"
+AnalogOut speaker(p18);
+Ticker sampletick;
+DigitalOut myled(LED1);
+//Plays Audio Clip using Array in Flash
+//
+//setup const array in flash with audio values
+//from free wav file conversion tool at
+//http://ccgi.cjseymour.plus.com/wavtocode/wavtocode.htm
+//see https://os.mbed.com/users/4180_1/notebook/using-flash-to-play-audio-clips/
+#include "cylonbyc.h"
+
+#define sample_freq 11025.0
+//get and set the frequency from wav conversion tool GUI
+int i=0;
+
+//interrupt routine to play next audio sample from array in flash
+void audio_sample ()
+{
+ speaker.write_u16(sound_data[i]);
+ i++;
+ if (i>= NUM_ELEMENTS) {
+ i = 0;
+ sampletick.detach();
+ myled = 0;
+ }
+}
+int main()
+{
+ while(1) {
+ myled = 1;
+//use a ticker to play send next audio sample value to D/A
+ sampletick.attach(&audio_sample, 1.0 / sample_freq);
+//can do other things while audio plays with timer interrupts
+ wait(10.0);
+ }
+}
