Yikai-Liao / symusic

A swift and unified toolkit for symbolic music processing
https://yikai-liao.github.io/symusic/
MIT License
135 stars 9 forks source link

Synthetized song sounds off key when using the FluidR3Mono_GM soundfont #55

Open martinResearch opened 2 weeks ago

martinResearch commented 2 weeks ago

Describe the bug

The rendered notes sound off key when using the FluidR3Mono_GM soundfont.

To Reproduce

pip install symusic==0.5.4 and then

launch the script

import requests
from symusic import Score, Synthesizer, dump_wav
from pathlib import Path

def download_file(url, filename):
    response = requests.get(url)
    with open(filename, "wb") as f:
            f.write(response.content)
def main():
    midi_file = Path(__file__).parent / "1080-c01.mid"
    sf_path = Path(__file__).parent / "FluidR3Mono_GM.sf3"

    url = "http://www.jsbach.net/midi/1080-c01.mid"
    download_file(url, midi_file)

    # https://github.com/musescore/MuseScore/blob/master/share/sound/FluidR3Mono_GM.sf3
    url = "https://github.com/musescore/MuseScore/raw/2.1/share/sound/FluidR3Mono_GM.sf3"

    download_file(url, sf_path)

    score = Score(midi_file)

    synth = Synthesizer(
            sf_path = sf_path,
            sample_rate = 44100, 
        )
    audio = synth.render(score, stereo=True)  
    ouput_file = Path(__file__).parent / "out.wav"
    dump_wav(str(ouput_file), audio, sample_rate=44100, use_int16=True)

if __name__ == "__main__":
    main()

Expected behavior

The songs sounds off key. https://github.com/user-attachments/assets/90fa0642-8e53-471d-9565-af798c71e8f1

Using the default soundfont it sounds better in therm of key, although it seems there is a bit temporal misalignment between the tracks w.r.t the original and it sound a bit messy (not sure I am not a musicians!). https://github.com/user-attachments/assets/142082ec-42a0-4973-8f9d-6faf6e09dc4f

Desktop (please complete the following information):

lzqlzzq commented 2 weeks ago

Synthesize functionality is still experimental and we obeserved more bugs paticularly in windows...... You may use fluidsynth for more stable synthesis. We will have a major refactory for prestosynth maybe in next year and I please gather the problems with one issue: https://github.com/lzqlzzq/prestosynth/issues/1