LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

piano

Solved!
Go to solution
Binary is the raw bits - exactly the way the computer handles information.  You're not trying to handle it on a character-by-character basis; don't think of it that way.  Each character is one byte - 8 bits - but in order for you to get meaningful information out of that file you might need to read 4 bytes and combine them into a 32-bit integer; or maybe you only need to read the first and last 2 bits of each byte and ignore the middle 4, so the way you're displaying the data as text is meaningless, and there's no simple way to convert it to a text representation that would help you.  Instead you need to study the MIDI format, then write code that can read a sequence of bytes and get you the information you need out of it.
Message 21 of 39
(2,454 Views)

nathand wrote:
Binary is the raw bits - exactly the way the computer handles information.  You're not trying to handle it on a character-by-character basis; don't think of it that way.  Each character is one byte - 8 bits - but in order for you to get meaningful information out of that file you might need to read 4 bytes and combine them into a 32-bit integer; or maybe you only need to read the first and last 2 bits of each byte and ignore the middle 4, so the way you're displaying the data as text is meaningless, and there's no simple way to convert it to a text representation that would help you.  Instead you need to study the MIDI format, then write code that can read a sequence of bytes and get you the information you need out of it.

 

So would something like this work?

Read the binary file, each time I see 1000**** or 1001****, add the last 4 bits to an array.

Then I should have an array of  nnvv (as described in the link I posted).

Then I could work with that data.

 

.... or is that easier said than done?

 

Does 'read binary file' read one bit at a time? Or groups of 8 bits (1 byte) at a time?

I ask this because the program may see:

00100000    0******

and not differentiate where the byte starts and ends, thereby seeing 1000000.

 

Or is that not correct?

 

Cory K
0 Kudos
Message 22 of 39
(2,450 Views)

It looks like people have run into this problem before.

Maybe I'll use this tool to convert the MIDI files to Text files.

They have documented how these text file are formatted, so I will see what I can do from here.

Thanks for your continuing help everyone.

Cory K
0 Kudos
Message 23 of 39
(2,441 Views)
Solution
Accepted by Cory_K
You don't have necessarly to work with midi files. You could use a midi interface from your keybard and then "play" the note using dll call functions. Check the links on NI Discussion Foruns about it. http://zone.ni.com/devzone/cda/tut/p/id/6223 Ricardo
RKO
Message 24 of 39
(2,428 Views)

Read Binary File reads in units of bytes at a minimum, but can read larger chunks of data if you wire a larger type to the data type input.

You probably cannot simply search through the file for those two patterns, since you want to make sure that you're only finding those patterns in the sections of the file where they matter.  That is, the same pattern might appear both in a track and in the header; you only want it in the track.

I think you'll find it's easier to write code to parse the MIDI file than to parse a text version of it, because text varies in length and involves a lot of number conversion, whereas the binary format is consistent.  For example, a note frequency will always be the same number of bits in the binary version, but could be 1, 2, or 3 characters in text.  Also, you'll learn a lot from working in binary and dealing with data on the bit level.

0 Kudos
Message 25 of 39
(2,427 Views)

nathand wrote:

Read Binary File reads in units of bytes at a minimum, but can read larger chunks of data if you wire a larger type to the data type input.

You probably cannot simply search through the file for those two patterns, since you want to make sure that you're only finding those patterns in the sections of the file where they matter.  That is, the same pattern might appear both in a track and in the header; you only want it in the track.

I think you'll find it's easier to write code to parse the MIDI file than to parse a text version of it, because text varies in length and involves a lot of number conversion, whereas the binary format is consistent.  For example, a note frequency will always be the same number of bits in the binary version, but could be 1, 2, or 3 characters in text.  Also, you'll learn a lot from working in binary and dealing with data on the bit level.


..... this is gonna be a lot more difficult than I planned in the beginning. OK, well, I am on summer vacation as of last week, so it looks like I'll be spending a lot of time with my good friend LabVIEW Smiley Very Happy
Cory K
0 Kudos
Message 26 of 39
(2,433 Views)

OK, after a lot more toil with binary that I would ever like to experience again, I figured out how to get some usable information out of the MIDI files.

I have successfully gotten the VI to read the file, then play the notes (and chords) according to the timing specified in the MIDI file.

 

I am still having a little trouble playing the sound to accompany the visual.
I have an array of :
Key    Hertz_Value

for each piano key.

 

I use the Beep function, by inputting Hertz and Duration, but it sounds like crap.

 

From a hertz value, does anyone know how I could output a sound that sounds a little more like a piano key?

 

Edit: Wait a minute.... I just read Ricardo's post. I'm going to look into that before I post back again.

Message Edited by Cory K on 06-15-2009 11:18 PM
Cory K
0 Kudos
Message 27 of 39
(2,366 Views)
Aha! Thats exactly what I was looking for.
With any luck, this VI will be done  some time soon.

.... and to think that I started this VI months ago as a favor Smiley Very Happy
Cory K
0 Kudos
Message 28 of 39
(2,363 Views)

I cant figure out why this VI isnt outputting any sound.

I know it worked at one point, because I heard something resembling a piano.

... then I messed with it, and it stopped Smiley Sad

 

All I did was connect the controls on 'Top-Level.vi' to connectors.
I wired in values for: wait (ms), note, volume, MIDI device.

For some reason, after I did that, it doesnt want to work any more.

Cory K
0 Kudos
Message 29 of 39
(2,339 Views)
Works fine for me if I set MIDI device to 0.  Looks like for some reason you set it to 1 and that broke it?
0 Kudos
Message 30 of 39
(2,336 Views)