I am new to Fmod and sound programming in general, and am a little confused about the concept of frequency in Fmod. I want to make an instrument by playing one or more simple sounds in loops, like for instance a flute sound, and then be able to change the pitches by the keyboard. I have seen in one of the examples that one uses FMOD_Channel_SetFrequency to do this. But when I use FMOD_RESULT Channel::getFrequency on a sound I get the number 44100. But isn’t this the samplerate? And is it recommended to change pitch by changing the samplerate? Is it not better to use interpolation?
I have also tried to use the command FMOD_RESULT FMOD_ChannelGroup_SetPitch, but then I get the error message that it is incompatible with a previous setpitch command in fmod.h, and I have no idea what that means.
Any help would be appreciated. Thanks in advance.
- Varun asked 4 years ago
Frequency and pitch are related, the frequency is the sample rate. So if you playback a 44100 Hz sound at 22050 Hz, that will be the equivalent of a pitch of 0.5, or down one octave. Channels have setFreqency instead of setPitch to give greater control. This allows you to tweak the resampler on the channel directly. ChannelGroup::setPitch propagates all the pitch values and calls setFrequency internally. It is often nicer to use the setPitch interface so I would reccomend just adding your Channel to a new ChannelGroup and using the setPitch function on that ChannelGroup.
FMOD_ChannelGroup_SetPitch should work, when you say you get an error message, what is the FMOD_RESULT returned from FMOD_ChannelGroup_SetPitch ?
Thank you very much for your answer.
Yes, I believe I understand the relationship between sample rate and frequency. I am just uncertain whether changing the pitch by changing the sample rate is flexible and efficient enough if I have many sounds being played together with frequent and rapid pitch shifts. I believe that the most common way of making pitch shifts in digital sound systems is by interpolation, which means that you add samples to reduce the pitch and remove samples to increase it. But I don’t know if one method is preferable to the other. To change the sample rate seems, however, to be much simpler.
When it comes to the error I mentioned, it was not a run-time error, but a syntax error, and related to me not being equally knowledgeable in all aspects of c programming.
[quote:38z00d3e]I believe that the most common way of making pitch shifts in digital sound systems is by interpolation, which means that you add samples to reduce the pitch and remove samples to increase it.[/quote:38z00d3e]
That is correct, so when you increase the pitch you also increase the speed; this is know as [i:38z00d3e]time variant[/i:38z00d3e] pitch shift. Both setPitch and setFrequency use this.
If you want [i:38z00d3e]time invariant[/i:38z00d3e] pitch shift (the speed is the same when the pitch changes) you can use FMOD_DSP_PITCHSHIFT. This DSP effect will analyse the freqency spectrum of the audio and change it but it is significantly more expensive in terms of CPU usage.
Please login first to submit.