Control sound line-in - c#

How Can I control (tune up or down) the level of the line-in or microphone channel? and how can I visualize the spec (as a graph or something)?

Also see Alvas.Audio RecordPlay example http://alvas.net/alvas.audio.aspx

you can try using the mixer APIs to find the line in volume control. I've found it is very tricky to pick out the right one (especially if you want it to work in both XP and Vista/Win7). Have a look at .NET Voice Recorder for an example of how to use NAudio to do this.

Related

Recording sound in real time with c++ or C#

I have a professional sound card, and I want to record the signals from the guitar with c++ or c# for developing guitar effects in real time.
How can i record in real time through a c++ method ?
Is it mean that I need the sound card API ?
this one is enough?
Although may not be as easy as using a pre-built library, you may be able to get a C++ SDK for your sound card from the manufacturer. I would start by browsing their site or contacting support.
If that isn't an option, you can also use DirectSound which is part of the DirectX family of products. The learning curve is fairly steep but I believe it should do just about anything you want.
One final option is to look at a favorite tool (such as sound forge). A number of these tools support automation which means you can click through the app, decide what you want, then automate that sequence of events (See this as an example).
Hope that helps, best of luck!
Side Note: I have developed a number of hardware interfaces and in my experience its best to start with an example that does at least something like what you are looking for, then modify the code from there. If any particular option doesn't have an example like this I would probably skip it in favor of an example that does.
Examples
Direct Sound - Microsoft has a learning site for direct sound which you can find here. I also found this blog article which has an example for recording audio with direct sound.
Sound Forge - If you download the "Script Developers Kit" there are examples for C# in the scripts folder that should get you started. I believe this particular tool is more focused on editing and effects but I am guessing there should be automation for recording.
To just record audio in real time, any API will be fine. Note that WASAPI is the primary API (since Vista), and legacy APIs like WaveIn API, DirectSound are implemented on top of WASAPI as compatibility layers.
Regular APIs assume you are okay to certain processing latency/overhead, on the order of tens of milliseconds.
If you are going to be faster than this, and you need real time performance, such as to process data and return in back for playback as soon as possible, you need so called exclusive mode streams, where you can achieve latencies on the order of a few milliseconds, which is on par to professional audio development kits.
Windows SDK has a few audio recording samples in \Samples\multimedia\audio (C++)
It's probably a good idea to use a third party library for that.
There's a multitude of options. The ones I know of are portaudio and STK.
I like the Fmod API which supports recording (Sound recording with FMOD library) and realtime effects.

News Marquee over analog TV stream - C#

I want to put a news marquee over an analog TV stream using c#, I can stream analog TV using DirectShow but I can't figure out how to mix it with rotating text, should I create a filter? or I have to use another technology than DirectShow?
DirectShow is the simplest way of doing this but it does have a bit of a learning curve, particularly coming from C#. The Wikipedia page gives you a basic overview of DirectShow.
DirectShow tools are available in the latest Windows SDK. Using C++ for DirectShow programming is more straightforward but you can use DirectShow fairly easily via COM interop or DirectShow.net (which I haven't tried yet). If using COM interop the following article is helpful:
http://blogs.msdn.com/b/ericgu/archive/2004/09/20/232027.aspx
You may be able to use the VMR overlay filter if the animation performance is smooth enough. See the following articles
http://www.codeproject.com/KB/audio-video/VideoPicture.aspx
http://www.codeproject.com/KB/audio-video/Ticker.aspx
http://msdn.microsoft.com/en-us/library/dd407344(v=vs.85).aspx
Alternatively you will need to write your own filter that renders the text on each frame adjusting its position in synch with the time stamps of the video frames. If you only need to do this inside your own application then the following approach might be easiest
http://www.sichbo.ca/Free_Code/100_C_Sharp_directshow_filters
Microsoft officially recommend that DirectShow filters should be created in C++ for performance reasons but overlaying scrolling text should be OK in C# as the bottleneck will be the APIs used to overlay the text if you program carefully.
Actually you don't have to write a filter to draw some text over your video. Just make a graph where uncompressed video goes through sample grabber (one of standard DirectShow filters), set up a callback for the sample grabber and you'll be able to modify the video data in your callback. Doing it in C# is very easy using DirectShow.NET but not optimal due to marshalling. You can first build such a graph in GraphEditPlus, then it will show you source code in C# or C++ of how to build this graph and use sample grabber.

Audio API in C#

I need to take an audio file recorded by a man and convert it to a child's voice and mix it with a background voice track.
I have searched the internet trying to find a good program to do this but I didn't find it. Is there a C# API that can help me to implement it myself?
NAudio is .NET based and has a mixing engine - might be worth looking at for your purposes.
I think using a API and writing it yourself may fall under the "too difficult to do so" category. I would recommend using a free multi-track audio editor like Audacity, it has a pitch shift ability (that will do your child voice requirement) and you can play two files on top of each other (to do the background voice requirement)
If you still want/need a API the key word to look for when searching for the child's voice ability is "Pitch shifting"
There is some new functionality in System.Windows.Media namespace using MediaPlayer class with WPF.
But what you are doing requires signal processing and best done in C++. I do not know any good Signal Processing libraries in .NET but Emgu openCV is wrapper around OpenCV which can do advanced signal processing.
What you are trying to do requires advanced signal processing and if you do not have such a background there is no easy way to do it.
Rubber Band Library by Breakfast Quay is a C++ library (released under GPL) that can change the pitch of a recording without changing the speed. It also features formant processing, which can help with changing a voice between a man/woman/child.
See http://rubberbandaudio.com/.

C# tutorial for "listening" to the line in device

I know the obvious answer is "try google..." but i have and I either end up with graphics or cmd-line tutorials, so...
Can anyone point I in the direction of a c# tutorial for "listening" to the audio line-in? Or is it straight forward with the right namespace included? Is it even possible without using directx or some such.
I want to detect external audio activity and report it on screen.
Cheers,
This code sample looks like it has everything that you need: VolumeMeter
Presumably you just need to change the code so that instead of rendering the current volume levels you could return a flag indicating whether "something" is going on.
It's using the Managed DirectX library, which is a managed code wrapper for the native DirectX APIs.
You need an external library to do that. These have .NET bindings:
FMOD is widely used in games, and has an opensource license (and a paid one).
BASS Audio Library is another choice. It's a bit more lightweight.
IrrKlang I haven't use this one, but I was told it is worth the money
NAudio I found just now, because I forgot the IrrKlang's name, and had to google for it. This one looks promising.
OR MDX can do this I think.
check out the VoiceRecorder sample application on Codeplex which shows how to do this using NAudio. This Coding4Fun article explains it in more detail.

Does XNA provide audio input (line in)?

Does XNA provide a means of audio input from the line-in? I looked at the MSDNA website but can't find anything on audio input. If it is indeed possible, a snippet of code or a tutorial website would be great.
Edit:
I need to do buffered reads from the audio-line in. I'm not so much interested in the implementation but rather if it has low latency.
Also development will be implemented into a PC only game.
I think all sound files need to be compiled by XACT before they can be used in XNA.
So either you get hold of DirectSound and look at the sample in:
\Samples\Managed\DirectSound\CaptureSound
...or you could interop with winmm.dll. This guy has made a small example of how to do it:
http://www.codeproject.com/KB/audio-video/cswavrec.aspx
And this guy writes some more about enumerating all sound recording devices:
http://www.codeproject.com/KB/cs/Enum_Recording_Devices.aspx
Hope it helps!
Edit:
I'm not sure what you want to do with your audio stream so this tutorial might be of interest as well:
http://nyxtom.vox.com/library/post/recording-audio-in-c.html
Edit 2:
What he said (in the comment)
|
|
V
If you're looking at doing a Windows only project, you could certainly capture the audio coming in with code from outside the XNA framework and play it back with the same. Because of how the XNA content manager works, you wouldn't be able to use the regular playback methods because the content manager translates everything into .xnb files at compile time and reads them from there. Nothing keeping you from playing using standard windows API calls though. You wouldn't really have an XNA project at that point, but I don't suppose the distinction is all that important since you're not looking to be compatible with the other platforms anyway.
To answer your question, no, you can't access audio line-in through the XNA APIs. You'd have to look at some other library such as Port Audio that would give you access to features like that. But then you'd be restricted to running on windows (ie. no xbox or zune).
disclaimer: not sure if port audio specifically has this functionality as I just found it quickly via google. Was just trying to illustrate that you'd have to use some other API.

Categories