The pitch or frequency of a sound is sometimes lowered

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

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.

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.

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.

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.

Ok, thank you very much for your answers.

Sincerely