ssb22 / midi-beeper

MIDI Beeper
http://ssb22.user.srcf.net/mwrhome/midi-beeper.html
Apache License 2.0
10 stars 0 forks source link

OverFlowError when playing specific MIDI file #1

Closed Robotition closed 6 months ago

Robotition commented 7 months ago

This is the output I get from playing this MIDI file:

Parsing MIDI file BeatIt.mid
Traceback (most recent call last):
  File "/home/luka/Downloads/midi-beeper.py", line 829, in <module>
    MidiInFile(MidiToBeep(), midiFile).read()
  File "/home/luka/Downloads/midi-beeper.py", line 802, in read
    p.parseMTrkChunks()
  File "/home/luka/Downloads/midi-beeper.py", line 794, in parseMTrkChunks
    self.dispatch.eof()
  File "/home/luka/Downloads/midi-beeper.py", line 711, in eof
    self.outstream.eof()
  File "/home/luka/Downloads/midi-beeper.py", line 663, in eof
    dedup_midi_note_chord(list(d.keys()),minLen)
  File "/home/luka/Downloads/midi-beeper.py", line 445, in dedup_midi_note_chord
    add_midi_note_chord(dedup_chord,dedup_microsec)
  File "/home/luka/Downloads/midi-beeper.py", line 372, in add_midi_note_chord
    cumulative_params.append(chord(list(map(to_freq,noteNos)),millisecs))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/luka/Downloads/midi-beeper.py", line 455, in to_freq
    else: return (A/32.0)*math.pow(2,(n-9)/12.0)
                          ^^^^^^^^^^^^^^^^^^^^^^
OverflowError: math range error
ssb22 commented 7 months ago

Thanks for reporting. I think the root cause is we're interpreting pitch-bend wrongly: the high_nibble == 0xE0 block appears to get the MSB and LSB switched around, and pitch_bend() ran off of the LSB (which was actually the MSB), and this worked only if the actual LSB was 0, which it will be if the MIDI was generated by a music program slurring to another note (like the ones I used for testing), but if someone comes along with a synth that has a super-accurate analogue pitch-bend sensor it could add bits to the other byte and throw us off. That would result in just a wrong note (not a crash) if it weren't for the pitch-bend range being set so high: the wrong data made us try to pitch-bend by thousands of octaves, which would take us way above the Planck frequency i.e. even the Big Bang couldn't provide enough energy to play that note.

Replacing stream.pitch_bend(channel, value) with stream.pitch_bend(channel, data[1]) should fix it; I'll get a patch in later.

Also, I think the MIDI Registered Parameter Numbers (RPNs) are controllers 100 and 101, not 64 and 65, so continuous_controller seems wrong there as well but I'll double check.