//设置播放通知,一般用处有二: //1. 通知程序写入下一段声音数据 //2. 通知做某一个操作 HRESULT SetStopNotification(HANDLE hEvent, LPDIRECTSOUNDBUFFER8 lpDsbSecondary){ LPDIRECTSOUNDNOTIFY8 lpDsNotify; DSBPOSITIONNOTIFY PositionNotify; HRESULT hr; if (SUCCEEDED(hr = lpDsbSecondary->QueryInterface(IID_IDirectSoundNotify8, (LPVOID*)lpDsNotify) )){ PositionNotify.dwOffset = DSBPN_OFFSETSTOP; PositionNotify.hEventNotify = hEvent; hr = lpDsNotify->SetNotificationPositions(1, &PositionNotify); lpDsNotify->Release(); } return hr; }
/** * @brief Configures the replay buffer so that at appropriate positions of replay, a notification is sent. * @details * @param[in] p_secondary_buffer * @param[in] notify_array * @param[in] notify_array_count * @return */ static HRESULT set_play_notifications(LPDIRECTSOUNDBUFFER8 p_secondary_buffer, DSBPOSITIONNOTIFY * notify_array, size_t notify_array_count) { HRESULT hr; LPDIRECTSOUNDNOTIFY8 p_notify_itf = NULL; hr = p_secondary_buffer->QueryInterface(IID_IDirectSoundNotify8, (LPVOID*)&p_notify_itf); if (SUCCEEDED(hr)) { hr = p_notify_itf->SetNotificationPositions(notify_array_count, notify_array); p_notify_itf->Release(); debug_outputln("%4.4u %s : 0x%8.8x %u", __LINE__, __FILE__, hr, notify_array_count); for (size_t idx = 0; idx < notify_array_count; ++idx) { debug_outputln("%4.4u %s : 0x%8.8x %u", __LINE__, __FILE__, notify_array[idx].hEventNotify, notify_array[idx].dwOffset); } } return hr; }