Record specific application audio with naudio - c#

Based on this naudio tutorial, I'm aware that naudio has the ability to record audio output in Windows. The article also mentions that you can set naudio to only record audio mixed by naudio.
It seems to me as though the tools to accomplish application-specific recording are in there, but I can't put the pieces together. Thoughts?

As far as I am aware, it is not possible with WASAPI to record sound from a single application of your choosing. Windows 8 does give you the ability to enumerate through the streams and set their volumes, but I don't think you can capture them. At present NAudio's WasapiLoopbackCapture class can only be used to capture the combined output from all applications.
To record the audio you output yourself, have a look at the SavingWaveProvider example I discuss here on my blog.

Related

Grab Audio Sessions as they appear in the windows audio mixer (C# or C++)

I'm trying to figure out how to grab the individual audio streams as they appear in the audio mixer to reroute them to an aggregate audio device. I'm specifically looking to keep them as discreet streams for the purposes of the program I'm making (If they're muxed down to a 2-channel mix, that defeats the purposes of what I'm trying to achieve.)
E.X.: (As I've just made this account, I apparently am not able to post images, so here's a link to the image)
windows audio mixer
In this, I'm hoping to grab "System Sounds" and "Stream Client Bootstrapper" as discreet audio streams to route elsewhere, while maintaining their original destination as well (essentially copying the audio going to the original audio device to another simultaneously).
I'm looking to do this in either C# or C++. I've perused the audio APIs that microsoft has published, and while some things look to be close to what I'm trying to do, nothing has hit the nail on the head. I appreciate any help. Thanks.
The sessions can be enumerated using IAudioSessionManager2::GetSessionEnumerator and friends (sample C++ code is here and there). Standard Windows volume mixer application is using this API as well.
The API however has no access to data streams, you won't have either (you certainly don't have data whether they are downmixed or not). Neither you can reroute streams to another device. Applications are not allowed to interfere that deep. The best you can do is to create your own device, interactively select it as default output device and then accept data from applications playing audio through this device.

Implement on media monitoring (like radio ads monitoring)

I want to develop an Audio Monitoring Software, for example to know how many ads of certain company where published on x radio station ?
There is any way to analyse "realtime" the audio stream and detect when any version of an ad is played on the radio?
Or the best way is to analyse every x seconds the audio fragment, if this is the way to go, what can I do to know if only a segment of an audio has the sample audio (for example analyse 20 minutes of radio and return true if the spot (ad) where player in that audio sample)
(Sorry for my English, I hope is understandable)
I guess realtime could be difficult due to the fact that you have to analyze your radiostream. For that you need to cache, analyze / fingerprint and run against an existing database.
But take a look on these questions:
https://stackoverflow.com/questions/2462410/acoustic-fingerprint-opensource
Musicbrainz fingerprinting
More Links:
http://acoustid.org
https://musicbrainz.org/doc/Fingerprinting
http://echoprint.me // service by spotify / echonest
https://www.audiblemagic.com/broadcast-infrastructure
Good luck.
An excellent open-source audio fingerprinting library in Python can be found here:
http://github.com/worldveil/dejavu
It allows you to fingerprint an audio file once, store the fingerprints in a database, and do continual recognition and adding fingerprints as time goes on.
You can even fingerprint small sections of song to save disk storage if you are just doing on-disk deduplication.

Capture a DVB-T Stream to a movie-file

I have a form with a liveview of the tv-signal (from dvb-t stick). I've the sampleproject "DTViewer" from http://directshownet.sourceforge.net/about.html.
Now I try to capture the stream to a movie-file by clicking a button, but how?
I use C# and DirectShow.NET.
I tried to search in many sampleprojcets but these are made for videoinputs not a dvb-t stick with a BDA (Broadcast Driver Architecture) interface.
Help!
Don’t really know what exactly do you mean by a “movie-file”, but I can tell you how to capture the entire MUX (transport stream). Create a graph with a Microsoft DVBT Network Provider, You_Name_It BDA DVBT Tuner, You_Name_It BDA Digital Capture and MPEG-2 Demultiplexer filters. Once you connect them, enumerate all output pins on the MPEG-2 Demultiplexer and render them. Tune the frequency of your choice (put_TuneRequest). At this point everything is ready to run the graph, but don’t run it! Enumerate all filters in the graph. Disconnect all filters except Microsoft DVBT Network Provider, You_Name_It BDA DVBT Tuner and You_Name_It BDA Digital Capture. Remove all these disconnected filters from the graph except the MPEG-2 Demultiplexer (it has to be in the graph although it is not connected). Add Sample Grabber filter and NULL Renderer filter. Connect Digital Capture filter to Sample Grabber and Sample Grabber to NULL Renderer. You can run the graph now. Through the callback in Sample Grabber filter you will receive the entire MUX. Of course, there is still some work to demux the data, but once you do that, you can capture all TV programs in one MUX at once. The easiest way is to capture it in a TS format because the TS is being broadcasted (188 bytes long packets).
It seems to me VLC has BDA support (BDA.c file reference), maybe you can snoop up something from their code?
There is no simple answer to your question. I have started one such project and have found out that there is very little I know about it, so here is little something from my research.
First, you'll have to understand that dvb-t tuner card or stick doesn't give video frames in the classical sense, but the decoding is done in the pc, on the cpu. External card will provide you with compressed data only, as it fetches it from the air.
Next - data that is delivered to you will be in MPEG2 or MPEG4 Transport Stream format. Which is suitable for streaming or broadcasting, not for saving to file. VLC is able to play TS written to the file, but to record a proper video file, you'll have to either transcode the file or repack it to Program Stream. Google it a little, you'll find the differences.
More - one frequency on the air consists of many channels, and that channel packing is called 'mux'. So - from the BDA tuner/capturer you'll get ALL data, and you'll have to demux it manually or let BDA demuxer do it for you.
Hope that's enough info to get you started, I can post you some interesting links when I get to the real keyboard.

Best way to implement audio playback

I'm working on an application that will read in file paths and play audio files. I'm trying to keep this as simple as possible--by using existing codecs and free/open utilities. I'd like some suggestions on the best way to do this. I've had two ideas, both involving FFmpeg:
Create a simple GUI that allows the user to read pass in file(s) to be played, and then a ffplay.exe process is run in the background to play the file(s).
Go more in-depth by just using libavcodec and basing my project off the functionality available with that.
There are only a few main goals I have for this.
Be able to read in and play multiple files without breaks between them
Start playback at an arbitrary spot (based on a percent of total duration) within the track
Stop playback after an arbitrary amount of time, and move to the next track
Which of my two methods seem the most practical for this project? Is there a better--or perhaps less feature-intensive--alternative to FFmpeg that you would suggest.
This is for a Windows application written in C#.
Edit: One of the reasons that I started with FFmpeg is that it can handle many file types, notably MP3, AAC, Flac.
Edit2: If the use of libavcode.dll is the best option, it would also be helpful to get some info on implementing that in C#.
The BASS audio library has C# bindings and works very well with common audio formats (e.g. MP3) with plug-ins for other formats (e.g. AAC).
However, for commercial development, you require a license to use BASS.

Is it possible to transcode audio in C# using DirectSound?

I want to transcode a lot of audio from its source format to PCM without resampling or messing with the sample size. I figure if Windows Media Player can play the file and it doesn't use a legacy ACM codecs it must be using DirectSound to do so (this is on Windows XP and Windows Server 2k3). So is it possible to access DirectSound from C# and do so? I've tried searching the web but all the examples have been about playback which I have no interest in doing.
DirectSound is an audio playback API, you mean DirectShow. Windows Media player does use DirectShow to play audio files. In theory, all you need to do is build the same playback graph that media player uses, but replace the audio driver on the end with a .WAV writer filter.
This is somewhat easier to do in C++ code, since the DirectShow graph object is really designed to be called from C++, but with a good set of interop definitions, you can do this in C#.
There's http://directshownet.sourceforge.net/ for serious hacking with DirectShow in .NET, but that's probably overkill for your problem.
I would suggest getting a copy of GraphEdit if you don't already have one. You can use it to "prototype" direct show graphs interactively. drop a file into graphedit. then delete the filter on the end and replace it with a file writer filter.
One problem you will have is that there is no .WAV file writer filter in the default set of o DirectShow filters, you will have to find or write one.
If you just want to get the files converted, and could care less about learning how to write code using DirectShow, I would suggest that you just get a copy of Sound Forge (possibly even a demo version). It has a scripting language (C#,vb) that can be used to easily batch process most audio file formats.
Conversion to WAV can be done from the Windows command line using SoX (Sound eXchange, http://sox.sourceforge.net/). You could write a batch file or a C# application that calls SoX with the proper attributes. I'm not sure how WinAMP's feature works specifically, but it has a file writer output option built in as well. You can stream the entire playlist to wave files.
Have a look at this article on CodeProject about audio conversion here and here.

Categories