Vasanth Kumar / Mbed 2 deprecated RapidMP3_check

Dependencies:   RAPIDMP3 mbed

Fork of RapidMP3_check by Vasanth Kumar

Committer:
vasanth
Date:
Fri Nov 21 07:39:09 2014 +0000
Revision:
0:a540b792fbf0
Child:
1:dbb63bd6c828
RapidMP3 check first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vasanth 0:a540b792fbf0 1 #include "mbed.h"
vasanth 0:a540b792fbf0 2 #include "RAPIDMP3.h"
vasanth 0:a540b792fbf0 3
vasanth 0:a540b792fbf0 4
vasanth 0:a540b792fbf0 5 RAPIDMP3 rmp3(D8, D2); /// Tx, Rx
vasanth 0:a540b792fbf0 6 Serial pc(USBTX, USBRX);
vasanth 0:a540b792fbf0 7
vasanth 0:a540b792fbf0 8 int main() {
vasanth 0:a540b792fbf0 9
vasanth 0:a540b792fbf0 10 wait(1.0);
vasanth 0:a540b792fbf0 11
vasanth 0:a540b792fbf0 12 pc.puts("RAPID_MP3_V1 module demonstration\r\n");
vasanth 0:a540b792fbf0 13
vasanth 0:a540b792fbf0 14 while (1) {
vasanth 0:a540b792fbf0 15
vasanth 0:a540b792fbf0 16 // Play track till its end
vasanth 0:a540b792fbf0 17 rmp3.playFile("munthi.mp3");
vasanth 0:a540b792fbf0 18 rmp3.waitEndOfPlay();
vasanth 0:a540b792fbf0 19
vasanth 0:a540b792fbf0 20
vasanth 0:a540b792fbf0 21 // Play track for a specified duration
vasanth 0:a540b792fbf0 22 rmp3.playFile("sempove.mp3");
vasanth 0:a540b792fbf0 23 wait(20.0);
vasanth 0:a540b792fbf0 24 rmp3.stop();
vasanth 0:a540b792fbf0 25 wait(5.0);
vasanth 0:a540b792fbf0 26
vasanth 0:a540b792fbf0 27 // Play, pause and resume a track
vasanth 0:a540b792fbf0 28 rmp3.playFile("karug.mp3");
vasanth 0:a540b792fbf0 29 wait(10.0);
vasanth 0:a540b792fbf0 30 rmp3.playPause();
vasanth 0:a540b792fbf0 31 wait(5.0);
vasanth 0:a540b792fbf0 32 rmp3.playResume();
vasanth 0:a540b792fbf0 33 wait(5.0);
vasanth 0:a540b792fbf0 34
vasanth 0:a540b792fbf0 35 // Set volume level to 2
vasanth 0:a540b792fbf0 36 rmp3.volumeSet(2); // 0 is max, 9 is mute
vasanth 0:a540b792fbf0 37 wait(5.0);
vasanth 0:a540b792fbf0 38
vasanth 0:a540b792fbf0 39 // Increase volume one level
vasanth 0:a540b792fbf0 40 rmp3.volumeInc();
vasanth 0:a540b792fbf0 41 wait(5.0);
vasanth 0:a540b792fbf0 42
vasanth 0:a540b792fbf0 43 // Decrease volume one level
vasanth 0:a540b792fbf0 44 rmp3.volumeDec();
vasanth 0:a540b792fbf0 45 wait(5.0);
vasanth 0:a540b792fbf0 46
vasanth 0:a540b792fbf0 47 // Read and display current volume level in PC UART
vasanth 0:a540b792fbf0 48 uint8_t volume = rmp3.volumeGet();
vasanth 0:a540b792fbf0 49 pc.printf("current volume level = %d\r\n", volume);
vasanth 0:a540b792fbf0 50 wait(5.0);
vasanth 0:a540b792fbf0 51
vasanth 0:a540b792fbf0 52 // Read the playback status
vasanth 0:a540b792fbf0 53 uint8_t playStatus = rmp3.getPlaybackStatus();
vasanth 0:a540b792fbf0 54 if (playStatus == RMP3_BUSY) {
vasanth 0:a540b792fbf0 55 pc.puts("Device is busy\r\n");
vasanth 0:a540b792fbf0 56 // Stop the current playback
vasanth 0:a540b792fbf0 57 rmp3.stop();
vasanth 0:a540b792fbf0 58 wait(5.0);
vasanth 0:a540b792fbf0 59 }
vasanth 0:a540b792fbf0 60 pc.puts("Device is free\r\n");
vasanth 0:a540b792fbf0 61 wait(5.0);
vasanth 0:a540b792fbf0 62
vasanth 0:a540b792fbf0 63 // Record audio as .wav file for a specified time
vasanth 0:a540b792fbf0 64 rmp3.recordFile("rec_001.wav");
vasanth 0:a540b792fbf0 65 wait(20.0);
vasanth 0:a540b792fbf0 66 rmp3.stop();
vasanth 0:a540b792fbf0 67
vasanth 0:a540b792fbf0 68
vasanth 0:a540b792fbf0 69 // Play the recorded audio till its end
vasanth 0:a540b792fbf0 70 rmp3.playFile("rec_001.wav");
vasanth 0:a540b792fbf0 71 rmp3.waitEndOfPlay();
vasanth 0:a540b792fbf0 72
vasanth 0:a540b792fbf0 73 wait(5.0);
vasanth 0:a540b792fbf0 74
vasanth 0:a540b792fbf0 75 // loop again.
vasanth 0:a540b792fbf0 76 }
vasanth 0:a540b792fbf0 77 }
vasanth 0:a540b792fbf0 78
vasanth 0:a540b792fbf0 79
vasanth 0:a540b792fbf0 80 //DigitalOut myled(LED1);
vasanth 0:a540b792fbf0 81
vasanth 0:a540b792fbf0 82 ///** Send Rapid MP3 response to PC */
vasanth 0:a540b792fbf0 83 //static void sendResponse(uint8_t response) {
vasanth 0:a540b792fbf0 84 // if (response == RMP3_OK) {
vasanth 0:a540b792fbf0 85 // pc.puts("OK\r\n");
vasanth 0:a540b792fbf0 86 // } else if (response == RMP3_ER) {
vasanth 0:a540b792fbf0 87 // pc.puts("ER\r\n");
vasanth 0:a540b792fbf0 88 // /// error in command
vasanth 0:a540b792fbf0 89 // while (1) {
vasanth 0:a540b792fbf0 90 // myled = !myled;
vasanth 0:a540b792fbf0 91 // wait(0.2f);
vasanth 0:a540b792fbf0 92 // }
vasanth 0:a540b792fbf0 93 // }
vasanth 0:a540b792fbf0 94 //}
vasanth 0:a540b792fbf0 95
vasanth 0:a540b792fbf0 96
vasanth 0:a540b792fbf0 97
vasanth 0:a540b792fbf0 98 //int main() {
vasanth 0:a540b792fbf0 99 //
vasanth 0:a540b792fbf0 100 // /** Application Code.....*/
vasanth 0:a540b792fbf0 101 // uint8_t response;
vasanth 0:a540b792fbf0 102 //
vasanth 0:a540b792fbf0 103 // pc.puts("RAPID_MP3_V1\r\n");
vasanth 0:a540b792fbf0 104 //
vasanth 0:a540b792fbf0 105 //
vasanth 0:a540b792fbf0 106 // /** Wait for RMP3 module Initialization (LED1 Indication) */
vasanth 0:a540b792fbf0 107 // response = rmp3.waitDeviceFree();
vasanth 0:a540b792fbf0 108 // pc.puts("Initialized Successfully\r\n");
vasanth 0:a540b792fbf0 109 // sendResponse(response);
vasanth 0:a540b792fbf0 110 // myled = 1;
vasanth 0:a540b792fbf0 111 // wait(1.0f);
vasanth 0:a540b792fbf0 112 //
vasanth 0:a540b792fbf0 113 //
vasanth 0:a540b792fbf0 114 // /** Check RMP3 module communication */
vasanth 0:a540b792fbf0 115 // response = rmp3.checkDevice();
vasanth 0:a540b792fbf0 116 // pc.puts("DEVICE CHECK\r\n");
vasanth 0:a540b792fbf0 117 // sendResponse(response);
vasanth 0:a540b792fbf0 118 // wait(1.0f);
vasanth 0:a540b792fbf0 119 //
vasanth 0:a540b792fbf0 120 //
vasanth 0:a540b792fbf0 121 // while (1) {
vasanth 0:a540b792fbf0 122 //
vasanth 0:a540b792fbf0 123 // /** Play an MP3 file and wait till it gets completed */
vasanth 0:a540b792fbf0 124 // response = rmp3.playFile("munthi.mp3");
vasanth 0:a540b792fbf0 125 // if (response == RMP3_OK) {
vasanth 0:a540b792fbf0 126 // pc.puts("TRACK 1 started...\r\n");
vasanth 0:a540b792fbf0 127 // rmp3.waitEndOfPlay();
vasanth 0:a540b792fbf0 128 // pc.puts("TRACK 1 ended\r\n");
vasanth 0:a540b792fbf0 129 // }
vasanth 0:a540b792fbf0 130 // sendResponse(response);
vasanth 0:a540b792fbf0 131 // wait(1.0f);
vasanth 0:a540b792fbf0 132 //
vasanth 0:a540b792fbf0 133 //
vasanth 0:a540b792fbf0 134 // /** Play an MP3 file and stop it after 20 seconds */
vasanth 0:a540b792fbf0 135 // response = rmp3.playFile("sempove.mp3");
vasanth 0:a540b792fbf0 136 // pc.puts("TRACK 2 started...\r\n");
vasanth 0:a540b792fbf0 137 // sendResponse(response);
vasanth 0:a540b792fbf0 138 // wait(20.0f);
vasanth 0:a540b792fbf0 139 // response = rmp3.stop();
vasanth 0:a540b792fbf0 140 // pc.puts("TRACK 2 stopped after 20 sec\r\n");
vasanth 0:a540b792fbf0 141 // sendResponse(response);
vasanth 0:a540b792fbf0 142 //
vasanth 0:a540b792fbf0 143 // /// wait before looping again...
vasanth 0:a540b792fbf0 144 // wait(5.0f);
vasanth 0:a540b792fbf0 145 //
vasanth 0:a540b792fbf0 146 // }
vasanth 0:a540b792fbf0 147 //
vasanth 0:a540b792fbf0 148 //}