I wanted to make a program that converted music to midi.
The plan:
- Take in a .wav file as input
- Extract the samples
- Run a FFT (Fast Fourier Transform) on the samples to extract notes
- Generate a midi from those notes
The project was written in nodejs, hosted as an API on my $1.06/mo server. This was my first time doing anything server side, and it was quite fun. The server runs nginx, with this project being hosted as a microservice. I would make a website for the API, but the API is too slow for me to consider making it accessible in any form.
As for the project itself, it was not smooth sailing. I told myself I would never write another program in js after last year, but nodejs was just so alluring with how easy it was to setup a hello world endpoint. Thankfully, node has a deep repository of libraries, so most of the hard part was taken care of.
The result
So the results aren't... good. It's pretty laughable how bad the midis are. The program works best with songs which are very simple, but even then, it's quite flawed.
That said, if you focus hard enough, you can generally hear the source song in the midi.
When I first got midis to generate properly, I found that the songs were much lower pitched than I was expecting. Lower frequencies had much greater magnitudes than I would've expected. I did try to weigh higher frequencies more, but it seems like the songs guaranteed to never be at the right pitch.
Potential improvements for the future
The biggest flaw with the program by far is the fact that it only takes the greatest magnitude frequency, locking it to one note at a time. This completely ignores the fact that songs almost never have just one note at a time, and is the main reason everything sounds so awful. Taking multiple peaks into account would be a much better idea.
Volume control is also something the program lacks right now. All notes are played at the max volume right now since, while I tried varying the volumes between notes, it didn't work well.
Conclusion
Ultimately, this was an incredible learning experience of a project. I got to try server-side development and delve into some cool math concepts, and I got a product which I find to be absolutely hilarious.
Log in or sign up for Devpost to join the conversation.