Maximillian Sine wave is coming out distorted


#1

Hello there!

I was trying to get a basic sine wave of 440Hz out from the Maximillian Library. I was going alone with The Audio Programmer’s guide(Juce #23) and by 8:50 in, I was not getting a sine wave output, but some distorted sound. However, it worked in the video, and I am not sure why.

I have included the for loop of the jucer file in question(located in SynthVoice.h). I talked to the people in the Discord, and it appears to be something I am overlooking/don’t know about.

I am a n00b at this and have concluded that changing the sample rate and buffer size messes with the pitch, which should not be happening at A=440Hz.

Thank you for any insight on this!

ofoot


#2

Don’t increment (++) the startSample variable. Try doing something like this instead :

outputBuffer.addSample(channel,startSample+sample, theWave);

#3

I tried this, but I am still getting a distorted sine wave:


#4

Since the startSample is an argument by value, it is in the function’s context a copy, so you can use it. But your actual problem is, that the generated Sine is not a continuous wave, but keeps starting over with each new generated audio block.

You need a member variable instead, that keeps the position in your sine wave, since the buffer size is most likely not a multiple of your sine waves period.

EDIT: sorry, just see now, that you are pulling the wave from the osc1, so the continuity is taken care of…


#5

Are you sure your audio hardware is itself working correctly? How are you testing the code, as a standalone app or as a plugin?


#6

I have sampled and dumped into Ableton as a VST, and as standalone. Should I test on my desktop that has a Focusrite DAC?

Edit: I did an internal recording.

Edit2: and looked at harmonics in EQ8 and tuner


#7

Well, how does the resulting waveform look like? Does it look like a signal discontinuity issue or a level clipping issue? Or both? Did you try making the oscillator a bit quieter? (Multiply the output by 0.9 or something…)


#8

For starters, there is a beat frequency, and the wave looks like this with 24.0dB of gain:

Edit: So I don’t think volume is the issue.


#9

@ofoot are you using a Release build of your plugin?


#10

I don’t think so. Where would I check for that/how does that matter?


#11

I have debug mode enabled and release mode disabled. I think.Based on the Debug/Release sections of the exporters.


#12

To make it simple: a Debug build is big and slow, a Release build is small and fast.
In a Debug build, there are a lot of sanity checks (for instance jassert in JUCE code) and the compiler is not optimizing the code at all.
In a Release build, the sanity checks are skipped and the compiler (and sometimes the linker) optimizes the code.

I guess what you meant is that in your Projucer project you have one configuration which has “Debug Mode” set to “Enabled” (that’s the “Debug” configuration) and one configuration which has “Debug Mode” set to “Disabled” (that’s the “Release” configuration).

This is perfectly normal, but it only tells us that your project has 2 different configurations. It doesn’t tell us which one you use when building your project.

Since you mentioned Live (technically you mentioned Ableton, but that’s the name of the company, not of the DAW), I guess you are either on macOS or Windows, so you’re most likely using Xcode or Visual Studio to build your project.

To build the Release configuration:

  • in Xcode, you need to navigate the Product menu, then Build For, and then Profiling
  • in Visual Studio, you need to change the “Solution Configuration” first
    image
    and then you can build your project as before.

#13

I did the Release config and it still didn’t work.

Any suggestions beyond that?