0

How to write a code to make piano??

Make piano

7th Feb 2021, 9:04 PM
Sujan Sherpa
Sujan Sherpa - avatar
2 odpowiedzi
+ 4
You want to make something like: https://virtualpiano.net/ ? I made a very basic piano in QuickBasic that simply played a specific pitch for a short time interval where each key corresponded with a different pitch. I didn't support multiple pitches at the same time. This much is fairly simple in most programming languages. To play a specific frequency in JavaScript is explained here with an example playing part of the Star Wars theme: https://stackoverflow.com/questions/39200994/how-to-play-a-specific-frequency-with-javascript If you use JavaScript, some libraries like this could help make a realistic piano sound: https://keithwhor.com/music/ Every device that can play a midi file can synthesize various instruments so there might be a way to tap into that functionality. The .mid or MIDI file format is essentially musical notes for multiple instruments synthesized in parallel. MIDI is to music what SVG is to graphics in that MIDI is high-level instructions on how to play something instead of describing every millisecond of wave form. I'm not sure how you'd go far beyond the basics with audio, though. You could use separate recordings for each key to get a very realistic piano key sound. I'm not sure how you'd simulate the sound of holding the piano key down. You'd want to also play multiple pitches together if multiple keys are hit at a time. If I was making something like that now using JavaScript, I would definitely listen for touch events( touchstart, touchend...) so people could play it with multitouch on a touch screen in addition to listening to keyboard events. Making the keys clickable in a simulated piano image would be much easier than simulating the piano's audio realistically.
7th Feb 2021, 10:15 PM
Josh Greig
Josh Greig - avatar
0
If you think the other answer really answers your question, please hit the checkmark to indicate that.
27th Feb 2021, 7:30 AM
Josh Greig
Josh Greig - avatar