Quick hack to make NSX-39 (Poke-Miku) USB MIDI device to speak "mbed" from mbed which acts as an USB host.

Dependencies:   FatFileSystem mbed

Fork of MIDI_BlueUSB by Radio Junk Box

Description of the project

This is quick hack to control Poke-miku (NSX-39) from mbed. The mbed acts as an USB host and controls USB MIDI device NSX-39. It speaks "mbed" if you send "s¥n" from virtual USB serial (connected to PC or Mac) or push SW connected to p21. It plays MIDI file "test.mid" on local file-system if you push SW connected to p22. You can find files that I have tested at the bottom. The standard MIDI file support is still preliminary. See TestShell.cpp for the hack. This program is derived from MIDI_BlueUSB (http://mbed.org/users/radiojunkbox/code/MIDI_BlueUSB/) by Radio Junk Box.

ポケミク(NSX-39)を無改造のままmbedから鳴らせるようにしてみました。mbedがUSB hostになって、USB MIDIデバイスのポケミクを鳴らします。mbedのバーチャルシリアル(USBシリアル)にPCからs\nを送るか、p21につないだスイッチを押すとmbedとしゃべります。p22につないだスイッチを押すと、ローカルファイルシステム(.binと同じ場所)に保存した test.mid を再生します。試したファイルは下にある test1.mid と test2.mid です。MIDIファイルのサポートはまだまだ完全とはいえません。

tested MIDI files

Video: Poke-miku speaks `mbed'

Revision:
1:892f8922bdc4
Parent:
0:79620c558b0c
Child:
2:7576d1327cf1
--- a/TestShell.cpp	Fri May 11 10:05:40 2012 +0000
+++ b/TestShell.cpp	Sat Apr 05 06:25:43 2014 +0000
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#include "mbed.h"
 #include "Utils.h"
 #include "USBHost.h"
 #include "hci.h"
@@ -85,6 +86,34 @@
 
 #define WII_REMOTE 0x042500
 
+void NoteOn(u8 ch, u8 note, u8 velocity)
+{
+    static u8 d[64] = {0x09};
+    d[1] = 0x90 | (ch & 0x7f);
+    d[2] = note & 0x7f;
+    d[3] = velocity & 0x7f;
+    USBBulkTransfer(1, 2, d, 4, NULL, NULL);
+}
+
+void NoteOff(u8 ch, u8 note, u8 velocity)
+{
+    static u8 d[64] = {0x08};
+    d[1] = 0x80 | (ch & 0xf);
+    d[2] = note & 0x7f;
+    d[3] = velocity & 0x7f;
+    USBBulkTransfer(1, 2, d, 4, NULL, NULL);
+}
+
+void Miku(u8 chr)
+{
+    static u8 d[64] = {0x04, 0xf0, 0x43, 0x79,
+                       0x04, 0x09, 0x11, 0x0a, 
+                       0x07, 0x00, 0x00, 0xf7};
+    d[10] = chr;
+    USBBulkTransfer(1, 2, d, 12, NULL, NULL);
+}
+
+
 class HIDBluetooth
 {
     int _control;   // Sockets for control (out) and interrupt (in)
@@ -305,6 +334,40 @@
         for(;;)
         {
             const char* cmd = ReadLine();
+            if (strcmp(cmd,"s") == 0) {
+/*
+                static u8 d[64] = {0x09, 0x91, 0x4e, 0x7f};
+                USBBulkTransfer(1, 2, d, 4, NULL, NULL);
+*/
+    Miku(3);
+    wait(0.001);
+    NoteOn(0, 72, 0x7f);
+    wait(0.8);
+    NoteOff(0, 72, 0x7f);
+    wait(0.001);
+ 
+    Miku(124);
+    wait(0.001);
+    NoteOn(0, 74, 0x7f);
+    wait(0.5);
+    NoteOff(0, 74, 0x7f);
+    wait(0.001);
+ 
+    Miku(79);
+    wait(0.001);
+    NoteOn(0, 76, 0x7f);
+    wait(0.5);
+    NoteOff(0, 76, 0x7f);
+
+    wait(0.2);
+
+    Miku(50);
+    wait(0.001);
+    NoteOn(0, 76, 0x7f);
+    wait(0.5);
+    NoteOff(0, 76, 0x7f);
+
+            } else 
             if (strcmp(cmd,"scan") == 0 || strcmp(cmd,"inquiry") == 0)
                 Inquiry();
             else if (strcmp(cmd,"ls") == 0)