Home > Software engineering >  AudioKit v5 - Why is the loudness of the DynamicOscillators different depending on which Waveform Ta
AudioKit v5 - Why is the loudness of the DynamicOscillators different depending on which Waveform Ta

Time:11-01

I am using AudioKit to build a simple music application that plays sound when buttons are pressed. When a button is pressed, I call .openGate() on an Amplitude Envelope that has a Dynamic Oscillator as an input.

However, I notice that when I call .setWaveForm(Table(.sine)) on the DynamicOscillators, the sound coming out of the speakers is very quiet when compared to when I call .setWaveForm(Table(.square)). Using a .sawtooth or .triangle table results in an intermediate loudness.

Ideally, the DynamicOscillators would have the same loudness regardless of which waveform is set.

I have assigned an amplitude of 1.0 to each oscillator.

Any ideas?

CodePudding user response:

I think this is because a squarewave does normally sound louder than a sinewave/triangle when both have the same amplitude. You can observe this behavior on most synths.

CodePudding user response:

The square wave is louder for a given amplitude. This is based on its RMS power. It is literally driving the air more than a sine wave.

The RMS power of a square wave is the amplitude. The RMS power of a sine wave is amplitude/sqrt(2). So to make them match, you should drive the square wave at an amplitude of 0.707 (-3dB)

A sawtooth wave has an RMS of 1/sqrt(3), or 0.577 (-4.8dB). You notice the difference between the square and sine more than between sine and sawtooth because we hear on a log scale (dB). It's a bigger jump from 0 to -3dB than from -3dB to -4.8dB. But if you want all of these to match, you'll need to scale both the sine and square waves down to the sawtooth wave.

  • Related