News for hackers. Stuff that matters.
Re:Show HN by earlyriser on Saturday March 29, 2025 @09:10AM (#43515245)
Not sure if you can help me here or someone reading this.

I'm trying to find something to programatically make piano sounds (and record an mp3) based on 2 params midi note and velocity. I'm making a videogame and I need the mp3 piano notes.

I got a free piano sample library, but the sounds start not always at the same microsecond, so I think I need to produce the samples by myself.

Re:Show HN by bartread on Saturday March 29, 2025 @11:46AM (#43516408)
Your computer’s sound card probably has a built-in MIDI library (like general MIDI) that will include a piano as an instrument.

You could use a sequencer (like the one built in to Reaper, which is free) to sequence the notes you need using your sound card as the MIDI device.

You can then export your track as a WAV file and chop it up into individual notes using Audacity. You can then export each individual note as a separate MP3, and load them into your game.

Note that I’m using the word “soundcard” very loosely here: in many cases sound hardware is onboard nowadays. The point is your computer will have sounds you need built in.

You could also take one piano note sample and simply play it at different pitches, but the issue here is it will only sound good within a smallish range of notes - maybe an octave maximum.

Whereas your computer’s sound hardware is likely to have a piano as a wave table instrument that uses multiple or many samples or fragments of samples for each note and will sound better, though possibly still a bit synthetic.

Re:Show HN by epcoa on Saturday March 29, 2025 @04:12PM (#43518303)
> Your computer’s sound card probably has a built-in MIDI library (like general MIDI) that will include a piano as an instrument.

> Note that I’m using the word “soundcard” very loosely here: in many cases sound hardware is onboard nowadays.

Mainstream computers haven't had "soundcards" or any kind of built-in hardware synthesis for many years. What you have for hardware is mostly just a digital to analog converter with some mixing features and possibly some basic DSP functions.

> The point is your computer will have sounds you need built in. > Whereas your computer’s sound hardware is likely to have a piano as a wave table instrument

They're going to be on the hard drive as files and synthesis is entirely in software, from which you have numerous options, including what comes with the OS.

Hardware wave table synthesis as a builtin is long obsolete.

Re:Show HN by squircle on Saturday March 29, 2025 @11:59AM (#43516490)
If your game is web based, toneJS may work for developing a prototype. Using basic wave forms and messing with various filters can produce piano like tones.
Re:Show HN by jstrom on Saturday March 29, 2025 @09:34AM (#43515418)
This paper produces a good result: http://large.stanford.edu/courses/2007/ph210/otey2/. If you game is OK sounding synthetic, I've had good results simulating a string plucked off center, decay each harmonic proportional to the frequency, then adding reverb.

A sound font or VST plug-in with appropriate licenses may be another route, but I can't speak to how difficult that would be to work with. It's on my to-do list.

Re:Show HN by earlyriser on Saturday March 29, 2025 @10:14AM (#43515720)
Yes this looks perfect for what I'm trying to do. Thanks!
Re:Show HN by darepublic on Saturday March 29, 2025 @10:30AM (#43515859)
Can you edit the sound files with ffmpeg to get rid of any empty space before the sound effect?
Re:Show HN by earlyriser on Saturday March 29, 2025 @12:37PM (#43516730)
Yes, I could do that, but I'm not happy also with the quality of the samples and I need to produce more velocities.