Big Mouth Billy Bass player that takes raw wavefiles and decision list text files from an SD card

Dependencies:   SDFileSystem mbed BillyBass

Files at this revision

API Documentation at this revision

Comitter:
bikeNomad
Date:
Wed Jun 19 16:12:36 2013 +0000
Parent:
12:1206e56712d8
Child:
14:79b3fd23c7b5
Commit message:
added second bass; moved config.; works though outputs may be wrongly connected on my board

Changed in this revision

BillyBass.lib Show annotated file Show diff for this revision Revisions of this file
config.hpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/BillyBass.lib	Tue Jun 18 14:10:40 2013 +0000
+++ b/BillyBass.lib	Wed Jun 19 16:12:36 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/bikeNomad/code/BillyBass/#f009306756b3
+http://mbed.org/users/bikeNomad/code/BillyBass/#869b3711bdb3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config.hpp	Wed Jun 19 16:12:36 2013 +0000
@@ -0,0 +1,69 @@
+#ifndef __included_config_hpp
+#define __included_config_hpp
+
+// configuration for Billy Bass
+#define MAX_FISH 2
+
+// SD card layout: all files in BASS_DIRECTORY ("/sd/SD_Files/")
+//
+// Each pair of files in that directory are named like:
+//      "<seqnum>_<fishnum>_filename.raw"   (16-bit mono raw little-endian samples, sample rate=SAMPLE_RATE_HZ)
+// and
+//      "<seqnum>_<fishnum>_filename.txt"   (tab-separated text file with starttime,endtime,<mouth|head|body|tail>
+// text files are as exported from Audacity's label tracks
+//
+#define SD_NAME "sd"
+#define SD_ROOT "/" SD_NAME
+#define BASS_DIRECTORY SD_ROOT "/SD_Files"
+// length of BASS_DIRECTORY without NUL
+#define BASS_DIRECTORY_LENGTH 12
+#define MAX_BASENAME_LENGTH 30
+#define MAX_PATH_LEN \
+        BASS_DIRECTORY_LENGTH + 1 \
+        + MAX_BASENAME_LENGTH + 1
+
+// limits of .txt files
+#define MAX_ACTIONS_LINES_PER_SONG 60
+#define MAX_ACTIONS_PER_SONG MAX_ACTIONS_LINES_PER_SONG*2
+#define MAX_TEXT_FILE_LENGTH 2048
+
+// Sample configuration
+typedef int16_t Sample_t;   // 16-bit raw, LE samples
+const float SAMPLE_RATE_HZ = 8000.0;
+const unsigned SAMPLE_PERIOD_USEC = (unsigned)(1.0e6/SAMPLE_RATE_HZ);
+
+// Player configuration
+const size_t BUFFER_SIZE = 512;
+const size_t SAMPLES_PER_BUFFER = BUFFER_SIZE / sizeof(Sample_t);
+const float SECONDS_PER_CHUNK = SAMPLES_PER_BUFFER / SAMPLE_RATE_HZ;
+
+#define SERIAL_BAUD 115200
+#define ANALOG_OUTPUT_BIAS  0x8000
+
+
+// Power:
+// Power GND  J9/14
+// Vin (6V)   J9/16
+
+// I/O configuration
+#define BASS1_TAIL  PTB0   /* J10/2 */
+#define BASS1_MOUTH PTB1   /* J10/4 */
+#define BASS1_BODY  PTB2   /* J10/6 */
+#define BASS1_BUTTON PTD5  /* J2/4 */
+
+#define BASS2_TAIL  PTB3  /* J10/8 */
+#define BASS2_MOUTH PTC2  /* J10/10 */
+#define BASS2_BODY  PTC1  /* J10/12 */
+#define BASS2_BUTTON PTA13 /* J3/2 */
+
+// SD Card (3.3V)
+// PTD0 J2/6 D10 - Used for CS of SPI
+// PTD2 J2/8 D11 - Used for MOSI of SPI
+// PTD3 J2/10 D12 - Used for MISO of SPI
+// PTC5 J1/9  Used for SCLK of SPI (must solder if using shield)
+#define SD_MOSI PTD2
+#define SD_MISO PTD3
+#define SD_SCLK PTC5
+#define SD_CS   PTD0
+
+#endif
--- a/main.cpp	Tue Jun 18 14:10:40 2013 +0000
+++ b/main.cpp	Wed Jun 19 16:12:36 2013 +0000
@@ -4,64 +4,31 @@
 #include "player.hpp"
 #include "action.hpp"
 
-// Power:
-// Power GND  J9/14
-// Vin (6V)   J9/16
+//                 tailPin,  mouthPin, bodyPin   inverted
+// BillyBass testBass(LED_RED, LED_GREEN, LED_BLUE, true);
 
-//                 tailPin,  mouthPin, bodyPin   inverted
-BillyBass testBass(LED_RED, LED_GREEN, LED_BLUE, true);
-
-//               tailPin, mouthPin, bodyPin
-//                  J3/2,  J3/1, J3/3
-BillyBass realBass(PTA13, PTC12, PTC13);
-
-DigitalIn pushbutton(PTD5); // J3/4
+//                 tailPin,        mouthPin,      bodyPin
+BillyBass bass1(BASS1_TAIL,     BASS1_MOUTH,   BASS1_BODY);
+//                 tailPin,        mouthPin,      bodyPin
+BillyBass bass2(BASS2_TAIL,     BASS2_MOUTH,   BASS2_BODY);
+DigitalIn button1(BASS1_BUTTON);    // J3/4
+DigitalIn button2(BASS2_BUTTON);   // J3/2
 
 // Analog:
 // GND   J3/14
 // VrefH J3/16
 AnalogOut speaker(PTE30);              // J10/11
 
-// PTD0 D10 - Used for CS of SPI
-// PTD2 D11 - Used for MOSI of SPI
-// PTD3 D12 - Used for MISO of SPI
-// PTC5 J1/9  Used for SCLK of SPI
-
-//              MOSI, MISO, SCLK,   CS, name
-SDFileSystem sd(PTD2, PTD3, PTC5, PTD0, SD_NAME);
-
+//                 MOSI,    MISO,    SCLK,    CS, name
+SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCLK, SD_CS, SD_NAME);
 Serial pc(USBTX, USBRX);
 
-static void biggestAllocation()
-{
-    size_t blksize = 16384;
-    char *m;
-
-    while (blksize > 0 && (m = (char *)malloc(blksize)) == 0) {
-        blksize -= 1024;
-    }
-
-    char *heaptop = m + blksize;
-    fprintf(stderr, "biggest: %u, heaptop: %p, current SP: %p, room: %u\r\n",
-            blksize,
-            heaptop,
-            __current_sp(),
-            (char *)__current_sp() - heaptop);
-
-    free(m);
-}
-
-static void dumpHeap()
-{
-    biggestAllocation();
-    __heapstats((__heapprt)fprintf,stderr);
-    __heapvalid((__heapprt)fprintf,stderr, 0);
-}
-
 int main()
 {
     SongPlayer player;
     pc.baud(SERIAL_BAUD);
+    button1.mode(PullUp);
+    button2.mode(PullUp);
 
     fprintf(stderr, "*** REBOOT ***\r\n");
 
@@ -77,13 +44,14 @@
     while (dirent *d = readdir(bassDir)) {
         Song *song = Song::newSong(d->d_name);
         if (song) {
-            pc.printf("Playing %s\r\n", song->getSampleFileName());
+            fprintf(stderr, "Waiting to play %s\r\n", song->getSampleFileName());
+            while (!(!button1 || !button2))
+                wait(0.1);
             player.playEntireSong(song);
-            pc.printf("total length: %f done: %u\r\n", player.timeInSong, player.actionsDone);
+            fprintf(stderr, "total length: %f done: %u\r\n", player.timeInSong, player.actionsDone);
         }
     }
-
     closedir(bassDir);
-    pc.printf("Done.\r\n");
+    fprintf(stderr, "Done.\r\n");
 }