0

So I am trying to convert a midi file to a bin file, so it can be played using motherboard beeps in a bootloader. Or can you directly play midi files in a bootloader?

I tried using this python script, but it puts out completely empty files: (Usage: Midi2Bin.py [MidiFile] [OutputFile])

import midi, sys

pattern = midi.read_midifile(sys.argv[1])

def pitchconv(pitch):
    return int(round(1193180.0 / (2**((pitch-69)/12.0)*440), 0))

with open(sys.argv[2], "wb") as out:
    pitches = [pitchconv(event.pitch) for event in pattern[1] if isinstance(event, midi.NoteOnEvent)]

    b = 0
    d = 0
    
    t = 0
    o = -1
    for event in pattern[1]:
        if isinstance(event, midi.NoteOnEvent):
            if event.velocity == 0:
                d += int(round(event.tick/48.0, 0))
                p = pitchconv(event.pitch)
                out.write(chr(p & 0xff) + chr(d << 5 | p >> 8))
                b = 0
            else:
                d = int(round(event.tick/48.0, 0))

I have been trying to find a solution for 2 days straight now and I can't find it.

Midi File

Davide_24
  • 67
  • 7
  • 1
    Use any midi player that has file output, e.g. timidity. Anyway, you won't get much quality with the pc speaker. – Jester Feb 15 '22 at 13:59
  • 1
    What format is the bin file supposed to have? Bin is not a file format I am aware of. – fuz Feb 15 '22 at 22:48
  • 1
    Please be more specific about the format you are trying to produce, ideally provide a spec. – Xaser Feb 16 '22 at 23:24

0 Answers0