after some time, the audio pitch gets sharper, then makes only noices which makes me think that the problem is in the way i fill the buffer
int AudioThreadProc(AUDIOSTRUCT* audio) {
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
HANDLE buffReady = CreateEvent(0, 0, 1, 0);
audio->client->lpVtbl->SetEventHandle(audio->client, buffReady);
unsigned int soundBuffSize;
audio->client->lpVtbl->GetBufferSize(audio->client, &soundBuffSize);
audio->client->lpVtbl->Start(audio.client);
static float time = 0;
float dtime = 1 / (float)44100;
for (;;) {
WaitForSingleObject(buffReady, INFINITE);
unsigned int soundFrames;
audio->client->lpVtbl->GetCurrentPadding(audio->client, &soundFrames);
unsigned int FramesToFill = soundBuffSize - soundFrames;
unsigned short int* soundBuff;
audio->render->lpVtbl->GetBuffer(audio.render, FramesToFill, &soundBuff);
for (unsigned int i = 0; i < FramesToFill; i++) {
unsigned short int soundWave = audio->callback(time);
time += dtime;
*soundBuff++ = soundWave;
*soundBuff++ = soundWave;
}
audio->render->lpVtbl->ReleaseBuffer(audio.render, FramesToFill, 0);
}
return 0;
}
the callback funtion its only a sine wave generator
float callback(float time){
returns sin(pitch * PI2 * time) * 0xFFFF;
}
//...
audio.callback = callback;