Почему WaitForMultipleObjects () перестает работать после одного цикла?

Я использую DirectSound для воспроизведения музыки на C ++. Я использую переменные DSBPOSITIONNOTIFICATION, чтобы определить, когда воспроизведение secondaryBuffer переменная (типа IDirectSoundBuffer8*) достигла либо одной четверти, трех четвертей или конца своего размера. Код, используемый для создания уведомлений и воспроизведения музыки, показан ниже.

LPDIRECTSOUNDNOTIFY8 directSoundNotify;
HANDLE playEventHandles[3];
playEventHandles[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
playEventHandles[1] = CreateEvent(NULL, FALSE, FALSE, NULL);
playEventHandles[2] = CreateEvent(NULL, FALSE, FALSE, NULL);

secondaryBuffer->QueryInterface(IID_IDirectSoundNotify8, (LPVOID*)&directSoundNotify);

//This is the size of secondaryBuffer
int averageBytes = wfx.Format.nAvgBytesPerSec * 4;

//Create notification information
DSBPOSITIONNOTIFY positionNotify[3];
positionNotify[0].dwOffset = averageBytes / 4;
positionNotify[0].hEventNotify = playEventHandles[0];
positionNotify[1].dwOffset = averageBytes - (averageBytes / 4);
positionNotify[1].hEventNotify = playEventHandles[1];
positionNotify[2].dwOffset = averageBytes;
positionNotify[2].hEventNotify = playEventHandles[2];
directSoundNotify->SetNotificationPositions(1, positionNotify);
directSoundNotify->Release();

secondaryBuffer->Play(0, 0, 0);

do
{
//Wait for notifications
DWORD notification = WaitForMultipleObjects(3, playEventHandles, FALSE, INFINITE);

//First quarter notification - Fill second half if not all data has been received
if (notification == 0)
{
//This function is handled elsewhere in the program - It obtains music from a server using sockets
ReceiveMusic();
}
//Third quarter notification - Fill first half if not all data has been received
else if (notification == 1)
{
ReceiveMusic();
}
//Playback ended notification - Reset play position
else if (notification == 2)
{
secondaryBuffer->SetCurrentPosition(0);
secondaryBuffer->Play(0, 0, 0);
}
} while (size < dataBufferSize); //While size (current amount of song loaded) is less than dataBufferSize (total size of song that is in the process of being loaded)
//The size and dataBufferSize are initialised and handled elsewhere in the program, but they work properly - There shouldn't be a problem with the loop termination condition

Функция WaitForMultipleObjects() способен определить, когда произошло событие (он успешно замечает событие первого квартала). Тем не менее, он перестает работать на втором цикле. Программа достигает функции, но она просто сидит там навсегда, не замечая, когда произошло другое событие (я уверен, что secondaryBuffer все еще играет, поэтому он должен заметить, что он достиг трех четвертей воспроизведения или остановился). Как я могу изменить код так, чтобы функция фактически замечала события в будущих циклах?

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector