skytnt commited on
Commit
5b21cca
1 Parent(s): b5d92aa

Update midi_synthesizer.py

Browse files
Files changed (1) hide show
  1. midi_synthesizer.py +4 -3
midi_synthesizer.py CHANGED
@@ -45,9 +45,10 @@ def synthesis(midi_opus, soundfont_path, sample_rate=44100):
45
  synthesized = np.zeros((max([w.shape[0] for w in waveforms]), 2), dtype=np.int32)
46
  for waveform in waveforms:
47
  synthesized[:waveform.shape[0]] += waveform
48
- max_val = np.abs(synthesized).max()
49
- if max_val != 0:
50
- synthesized = (synthesized / max_val) * np.iinfo(np.int16).max
 
51
  synthesized = synthesized.astype(np.int16)
52
 
53
  return synthesized
 
45
  synthesized = np.zeros((max([w.shape[0] for w in waveforms]), 2), dtype=np.int32)
46
  for waveform in waveforms:
47
  synthesized[:waveform.shape[0]] += waveform
48
+ if synthesized.shape[0] > 0:
49
+ max_val = np.abs(synthesized).max()
50
+ if max_val != 0:
51
+ synthesized = (synthesized / max_val) * np.iinfo(np.int16).max
52
  synthesized = synthesized.astype(np.int16)
53
 
54
  return synthesized