Monday, March 1, 2010

The soft side of firmware

Hey Guys!

Its me again, and today I am going to tell you how the firmware for our E-Oc will work! The design behind the E-Oc software for our prototype will be pretty straight forward guys, one of the biggest features people have shouted for is configurable fingering! Which I plan to support so lets talk about that now.

So, users will be able to configure their E-Oc to have diffrent button configurations play different notes. What happens when a user presses a button, is it causes two pins of our micro controller to go "hot" which means there is voltage flowing through them, this is called an "input"

We can get "input" states in code, normally as a 1, which means "on" or a 0 which means "off", so each time a button gets pressed we get that pins input state and save it to a matrix in its own little place.... Wait, you don't know what a matrix is... no.. im not neo.. I will explain.

A matrix is a group of numbers, for instance
[0,0,0,0]
[1,1,0,0]
[1,1,0,0]

Thats a visual representation, of a matrix. So on a 12 hole Oc we would have 12 places in our matrix. Ohh Its starting to come together now is it not?

So what happens is when a button is pressed it sets that buttons place in the matrix to a 1. So for instance if a user was playing a C then the matrix would look like this.

[1,1,1,1]
[1,1,1,1]
[1,1,0,0]

Which would mean that all the buttons besides the sub holes where held down. Lol, im kind of new to the Oc, so I am not sure if the sub holes are used in the tonic.. but yeah.

So what happens then is every millisecond (1000th of a second) we check the matrix to see what buttons are pressed and play the correct note for the buttons pressed.

So changing out what note is played will be as simple as changing what the matrix has to look like to play each note. Of course you guys will get a nice little windows program to point and click your way through it, but what will be happening behind the scenes is that we will just be placing a text file on the E-Oc that will look something like this...

[1,1,1,1]
[1,1,1,1] = C
[1,1,0,0]

[1,1,1,1]
[1,1,1,1] = D
[1,0,0,0]

Its a little different then that when we program but thats a good visual of it.

So thats the basics of how fingering and playing the note will work software side, pretty simple hey?

So now lets talk about blowing, the air sensor we picked out plugs into our micro controller just like our buttons, but when it senses air instead of giving a 0 or 1, it returns a decimal depending on the amount of air.

So .00 would be no air flow at all, and .99 would be like blowing as hard as you can in the E-Oc, so in code we just set the return of our air sensor to the volume of our stereo chip, every millisecound as well.

That sets our volume to our breath pressure, there of course will need to be a bit of calibration in testing, cause you don't want the volume to go up and down like crazy when your trying to blow constantly, but with a little bit of testing I am sure we can get something nice!


Theres other code, for other things like on and off switches, and system stuff, but thats really technical and I won't bore with the nerdyness haha!

So guys, I know that this was a long read, with lots of boring stuff, but I hope you enjoyed it!

Thanks again, and don't forget to comment!

3 comments:

  1. I'm no programmer, but out of curiosity: What would be the downside of an approach where you keep the last known matrix in memory, and use that until you get input that another button has been pushed?

    Or is that why we have to keep scanning the state of the buttons - because pushing a button does not fire any kind of event, it just changes the button state?

    ReplyDelete
  2. Right!

    We have to keep scanning to get a "snap shot" of the button states every millisecound, buttons dont "fire events" like they do in programming languages like VB.net.

    Because there are times where a button is used as a mechanical means as well, like to switch a light on.

    plus if each button fired its own event, that would get kind of hectic based on the nature of the ocarina things go get way out of wack lol

    ReplyDelete
  3. I'm excited that you've started work on this! I'm also very interested in how you're programing it because I've actually done some micro-controller programming myself, and it sounds like a fun project! I've never worked with sound though, so I want to know how it works.

    Are you by any chance programming it in C and using MPLab IDE?

    ReplyDelete