Spaces:
Running
on
Zero
Running
on
Zero
Update midi_synthesizer.py
Browse files- 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 |
-
|
49 |
-
|
50 |
-
|
|
|
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
|