Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8110993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:57:03+00:00 2026-06-06T01:57:03+00:00

I’m using NAudio to do a few tasks: Locate the Stereo Mix source line

  • 0

I’m using NAudio to do a few tasks:

  1. Locate the “Stereo Mix” source line
  2. Un-mute the “Stereo Mix” source line by enabling any line controls present
  3. Mute all other source lines on the same input device by disabling any line controls present

The program I’ve written can perform task 1 okay, but tasks 2 and 3 fail.

Specifically, this block of code causes the ArgumentException to be thrown:

if( control.IsBoolean ) {

    BooleanMixerControl boolControl = (BooleanMixerControl)control;
    boolControl.Value = isMuted;
    set = true;

    if( boolControl.Value != isMuted )
        throw new ArgumentException("Could not set line muted value.");
}

Here is a static class that I use to perform these tasks. It has a dependency on the current version of NAudio:

public static class RecordSourceManager {

    public static Boolean GetMicrophoneMuted(String deviceName) {

        Mixer mixer = GetMixer( deviceName );
        if( mixer == null ) throw new ArgumentException("Specified device \"" + deviceName + "\" does not exist.");

        foreach(MixerLine line in mixer.Destinations) {

            foreach(MixerLine sourceLine in line.Sources) {

                if( sourceLine.ComponentType == MixerLineComponentType.SourceMicrophone ) {

                    return GetLineMuted( sourceLine );
                }
            }
        }

        throw new ArgumentException("Specified device \"" + deviceName + "\" does not contain a microphone device.");
    }

    public static void SetMicrophoneExclusive(String deviceName, Boolean enableMicrophoneExclusivity) {

        Mixer mixer = GetMixer( deviceName );
        if( mixer == null ) throw new ArgumentException("Specified device \"" + deviceName + "\" does not exist.");

        foreach(MixerLine line in mixer.Destinations) {

            foreach(MixerLine sourceLine in line.Sources) {

                if( sourceLine.ComponentType == MixerLineComponentType.SourceMicrophone ) {

                    SetLineMuted( sourceLine, !enableMicrophoneExclusivity );

                } else {

                    SetLineMuted( sourceLine, enableMicrophoneExclusivity );
                }
            }
        }
    }

    public static Boolean GetStereoMixMuted(String deviceName) {

        Mixer mixer = GetMixer( deviceName );
        if( mixer == null ) throw new ArgumentException("Specified device \"" + deviceName + "\" does not exist.");

        foreach(MixerLine line in mixer.Destinations) {

            foreach(MixerLine sourceLine in line.Sources) {

                if( IsStereoMix( sourceLine.Name ) ) {

                    return GetLineMuted( sourceLine );
                }
            }
        }

        throw new ArgumentException("Specified device \"" + deviceName + "\" does not contain a microphone device.");
    }

    public static void SetStereoMixExclusive(String deviceName, Boolean enableStereoMixExclusivity) {

        Mixer mixer = GetMixer( deviceName );
        if( mixer == null ) throw new ArgumentException("Specified device \"" + deviceName + "\" does not exist.");

        MixerLine stereoMix;
        MixerLine parentLine;

        GetStereoMixLine( mixer, out stereoMix, out parentLine );
        if( stereoMix == null ) throw new ArgumentException("Specified device \"" + deviceName + "\" does not contain a Stereo Mix line.");

        foreach(MixerLine source in parentLine.Sources) {

            Boolean ok;

            if( IsStereoMix( source.Name ) ) {

                ok = SetLineMuted( source, !enableStereoMixExclusivity );

            } else {

                ok = SetLineMuted( source, enableStereoMixExclusivity );
            }

            if( !ok ) throw new ArgumentException("Could not set line muted state.");
        }
    }

    private static Mixer GetMixer(String deviceName) {

        foreach(Mixer mixer in Mixer.Mixers) {

            //wtr.WriteLine("Mixer: {0}, Mfg: {1}", mixer.Name, mixer.Manufacturer );
            if( String.Equals( mixer.Name, deviceName, StringComparison.OrdinalIgnoreCase ) ) return mixer;
        }

        return null;
    }

    private static void GetStereoMixLine(Mixer device, out MixerLine stereoMix, out MixerLine parentLine) {

        foreach(MixerLine line in device.Destinations) {

            foreach(MixerLine source in line.Sources) {

                if( IsStereoMix( source.Name ) ) {

                    stereoMix  = source;
                    parentLine = line;
                    return;
                }
            }

        }

        stereoMix  = null;
        parentLine = null;
    }

    private static Boolean IsStereoMix(String sourceName) {

        String[] names = new String[] {
            "Stereo Mix",
            "What U Hear",
            "What \"U\" Hear",
            "What-U-Hear",
            "Playback Redirect",
            "Wave Out",
            "Wave Out Mix",
            "Wave-Out Mix"
        };

        foreach(String name in names) {

            if( String.Equals( sourceName, name, StringComparison.OrdinalIgnoreCase ) ) return true;
        }

        return false;
    }

    private static Boolean SetLineMuted(MixerLine line, Boolean isMuted) {

        Boolean set = false;

        foreach(MixerControl control in line.Controls) {

            // Can't test if control's name == "Mute" because sometimes it's "Mic Volume" (even though it's boolean). Same goes for GetLineMuted.
            if( control.IsBoolean ) {

                BooleanMixerControl boolControl = (BooleanMixerControl)control;
                boolControl.Value = isMuted;
                set = true;

                if( boolControl.Value != isMuted )
                    throw new ArgumentException("Could not set line muted value.");
            }

        }

        return set;
    }

    private static Boolean GetLineMuted(MixerLine line) {

        foreach(MixerControl control in line.Controls) {

            if( control.IsBoolean ) {

                BooleanMixerControl boolControl = (BooleanMixerControl)control;
                return boolControl.Value;
            }
        }

        return false;
    }
}

I thought I’d take a look at NAudio’s BooleanMixerControl class, and I see this:

public bool Value {
    get {
        base.GetControlDetails();
        return (this.boolDetails.fValue == 1);
    }
    set {
        MmException.Try(MixerInterop.mixerSetControlDetails(base.mixerHandle, ref this.mixerControlDetails, base.mixerHandleType), "mixerSetControlDetails");
    }
}

Interestingly it seems the value argument to the property setter is being ignored, the mixerSetControlDetails call therefore won’t do any useful work. Is this a bug in NAudio?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:57:04+00:00Added an answer on June 6, 2026 at 1:57 am

    This feature is not implemented, and probably should be replaced with a NotImplementedException. It was amongst the first code I ever wrote for NAudio back in 2002 when I was just beginning to learn about PInvoke and pinning, and if you look at the NAudio source you will see the code that uses the value is commented out, presumably because it caused some kind of memory exception when I originally tried it.

    /// <summary>
    /// The current value of the control
    /// </summary>
    public bool Value 
    {
        get 
        {
            GetControlDetails(); // make sure we have the latest value
            return (boolDetails.fValue == 1);
        }
        set 
        {
            //GetControlDetails();
            //MixerInterop.MIXERCONTROLDETAILS_BOOLEAN boolDetails = (MixerInterop.MIXERCONTROLDETAILS_BOOLEAN) Marshal.PtrToStructure(mixerControlDetails.paDetails,typeof(MixerInterop.MIXERCONTROLDETAILS_BOOLEAN));
            //boolDetails.fValue = (value) ? 1 : 0;
            // TODO: pin the memory
            MmException.Try(MixerInterop.mixerSetControlDetails(mixerHandle, ref mixerControlDetails, MixerFlags.Value | mixerHandleType), "mixerSetControlDetails");
        }
    }   
    

    The reason it has never been fixed is that I’ve never needed to use it myself, but if someone wants to contribute a fix I’d be glad to include it in NAudio.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.