Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 15 of 15

Thread: Compatibility between Wavetable-Synthesis and teensy audio library

  1. #1

    Compatibility between Wavetable-Synthesis and teensy audio library

    I have been using Wavetable-Synthesis for a project and it seems to have broke with the recent update.

    It looks like large parts of it have been incorporated into the teensy audio library (in synth_wavetable.[h/cpp], but in a way that conflicts with the Wavetable-Synthesis. Also, previously converted sound font files don't work anymore and how to convert them does not seem immediate.

    I do not see a new import tool with the teensy audio library either.

    Any idea on how to get things working again?

    Thanks!

  2. #2
    Senior Member
    Join Date
    Apr 2014
    Posts
    281
    I must have been posting at the same time as your post...just see it now.

    We may have come across the same problem.....my post was about the output from the windows pre compiles sf2 decoder.exe not being compatible with 1.44 release run on arduino 1.8.7......
    There is a change to the data structure.......I find 1.44 beta2 with some edits works...?????

    What versions and files/ sketches are you using...???

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,367
    Quote Originally Posted by laughingrice View Post
    Any idea on how to get things working again?
    A quick fix to keep using the old code would involve deleting synth_wavetable.cpp and synth_wavetable.h, and edit Audio.h to no longer include synth_wavetable.h.

    Unfortunately the original code had many global symbols, some using rather common names likely to conflict with other code. To bring it into the library, those had to change.

  4. #4
    I just went through your post again and it does seem like the same problem. There were a bunch of naming changes at some point it seems.
    I tested this with teensyduino 1.44

    After a lot of work I got it to work. I'm using the python version from git (on a Mac), hosted here https://github.com/TeensyAudio/Wavetable-Synthesis
    Might try updating the code at some point this week when I have some time, as I also found that I need to cut the RELEASE_COUNT by a factor of 6 as letting go of the piano key had too much sustain

    Requires adding AudioSynthWavetable:: to the following in the cpp and h file produced by the sf2 decoder (hope I didn't miss any)

    sample_data
    instrument_data
    SAMPLES_PER_MSEC
    ENVELOPE_PERIOD
    UNITY_GAIN
    LFO_PERIOD

    Also requires changing

    CENTS_SHIFT => WAVETABLE_CENTS_SHIFT
    NOTE => WAVETABLE_NOTE_TO_FREQUENCY
    DECIBEL_SHIFT => WAVETABLE_DECIBEL_SHIFT

  5. #5
    Ok, I hope that this link will have a shelf life of more than two days (some changes at work that may invalidate it),
    these updates to decoder.py will make the output work with the new changes

    https://www.dropbox.com/s/up2fccatyf...ecoder.py?dl=0

  6. #6
    I also think that under the get_timecents_value function in the same file it should read

    val = gen.cents * 100.0 if gen else default

    instead of

    val = gen.cents * 1000.0 if gen else default


    matches what I would expect cents to mean and decay time sounds correct now

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,367
    Here is the updated SoundfontDecoder.

    https://github.com/PaulStoffregen/SoundfontDecoder

  8. #8
    Senior Member
    Join Date
    Apr 2014
    Posts
    281
    thanks for the decoder. assume it needs to be run on python 3.6. tried on laptop with Lubuntu 18.04 which has Python 3.6 included, so ran the sf2utils install and then tried to run the decoder but get errors sf2utils not found...???? as below


    lub18@lub18-3000-C200:~$ pip install sf2utils
    Collecting sf2utils
    Using cached https://files.pythonhosted.org/packa...3-none-any.whl
    Installing collected packages: sf2utils
    Successfully installed sf2utils-0.9.0

    File "./SoundfontDecoder-master/decoder.py", line 28, in <module>
    from sf2utils.sf2parse import Sf2File
    ModuleNotFoundError: No module named 'sf2utils'

  9. #9
    Thanks, seem to work, will test farther tomorrow (had a busy weekend).

    The one comment, is that I think that my comment regarding using 100 instead of 1000 in get_timecents_value still holds.
    Basing subjectively on how the piano sounds as well as objectively on how FluidSynth plays the same sound font.

    The note just carries on for way too long when letting go of a key otherwise.

    On anther note, is there a simple way to load the instrument from SD card instead of memory? (would allow switching instruments when each on barely fits in memory).

    Thanks

  10. #10
    Senior Member
    Join Date
    Apr 2014
    Posts
    281
    Yes, got it to work, on a Win10, python3.6.6.....my lubuntu setup just needs sorted sometime, thanks

  11. #11
    Everything runs and plays now, the problem is that it does not play correctly. The amplitude decays incorrectly. I attached the output from the WavetableSynth (left) and Fluidsynth (right), both for middle C on the same sound font file, plot is of waveform in dB

    Any ideas where to start to correct this or if there is a better place to inquire?

    Thanks

    Click image for larger version. 

Name:	Screenshot 2018-10-04 13.07.26.jpg 
Views:	2 
Size:	36.8 KB 
ID:	14888

  12. #12
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,546
    Left: I'd say, it's exponential - might be intended?
    Right: Fluidsynth does not look very healty, too..

  13. #13
    Senior Member
    Join Date
    Apr 2014
    Posts
    281
    Just to clearup my earlier post..........Paul's new Decoder works OK on Lubuntu 18.04 and Python3.6......use ..... pip3 install sf2utils .... to install the utilities
    and ...... python3 controller.py ...... to run the decoder GUI.

  14. #14
    Quote Originally Posted by Frank B View Post
    Left: I'd say, it's exponential - might be intended?
    Right: Fluidsynth does not look very healty, too..
    I dug deeper

    1. had a look at mac's garage band, different instrument, but also shows similar behavior to fluidsynth
    2. BTW, fluidsynth and garage band show an exponential decay behavior (linear in dB domain), the behavior of synth wavetable is linear in the amplitude domain (logarithmic in dB domain)

    For decay, which is attenuation driven, physics describe an exponential decay behavior: exp(-at)

    I started looking into fixing the code and ran into this comment:

    Code:
    	// Definitions of the states generally follow the SoundFont spec, with a major exception being that all
    	// volume scaling is linear realtive to amplitude; this is correct with respect to the attack, but not
    	// the correct implementation relative to the decay and release which should be scaling linearly relative
    	// to centibels. Practically this means the decay and release happen too slowing intially, and too quick
    	// near the end
    Looking to see what else I can do to the code

  15. #15
    I modified the library to do exponential attenuation on Delay and Release per the Soundfont spec.

    Modified code can be found in my fork of the Audio library in case there is interest in pulling it into mainline or someone else wants to use it (not sure how to suggest a change to the library officially, don't work with GitHub much)
    https://github.com/laughingrice/Audio

    Doing proper exponential attenuation is probably to computationally intensive, so I did a 10 stop linear spline approximation instead, should add very little overhead.
    Output looks and sounds much more like I would expect now, first signal is the results of holding the key, second one is a key press and immediate release.

    Next target is to see how to handle a stereo sound font, although it looks like most midi players also add an envelope modulation as seen in the fluid synth output that I need to look into at some point as well

    Click image for larger version. 

Name:	Screenshot 2018-10-10 16.44.46.png 
Views:	1 
Size:	15.7 KB 
ID:	14925
    Last edited by laughingrice; 10-10-2018 at 09:32 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •