user1828100
user1828100

Reputation: 27

How do I change my sound card settings using C#

I have a simple c# console app that plays a wav file. I want to change the sound card settings in C# in my app to 24bit/48Khz. How do I do that programtically?

    static void Main(string[] args)
    {
        SoundPlayer simpleSound = new SoundPlayer(MyProg.Properties.Resources.BOOTLOAD48000);
        simpleSound.Play();

     }

Upvotes: 0

Views: 799

Answers (3)

Mark Heath
Mark Heath

Reputation: 49482

To force Windows to use a specific sample rate you need to use WASAPI in exclusive mode. Otherwise, you are sharing the soundcard with other applications, and they may need it to be at a different sample rate. NAudio allows you to do this. You need to pass AudioClientShareMode.Exclusive into the constructor for WasapiOut.

Note that WASAPI can only be used on Windows Vista and above.

Upvotes: 0

Roman Ryltsov
Roman Ryltsov

Reputation: 69632

Audio playback subsystem is not as straightforward as you might thought of. At the very least, your playback does not go to sound card directly: it is queued somewhere into cozy place so that data is mixed behind the scenes with audio from other applications, if any, and then its forwarded to the device.

I have no faintest idea why you want, or even need, to have it bit accurate on hardware, however if it is what you really need then you need to leverage low level exclusive access APIs to get an intimate connection with audio rendering hardware and deliver the data right into playback buffer bypassing any mixing that typically takes place on the way. Most likely those APIs are native, and for sure you will need to delivier raw data after you already managed to take it out of the file. It is going to be not as easy as SoundPlayer.Play.

The good news however is that if the hardware is really capable of playing this format, you have good chances to do the mentioned.

Upvotes: 1

avishayp
avishayp

Reputation: 706

The sample rate, bit depth, channels, and anything else, is embedded in the wav file's header.

The straight forward way to resample is by using a 3rd party S.A NAudio. search stackoverflow to find more detailed answers.

Upvotes: 1

Related Questions