Why does this second call fail?

Started by
22 comments, last by Gyannea 20 years, 2 months ago
I''m trying to follow what you have done but I am afraid I don''t know C# (have no idea how it relates to C/C++).

I had to use a ->QueryInterface() method on the directsound object to even begin. Is that where you are having the error?

I create the DirectSound Capture buffer and then use the query interface with the GUID identifier for the Notify interface. After I get that, then I set up the notification events. Unfortunately, at least in C/C++ you can''t just call the Create object function as you can for the Direct Sound object and Direct Sound Buffer object.

Here''s my code (directsoundcapture buffer has been created:

// Create Notification interface for the capture buffer
if(FAILED(pdsRXBufOb->QueryInterface(IID_IDirectSoundNotify, (void **)&pdsNotifyOb)))
{
return(DSC_QUERY_NOTIFY_FAIL);
}
// Now the notify object is given by ''pdsNotifyOb->...''

// Create the notification points and Event object
dsNotify = new DSBPOSITIONNOTIFY [temp]; // Allocate memory for the structure array
offset = bytestoread - 1;
hevent = CreateEvent(NULL, FALSE, FALSE, NULL); // Create event object unsignaled
for(index = 0; index < temp; index++) // Load the notify structure with positions
{
(dsNotify + index)->dwOffset = offset;
(dsNotify + index)->hEventNotify = hevent;
offset = offset + bytestoread;
}
if(FAILED(pdsNotifyOb->SetNotificationPositions(temp, dsNotify)))
{
delete dsNotify;
dsNotify = NULL;
CloseHandle(hevent);
hevent = NULL;
SAFE_RELEASE(pdsNotifyOb);// Release buffer notify object
return((DSC_NOTIFY_POS_FAIL));
}
delete dsNotify;
dsNotify = NULL;
SAFE_RELEASE(pdsNotifyOb);// Release buffer notify object

========================== End of junk

Maybe you can help me out with the C# stuff and tell me where you are.

Brian
Brian Reinhold
Advertisement
Cheers for the quick reply!

It seems most of our code is very similar, or at least most that you added in this post, that is. Although I don''t know c/c++ myself, it does appear that from the section where you "Create the notification points and Event object" onwards, there are great similarities between the code. Which bit is it that you would like me to explain? Would you like me to run through all of it? I''d be happy to as I''m desperate for help as this run-time exception has really got me flummoxed. In your code I do not understand what QueryInterface is used for, as I said i''m unfamiliar with c++. I copied the code over to the VS debugger but I got a lot of ambiguity in the topics which were shown when I used the dynamic help to try and resolve why it was used.

Thanks for replying, and for showing interest, it''s people like you who are great help in these forums.

r.casson
Just thought i''d post to say that I figured out this particular problem. In both managed and unmanaged code there are certain properties that have to be set to ensure the buffer is created without an argument exception being thrown. In the sdk documentation for unmanaged C++, these guidelines are clearly set out. As an example, on the url that follows, there is a description of each property and how it would be applied when writing in unmanaged c++:

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/htm/dsbufferdesc.asp


Unfortunately, the documentation for c# is very lacking. Therefore, i''d advise any one who has similar problems when writing managed code to refer to both the managed and unmanaged sdk documentation and try and apply the code examples and class descriptions to your own code, as it appears the managed documentation is quite incomplete.

Cheers,

richard casson
There are two interesting items here. One has nothing to do with the problem, and the other does. First I got an email notification that someone had responded to my post yesterday, yet when I went to this site, the latest post was my post. Now I got another notification and I see two posts (both by you). Weird.

Now for the DirectSound Stuff. I found something similar trying to set notifications for DirectSoundBuffers (but not DirectSoundCaptureBuffers). In order to use notifications at all, you had to specify a special flag regarding that aspect in the buffer properties structure.

What I also learned is that using notifications on the DirectSoundBuffer may limit your ability to do hardware accelleration. Hopefully, newer soundcards/drivers don''t have that restriction. On the other hand, capture buffers don''t have that restriction.

So I have removed notifications on the playback and only have them on the capture, and I base everything on the capture timing. That works for my application since I am controlling a radio and ALWAYS receive (capture). When I send (playback) I use the same sample rate, write the same size hunk to the playback buffer as I read from the capture buffer, and do everything in one high priority thread.

You would think everything would be hunky dory, right? No. For some reason, at some (most) sample rates, the capture takes longer than the send. The only way that can be as far as I know is that there are two clocks. So when I am sending, every once and a while I have to load the playback buffer twice for one read of the capture buffer.

Brian

PS Glad you solved your problem. It''s hard to find much info on DirectSound and even harder to find it on DirectSoundCapture and virtually impossible to find anything about use of both.
Brian Reinhold

This topic is closed to new replies.

Advertisement