How to mute a WaveOut? I know I can save current volume to variable, then set Volume to 0f. To unmute I just read that saved variable. However in Windows Volume Control panel it not shows "mute icon". Is any way to mute output just telling it to that system which is using WaveOut? Subquestion: DirectSoundOut uses DirectX, AsioOut uses Asio driver, and what is using WaveOut?
You won't see the mute icon because it is not muting your soundcard for all applications, just for the instance of WaveOut you are using. This is because NAudio is passing the handle to waveOutSetVolume, not the device identifier. You could call WaveInterop.waveOutSetVolume directly with the device identifier.
Related
Is there any way to play audio directly into a capture device in C#? In my project I will have to feed later on a virtual capture driver with audio so I can use it in other programs and play the wanted audio anywhere else, but Im not sure it is possible in C#, I tried to do this with NAudio (which is truly amazing):
var enumerator = new MMDeviceEnumerator();
MMDevice captureDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Multimedia);
WasapiOut wasapiOut = new WasapiOut(captureDevice, AudioClientShareMode.Shared, false, 0);
But ultimately it just throws a COMException with the code 0x88890003 which translates to the error "The AUDCLNT_STREAMFLAGS_LOOPBACK flag is set but the endpoint device is a capture device, not a rendering device". So in the end is there any possible solution or do I have to turn to another language like C++?
You cannot push audio to the device which generates audio on its own, "capture device".
Loopback mode means that you can have a copy of audio stream from a rendering device, but this does not work the other way.
The way things can work more or less as you assumed is when you have a special (and custom or third party, since no stock implementation of the kind exists) implementation of audio capture device, designed to generate audio supplied by external application such as your pushing the payload audio data via an API.
Switching to C++ will be of no help with this challenge.
I have little desktop app which uses UWP API to capture data from webcam (MediaCapture). On my computer it works fine -- I can capture video and audio. When I run the same program on the other computer it crashes -- as I found out I had to disable audio recording:
var media_settings = new MediaCaptureInitializationSettings();
// audio+video by default
media_settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Video;
await mediaCapture.InitializeAsync(media_settings);
Is there a way to find out in advance if given webcam supports audio recording? By "in advance" I mean the other way than trying, catching exception and in second take disabling audio :-).
You can find out if the given webcam supports audio recording by enumerating the audio devices before you initialize the MediaCaptureInitializationSettings object. After finishing enumerating the audio device, you can find whether there is a audio device from the webcam or not.
You can follow the Enumerate devices topic or see the DeviceEnumerationAndPairing sample directly to find the AudioCapture device, then you should be able to judge if there is a audio device from the webcam.
Is there any way in c#/.net of recording the current audio being played? I've searched a lot on the internet but the only result I could find is recording using a microphone.
I dont want to record using microphone input, I want to record what is being played on the computer when I click a record button.
Thanks
You have two options here:
Hardware loopback device - virtual "Stereo Mix" audio device, which acts as a regular audio capture device and in the same time produces a copy of mixed audio feed played through default audio output device of the system. Since such device shows up as real audio input device, you can use standard APIs, libraries and even exitsing applications to record from such device.
Programmatic access to a virtual loopback device as if it was microphone-like device. API on the background will duplicate played audio content and make it available for reading back as it plays. The good news is that you can access the mixed audio feed for device of your interest.
Both options are described in detail in Loopback Recording article on MSDN and available via standard audio APIs, specifically WASAPI.
For C# development you are likely to use a wrapper like NAudio.
For option 1 you will find quite a few questions on StackOverflow, and for the other option the keyword is AUDCLNT_STREAMFLAGS_LOOPBACK.
The only way to be able to receive data from another application is if the developer provides an access point, normally through some SDK, API, or other means. Without this, there is no way for your application code to receive the bytes from the other application.
The reason a microphone works is because it is receiving the sound output bytes from the application and sending those soundwave bytes back into your PC to render and output the sound. Since you have access to these bytes from the microphone you are able to capture the sound.
See if there is an API or an SDK from the developer of the application you are trying to get sound from.
I have an application which needs to play multiple audio files using nAudio but I want to mute any one when I want to. I set the Volume property of the instance of the WaveOut i want to Zero.
myWaveOut.Volume=0;
The problem is when I do that all the audio out of that application mutes. Even thou all the audio uses its own instance of WaveOut.
Why is this happening, and how can I resolve it?
The WaveOut.Volume property sets the device volume. To set the stream volume, insert a VolumeSampleProvider into your signal chain, or more simply just use the AudioFileReader class which has a Volume property.
Separate audio channels volume is adjusted in other way than the main volume. There is quite related discussion on NAudio codeplex page.
I need to be able to play a "ding" sound in Windows 8 (a kind of beep that fades out gently), similar to what is seen here: http://tonematrix.audiotool.com/
Is it possible to somehow play this given a frequency? Or can I download sound files for this anywhere?
I noticed how the SoundPlayer no longer works, so the old code I used in my desktop program won't work anymore.
If you have a sound file of it, such as an mp3 or wav, use the MediaElement control. There are a few ways of doing this. For example, set the Source property to a URL (Uri class) or call SetSource() then the Play method.
Windows 8 does not include an easy way to generate a tone or pitch (assuming you mean metro/Windows Store apps). If you can generate the bytes needed to play the sound, place them in a buffer, create an IRandomAccessStream for it then pass it to SetSource. You can emulate the fade out by setting the Volume with a Timer.
It would be nice if there was a "fade out" audio effect that could be used with SetAudioEffect but Microsoft does not provide any audio effects at this time.