Поделиться через


AudioSink Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Inheritance Hierarchy

System.Object
  System.Windows.Media.AudioSink

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

Syntax

'Declaration
Public MustInherit Class AudioSink
public abstract class AudioSink

The AudioSink type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows Phone AudioSink Initializes a new instance of the AudioSink class.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows Phone CaptureSource Gets or sets a capture source that is associated with this AudioSink.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone Finalize Frees the resources that are used by the AudioSink class. (Overrides Object.Finalize().)
Public methodSupported by Silverlight for Windows Phone GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone OnCaptureStarted When overridden in a derived class, is invoked when an audio device starts capturing audio data.
Protected methodSupported by Silverlight for Windows Phone OnCaptureStopped When overridden in a derived class, is invoked when an audio device stops capturing audio data.
Protected methodSupported by Silverlight for Windows Phone OnFormatChange When overridden in a derived class, is invoked when an audio device reports an audio format change.
Protected methodSupported by Silverlight for Windows Phone OnSamples When overridden in a derived class, is invoked when an audio device captures a complete audio sample.
Public methodSupported by Silverlight for Windows Phone ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

To obtain audio information from an audio input device in Silverlight, 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.

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.

Version Information

Silverlight

Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

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