"Capture buffer" Notification
If you want to regularly copy data from the "Capture buffer", your applicationProgramYou must know when the read pointer (The position of the read pointer is the highest position where data can be safely read) will arrive at a specific position in the buffer zone. One way to obtain this information is throughIdirectsoundcapturebuffer8: getcurrentpositionMethod to poll the position of the read pointer. Another more effective method is to use notification ). UseIdirectsoundpolicy8: setnotifposipositionsMethod, you can set several points in the buffer, where the event will be triggered. You cannot set it when the buffer zone is in use.
First, you must getIdirectsoundpolicy8Interface. You can useQueryInterfaceMethod.
Use Win32CreateeventMethod To create an event object for each notification location. Place the event handle in the heventpolicy member of a dsbpositionpolicy struct. In the dwoffset member of this struct, specify the offset of the event to be triggered in the buffer zone. If you want to set multiple notification locations, pass the address of this struct (or struct array)SetnotifposipositionsMethod.
In the following example, three notification locations are set in the buffer for one second. The first event is triggered when the reading pointer approaches the buffer point, the other event is triggered when the reading pointer's buffer end point, and the third event is triggered when the capture stops.
Code
Hresult setcapturenotifications (lpdirectsoundcapturebuffer8 pdscb)
{
# Define Cevents 3
Lpdirectsoundpolicy8 pdsnotify;
Waveformatex WFX;
Handle rghevent [cevents]={0};
Dsbpositionnotify rgdsbpn [cevents];
Hresult hr;
If (Null = Pdscb) Return E_invalidarg;
If (Failed (HR = Pdscb -> QueryInterface (iid_idirectsoundnotify, (lpvoid * ) & Pdsnoodle )))
{
Return HR;
}
If (Failed (HR = Pdscb -> Getformat ( & WFX, Sizeof (Waveformatex), null )))
{
Return HR;
}
// Create events.
For ( Int I = 0 ; I < Cevents; ++ I)
{
Rghevent [I] = Createevent (null, true, false, null );
If (Null = Rghevent [I])
{
HR = Getlasterror ();
Return HR;
}
}
// Describe communications.
Rgdsbpn [ 0 ]. Dwoffset = (WFX. navgbytespersec / 2 ) - 1 ;
Rgdsbpn [ 0 ]. Heventpolicy = Rghevent [ 0 ];
Rgdsbpn [ 1 ]. Dwoffset = WFX. navgbytespersec - 1 ;
Rgdsbpn [ 1 ]. Heventpolicy = Rghevent [ 1 ];
Rgdsbpn [ 2 ]. Dwoffset = Dsbpn_offsetstop;
Rgdsbpn [ 2 ]. Heventpolicy = Rghevent [ 2 ];
// Create communications.
HR = Pdsnoodle -> Setnotifpositions (cevents, rgdsbpn );
Pdsnoodle -> Release ();
Return HR;
}
View others:
Yan
1. enumerate "capturing devices"
2. Create a "capture device object"
3. "capture device" Performance
4. Create a "capture buffer"
5. "Capture buffer" Information
6. "Capture buffer" Notification
7. "Capture buffer" Special Effect
8. Use "Capture buffer"
9. Write to WAV file