Quote:Name: DSERR_PRIOLEVELNEEDED Description: The caller does not have the priority level required for the function to succeedI have tried to do many things, but no use. It's just an ordinary secondary sound buffer. I can't figure this out. Thanks in advance
DirectSound buffer-play(...) returns DSERR_PRIOLEVELNEEDED error
Hi i have a direct sound program in which I have a capture buffer created, then a sound buffer. The capture buffer will write to the sound buffer. Both are created successfully, or no errors are thrown, but when I use the play function:
if( FAILED( hr = pBuffer->Play( 0, 0, DSBPLAY_LOOPING ) ) )
it returns 0x88780046 and through the error look up tool that's
Well, the DirectSound documentation says:
jfl.
Quote:DirectSound Return Values by NameSo, have you set the priority level to DSSCL_PRIORITY or above (IDirectSound8::SetCooperativeLevel( hwnd, DSSCL_PRIORITY );)?
DSERR_PRIOLEVELNEEDED
A cooperative level of DSSCL_PRIORITY or higher is required.
jfl.
Here is all the relevant directsound code. Somewhat compacted of course, and clean up code removed:
EDIT: Please use 'source' tags for longer/wider fragments of code. Thanks!
[Edited by - jollyjeffers on January 29, 2006 8:59:40 AM]
CoInitialize( NULL ); g_hNotify = CreateEvent( NULL, FALSE, FALSE, NULL ); deviceNum = 0; if( FAILED( hr = CoCreateInstance( (const IID &)CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, IID_IDirectSound8, (LPVOID *)&pSound ) ) ) { Error( "Could Not Create DirectSound 8", hr ); exit(0); } pSound->Initialize( NULL ); pSound->SetCooperativeLevel( 0, DSSCL_PRIORITY ); if( FAILED( DirectSoundCaptureEnumerate( EnumerateDevices, 0 ) ) ) { MessageBox( 0, "Failure to Enumerate Capture Devices.\nDo you have a sound card correctly installed?", 0, 0 ); exit(0); } cout << "0) Primary Sound Capture Device" << endl; for( int i = 1; i < deviceNum; i++ ) { cout << i << ") " << g_cDeviceList.lpcstrDescription << endl; } cout << endl << "Enter selection: "; int selection = 0; cin >> selection; WAVEFORMATEX wfx; DSBUFFERDESC dbsd; DSCBUFFERDESC dcbsd; LPDIRECTSOUNDBUFFER pDsb = NULL; HRESULT hr; memset( &wfx, 0, sizeof(WAVEFORMATEX) ); wfx.wFormatTag = WAVE_FORMAT_PCM; wfx.nChannels = 2; wfx.nSamplesPerSec = 44100; wfx.wBitsPerSample = 16; wfx.nBlockAlign = wfx.nChannels*(wfx.wBitsPerSample/8); wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; memset( &dbsd, 0, sizeof( DSBUFFERDESC ) ); memset( &dcbsd, 0, sizeof( DSCBUFFERDESC ) ); dcbsd.dwSize = sizeof( DSCBUFFERDESC ); dbsd.dwSize = sizeof( DSBUFFERDESC ); dcbsd.dwFlags = 0; dbsd.dwFlags = DSBCAPS_GLOBALFOCUS; dcbsd.dwBufferBytes = dbsd.dwBufferBytes = 1 * wfx.nAvgBytesPerSec; dcbsd.lpwfxFormat = dbsd.lpwfxFormat = &wfx; dbsd.guid3DAlgorithm = DS3DALG_DEFAULT; dcbsd.dwFXCount = 0; dcbsd.lpDSCFXDesc = NULL; dBufSize = dcbsd.dwBufferBytes; if( FAILED( hr = DirectSoundCaptureCreate8( g_cDeviceList[selection].lpGuid, &pCapture, NULL ) ) ) { Error( "Failed To Create DirectSound Capture Device", hr ); exit(0); } LPDIRECTSOUNDCAPTUREBUFFER cbuf; if( FAILED( hr = pCapture->CreateCaptureBuffer( &dcbsd, &cbuf, NULL ) ) ) { Error( "Failed To Create DirectSound Capture Buffer", hr ); exit(0); } if( FAILED( hr = cbuf->QueryInterface( IID_IDirectSoundCaptureBuffer8, (VOID **)&pCaptureBuffer ) ) ) { Error( "Failed to obtain DirectSoundCaptureBuffer8 object from \"cbuf\"", hr ); exit(0); } cbuf->Release(); LPDIRECTSOUNDBUFFER buf; if( FAILED( hr = pSound->CreateSoundBuffer( &dbsd, &buf, NULL ) ) ) { Error( "Failed To Create Main DirectSound Output Buffer", hr ); exit(0); } if( FAILED( hr = buf->QueryInterface( IID_IDirectSoundBuffer8, (VOID **)&pBuffer ) ) ) { Error( "Failed to obtain DirectSoundBuffer8 object from \"buf\"", hr ); exit(0); } buf->Release(); if( FAILED( hr = pCaptureBuffer->QueryInterface( IID_IDirectSoundNotify8, (VOID **)&pNotify ) ) ) { Error( "Unable To Create IDirectSoundNotify8 interface.", hr ); exit(0); } DSBPOSITIONNOTIFY notifies[3]; notifies[0].dwOffset = 0; notifies[1].dwOffset = (dbsd.dwBufferBytes/3); notifies[2].dwOffset = 2*(dbsd.dwBufferBytes/3); notifies[0].hEventNotify = notifies[1].hEventNotify = notifies[2].hEventNotify = g_hNotify; if( FAILED( hr = pNotify->SetNotificationPositions( 3, notifies ) ) ) { Error( "Unable to set notification Positions", hr ); exit(0); } if( FAILED( hr = pBuffer->Play( 0, 0, DSBPLAY_LOOPING ) ) ) Error( "Failure to play buffer", hr );
EDIT: Please use 'source' tags for longer/wider fragments of code. Thanks!
[Edited by - jollyjeffers on January 29, 2006 8:59:40 AM]
I'm pretty certain that you cannot pass in a null HWND to IDirectSound8::SetCooperativeLevel(). Try testing SetCooperativeLevel() for failure (it will probably be E_INVALIDARG or DSERR_INVALIDPARAM, depending on which documentation you check).
[edit] Also, for large blocks of code like the above, use source tags instead of code tags.
jfl.
[edit] Also, for large blocks of code like the above, use source tags instead of code tags.
jfl.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement