Sound Problem with Maximilian Library Square Wave

Hey Community,

i am learning program a simple synthesizer, and i use the Maximilian Library for Osc’s, Envelepes etc…

I managed to get a sinewave responding to my MIDI Input, reacting to velocity, pitch and an fixed envelope.

No Problem so far. If i say now it should be a squarewave, it sounds not really nice, and compared to other softsynths squarewaves it is for sure not a real square. I think i hear some aliasing effect etc…

Maybe someone got an Idea?

here a piece of code, for the moment the envelope and filters etc are commented out, so i can focus on the true squarewave.

void renderNextBlock (AudioBuffer <float> &outputBuffer, int startSample, int numSamples)
    {

        

        for (int sample = 0; sample < numSamples; ++sample)
        {
            sineOsc1Value = osc1Sine.square(783.991);
//            envOutput = env1.adsr(sineOsc1Value, env1.trigger);
//            filtered = filter1.lores(envOutput, 200, 1);

            
            

            
            for (int channel = 0; channel < outputBuffer.getNumChannels(); ++channel)
            {
                outputBuffer.addSample(channel, startSample, sineOsc1Value);
            }
            ++startSample;
        };
    }

This Code is copied from the SynthVoice Section of my Synthesizer. The Function is called in the processBlock in the PluginProcessor.cpp

Followed the Tutorials from Joshua Hedge (The Audio Programmer) on Youtube. Thanks by the way for your videos, again :wink:

Greetings.
Manuel

EDIT: the frequency is just on a fix value for the moment, it is a Note G.

Looks like the Maximilian square wave implementation is just a basic square wave function which doesn’t take into account it will alias. You could attempt doing some very heavy oversampling for your DSP but probably not worth it. Probably better to do your own oscillator implementation or use other library code that limits the number of harmonics generated.

Hey,

Thank you for the fast reply.
Do you know about any other free maximilian alternatives?

Greetings,
Manuel

Your best bet is JUCE’s DSP module! It’s great, though not as approachable as Maximilian. Your results will be much better however (having used both).