Giter VIP home page Giter VIP logo

Comments (20)

schellingb avatar schellingb commented on May 30, 2024 4

@mmontag Controlling low pass filter by velocity is done using modulators which we unfortunately don't support at the moment. According to the spec there are default modulator rules regarding 'MIDI Note-On Velocity to Filter Cutoff' which might be easier to implement than full modulator support but I'm not sure if that alone would make your instrument sound nice.

Speaking of the overall synth quality, a few months ago I was pointed to the article Using SoundFonts in 2016 by S. Christian Collins which contains a test that checks a synth's compliance with the official SoundFont specification. A special MIDI file with a special SF2 file can be downloaded with the 'run the tests yourself' link on that article. We're.... doing ok I think? Overall not awesome but it seems no synth is perfect.

image

This image shows the stereo wave spectrum of the 'correct' recording included in the test on the top and the rendered result by TSF.

  • Test 7 "Mod wheel to LFO" we seem to do wrong, this might be an easy fix.
  • Test 12, 13, 14, 19 b and c are using modulators which we don't have and would need quite a lot of code to implement.
  • Test 16 and 17 use reverb and chorus which we don't have but implementation should be much easier than modulators.
  • Test 18 makes our simple linear sample interpolation hearable (but it's not too bad).

Btw. I'm not sure why the correct recording shows so much purple after the reverb test started but somehow some small noise remains until the end (maybe because of the ogg compression?).

from tinysoundfont.

schellingb avatar schellingb commented on May 30, 2024 3

Hi there!

It's a very good question (-:
So let's divide the answer into three parts.
SoundFont2 support, MIDI loading and MIDI playback.

SoundFont2 support:
As mentioned in the NOT YET IMPLEMENTED on top of tsf.h, we are missing support for ChorusEffectsSend and ReverbEffectsSend generators and support for modulators. Both are described in the SF2 specs. Modulators seem a daunting task to implement and not used by many sound fonts I encountered. The chorus and reverb would be nice to have, not sure if these are widely used either.

MIDI loading:
tml is very bare bones, but so is MIDI itself. It is a one way loading with no editing features. It converts all timing to milliseconds and throws away the more exact timing, track information (just keeps channel numbers), sysex (device specific) messages and meta data (strings like titles, tracknames, lyrics). I wanted to add support for getting the meta data but it is not finished yet.

MIDI playback:
Besides regular instrument selection, note on and off, we do have support for pitchwheel, pan and volume messages. Which are the most common ones. I think the biggest missing thing is support for switches like sustain, portamento, sostenuto, soft pedal and legato. I have not evaluated how hard implementation of these would be.

I think for various usage scenarios it can very well be replacing Fluidsynth. It certainly has done that for me. But if you want to have a generic MIDI player, you won't be able to make a perfectly accurate (as much as possible for MIDI anyway) one with TinySoundFont at this point.

IMHO certainly size (bloat, overhead, library requirements) and license (MIT/zlib) are good arguments for it. What kind of project would you like to use it for or what features do you think would be essential?

from tinysoundfont.

schellingb avatar schellingb commented on May 30, 2024 3

Hi again.
Thank you so much for the praise, it really is thanks to your testing though! :-)

Strange sounds indeed! That was a lucky catch with your custom sound font defining presets on the bank 128 and that MIDI file only sending a single bank select message (MSB) and not a pair (MSB+LSB) which needs to be handled differently.

I also ended up tweaking the handling of MIDI channel volume and expression events a bit but I have no idea what would be the "correct" way. At least BassMIDI has some kind of volume curve I think but nothing definitive I could find about it.

Give it another test with the updated player still at https://schellingb.github.io/TinySoundFont/CustomSoundFont.html

Thanks!!

from tinysoundfont.

porres avatar porres commented on May 30, 2024 1

what about microtonal capabilities? you can specify any set of frequencies for all keys in fluidsynth

from tinysoundfont.

RyanBram avatar RyanBram commented on May 30, 2024

Hi.
Thank you for the very clear explanation.

I am not a real programmer. I create my game with tools such as RPG Maker MV or GDevelops. Both of them are HTML5 based program. For desktop game, I use nwjs to launch the game, but I really miss MIDI support which previously available in old version of RPG Maker (maybe for the sake of web compatibility). Your library looks lightweight and portable enough to be integrated in FFMPEG library shipped with nwjs, so I think I can just commission someone to compile custom version of FFMPEG integrated with your library or maybe converting your library to asm.js for MIDI support in my HTML5 game.

I don't know what I will be miss from your library as there is no commandline player to test my MIDI music and soundfont with your library.

And you are right, your MIDI library is the only non-copyleft open source library I ever know. Fluidsynth, Timidity++, and WildMIDI are under LGPL or GPL.

Best regards,
RyanBram

from tinysoundfont.

schellingb avatar schellingb commented on May 30, 2024

Hi again

I hacked together a web MIDI player using TinySoundFont, TinyMidiLoader and my ZillaLib multimedia framework which compiles to a bunch of platforms, one being HTML with Asm.js.

You can check it here:
https://schellingb.github.io/TinySoundFont/CustomSoundFont.html

It sounds fine in Firefox, but in Chrome it added weird crackling noises during playback on my machine. Ahh webaudio, the bane of my existence.

from tinysoundfont.

RyanBram avatar RyanBram commented on May 30, 2024

Hi. Thanks for letting me try your software.
It is amazed to know that TinySoundFont can works in HTML5 too. Although most MIDI files can be played fairly well, but I found a song is played too different.
If you don't mind, I attached the MIDI file, the SF2 and the pre-rendered of expected result here.
Music.zip

Thanks.

from tinysoundfont.

schellingb avatar schellingb commented on May 30, 2024

Thank you for that great test case!

I fixed and improved some parts and we are now much closer.
We still lack support for chorus and reverb effects which would make this MIDI sound better for sure.

What do you think?
Updated player still at https://schellingb.github.io/TinySoundFont/CustomSoundFont.html

from tinysoundfont.

RyanBram avatar RyanBram commented on May 30, 2024

Hi.
I am really really glad when reading this pretty good news.

I have tried some of my MIDI collections and I am very happy most of them already played pretty much improved compared to previous version. But I found at least 3 issues, just to let you know:

  1. The first 30 seconds in MIDI file attached in my previous message still has issue in
    Polysynth sound, but the rest of it sounds really improved;
  2. The following
    MIDI file doesn't produce Drum sound at second 19;
  3. A sound or noise won't stop when switching this MIDI file
    MIDI file with other MIDI file during playback.

From me myself, the absent of Chorus and Reverb isn't a big issue compared to above issues, but surely Chorus and Reverb would be a very nice to have features. (^_^)

Best regards,
Ryan

from tinysoundfont.

schellingb avatar schellingb commented on May 30, 2024

Hi,

Thanks again so much for the testing and the nice test cases!!

I was able to fix attack and decay behavior of the mod envelope which caused the polysynth instrument to played wrong (probably others, too). It sounds good to me now.

The second problem was only an issue in the web player but it's fixed now.

The third one I was not able to reproduce but I made sure things reset fully when loading another MIDI file, hopefully that fixes that as well.

Updated player still at https://schellingb.github.io/TinySoundFont/CustomSoundFont.html

from tinysoundfont.

RyanBram avatar RyanBram commented on May 30, 2024

Hi.
I am really, really impressed with the last improvement, and million thanks to you for creating and improving this MIDI player. I have randomly tried hundreds of my collection and all of them is played very accurate and comparable with other MIDI synthesizer I have tried (BassMIDI, Synthfont, Fluidsynth, Timidity).

Just before I want to mark this as solved, I found one MIDI file that have strange sound when played using custom soundfont, but sounds normal when using built-in soundfont or played in other MIDI synthesizer.

This is the MIDI file:
1-11 Fanfare.zip

from tinysoundfont.

RyanBram avatar RyanBram commented on May 30, 2024

From this point, I can consider that TinySoundFont and TinyMidiLoader can be used as Fluidsynth replacement. Chorus, Reverb and any additional features should be added by opening new issue, but for basic MIDI and SF2 support, I can said it is fairly accurate now.

I am really sure many other project developers will come here and use this library.

Thank you very much, Bernhard for making this happen.

from tinysoundfont.

mmontag avatar mmontag commented on May 30, 2024

Hi, I was poking around and found this thread very useful, even anecdotal parts like "I have randomly tried hundreds of my collection and all of them is played very accurate and comparable with other MIDI synthesizer."

Perhaps you could include some of these colorful details about what to expect in the primary README file?

I also have a question that I will drop here, just in case you see it:

One exceptional SF2 I've used was a Grand Piano patch that made use of the low pass filter, based on the velocity of the note. The softer notes were greatly attenuated in the high end. Harder notes sounded bright. Is this SF2 feature (I'm not sure what to call it) supported by TinySoundFont?

Thanks,
Matt

from tinysoundfont.

RyanBram avatar RyanBram commented on May 30, 2024

Hi, @mmontag , (^_^)
First of all, I cannot give any technical explanation about this issue, because I am not an advanced musician, nor a programmer. And even I am not a native English speaker.

Second, related to your question.
What I mean about accurate in this issue is that this library can play my MIDI collections without messing their tone, instrument, and tempo. Before I open this issue, some musics sound broken or sound very different compared to when playing using bass, fludsynth, or timidity. And after many fixes, finally I think many sound issue has been solved. There are no standard measurement to proof it, as I only use my "ear" to listen many random MIDI files that I throw to this library.

Hopefully that @schellingb will give you more scientific and detailed answer about your issue. Or maybe you can just try your music here https://schellingb.github.io/TinySoundFont/CustomSoundFont.html and find out the result.

Best regards,
Ryan

from tinysoundfont.

mmontag avatar mmontag commented on May 30, 2024

Thanks @RyanBram, I'm trying it out now on my own project. I love the small size of the library.
I will say it's hard to get a feel for quality because it also depends on the MIDI file and the SF2.

I am close to being able to swap TinySoundFont and FluidSynth so they can be compared easily.

from tinysoundfont.

mmontag avatar mmontag commented on May 30, 2024

@schellingb thanks, very interesting. I came across the Using SoundFonts in 2016 page too.

Hmm...of course, you can only tell so much from a spectrogram. I don't expect it to be a musical result, but are there audio samples of this test file?

Here is a song that's not working quite right for me:
https://mmontag.github.io/chip-player-js/ click on KOOLTHIN.MID. (It's running TML/TSF.) You can also right-click to download. Channel 16 is being played by a piano but it's supposed to be percussion. Is this a problem with Tiny Midi Loader?

from tinysoundfont.

schellingb avatar schellingb commented on May 30, 2024

The 'run the tests yourself' link on the article is a download which comes with SF2, MID and an OGG encoded "correct" output. You can run the MID with that SF2 through TSF/TML to get our result. I can upload it if you want.

These are the first few messages on KOOLTHIN.MID's channel 16 (15 when zero indexing) and as there is no PROGRAM_CHANGE message it will stay on the default program (piano). The MIDI percussion channel is 10 which for this MID plays fine.

[    0] [CONTROL]                           TML_VOLUME_MSB (  7) on Channel  15, Value 103
[    0] [CONTROL]                              TML_PAN_MSB ( 10) on Channel  15, Value  64
[    0] [PITCH] Channel  15, Value   8192
[    0] [CONTROL]                       TML_SUSTAIN_SWITCH ( 64) on Channel  15, Value   0
[    0] [CONTROL]                  TML_MODULATIONWHEEL_MSB (  1) on Channel  15, Value   0
[    0] [CONTROL]                           TML_VOLUME_MSB (  7) on Channel  15, Value 103
[    0] [CONTROL]                              TML_PAN_MSB ( 10) on Channel  15, Value  64
[    0] [PITCH] Channel  15, Value   8192
[    0] [CONTROL]                       TML_SUSTAIN_SWITCH ( 64) on Channel  15, Value   0
[    0] [CONTROL]                  TML_MODULATIONWHEEL_MSB (  1) on Channel  15, Value   0
[    0] [CONTROL]                           TML_VOLUME_MSB (  7) on Channel  15, Value 103
[    0] [CONTROL]                              TML_PAN_MSB ( 10) on Channel  15, Value  64
[    0] [PITCH] Channel  15, Value   8192
[    0] [CONTROL]                       TML_SUSTAIN_SWITCH ( 64) on Channel  15, Value   0
[    0] [CONTROL]                  TML_MODULATIONWHEEL_MSB (  1) on Channel  15, Value   0
[ 1411] [NOTEON] CHANNEL: 15 - NOTE ON: 55 - VEL: 74
[ 1411] [NOTEON] CHANNEL: 15 - NOTE ON: 36 - VEL: 99

I think if it wants a secondary percussion channel it would need to send BANK_SELECT 128 control change events followed by a program change.
In XMPlay with BASSMIDI it plays the same. XMPlay has a mysterious 'Detect channel 16 drums' option which even when set KOOLTHIN.MID plays a piano on channel 16.
Does FluidSynth play drums?

from tinysoundfont.

mmontag avatar mmontag commented on May 30, 2024

Haven't gotten around to trying FluidSynth just yet.
But it does play channel 16 drums on the macos app "MIDIPlayer X".

"Detect channel 16 drums" sounds like a promising lead 🙂

Edit: I was mistaken, this file doesn't sound right in MIDIPlayer X either.
I think these are very old MIDI files that shipped with Voyetra software in the nineties.
Funny thing is, I think the Channel 16 data is duplicating the Channel 10 data, so the proper way to handle it is probably to ignore it. Then it would make sense that "Detect channel 16 drums" means you look for virtually identical note-on messages on channel 10 and 16. Just speculating.
capture_2018-09-07_03 08 31

from tinysoundfont.

mmontag avatar mmontag commented on May 30, 2024

Looks like that is sort of the case, with a few exceptions (i.e. CH 9 Key 51 maps to CH 15 Key 44):

CH: 9   Key: 55   Vel: 74     |    CH: 15   Key: 55   Vel: 74     
CH: 9   Key: 36   Vel: 99     |    CH: 15   Key: 36   Vel: 99     
CH: 9   Key: 38   Vel: 82     |    CH: 15   Key: 38   Vel: 82     
CH: 9   Key: 36   Vel: 91     |    CH: 15   Key: 36   Vel: 91     
CH: 9   Key: 49   Vel: 74     |    CH: 15   Key: 49   Vel: 74     
CH: 9   Key: 38   Vel: 62     |    CH: 15   Key: 38   Vel: 62     
CH: 9   Key: 38   Vel: 112    |    CH: 15   Key: 38   Vel: 112    
CH: 9   Key: 36   Vel: 107    |    CH: 15   Key: 36   Vel: 107    
CH: 9   Key: 57   Vel: 74     |    CH: 15   Key: 57   Vel: 74     
CH: 9   Key: 46   Vel: 74     |    CH: 15   Key: 46   Vel: 74     
CH: 9   Key: 38   Vel: 87     |    CH: 15   Key: 38   Vel: 87     
CH: 9   Key: 38   Vel: 111    |    CH: 15   Key: 38   Vel: 111    
CH: 9   Key: 36   Vel: 97     |    CH: 15   Key: 36   Vel: 97     
CH: 9   Key: 49   Vel: 74     |    CH: 15   Key: 49   Vel: 74     
CH: 9   Key: 41   Vel: 74     |    CH: 15   Key: 41   Vel: 74     
CH: 9   Key: 38   Vel: 127    |    CH: 15   Key: 38   Vel: 127    
CH: 9   Key: 46   Vel: 127    |    CH: 15   Key: 46   Vel: 127    
CH: 9   Key: 57   Vel: 94     |    CH: 15   Key: 57   Vel: 94     
CH: 9   Key: 36   Vel: 114    |    CH: 15   Key: 36   Vel: 114    
CH: 9   Key: 51   Vel: 40     |    CH: 15   Key: 44   Vel: 31     
CH: 9   Key: 51   Vel: 69     |    CH: 15   Key: 44   Vel: 39     
CH: 9   Key: 37   Vel: 75     |    CH: 15   Key: 37   Vel: 75     
CH: 9   Key: 51   Vel: 28     |    CH: 15   Key: 44   Vel: 31     
CH: 9   Key: 51   Vel: 43     |    CH: 15   Key: 44   Vel: 31     
CH: 9   Key: 51   Vel: 69     |    CH: 15   Key: 44   Vel: 39     
CH: 9   Key: 37   Vel: 94     |    CH: 15   Key: 37   Vel: 94     
CH: 9   Key: 51   Vel: 36     |    CH: 15   Key: 44   Vel: 31     
CH: 9   Key: 51   Vel: 40     |    CH: 15   Key: 44   Vel: 31     
CH: 9   Key: 51   Vel: 59     |    CH: 15   Key: 44   Vel: 31     
CH: 9   Key: 37   Vel: 97     |    CH: 15   Key: 37   Vel: 97     
CH: 9   Key: 51   Vel: 36     |    CH: 15   Key: 44   Vel: 31     
CH: 9   Key: 51   Vel: 51     |    CH: 15   Key: 44   Vel: 31     
CH: 9   Key: 51   Vel: 51     |    CH: 15   Key: 44   Vel: 31     
CH: 9   Key: 37   Vel: 97     |    CH: 15   Key: 37   Vel: 97     
...

from tinysoundfont.

schellingb avatar schellingb commented on May 30, 2024

Yeah I listened to channel 16 with tsf_channel_set_bank_preset(g_TinySoundFont, 15, 128, 0); which sets the drum instrument and it clearly sounds like it was meant to be drums.
But trying to detect such a track by code seems too weird of a workaround...
As long as other players play it the same way broken I think we have to live with it :-)
Or offer some custom channel instrument configuration UI.

from tinysoundfont.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.