This sample application uses the Core Audio APIs to capture audio data from an input device specified by the user and writes it to a uniquely named .wav file in the current directory. This sample demonstrates event-driven buffering.
This topic contains the following sections.
- Downloading the Sample
- Building the Sample
- Running the Sample
- Related topics
This sample demonstrates the following features.
- MMDevice API for multimedia device enumeration and selection.
- WASAPI for stream management operations such as starting and stopping the stream, and stream switching.
|Windows SDK||Windows 7|
Downloading the Sample
This sample is available in the following locations.
|Windows SDK||\Program Files\Microsoft SDKs\Windows\v7.0\Samples\Multimedia\Audio\CaptureSharedEventDriven\...|
Building the Sample
To build the CaptureSharedEventDriven sample, use the following steps:
- Open the CMD shell for the Windows SDK and change to the CaptureSharedEventDriven sample directory.
- Run the command
start WASAPICaptureSharedEventDriven.slnin the CaptureSharedEventDriven directory to open the WASAPICaptureSharedEventDriven project in the Visual Studio window.
- From within the window, select the Debug or Release solution configuration, select the Build menu from the menu bar, and select the Build option. If you do not open Visual Studio from the CMD shell for the SDK, Visual Studio will not have access to the SDK build environment. In that case, the sample will not build unless you explicitly set environment variable MSSdk, which is used in the project file, WASAPICaptureSharedEventDriven.vcproj.
Running the Sample
If you build the demo application successfully, an executable file, WASAPICaptureSharedEventDriven.exe, is generated. To run it, type
WASAPICaptureSharedEventDriven in a command window followed by required or optional arguments. The following example shows how to run the sample by specifying capture duration on the default multimedia device.
WASAPICaptureSharedEventDriven.exe -d 20 -multimedia
The following table shows the arguments.
|-l||Audio capture latency in milliseconds.|
|-d||Audio capture duration in seconds.|
|-m||Disables the use of MMCSS.|
|-console||Use the default console device.|
|-communications||Use the default communication device.|
|-multimedia||Use the default multimedia device.|
|-endpoint||Use the endpoint identifier specified in the switch value.|
If the application is run without arguments, it enumerates the available devices and prompts the user to select a device for the capture session. The default console, communication, and multimedia devices are listed followed by devices and the endpoint identifiers. If no duration is specified, the audio stream from the specified device is captured for 10 seconds. The application writes the captured data to a uniquely named .wav file.
CaptureSharedEventDriven demonstrates event-driven buffering. The audio client instantiated for this sample is configured to run in shared mode and the client's processing of the audio buffer is made event driven by setting the AUDCLNT_STREAMFLAGS_EVENTCALLBACK flag in the call to IAudioClient::Initialize. The sample shows how the client must provide an event handle to the system by calling the IAudioClient::SetEventHandle method. After the capture session begins and the stream starts, the audio engine signals the supplied event handle to notify the client each time a buffer becomes ready for the client to process. The audio data can also be processed in a timer-driven loop. This mode is demostrated in the CaptureSharedTimerDriven sample.