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'

Committer:
non
Date:
Tue Apr 29 06:01:52 2014 +0000
Revision:
4:cd0d8ce967d8
Parent:
0:79620c558b0c
Fix issues when it plays a MIDI file which has multi tracks.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
radiojunkbox 0:79620c558b0c 1
radiojunkbox 0:79620c558b0c 2
radiojunkbox 0:79620c558b0c 3 #include "mbed.h"
radiojunkbox 0:79620c558b0c 4 #include "Utils.h"
radiojunkbox 0:79620c558b0c 5
radiojunkbox 0:79620c558b0c 6 void printfBytes(const char* s, const u8* data, int len)
radiojunkbox 0:79620c558b0c 7 {
radiojunkbox 0:79620c558b0c 8 printf("%s %d:",s,len);
radiojunkbox 0:79620c558b0c 9 if (len > 256)
radiojunkbox 0:79620c558b0c 10 len = 256;
radiojunkbox 0:79620c558b0c 11 while (len-- > 0)
radiojunkbox 0:79620c558b0c 12 printf(" %02X",*data++);
radiojunkbox 0:79620c558b0c 13 printf("\n");
radiojunkbox 0:79620c558b0c 14 }
radiojunkbox 0:79620c558b0c 15
radiojunkbox 0:79620c558b0c 16 void printHexLine(const u8* d, int addr, int len)
radiojunkbox 0:79620c558b0c 17 {
radiojunkbox 0:79620c558b0c 18 printf("%04X ",addr);
radiojunkbox 0:79620c558b0c 19 int i;
radiojunkbox 0:79620c558b0c 20 for (i = 0; i < len; i++)
radiojunkbox 0:79620c558b0c 21 printf("%02X ",d[i]);
radiojunkbox 0:79620c558b0c 22 for (;i < 16; i++)
radiojunkbox 0:79620c558b0c 23 printf(" ");
radiojunkbox 0:79620c558b0c 24 char s[16+1];
radiojunkbox 0:79620c558b0c 25 memset(s,0,sizeof(s));
radiojunkbox 0:79620c558b0c 26 for (i = 0; i < len; i++)
radiojunkbox 0:79620c558b0c 27 {
radiojunkbox 0:79620c558b0c 28 int c = d[i];
radiojunkbox 0:79620c558b0c 29 if (c < 0x20 || c > 0x7E)
radiojunkbox 0:79620c558b0c 30 c = '.';
radiojunkbox 0:79620c558b0c 31 s[i] = c;
radiojunkbox 0:79620c558b0c 32 }
radiojunkbox 0:79620c558b0c 33 printf("%s\n",s);
radiojunkbox 0:79620c558b0c 34 }
radiojunkbox 0:79620c558b0c 35
radiojunkbox 0:79620c558b0c 36 void printHex(const u8* d, int len)
radiojunkbox 0:79620c558b0c 37 {
radiojunkbox 0:79620c558b0c 38 int addr = 0;
radiojunkbox 0:79620c558b0c 39 while (len)
radiojunkbox 0:79620c558b0c 40 {
radiojunkbox 0:79620c558b0c 41 int count = len;
radiojunkbox 0:79620c558b0c 42 if (count > 16)
radiojunkbox 0:79620c558b0c 43 count = 16;
radiojunkbox 0:79620c558b0c 44 printHexLine(d+addr,addr,count);
radiojunkbox 0:79620c558b0c 45 addr += 16;
radiojunkbox 0:79620c558b0c 46 len -= count;
radiojunkbox 0:79620c558b0c 47 }
radiojunkbox 0:79620c558b0c 48 }