0
0

Hi to all,
I built a class to generate synthetic tone and I would set the frequency of it that must be changed in real-time like an ambulance.
Firstly I set the frequency with the
[code:v00zbl3f]DSP::setParameter( FMOD_DSP_OSCILLATOR_RATE, initialValue_of_freq)[/code:v00zbl3f]
Now I would modify the frequency using Channel::setFrequency( freq ). Is this correct?
But I think that it does not work because I compare the result with some sound in the wiki pedia (for example at 440 Hz) and the 2 sound are different.
So my question is how can I set the frequency of a tone?
Reards
Franco

  • You must to post comments
0
0

[quote="mathew":2sa82uts]What you need to do is set the frequency of the channel to the frequency of the FMOD system. getSoftwareFormat can be used to get the frequency of the system. As an example:

[code:2sa82uts]
int frequency = 0;
system->getSoftwareFormat(&frequency, NULL, NULL, NULL, NULL, NULL);
channel->setFrequency(frequency);
[/code:2sa82uts][/quote:2sa82uts]

Mathew I tried your solution but it doesn’t work.
Sure is my mistake. I post here some code:

The startPlay start playing the tone
[code:2sa82uts]/*****************************************************
startPlay: start playind tone
*****************************************************/
void SoFMODTone::startPlay()
{
FMOD_RESULT result;

init();

result = SoFMODSystem::getInstance()->getSystem()->playDSP(FMOD_CHANNEL_FREE,
dsp, true, &currentChannel);

currentChannel->setMode((FMOD_MODE)(FMOD_3D | FMOD_SOFTWARE));

currentChannel->setVolume(volume.getValue());
currentChannel->setPitch( pitch.getValue() );

result = dsp->setParameter( FMOD_DSP_OSCILLATOR_TYPE, wave.getValue() );

TONECHECK(result);

if(currentChannel)
{
currentChannel->setPaused(false);

   // Doppler level
   currentChannel->set3DDopplerLevel(dopplerLevel.getValue());

   // some info        
   cout << "Generating " << waveform.getValue().getString() << " at " << pitch.getValue() <<"Hz.\n";

}
}

[/code:2sa82uts]

in the init routine I create and initialize the dsp

[code:2sa82uts]/********************************************************
init: create and initialize the oscillator
********************************************************/
void SoFMODTone::init()
{
FMOD_RESULT result;
int frequency = 0;

result = SoFMODSystem::getInstance()->getSystem()->createDSPByType(FMOD_DSP_TYPE_OSCILLATOR, &dsp);
TONECHECK(result);

result = dsp->setParameter(FMOD_DSP_OSCILLATOR_RATE, 440.0f);
TONECHECK(result);

SoFMODSystem::getInstance()->getSystem()->getSoftwareFormat(&frequency, NULL, NULL, NULL, NULL, NULL);
currentChannel->setFrequency(frequency); 

}
[/code:2sa82uts]

in the setPitch is where I would change the frequency

[code:2sa82uts]/******************************************************
setPitch
set the desired volume for the channel
******************************************************/
void SoFMODTone::setPitch( float _pitch )
{
// cout << "Setting frequency at " << _pitch << "Hz\n";
pitch.setValue( _pitch );
}[/code:2sa82uts]

Here I call frequency pitch bus is only a name.
And as example in tha main I do these calls:

[code:2sa82uts] // Add tone
SoFMODTone *wTone = new SoFMODTone();
wTone->setWaveform("TRIANGLE");
wTone->setVolume(0.5f);
wTone->setPitch(1000.0f);
wTone->startPlay();
[/code:2sa82uts]

In this example I would set 1KHz but doesn’t work, I can listen nothing.
Where are my mistakes? Can I have a help?
The fmod system object is wrapped in a singleton
Regards,
Franco

  • You must to post comments
0
0

[quote:1y955lue]
do you mean that every time I want change the frequency of the channel, I firstly have to call the getSoftwareFormat? Or only 1 time?
Franco
[/quote:1y955lue]

No, you set the frequency of the channel once to the value returned from getSoftwareFormat(), then if you want to change the frequency of the DSP unit, you do it via the DSP->setParameter call.

Just looking at your code above, you are setting the frequency of "currentChannel" during SoFMODTone::init(), this is before you have actually played the DSP on that channel so it will have no effect. Also you are not checking the result returned from that setFrequency() call so you wouldn’t notice. Make sure you error check every FMOD function to help catch these problems.

  • You must to post comments
0
0

If you’re attaching it to a channel the channel is probably resampling it to a different rate to that of the output. Either use addinput on the node returned from System::getDSPHEad, or use Channel::setFrequency to set the frequency to that of the output.

  • You must to post comments
0
0

Hi Mathew,

[quote="mathew":2gxo3g4q][quote:2gxo3g4q]
do you mean that every time I want change the frequency of the channel, I firstly have to call the getSoftwareFormat? Or only 1 time?
Franco
[/quote:2gxo3g4q]

No, you set the frequency of the channel once to the value returned from getSoftwareFormat(), then if you want to change the frequency of the DSP unit, you do it via the DSP->setParameter call.

Just looking at your code above, you are setting the frequency of "currentChannel" during SoFMODTone::init(), this is before you have actually played the DSP on that channel so it will have no effect. Also you are not checking the result returned from that setFrequency() call so you wouldn’t notice. Make sure you error check every FMOD function to help catch these problems.[/quote:2gxo3g4q]

Thanx for your help.
I will immediately try your suggestions and keep you infomed.
Regards,
Franco

  • You must to post comments
0
0

Hi Brett,
[quote="brett":1x6eghu9]If you’re attaching it to a channel the channel is probably resampling it to a different rate to that of the output. Either use addinput on the node returned from System::getDSPHEad, or use Channel::setFrequency to set the frequency to that of the output.[/quote:1x6eghu9]

Yes is attached to a channel.
For example if I set Channel::setFrequency(440) I don’t get a tone at 440 Hz.
I compare the output of the setFrequency with a wav that has 440 Hz (downloaded from a wikipedia) frequency and the 2 tones are different. To emit the same tone I have to multiply Channel::setFrequency(440 * aFactor) but this has no sense. Where is my mistake?
And can I have an example of use of System::getDSPHEad?
Regards,
Franco

  • You must to post comments
0
0

[quote="franco.amato":vdpg1r0a]Hi Mathew,

[quote="mathew":vdpg1r0a][quote:vdpg1r0a]
do you mean that every time I want change the frequency of the channel, I firstly have to call the getSoftwareFormat? Or only 1 time?
Franco
[/quote:vdpg1r0a]

No, you set the frequency of the channel once to the value returned from getSoftwareFormat(), then if you want to change the frequency of the DSP unit, you do it via the DSP->setParameter call.

Just looking at your code above, you are setting the frequency of "currentChannel" during SoFMODTone::init(), this is before you have actually played the DSP on that channel so it will have no effect. Also you are not checking the result returned from that setFrequency() call so you wouldn’t notice. Make sure you error check every FMOD function to help catch these problems.[/quote:vdpg1r0a]

Thanx for your help.
I will immediately try your suggestions and keep you infomed.
Regards,
Franco[/quote:vdpg1r0a]

Hi Mathew, I followed your instructions,
I have a question. I set to 0 the doppler level and for that I can understand nothing. Is this normal?
Franco

  • You must to post comments
0
0

Maybe this is the reason it’s not working!?

From the manual, setFrequency
[quote:372e8x8c]
Frequency limitations for sounds created with FMOD_HARDWARE in DirectSound.
Every hardware device has a minimum and maximum frequency. This means setting the frequency above the maximum and below the minimum will have no effect.
FMOD clamps frequencies to these values when playing back on hardware, so if you are setting the frequency outside of this range, the frequency will stay at either the minimum or maximum.
Note that FMOD_SOFTWARE based sounds do not have this limitation.
To find out the minimum and maximum value before initializing FMOD (maybe to decide whether to use a different soundcard, output mode, or drop back fully to software mixing), you can use the System::getDriverCaps function.
[/quote:372e8x8c]

  • You must to post comments
0
0

I’m not sure I understand your question, setting the doppler level to 0 should disable doppler calculations for that channel.

  • You must to post comments
0
0

[quote="icuurd12b42":18e7qrw9]Maybe this is the reason it’s not working!?

From the manual, setFrequency

Frequency limitations for sounds created with FMOD_HARDWARE in DirectSound.
Every hardware device has a minimum and maximum frequency. This means setting the frequency above the maximum and below the minimum will have no effect.
FMOD clamps frequencies to these values when playing back on hardware, so if you are setting the frequency outside of this range, the frequency will stay at either the minimum or maximum.
Note that FMOD_SOFTWARE based sounds do not have this limitation.
To find out the minimum and maximum value before initializing FMOD (maybe to decide whether to use a different soundcard, output mode, or drop back fully to software mixing), you can use the System::getDriverCaps function.
[/quote:18e7qrw9]

Hi I declared the channel with Channel::setMode with the FMOD_SOFTWARE flag but nothing changes.
IS not possible that I can not generate tone at a determinate frequency.
I would change the frequency in real time to simulate an ambulance or other kind of noise but the frequency emitted is not correct and I can not find the mistakes.
Can I have an help?
I can share some code.
Regards,
Franco

  • You must to post comments
0
0

[quote="franco.amato":1q0gyqb3][quote="icuurd12b42":1q0gyqb3]Maybe this is the reason it’s not working!?

From the manual, setFrequency

Frequency limitations for sounds created with FMOD_HARDWARE in DirectSound.
Every hardware device has a minimum and maximum frequency. This means setting the frequency above the maximum and below the minimum will have no effect.
FMOD clamps frequencies to these values when playing back on hardware, so if you are setting the frequency outside of this range, the frequency will stay at either the minimum or maximum.
Note that FMOD_SOFTWARE based sounds do not have this limitation.
To find out the minimum and maximum value before initializing FMOD (maybe to decide whether to use a different soundcard, output mode, or drop back fully to software mixing), you can use the System::getDriverCaps function.
[/quote:1q0gyqb3]

Hi I declared the channel with Channel::setMode with the FMOD_SOFTWARE flag but nothing changes.
IS not possible that I can not generate tone at a determinate frequency.
I would change the frequency in real time to simulate an ambulance or other kind of noise but the frequency emitted is not correct and I can not find the mistakes.
Can I have an help?
I can share some code.
Regards,
Franco[/quote:1q0gyqb3]

I can take a shot at it. if you PM me the code. There may alternatives. Like playing a looped wav recorded at a known frequency and fiddling with its frequency.

Did you say the frequency does change but not to the frequency you changed it too?

Getting the wav data (of the channel or the channel group and drawing it, especially if it’s a tone, you could be able to see by drawing a scale if the frequency is rigth…

getFrequency should also show some useful info.

  • You must to post comments
0
0

To reiterate what Brett said above, you need to set the frequency of the channel the DSP unit is playing on to match the frequency of the output. So one example of use would be this (summarized).

[code:3b49eahx]
createDSPByType() // create your oscillator
setParameter() // set the rate of the oscillator, e.g. 440Hz
getSoftwareFormat() // get the frequency of the system output (check docs for details)
playDSP() // play your oscillator on a channel
setFrequency() // set the frequency of the channel to match the output you got in getSoftwareFormat
[/code:3b49eahx]

Now that it is playing correctly at 440Hz, use setParameter() during runtime to alter the frequency of the oscillator as you require.

I hope this makes sense to you.

  • You must to post comments
0
0

[quote="mathew":1hl9179j]To reiterate what Brett said above, you need to set the frequency of the channel the DSP unit is playing on to match the frequency of the output. So one example of use would be this (summarized).

[code:1hl9179j]
createDSPByType() // create your oscillator
setParameter() // set the rate of the oscillator, e.g. 440Hz
getSoftwareFormat() // get the frequency of the system output (check docs for details)
playDSP() // play your oscillator on a channel
setFrequency() // set the frequency of the channel to match the output you got in getSoftwareFormat
[/code:1hl9179j]

Now that it is playing correctly at 440Hz, use setParameter() during runtime to alter the frequency of the oscillator as you require.

I hope this makes sense to you.[/quote:1hl9179j]

Hi Mathew thanx for your reply.
I don’t know how to use the getSoftwareFormat(). I read the doc but I don’t understand the concept.
Can you help me?
Regards,
Franco

  • You must to post comments
0
0

What you need to do is set the frequency of the channel to the frequency of the FMOD system. getSoftwareFormat can be used to get the frequency of the system. As an example:

[code:2c4ka3l5]
int frequency = 0;
system->getSoftwareFormat(&frequency, NULL, NULL, NULL, NULL, NULL);
channel->setFrequency(frequency);
[/code:2c4ka3l5]

  • You must to post comments
0
0

Hi Mathew,

[quote="mathew":2u3gx31e]What you need to do is set the frequency of the channel to the frequency of the FMOD system. getSoftwareFormat can be used to get the frequency of the system. As an example:

[code:2u3gx31e]
int frequency = 0;
system->getSoftwareFormat(&frequency, NULL, NULL, NULL, NULL, NULL);
channel->setFrequency(frequency);
[/code:2u3gx31e][/quote:2u3gx31e]

do you mean that every time I want change the frequency of the channel, I firstly have to call the getSoftwareFormat? Or only 1 time?
Franco

  • You must to post comments
Showing 14 results
Your Answer

Please first to submit.