Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect implementation of the amplitude when calculating the output signal #418

Open
UQMark opened this issue Jan 18, 2024 · 0 comments
Open

Comments

@UQMark
Copy link

UQMark commented Jan 18, 2024

I'm not entirely sure if the problem lies with the library itself, but I just couldn't find another explanation.
So... I have a basic for loop in which the audio output stream is formed based on the wave table and the parameters of the ADSR envelope.

int callbackFunction(void* outputBuffer, void* inputBuffer, unsigned int bufferFrames,
    double streamTime, RtAudioStreamStatus status, void* oscillatorParam)
{
    double* buffer = (double*)outputBuffer;
    struct Oscillator* oscillator = (struct Oscillator*)oscillatorParam;

    for (unsigned int i = 0; i < bufferFrames; i++)
    {
        float out = 0.0;

        if (midiManager.isActive())
        {
            if (midiManager.keyPressed)
            {
                adsr.triggerAttack();
                midiManager.keyPressed = false;
            }

            if (midiManager.keyReleased)
            {
                adsr.triggerRelease();
                midiManager.keyReleased = false;
            }

            midiManager.active = false;
        } 

        oscillator->volume = adsr.process();
        std::cout << "volume value: " << oscillator->volume << std::endl;
        out = filter.process(oscillator->process()) * oscillator->volume;

        buffer[i] = out;
    }

    return 0;
}

In the range of amplitude from 0.25 to 1.0, the resulting volume sounds exactly the same. Initially, I assumed that the problem lay in the implementation of ADSR, since when setting sustain= 0.25, the amplitude remained at the maximum level (that is, the final phase of the attack). Then I decided to remove the process function call and implemented the modulation using a knob controller. The problem has not disappeared, but I noticed that the variable oscillator->volume (as opposed to the actual volume) changes according to the parameters of the envelope (as it should be). This may mean that the problem is still in the implementation of the library itself. If this behavior had occurred as a result of an incorrectly formed wave table during the initialization of the oscillators, then even with the key held down, I would certainly have noticed a malfunction. In addition, the only block of code where an amplitude change can occur is precisely the for loop inside the callback function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant