Skip to content

Modulation envelope is not convex and has the wrong duration #55

@spessasus

Description

@spessasus

Hi sinshu,

I've found a bug in the soundfont implementation of meltysynth. It is not related to modulators or unsupported/unplanned features, so I'm opening an issue.

SF Specification, section 8.1.2:

26 attackModEnv
This is the time, in absolute timecents, from the end of the Modulation Envelope
Delay Time until the point at which the Modulation Envelope value reaches its peak.
Note that the attack is “convex”; the curve is nominally such that when applied to a
decibel or semitone parameter, the result is linear in amplitude or Hz respectively.

As you can see below, meltysynth uses linear attack instead of convex, and it is too short, compared to fluidsynth:
image

This was tested using the soundfont specification test

This code was used to render the file:

using MeltySynth;
using NAudio;
using NAudio.Wave;

class Program
{
    static void Main(string[] args)
    {
        Synthesizer synth =
            new Synthesizer("/home/spessasus/Desktop/SoundFont-Spec-Test/sf_spec_test.sf2", 44100);
        MidiFileSequencer seq = new MidiFileSequencer(synth);
        MidiFile mid = new MidiFile("/home/spessasus/Desktop/SoundFont-Spec-Test/sf_spec_test.mid");
        seq.Play(mid, false); ;
        var audioLeft = new float[(int)(44100 * mid.Length.TotalSeconds / seq.Speed)];
        var audioRight = new float[(int)(44100 * mid.Length.TotalSeconds / seq.Speed)];
        Console.WriteLine(audioLeft.Length);
        seq.Render(audioLeft, audioRight);
        WaveFormat waveFormat = new WaveFormat(44100, 16, 2); // 44100 Hz, 16-bit, Stereo
        using (WaveFileWriter writer = new WaveFileWriter("/home/spessasus/Desktop/meltysynth.wav", waveFormat))
        {
            for (int i = 0; i < audioLeft.Length; i++)
            {
                writer.WriteSample(audioLeft[i]);
                writer.WriteSample(audioRight[i]);
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions