NAudio Q&A Session 4
September 18. 2016 Posted in:
Here’s my latest NAudio Q&A livestream video.
- Mp3Frame is null while streaming mp3
- Using NAudio for my GameBoy emulator
- How to store a .WAV file in Windows 10 with NAudio
- NAudio get audio from cypress usb device
- NAudio and speech synthesis null reference error
- Reduce delay in mapping speaker and mic volume using NAudio
- MmException Unspecified Error calling WaveOutOpen
- Play four different wav files over ASIO on 4 stereo channels
- Sound Record from multiple inputs and outputs
Unfortunately I was interrupted by noisy builders and children before answering all the questions I wanted to. Here’s the final one I intended to tackle…
Want to get up to speed with the the fundamentals principles of digital audio and how to got about writing audio applications with NAudio? Be sure to check out my Pluralsight courses, Digital Audio Fundamentals, and Audio Programming with NAudio.
Great website and documentation, however i cannot seem to find an answer to the question below:Tim
I would like to know if there is a way to play a recorded file (mp3 or wav) and send the signal to a input device (WaveIn) e.g. Microphone
Can anybody help with that?
hi Tim, sadly that's not something the Windows APIs make possible. You need to purchase a "virtual audio cable" or similar which lets you play audio to a virtual output that is patched to another virtual inputMark Heath
Thanks for your quick response, not the answer i would like to hear but i understand why this isn't possible. This also seems the reason why i cannot find an application which already exist and does the trick.Tim
Hopefully i can find some time next week to try it. If you like i can send you an update if my project is finished if i can ever finish it :s
I would love to have a bit of direction on modifying the wave file writer to do something Mark mentioned in a comment on StackOverflow... it was related to playing then overwriting part of the audio... Mark's comment was - " I use a customised version of WaveFileWriter that can open an existing WAV file, and lets you reposition within the data chunk."Harold Day
When I set the position, checking block align, the writer still appends to the end of the wave instead of over writing it.
hi Harold, I'm afraid my customised WaveFileWriter that can write over an existing file is not open source - I made it for a commercial project. The general approach is, first create a blank WAV file of the duration you want. Then one thread can be playing from it, while another thread is using a customised version WaveFileWriter that can overwrite rather than append. It seems to work better than trying to read from a file that is being writtenMark Heath
Thanks for the reply, and a quick one I might add.Harold Day
That is the push along the path I needed. I had not thought about creating a second blank file. I tweaked the file permissions to the writer and the Audio file reader so that recording and playing/rewinding from the same file was easy . Overwrite capability was requested, so I was trying to do it to the same file I already had open. That didn't work so well. Thanks again for the response.
yes, you do need to make sure that the permissions used to open both streams don't deny the other accessMark Heath
another trick I used was in debug mode I'd fill the original file with a (quiet) sine wave, which made it very obvious if the reader was playing audio that hadn't been overwritten by the writer yetMark Heath
Hello Mark,Frank Post
I have a brief question regarding compatible multi-channel sounds cards that would allow proper input/output mapping using the MultiplexingWaveProvider. I have tried several Sound Blasters 7:1 and
5:1 internal cards as well as an ASUS DGX 5.1 sound card and using the ASIO4all driver with no luck. Either I
get no sound or I am getting sound throughout all the channels. For testing purposes, I used your sample code described in your article to test the card's compatibility.
Would you be so kind to let me know what Multi-Channel Audio Cards in particular are known to be compatible
with NAudio's input/output channel mapping?
Thank you for your time.
It very much depends on the drivers of particular cards. My only real experience of working with multi-output cards is pro-audio USB devices (e.g. Focusrite Scarlett series) which have ASIO drivers to support the multiple outputsMark Heath
Thank you Mark. I purchased the Focusrite Scarlett 2i4 2n Gen to test. Is it required to use AsioOut or can the WaveOutEvent be used for mapping multichannel input-to-outputs? I have a large code set that heavily uses theFrank Post
WaveOutEvent and when attempting to implement the AsioOut it continues to throw the exception "Unable to instantiate ASIO .. Check if STAThread is set". When using the WaveOutEvent it only realizes 1 input channel and 2 output channels instead to 4 available channels. I'd prefer to use the WaveOutEvent to avoid any major code modifications if possible. If the WaveOutEvent can be used is there any way for it to realize all the available input/output channels?
Thank you Mark for your time.
Yes, AsioOut is likely the only one you can use for multichannel ins and outs. What sort of application are you using it from - is it a console app?Mark Heath
Hi Mark ... it is a Windows Form Application ... it is an application that continues to grow over the past 5 years. The new feature that is being implemented is the ability to play multiple tracks at the same time through selected channels. There is a main form that acts as a controller "container" that invokes an instance of the music application and displays it as a tab. Each instance essentially plays a provided playlist of tracks mapped to one of the available outputs. Currently the application can play two instances using the WaveOutEvent by splitting the raw audio to right and left front. Now we would like to expand this to play at least up to 4 channels (4 playlist zones).Frank Post
Don't you have STAThread set on your main thread? The ASIOOut object should be created on the UI threadMark Heath