AudioSink Class
TOC
Collapse the table of content
Expand the table of content

AudioSink Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Exposes the capture graph for audio devices. Derive from this class to receive audio information and to obtain the capture graph through AudioSink.CaptureSource.

System.Object
  System.Windows.Media.AudioSink

Namespace:  System.Windows.Media
Assembly:  System.Windows (in System.Windows.dll)

public abstract class AudioSink

The AudioSink type exposes the following members.

  NameDescription
Public methodAudioSinkInitializes a new instance of the AudioSink class.
Top

  NameDescription
Public propertyCaptureSourceGets or sets a capture source that is associated with this AudioSink.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeFrees the resources that are used by the AudioSink class. (Overrides Object.Finalize().)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnCaptureStartedWhen overridden in a derived class, is invoked when an audio device starts capturing audio data.
Protected methodOnCaptureStoppedWhen overridden in a derived class, is invoked when an audio device stops capturing audio data.
Protected methodOnFormatChangeWhen overridden in a derived class, is invoked when an audio device reports an audio format change.
Protected methodOnSamplesWhen overridden in a derived class, is invoked when an audio device captures a complete audio sample.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

To obtain audio information from an audio input device in Windows Phone, you derive your custom audio sink from AudioSink.

AudioSink exposes several virtual callbacks:

You must provide overrides for the callbacks in order to compile when you derive from AudioSink. However, you can implement a basic but functional AudioSink that can have empty callback overrides and that uses only the methods of the CaptureSource from AudioSink.CaptureSource. For more information, see CaptureSource.

Important noteImportant Note:

multiple devices The 7x27a processor allows audio input on only one stereo bus at a time. This means applications cannot concurrently capture more than one audio source on these devices. If your application is using AudioSink along with FileSink on 7x27a devices, AudioSink will not get audio samples and AudioCaptureDevice will be set to null. FileSink works fine on the 7x27a processor. FileSink or AudioSink work correctly if used independently.

Implementing AudioSink Overrides

In order to work with raw audio from a capture graph, you must override OnSamples and provide an implementation in your audio sink that converts the sampleData to your destination format. You can then use the numbers that you obtained from BitsPerSample, Channels, and SamplesPerSecond to convert a bit stream to a PCM audio format. Your conversion logic could use a series of nested loops and appropriate data types (such as Byte for 8-bit and Int32 for 32-bit) to obtain discrete samples.

If you provide a meaningful override of OnSamples, you should also provide a meaningful OnFormatChange override. The AudioFormat information for this sink can change between the time that the device was first connected and the actual time of capture. Handling OnFormatChange is the only way to know the true format information at run time.

You can use OnCaptureStarted and OnCaptureStopped as UI change notifications to indicate to the user that the audio is currently being captured or that capture has stopped. You can also use the notifications as sentinels to block certain other actions in your application while the capture is ongoing.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Show:
© 2017 Microsoft