1

I have got one midi file, converted it into binary

Know i want to make a mp3 using that binary how can i do it.

i am using php as my scripting language

here is my code using which i am converting midi to binary

$filename = "flute.mid";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
for ($i = 0; $i < strlen($contents); $i++) {
$binary = sprintf("%08d", base_convert(ord($contents[$i]), 10, 2));
echo $binary;
}
fclose($handle);
lostTiger
  • 82
  • 2
  • 4

2 Answers2

1

Besides the conversion to ASCII-encoded binary which is useless and would only make the things much more complicated (I don't know any program that can read this format), MIDI contains events (musical notes, instruments, etc.), whereas MP3 files contain compressed sampled sound. To convert MIDI to MP3 you therefore need to use a synthesizer to generate sampled sound from the MIDI source, and then to compress the sampled audio data into MP3 format.

To synthesize MIDI to audio you can look for example at something like Timidity++ (http://timidity.sourceforge.net/). To compress the audio to MP3 you can use for example LAME (http://lame.sourceforge.net/). Both programs can be found as installable packages on many Linux distributions (on Ubuntu, package names are timidity and lame; both are in the Universe package repository).

Ale
  • 1,727
  • 14
  • 26
  • ok it would be very time consuming and complicated, my only concern is to play midi online i have created an embed player it is working on mozilla and explorer but it is not working on chrome please follow the link http://stackoverflow.com/questions/16272409/play-midi-files-using-chrome – lostTiger Apr 29 '13 at 08:44
  • if your aim is only to play the MIDI inside a web page, you can use for example a Flash or HTML5 MIDI player (e.g., http://code.google.com/p/flash-midi-player/ or http://mudcu.be/midi-js/). The one you have uses Windows Media Player, therefore it will only work for some users, not for everybody. – Ale Apr 29 '13 at 08:48
  • Ale i am using midi-js for playing midi files it is working on browser, but when i tried to play it using mobile phone it is not working – lostTiger Apr 30 '13 at 07:52
  • Probably the mobile phone lacks some HTML5 support. What mobile was it? Did you check what parts of HTML5 the mobile actually implements? It might be that it has no HTML5 sound support... and never forget that having something working on every platform is a though job! – Ale Apr 30 '13 at 16:16
1

See first thing you are converting MIDI into Binary. Second thing you are trying to convert it directly to mp3.

This thing is not possible in this way. Mp3 is Encoded Compressed format it can't be created in such a way. Even sometime try to open a mp3 in Notepad & then without making any change Save As it with new name by putting .mp3 at the end. The file with mp3 extension having same data as original will be created but it will not played by player.

So my point is that you have to research an encoding method to convert MIDI in mp3.

Nicolazinho
  • 175
  • 4
  • 13
Mrug
  • 4,963
  • 2
  • 31
  • 53