Question

I'm using DirectSoundFullDuplexCreate8 for recording and, under certain circumstances, playback under Win 7. I have a couple of questions.

One is very simple- will FullDuplex work with all audio hardware? In some cases we'll be using different devices for record and playback. So far that seems to work, but if there are machines that won't support the Win version of full duplex we can roll our own.

The other is probably a foolish question, but I don't see how to set up event notifications for recording. Here's the code I've got so far, but I don't see how to start recording or how to set things up so that I can copy the data being recorded to other buffers, including playback buffers:

hr = DirectSoundFullDuplexCreate8((LPCGUID)recordDeviceDS, (LPCGUID)playbackDeviceDS&capBufferDescription, &playBufferDescription, hWnd, DSSCL_PRIORITY, &pDSFullDuplex,     &pDSCaptureBuffer8, &pDSPlayBuffer8, NULL );
if (hr != DS_OK)
    return false;

// Set up the notify events
hr = pDSCaptureBuffer8->QueryInterface(IID_IDirectSoundNotify, (LPVOID*)&pDSNotify);
if (hr != DS_OK)
    return false;
for (int i = 0; i < 3; ++i)
{
    eventHandles[i] = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (eventHandles[i] == NULL)
        return false;
}
notifyEvents[0].dwOffset = 500;
notifyEvents[0].hEventNotify = eventHandles[0];

notifyEvents[1].dwOffset = 1000;
notifyEvents[1].hEventNotify = eventHandles[1];

notifyEvents[2].dwOffset = DSBPN_OFFSETSTOP;
notifyEvents[2].hEventNotify = eventHandles[2];

hr = pDSNotify->SetNotificationPositions(NUM_CAP_EVENTS, notifyEvents);
if (hr != DS_OK)
    return false;
pDSNotify->Release();

What comes next? I assume I use:

pDSCaptureBuffer8->Start(true);

to start capture, but I don't see any reference to how to set up a DS event handler function that is activated when the right amount of data has been accumulated.

Was it helpful?

Solution

Welcome to StackOverflow. For future reference, it's better to ask one precise question at a time.

One is very simple- will FullDuplex work with all audio hardware?

If memory serves, I don't think so. Especially if the hardware is USB or if the capture and recording devices aren't on the same sound card. And if it does work across differenty physical devices (or usb), you likely won't get any benefits from it such as AEC.

I believe the only reason why you would want to use DirectSoundFullDuplexCreate as opposed to just manually creating the capture and playback object seperates is for AEC (acoustic echo cancellation support). And if memory serves, the built in AEC in in Windows for DirectSound isn't very good and doesn't do echo cancellation very well. (YMMV)

As per MSDN:

Existing applications that access Windows XP Acoustic Echo Cancellation (AEC) features via the DirectSound API will no longer obtain AEC when running on Windows Vista.

The above will apply to Windows 7. Hence, consider DirectSoundFullDuplexCreate as a dead API. Just manually create a capture and playback buffer separately.

If you need AEC, you can look at using the AEC System Filter. There's an old sample applicaiton in the Windows SDK that shows you how to use it. http://msdn.microsoft.com/en-us/library/ff536174.aspx

but I don't see how to set up event notifications for recording. Here's the code I've got so far, but I don't see how to start recording or how to set things up so that I can copy the data being recorded to other buffers, including playback buffers:

Also, setting event handles on DirectSound objects can be unreliable. You are better off just polling the capture and playback buffer positions periodically (IDirectSoundCaptureBuffer8::GetCurrentPosition). You'd have to handle all the cases of waking up early and waking up late with event handles. So Sleep() will work just as well as WaitForSingleObject.

To start recording, call IDirectSoundCaptureBuffer8::Start()

Any other questions?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top