0
0

I need to play waveform tone sound. The frequency has to be changed dynamically.
I change the frequency using pDsp->setParameter(FMOD_DSP_OSCILLATOR_RATE,(float)dFrequency );
If I play a sinewave or saw wave, all works and sounds fine. If I use exactly the same code to play square wave or triangle wave, frequency is changing, but I get distortion in output tone. I tried setting lower volume, it did not help.
Here is the code I use:
[code:jvca7vvf]double dFrequency = 400;
FMOD::System *pSystem;
FMOD::DSP *pDsp;
FMOD::Channel *pChannel;
FMOD::System_Create(&pSystem);
pSystem->init(10, FMOD_INIT_NORMAL, 0);
pSystem->createDSPByType(FMOD_DSP_TYPE_OSCILLATOR, &pDsp);
pDsp->setParameter(FMOD_DSP_OSCILLATOR_RATE, (float)dFrequency);
pDsp->setParameter(FMOD_DSP_OSCILLATOR_TYPE, 1);//Waveform type.1=square.
pSystem->playDSP(FMOD_CHANNEL_FREE, pDsp, true, &pChannel);
pChannel->setPaused(false);
pChannel->setVolume((float)0.1);
while(dFrequency <= 800)
{//gradually increase frequency of the tone:
pDsp->setParameter(FMOD_DSP_OSCILLATOR_RATE,(float)dFrequency );
dFrequency = dFrequency + 10;
Sleep(100);
}
pChannel->stop();
pDsp->release();
m_pdspGenTone = NULL;
pChannel = NULL;
pSystem->close();
pSystem->release();
pSystem = NULL;[/code:jvca7vvf]

Any ideas why is it happening and how can I solve this?
Thanks.

  • You must to post comments
0
0

Distortion in a square wave! haha… that’s a good one! :)

Humour aside, what does the distortion sound like? What does it sound like it is doing instead of the expected square wave sweep?

  • You must to post comments
0
0

You can copy and paste the code from my post and hear it yourself.
Thanks.

  • You must to post comments
0
0

Hi guys,

Thanks for the report, I can hear a popping sound when the square wave changes pitch. We have found the problem and fixed it for the next release.

Here are the two versions:
[url:2njv96dk]http://www.fmod.org/files/square_sweep_old.wav[/url:2njv96dk]
[url:2njv96dk]http://www.fmod.org/files/square_sweep_new.wav[/url:2njv96dk]

  • You must to post comments
0
0

Thanks Peter!
I will wait for the next release.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.