Converting Music to MIDI and MIDI to Note Numbers

I’m trying to create a buzzer tone notes generator to NuttX.

During my searches I discovered that PX4 guys already implemented a buzzer tone alarm, but they did in their way (as a C++ driver instead of a standard NuttX C driver) :
https://github.com/PX4/Firmware/blob/master/src/drivers/stm32/tone_alarm/tone_alarm.cpp

They implemented the music notation used on QBasic PLAY command.

You can find the Note Numbers notation here:
http://cs.nyu.edu/courses/fall03/V22.0201-003/notes.htm

In that table we have the frequency, we can double check it here:
http://newt.phys.unsw.edu.au/music/note/

Now we need to convert MIDI to Note Numbers, it helps:
http://www.electronics.dit.ie/staff/tscarff/Music_technology/midi/midi_note_numbers_for_octaves.htm

Then I found that this guy did something similar, but used the values to AVR timer used on Arduino:
https://github.com/LenShustek/miditones

All I need to do is to convert his program to show Note Numbers instead AVR timer values.

To convert Music to MIDI I use WAON program:
https://sourceforge.net/projects/waon/

Update: Just discovered that miditones has a miditones_scroll that does exactly what I want:

$ miditones -b file
$ miditones_scroll -c file

The file.c will be created with the Note Numbers this way:

//duration    time    gen0  gen1  gen2  gen3  gen4  gen5         bytestream code
/*   11       0.000    5F#   6D#                           0000: */ 0x90,0x4E,0x91,0x57,0x00,0x0B,
/*  186       0.011    5F#   6D#   3B    6A    7C#   7F    0006: */ 0x92,0x3B,0x93,0x5D,0x94,0x61,0x95,0x65,0x00,0xBA,
/*   11       0.197    5F#   6D#   3B    6A    7C#         0010: */ 0x85,0x00,0x0B,

Update2: You can find the MIDI format explanation here: http://www.petesqbsite.com/sections/express/issue18/midifilespart1.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s