Waveform Capture: (6) "Capture buffer" Notification

Source: Internet
Author: User

"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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.