# The pitch or frequency of a sound is sometimes lowered

**URL:** <https://qa.fmod.com/t/the-pitch-or-frequency-of-a-sound-is-sometimes-lowered/14113>\
**Category:** FMOD Engine\
**Created:** [September 22, 2018, 2:43pm UTC](https://qa.fmod.com/t/the-pitch-or-frequency-of-a-sound-is-sometimes-lowered/14113 "2018-09-22T14:43:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keitel](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Keitel](https://qa.fmod.com/u/Keitel)\
**Post date:** [September 22, 2018, 2:43pm UTC](https://qa.fmod.com/t/the-pitch-or-frequency-of-a-sound-is-sometimes-lowered/14113/1 "2018-09-22T14:43:58Z")

</div>

I have made a kind of musical instrument in C for Windows, and it works good. Different self made buttons each play a specific tone of a scale. But sometimes when I have played for a while, some of the tones get lowered a little in pitch or frequency, and then a little later come back to the normal pitch again. But this I want to avoid. Any suggestions what can be the reason for this and what could be done about it?

Thanks in advance.

Sincerely

win

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [September 23, 2018, 3:00am UTC](https://qa.fmod.com/t/the-pitch-or-frequency-of-a-sound-is-sometimes-lowered/14113/2 "2018-09-23T03:00:46Z")

</div>

> play a specific tone of a scale

How are you making this sound? If you are generating a tone with sin/cos functions in math.h, its not uncommon for these to change shape based on the value of the input. I think it is to do with floating point innacuuracy as the numbers you feed it get higher. It is best to loop the input value constantly that you feed it (that is a modulus of 2PI) and keep the numbers low to keep the tone stable.

---

<div class="post-metadata">

**Author:** ![Keitel](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Keitel](https://qa.fmod.com/u/Keitel)\
**Post date:** [September 23, 2018, 10:18am UTC](https://qa.fmod.com/t/the-pitch-or-frequency-of-a-sound-is-sometimes-lowered/14113/3 "2018-09-23T10:18:08Z")

</div>

For each octave I have a sound file, a recording from a real instrument, of about 10 seconds length, which I play in a loop. It’s the G tone of each octave. I then use FMOD\_System\_PlaySound and FMOD\_Channel\_SetFrequency to change the pitch within the octave. I also use FMOD\_System\_Update after each time a tone is played.

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [September 23, 2018, 11:51pm UTC](https://qa.fmod.com/t/the-pitch-or-frequency-of-a-sound-is-sometimes-lowered/14113/4 "2018-09-23T23:51:25Z")

</div>

> [@](#):
>
> For each octave I have a sound file, a recording from a real instrument, of about 10 seconds length, which I play in a loop. It’s the G tone of each octave. I then use FMOD\_System\_PlaySound and FMOD\_Channel\_SetFrequency to change the pitch within the octave. I also use FMOD\_System\_Update after each time a tone is played.

If it is a standard wav, and it is just playing with no parameters being played, i’d have to see a repro of this, as i havent heard of anything like that. The resampler for FMOD is constant and doesnt change, the only outside factor I could think of at this point is your sound card driver.

---

<div class="post-metadata">

**Author:** ![Keitel](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Keitel](https://qa.fmod.com/u/Keitel)\
**Post date:** [September 24, 2018, 11:58am UTC](https://qa.fmod.com/t/the-pitch-or-frequency-of-a-sound-is-sometimes-lowered/14113/5 "2018-09-24T11:58:32Z")

</div>

Ok, so the sound card driver could be the reason. I am however also using a dsp alogorithm to make a smooth transition between the notes. I don’t know if that could have anything to do with it. The code is essentially like this:

```
float kfreq = 44100 * 0.6674f;    

FMOD_Channel_SetPaused(channel[0], 1);}					
result = FMOD_Channel_GetDSPClock(channel[0], &dspclock, &parentclock);
FMOD_System_Update(systemx);
result = FMOD_Channel_AddFadePoint(channel[0], parentclock, 1 );
endclock = parentclock + 400;
result = FMOD_Channel_AddFadePoint(channel[0], endclock, 0.0f );
result = FMOD_Channel_SetDelay(channel[0], 0, endclock, 1);
FMOD_System_Update(systemx);

result = FMOD_System_PlaySound(systemx, sound[soundnr], 0, 1, &channel[0]);
result = FMOD_System_Update(systemx);
FMOD_Channel_SetFrequency(channel[0], kfreq * scale[keynumber]);
FMOD_Channel_SetVolume(channel[0], keyboardvolume);

FMOD_Channel_SetPaused(channel[0], 0);
FMOD_System_Update(systemx);
```

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [September 25, 2018, 1:07am UTC](https://qa.fmod.com/t/the-pitch-or-frequency-of-a-sound-is-sometimes-lowered/14113/6 "2018-09-25T01:07:34Z")

</div>

> [@](#):
>
> Ok, so the sound card driver could be the reason. I am however also using a dsp alogorithm to make a smooth transition between the notes. I don’t know if that could have anything to do with it. The code is essentially like this:
> 
> ```
> float kfreq = 44100 * 0.6674f;    
> 
> FMOD_Channel_SetPaused(channel[0], 1);}					
> result = FMOD_Channel_GetDSPClock(channel[0], &dspclock, &parentclock);
> FMOD_System_Update(systemx);
> result = FMOD_Channel_AddFadePoint(channel[0], parentclock, 1 );
> endclock = parentclock + 400;
> result = FMOD_Channel_AddFadePoint(channel[0], endclock, 0.0f );
> result = FMOD_Channel_SetDelay(channel[0], 0, endclock, 1);
> FMOD_System_Update(systemx);
> 
> result = FMOD_System_PlaySound(systemx, sound[soundnr], 0, 1, &channel[0]);
> result = FMOD_System_Update(systemx);
> FMOD_Channel_SetFrequency(channel[0], kfreq * scale[keynumber]);
> FMOD_Channel_SetVolume(channel[0], keyboardvolume);
> 
> FMOD_Channel_SetPaused(channel[0], 0);
> FMOD_System_Update(systemx);
> 
> ```

What is the algorithm for the smooth transition? You mean the volume fade? That wouldnt affect the pitch. If you want to rule out a soundcard you can use FMOD\_OUTPUTTYPE\_WAVWRITER which will give you an idea of if the driver has a problem or not. You could detect any issue in the wav output, or if it was there at all in the fmod mixing side of things.

If you can play a single note in an example like the fmod playsound example, and you still get a frequency aberration - let me know with the code and source file, and I can check into it for you.

---

<div class="post-metadata">

**Author:** ![Keitel](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Keitel](https://qa.fmod.com/u/Keitel)\
**Post date:** [September 25, 2018, 10:04am UTC](https://qa.fmod.com/t/the-pitch-or-frequency-of-a-sound-is-sometimes-lowered/14113/7 "2018-09-25T10:04:46Z")

</div>

Ok. Thank you for the clarification. Another question related to this: It is possible to fine tune the frequency of a sound with very small diferences, also depending on how many decimals you use. I just wonder if it si possible to say anything in general about the accuracy of the output of these differences.

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [September 27, 2018, 1:09am UTC](https://qa.fmod.com/t/the-pitch-or-frequency-of-a-sound-is-sometimes-lowered/14113/8 "2018-09-27T01:09:03Z")

</div>

> [@](#):
>
> Ok. Thank you for the clarification. Another question related to this: It is possible to fine tune the frequency of a sound with very small diferences, also depending on how many decimals you use. I just wonder if it si possible to say anything in general about the accuracy of the output of these differences.

Channel::setFrequency takes a floating point frequency value so you can do fine frequency adjustments with that.

---

<div class="post-metadata">

**Author:** ![Keitel](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Keitel](https://qa.fmod.com/u/Keitel)\
**Post date:** [September 27, 2018, 8:11pm UTC](https://qa.fmod.com/t/the-pitch-or-frequency-of-a-sound-is-sometimes-lowered/14113/9 "2018-09-27T20:11:17Z")

</div>

Ok, thank you very much for your answers.

Sincerely
