Hello,
I am new to Cinder and am trying to use it to write synthesized audio and visuals that can be influenced in realtime.
I started by trying to write a simple fm synth. Two Sine Oscillators, that get multiplied and then the result as well as the individual sine waves gets send to the output:
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/audio/Voice.h"
#include "cinder/audio/Source.h"
#include "cinder/audio/Context.h"
#include "cinder/audio/GenNode.h"
#include "cinder/audio/GainNode.h"
#include "Resources.h"
using namespace ci;
using namespace ci::app;
using namespace std;
class test_01App : public App {
public:
void setup() override;
void draw() override;
audio::GenNodeRef mSine;
audio::GenNodeRef mSine2;
audio::GainNodeRef mGain;
audio::GainNodeRef mGain2;
audio::MultiplyNodeRef mMult;
};
void test_01App::setup()
{
auto ctx = audio::Context::master();
mSine = ctx->makeNode( new audio::GenSineNode );
mSine2 = ctx->makeNode( new audio::GenSineNode );
mMult = ctx->makeNode(new audio::MultiplyNode );
mGain = ctx->makeNode( new audio::GainNode );
mGain2 = ctx->makeNode( new audio::GainNode );
mSine->setFreq(220);
mSine2->setFreq(330);
mGain->setValue(0.1f);
mGain2->setValue(0.01f);
mMult -> getParam() -> setProcessor(mSine2);
mSine >> mMult;
mSine >> mGain;
mSine2 >> mGain;
mMult >> mGain2;
mGain >> ctx->getOutput();
mGain2 >> ctx->getOutput();
mSine->enable();
mSine2->enable();
ctx->enable();
}
However, I get a horribly distorted sound. If I only send mSine and the result of mMult to the output, the sound is fine. Why is mSine2 distorting if it gets used as a parameter for the mMult, but not if it doesn’t? Does the operator output get downsampled to be used as a control parameter?
Also, the sound of the mMult result on its own differs significantly from the sound of multiplying two sine waves of these frequencies in pure data. Why is that?
I would be very happy, if you could help me with these problems.