Sound played does not have the right frequency

I have made a program in C and Winapi in Visual Studio with Windows 10 that plays a sound file with different frequencies. However, the frequency of the sounds are not correct. It is about one and a half note lower than expected.

The sound file is in G, and to calculate the desimal number for C, as an example, I do the following:

Frequency of G * X = Frequency of C
X = Frequency of C / Frequency of G = 261.63 hz / 392.00 hz = 0.6674

I have another similar program, and the sounds have the right frequencies, so I can’t understand why it doesn’t work this time. Here’s a simplified version of the program, which is quite straightforward.

int Samplerate = 44100;
float Frequency = 44100 * 0.6674;

result = FMOD_System_Create(&system);
result = FMOD_System_SetSoftwareFormat(system, sampleRate, FMOD_SPEAKERMODE_MONO, FMOD_SPEAKERMODE_DEFAULT);
FMOD_System_SetDSPBufferSize(system, 1024, 4);
FMOD_System_Init(systemx, 12, FMOD_INIT_NORMAL, 0);

result = FMOD_System_CreateSound(system, “Sound1.wav”, FMOD_CREATESAMPLE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound[0]);

result = FMOD_System_PlaySound(systemx, sound[0], 0, 1, &channel[channelnumber]);
result = FMOD_Channel_SetFrequency(channel[channelnumber], Frequency);
FMOD_Channel_SetPaused(channel[channelnumber], 0);

Thanks in advance.

I have now come to realize that this problem only occurs in Debug mode. When running it in Release mode it works as expected. I don’t understand why it is like this, but the problem is solved.

Sounds like the issue may be due to differences in floating point precision/behavior between release and debug. Either way, I’m happy to hear that it isn’t an issue in release.