異世界


2012年11月22日 星期四

C# Windows混音器控制

資料來源 :  Audio Library Part I - (Windows Mixer Control)

 

Introduction

In this article, I'll show you how to use Windows Mixer from C#.

For some time, I was trying to get information about how to program the mixer from C#. I didn't have too much luck, and the few examples found were in C++, so… I took the hard and fun way... doing it myself.

This library is part of my Audio library to control Wave Audio (Playback/Recording), Mixer,Playback/Recording compressed files using ACM, basic speech recognition and some other stuff that I'll be releasing in future articles.

AudioMixer Namespace

 

Hierarchical Objects View
Sample screenshot

The hierarchical view shows how the classes are organized.

The main object Mixers contains two Mixer objects, Playback and Recording; those will work with default devices, but can be changed by setting the property Mixers.Playback.DeviceId orMixers.Recording.DeviceId.

I made it as simple as possible by hiding all the flat Win32 API implementation from the developer and creating a hierarchical set of objects.

Every mixer is autonomous, meaning you can have Playback mixer set to one soundcard and Recordingmixer to another one. Also each one contains two arrays or MixerLines (Lines, UserLines).

Lines object will contain all lines inside the mixer, for example all the lines that don't have controls associated with it or lines that are not source lines.

UserLines will contains all lines that the developer can interact with, having controls like Volume, Mute, Fadder,Bass, etc. (basically it is the same as Lines object but a filter was applied to it).

Every Line will contain a collection of controls, like Mute, Volume, Bass, Fader, etc.

If you are interested in knowing more about how Windows Mixer works, here is an excellent link with all the information about it.

Let's See Some Code

  • To Get the Audio Devices in the Computer
    foreach(MixerDetail mixerDetail in mMixers.Devices)
    {
        ...
        ...
    }


 



  • To Get the Input Devices

    foreach(MixerDetail mixerDetail in mMixers.Recording.Devices)
    {
        ...
        ...
    }



  •      More  ………

沒有留言:

張貼留言