bradhowes / SoundFonts

Powerful polyphonic synthesizer for iOS that relies on sound fonts for generating audio - https://bradhowes.github.io/SoundFonts/
MIT License
76 stars 9 forks source link

SF2 sounds different across apps #4

Closed benwiley4000 closed 1 year ago

benwiley4000 commented 2 years ago

First of all, thanks! This is a very cool app, great to be able to play sf2 files on the iPad.

I've noticed that if I compare the sound of a soundfont instrument across LMMS versus SoundFonts for iPad, it's noticeably different. My best guess would be some kind of low pass filter applied to the SoundFonts for iPad version, but it's hard to say exactly. Maybe it's just a lower default velocity for this app? Or maybe something more fundamental?

Here is the Soundfont. I'm using the instrument SK MHZ1 Brass. https://musical-artifacts.com/artifacts/1366

And here is a low quality video showing the difference between the two sounds.

https://user-images.githubusercontent.com/13558253/177812100-f2f0eea8-575f-49d3-b347-a7b61ffbc086.mp4

It's difficult for me to say which one is "correct". However if you watch this gameplay video that uses the original Megadrive sound you can hear that the polyphonic brass sound matches the LMMS playback more closely.

https://www.youtube.com/watch?v=3BguOvOrfBY

bradhowes commented 2 years ago

Hi Ben. Thanks for the query. I do not know LMMS and what it is based on, but I would not be surprised if it is using the high-quality FluidSynth library to perform the rendering. They have a reputation for very high fidelity to the SoundFont spec. For my app, it is currently relying on an Apple implementation known as AVAudoUnitSampler which is available on iOS and macOS. However, I do not have any information about how accurate their implementation of the SoundFont spec is.

My long-term plans are to move away from Apple's AVAudioUnitSampler and use my own SF2Lib library with the goal of having rendering quality as good as FluidSynth. Unfortunately, work has been slow in this migration due to other commitments.

That said, you might be able to improve on the audio output by using GarageBand to host SoundFonts AUv3 plugin. That way you can add additional filters.

benwiley4000 commented 2 years ago

Is there anything I could do to help? I'm not making a long term commitment but if the work could be broken down into smaller tasks that I might be able to handle, I'd be interested to know. I'm starting to learn Swift but I have good experience in other languages like Javascript, Python and C++. Looking to work in Swift more!

bradhowes commented 2 years ago

Thanks for the offer. I am more than happy to have other contribute, but I must warn you that it is not easy and right now there is very little documentation to help out. That said, the basics are in place and there is a configuration option to enable the use of the SF2Lib for rendering. To start:

The build will use Swift packages for the SF2Lib and AUv3Support dependencies. This is OK, but it is cumbersome to work with Swift packages that way. Instead, I usually switch to a local package so I can edit it in the same project as the SoundFonts code. This is a pain to set up because it requires removing the existing SF2Lib dependency and adding it back as a local repository. I don't have a document detailing what I do for that but I can put something together over the weekend if that interests you.

The SF2Lib has unit tests and will generate audio for them if you set the right flags in its Package.swift file (I just checked and it is currently enabled to do so by default). This could be one avenue to test out how well the library is rendering audio: add your SK MHZ1 Brass SF2 file to the build and run a test to generate output to hear how it sounds.

Currently, the SF2 library does not perform any filtering that is required in the SF2 spec. This includes the low-pass filter and the chorus effect. My rationale for omitting those is that there are existing options / plugins to do those kinds of things so implementing it in code was not a priority. However, it might make sense to embed such processing inline to better conform to the spec. There are bits of code in SoundFonts to support a chorus effect, but it is not functional yet.

benwiley4000 commented 2 years ago

Thanks so much for the information! I will try to clone the project this week and see if I can get somewhere.

Just one more question, what do you see as "TODO" before you switch in the released version to using SF2Lib (not including the unimplemented filters you already mentioned)?

bradhowes commented 2 years ago

Really, just lots of testing and bug fixing. As I mentioned, the rendering engine seems to be working so far as it generates audio without glitching, but I've only tested with a piano font so there could be plenty of cases that are not working correctly, including parameters settings (called generators in the SF2 spec) that are not working per spec. The SF2Lib code does have in-line documentation and there are various directory README files that should be fairly accurate.

benwiley4000 commented 2 years ago

Ok thanks! Sorry I just saw your message. I will take a look later today if I have time. Thanks for the info.

Ben

Le jeu. 7 juill. 2022, 4 h 53 p.m., Brad Howes @.***> a écrit :

Really, just lots of testing and bug fixing. As I mentioned, the rendering engine seems to be working so far as it generates audio without glitching, but I've only tested with a piano font so there could be plenty of cases that are not working correctly, including parameters settings (called generators in the SF2 spec) that are not working per spec. The SF2Lib code does have in-line documentation and there are various directory README files that should be fairly accurate.

— Reply to this email directly, view it on GitHub https://github.com/bradhowes/SoundFonts/issues/4#issuecomment-1178215651, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADHOD3MV2LTDMEMAWWHP3ITVS47V7ANCNFSM5253FCUA . You are receiving this because you authored the thread.Message ID: @.***>