Problem with amplitude blending for VST made in Unity3D

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.
Hi there
This is my first post here and I don't know if this is the best place for asking my question. Anyway I'm writing a vst like piece of software for my game inside unity and I have some problems making a smooth transition between notes. Notes mostly make a noise on creation specially when they have a low Attack duration. I wonder in a real software how engineers prevent the app from making these noises.
I recorded a graph from note amplitudes in different situations. There is a explanation on the image itself. My audio making function is an internal Unity function which can be used for post-processing on audio and in my case for generating noises. this method interval is based on project audio sample setting which currently is 44100 and is running every about 20ms.
To be clear I want to know how to blend amplitude of every notes together and diminish the unwanted speaker noises.
Unity_VST_Problem.png

Code: Select all (#)

private void OnAudioFilterRead(float[] data, int channels)
    {
        dTime = AudioSettings.dspTime;
        
        for (int i = 0; i < data.Length; i+= channels)
        {
            phase += 1 / sampling_frequency;

            waveData = 0;

            lock (lockObj)
            {
                foreach (Note note in notes)
                {
                    bool noteFinished = false;
                    float sound = (float)instruments[note.track].Sound(dTime, phase, note, out noteFinished); // tracks and instruments
                    waveData += sound;
                    
                    if (noteFinished && note.off > note.on)
                        note.active = false;
                }

                notes.RemoveAll(n => !n.active);
            }

            data[i] = volume * waveData;

            SinField = waveData;

            if (channels == 2)
            {
                data[i + 1] = data[i];
            }

            if (phase > sampling_frequency)
            {
                phase = 0.0;
            }
        }
    }
Thank you for any help
You do not have the required permissions to view the files attached to this post.

Post Reply

Return to “DSP and Plugin Development”