05-01-2009 11:05 AM
falkpl wrote:You could get fancy, and instead of using beep, you could create waveforms on the fly and feed it to a stream (buffer for audio output). The waveforms would be made from the note frequency and various harmonics with defined decays. There is probably some doccumentation of piano waveforms somewhere.
How would I change the sound from a beep, to sound more like a piano? Could you please explain further?
05-01-2009 11:41 AM
beep is single tome (frequency) true sound form instruments are the sum of numerous harminics on the note and different decays. I was never a good musician, but each instrument will be have unique characteristics on the harmonics and decays, this is why all instruments sound different and not like a synthetic pure tone. using this approach to making each note, you can mix multiple notes into the same waveform for cords and even modulate the overall waveform and decay the amplitude so that note durations fade out after the note is played. This can get very complex, but is probably what electrical pianos are doing.
05-01-2009 12:22 PM
I've just about finished up with Keyboard.VI Version 1.0 ![]()
The last thing that is holding me up is actually getting the files.
The easiest way to get music (besides .mp3) to work with is by downloading 'midi' files.
Somehow, I would need to convert the midi file into something I can actually use.
I would prefer if it was a text file or something easier to work with.
Any ideas?
05-11-2009 12:05 PM
OK, the piano part of the VI seems to be working great, provided I use a txt file as I described earlier.
The most common form of music I can find (that is easily compatible with a computer) is a 'MIDI' file.
Here is a detailed explination of how said file is formatted.
If you scroll to the very bottom of the page, it shows the Event Commands.
I'm thinking I could use 'Match Pattern' to find 'note on' and 'note off' events.
If I read the binary as strings, I can match:
1000****
1001****
for off and on respectively.
I'm assuming 'velocity' is the length of the note.
Does anyone have any advice on a better way to read the note and time?
These files contain MUCH more information about the song than I am looking for, but parsing out the file should enable me to extract only the pieces I am looking for.
another question I had was:
The notes they list are 0-127.
A piano only has 88 keys.
How would I account for the difference in number of notes? Or does a piano not contain all of the listed octaves?
05-11-2009 12:18 PM
Hi Cory
This application is very suitable through MIDI protocol. Everything is already defined and implemented. You just need to find a way to interface LabVIEW with MIDI implementation already in use in most of computer sound cards.
Ricardo
05-11-2009 12:29 PM - edited 05-11-2009 12:30 PM
I'm having a hard time opening a MIDI file in LabVIEW.
What exactly is it? A binary file?
I've tried both 'read text file' and 'read binary file', but get the following error:
And heres what the output looks like:
05-11-2009 12:33 PM
ROtake wrote:
Hi Cory
This application is very suitable through MIDI protocol. Everything is already defined and implemented. You just need to find a way to interface LabVIEW with MIDI implementation already in use in most of computer sound cards.
Ricardo
Hi Ricardo,
Playing the file is more of a secondary goal for this VI.
The primary reason I am creating this VI is to show the keys being pressed on the piano as it is played in real-time.
Once I figure that out, I will worry about playing the file.
05-11-2009 12:54 PM
I'm pretty sure that error is expected - it's telling you that it successfully read to the end of the file, in the same way that it would if you had specified some very large number of bytes to read (which is essentially what you've done by leaving the length input unwired). The file appears to be a binary file. The difference between binary and text files is handling of end-of-line and maybe some other special characters which can be translated when dealing with text but should be left untouched when treated as binary data. I haven't looked at the MIDI spec at all but my guess is that you'll want to create one or more clusters representing the MIDI data in a usable form, then break up the binary data you read from the file into appropriately sized chunks and typecast them to your clusters.
Cory K wrote:I'm having a hard time opening a MIDI file in LabVIEW.
What exactly is it? A binary file?
I've tried both 'read text file' and 'read binary file', but get the following error:
And heres what the output looks like:
05-11-2009 12:59 PM
I don't have much experience working with Binary.
How am I supposed to handle those characters, like the squares?
Is there a way to convert binary to ascii? Then I could figure out what I'm dealing with.
05-11-2009 01:19 PM
Cory,
All the bytes in both displays have already been converted to ASCII. Perhaps you want a display in hex. Or maybe you want to display the non-alphanumeric characters in hex?
Just change the string indicator display format to Hex or to '\' Codes Display. Neither of these changes the underlying data, only how it looks in the indicator.
Lynn