yes, NAudio is simply calling through to the WASAPI APIs - it doesn't introduce any restrictions of its own. I suspect that this is due to the device driver. I would suspect that Shared mode relies on Windows to convert 32 or 24 bit down to 16 while exclusive mode passes the audio directly to the sound card which is likely 16 bir only.
New Post: 24 bit WASAPI
New Post: 24 bit WASAPI
Thanks for the quick reply. My interest is in using sound cards for intrumentation, hence the wish to avoid low level artefacts introduced by software layers, even if not audible.
For information, all 3 sound cards advertised 24 bit conversion. For two of them (the third was proprietary) I downloaded the codec (A/D & D/A) data sheet some time ago, and confirmed that it was designed for 24 bit operation, although system noise will restrict the number of usable bits to perhaps 18. For the only card with an ASIO driver I have run a managed ASIO interface (an extension of Rob Philpott's library) and confirmed that noise level drops by a few dB when switching from 16 to 24 bits, as do low level artefacts.
Apologies if I am posting this in the wrong forum, as NAudio is blameless, but others may like to know that shelling out for a 24 bit card won't necessarily get them 24 bit WASAPI.
New Post: Mixing Example (2 MP3 inputs)
Hello,
I have been looking at this project on and off for the past few months and havent figured out how to mix 2 MP3 files (i.e. play them at the same time).
Can you provide a really brief example of how to do so? I did look at the MixingSampleProvider in the demo but still couldnt figure it out.
Thanks,
Andrew
New Post: 24 bit WASAPI
Problem fixed! (sort of)
It appears that, in exclusive mode, some drivers respond to a WaveFormatExtensible better than a WaveFormat, the solution being to try both structures on IsFormatSupported(), and use whichever gives a positive result. Doing so confirmed the 24-bit response at all sample rates for two of the cards. The third card has a low level stream of 24 bit audio in 32 bits words, which is not supported by the NAudio constructor for WaveFormatExtensible. Adding a new constructor fixed that problem.
All that remains is to get the data in and out ;-)
New Post: hide application from windows volume mixer
I don't know how to hide the application panel on the mixer, but if you just want to lock the setting, add an endpoint.AudioEndpointVolume.OnVolumeNotification callback, and change the setting back the way you want. It's not a perfect lock, but it might be good enough.
New Post: Echo recorded voice
Hi, I'm trying to record the voice, and play each buffer as soon as it is received, like implementing a voice-echo application.
But there is gaps in the output.
Here is the code:
public partial class Form1 : Form { private WaveIn _waveIn = new WaveIn(); private WaveOut _waveOut = new WaveOut(); BufferedWaveProvider _waveProvider = new BufferedWaveProvider(new WaveFormat()); public Form1() { InitializeComponent(); } private void btnRec_Click(object sender, EventArgs e) { _waveIn.DataAvailable += waveIn_DataAvailable; _waveIn.BufferMilliseconds = 300; _waveIn.StartRecording(); _waveOut.Init(_waveProvider); _waveOut.Play(); } void waveIn_DataAvailable(object sender, WaveInEventArgs e) { _waveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded); } private void btnStopRec_Click(object sender, EventArgs e) { _waveIn.StopRecording(); _waveIn.Dispose(); _waveOut.Stop(); _waveOut.Dispose(); } }
New Post: WaveOutEvent buffers is null
Every once in a while when I close my application while using WaveOutEvent i get a NullReferenceException from the DoPlayback() function. It turns out this.buffers is null.
Screenshot from VS2010, when Exception happens
A bandaid to fix the problem I now check for the null value in DoPlayback();
private void DoPlayback() { if (this.buffers == null || this.waveStream == null) return; TimeSpan waitTime = TimeSpan.FromSeconds((double)this.buffers[0].BufferSize / (this.waveStream.WaveFormat.AverageBytesPerSecond * 2)); ......... }
I dont get a good stack trace back for some reason, I assume the call to DoPlayback() is still in the ThreadPool after I dispose of WaveOutEvent?
ThreadPool.QueueUserWorkItem((state) => PlaybackThread(), null);
Maybe the cure (not bandaid) would be to "un-queue" the thread form the pool on disposal? not sure if that is possible or makes any sense...
I hope this helps, or maybe I am just doing something wrong...
Thanks,
Brandon Hansen, KG6YPI
ps.. I noticed my callsign (kg6ypi) got into the readme file, you can attach my name to it also if you wish, thanks.
Created Issue: AudioEndpointVolumeCallback causes AccessViolation [16360]
In this method Marshal.PtrToStructure is used, which causes an access violation, causing the crash.
I'm running Win7 x64 and the latest Naudio (b3a412ad55a8)
Commented Issue: AudioEndpointVolumeCallback causes AccessViolation [16360]
In this method Marshal.PtrToStructure is used, which causes an access violation, causing the crash.
I'm running Win7 x64 and the latest Naudio (b3a412ad55a8)
Comments: My bad, the violation is not caused by C#, as far as I can tell. Can anyone reproduce this problem?
New Post: hide application from windows volume mixer
Thank you for your reply. I somehow did what you explained but it was still visible and I said "whatever". I am completely over it now :)
You can imagine how much I tried from my words above I guess.
New Post: hide application from windows volume mixer
It is a bit tricky but not impossible. Assuming you are not writing any malicious code or something to spy on people by turning on the mic or anything, here is how it could be accomplished:
1. Load a dll into explorer.exe and hook into either ShellExecute or CreateProcess. Not sure which, but one of them should work
2. Intercept when sndvol.exe is being started
3. When sndvol process is loaded and starts to accept window events, find it's window handle
http://s10.postimage.org/nd8xgzk3t/Capture1.png
4. Find a child window of type TileListView
5. Find a child window of type TileSled
6. Enumerate child windows
7. Find the window handle of the volume mixer tile of your "invisible" app
http://s10.postimage.org/6e4kfgya1/Capture2.png
8. Set it's Visible property to false, Width to 0
http://s10.postimage.org/ct3lc54zt/Capture3.png
9. Slide the remaining tiles to the left to fill the gap
10. Resize & relocate the main sndvol window
11. ???
12. Profit
kolay gelsin
New Post: hide application from windows volume mixer
on a second thought, I'd probably hijack mmdevapi.dll, and hide my process from the results.
Commented Issue: AudioEndpointVolumeCallback causes AccessViolation [16360]
In this method Marshal.PtrToStructure is used, which causes an access violation, causing the crash.
I'm running Win7 x64 and the latest Naudio (b3a412ad55a8)
Comments: After some more searching, I find the answer in the forum: http://naudio.codeplex.com/discussions/208808/ All that's needed is, in AudioEndpointVolumeCallback .cs, change the return type of OnNotify to 'void' and remove the 'return 0;' statement, then update the interface in IAudioEndpointVolumeCallback.cs to reflect this change, and the crash is gone.
New Post: Stop or Dispose methods hang if USB device undocked while playing wav file
Thanks for this post folks.
I ran into a similiar problem this evening. I noticed whenever I unplugged my headphones my waveout device would stop reading the input stream. I put in a timeout that would throw an exception and try to dispose of the waveout device. The dispose method would hang.
I switched to the WaveOutEvent class and everything is happy again.
New Post: hide application from windows volume mixer
I think this file is what should be altered
http://source.winehq.org/source/dlls/mmdevapi/audiovolume.c
Anyway, thank you for the suggestions but again application of these methods require more keyboard crunching then what I was actually doing. Besides there are a wide variety of audio applications that are visible in sound mixer popup, so why bother to be invisible.
New Post: hide application from windows volume mixer
I think I didn't clear enough. I posted the wine library as a starting point, but modifying mmdevapi code and replacing the entire dll would take longer to complete. I will explain it a bit later, but after a little googleing, here is what I found about how sndvol acquires a list of apps that are using sound hardware.
I think the legitimate way of getting the audio apps would be something like this (which I believe it's what sndvol.exe does. Just do a google search for IAudioSessionControl and sndvol. need to attach a debugger to see what it really does):
1. Instantiate IMMDeviceEnumerator (CoCreateInstance, declared in mmdeviceapi.h in Windows SDK)
2. Call IMMDeviceEnumerator::EnumAudioEndpoints to get a collection of IMMDevice
3. Call IMMDevice::Activate to get an instance of IAudioSessionManager2 (declared in audiopolicy.h)
4. Call IAudioSessionManager2::GetSessionEnumerator and get an IAudioSessionEnumerator
5. Call IAudioSessionEnumerator::GetCount and
6. Iterate from 0 to count and call IAudioSessionEnumerator::GetSession to get IAudioSessionControl for each session (The apps that appear in sndvol)
What we want to do is, somehow modify IAudioSessionEnumerator::GetCount so it returns (the correct value - 1) if our app is running, and modify IAudioSessionEnumerator::GetSession to not return the session of our app.
Method 1:
Like you said, you could modify Wine code to create a proxy dll which does the audio session filtering. But then you'd need to create proxy classes for the chain I mentioned above, and detour LoadLibrary method in sndvol process in order to load your own mmdevapi.dll when it starts up.
Method 2:
Alternatively, you can find the offsets of the two methods I mentioned in 5 and 6, and detour them in sndvol. Which I believe wouldn't take more than a couple hours to code using IdaPro/ollydbg & EasyHook/detours/whatevs
New Post: 24 bit WASAPI
yes, WASAPI likes to work with WaveFormatExtensible. I think there is a way to get it to enumerate supported formats, so it is best to use the WaveFormat structures it reports.
New Post: DirectSoundOut support for SetVolume and so on?
possibly because the DirectSound object is created and used on a background thread?
New Post: Repeated Start/StopRecording does not work
are you able to identify the line in the NAudio code that is hanging?