Waveform Capture: (4) create a "capture buffer"

Source: Internet
Author: User
Create a "capture buffer" "

CallIdirectsoundcapture8: createcapturebufferMethod To create a capture buffer.
One of the parameters of this method is a dscbufferdesc struct that describes the features of the desired buffer. The last member of this struct is a waveformatex struct. This struct must be initialized in a specific WAV format.

NOTE: If your applicationProgramCapture these sounds while playing the sound. When the format of the capture buffer is different from that of the primary buffer, the creation of the capture buffer will fail. The reason is that some sound cards only have a single clock frequency and do not support capturing and playing at two different frequencies.

The following function creates a buffer to capture data in one second. Note: To pass in an interface for capturing device objects as a parameter, this interface must pass throughDirectsoundcapturecreate8Instead of using the previousDirectsoundcapturecreateFunction; otherwise, the buffer does not support the idirectsoundcapturebuffer8 interface.

Code
Hresult createcapturebuffer (lpdirectsoundcapture8 PDSC,
Lpdirectsoundcapturebuffer8 * Ppdscb8)
{
Hresult hr;
Dscbufferdesc dscbd;
Lpdirectsoundcapturebuffer pdscb;
Waveformatex WFX =
{Wave_format_pcm, 2 , 44100 , 176400 , 4 , 16 , 0 };
// Wformattag, nchannels, nsamplespersec, mavgbytespersec,
// Nblockalign, wbitspersample, cbsize
 
If (Null = PDSC) | (Null = Ppdscb8 )) Return E_invalidarg;
Dscbd. dwsize =   Sizeof (Dscbufferdesc );
Dscbd. dwflags =   0 ;
Dscbd. dwbufferbytes = WFX. navgbytespersec;
Dscbd. dwreserved =   0 ;
Dscbd. lpwfxformat =   & WFX;
Dscbd. dwfxcount =   0 ;
Dscbd. lpdscfxdesc = NULL;
 
If (Succeeded (HR = PDSC -> Createcapturebuffer ( & Dscbd, & Pdscb, null )))
{
HR = Pdscb -> QueryInterface (iid_idirectsoundcapturebuffer8, (lpvoid * ) Ppdscb8 );
Pdscb -> Release ();
}
Return HR;
}

 

 

View others:
statement
1. enumerate "capturing devices"
2. create "capture device object"
3. "Capture device" performance
4. create a "Capture buffer"
5. "Capture buffer" Information
6. "buffer capturing" Notification
7. "buffer capturing" 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.