Audio Playback in .Net / C #

I have been an experienced MFC programmer for many years who has been developing commercial applications in Objective-C for Mac and iOS in recent years. I'm trying to speed up work with .Net and C # (as soon as you need to convert one of my commercial applications from Mac to PC).

Now I’ve worked through a couple of books and as an exercise to get to know better .Net (and C #). I decided to convert one of my commercial applications to .Net as a training exercise and everything is going well (the interface works, all data structures are good), but I need to be able to play audio.

My Mac application generates audio from a series of mathematical formulas - imagine a wave generator - not exactly the same, but similar. On a Mac, I generate audio as 16-bit signed raw audio, use Core Audio to configure the audio output routing, and then get a callback whenever a new audio buffer is required for audio routing (so that I can generate audio on the fly).

I need to do the same on a PC. Unfortunately, I find the MSDN documentation as an example of "Can't see a tree for trees," since such extensive documentation exists. I can find classes that will allow me to download and play mp3 / wav files, etc., but I need to generate real-time audio. Can someone point me in the right direction to find something that will allow me to fill the buffers on the fly when they play on them?

thanks

+7
source share
5 answers

I used this sample in several projects with good results. This is the .Net wrapper for the Windows Waveform Audio API using P / Invoke . Other options:

+3
source

I created a class that can play the sound specified as Stream . Therefore, if you can pack the sound generator into a Stream -compatible interface, it may be right for you.

How I did it - I used the unmanaged waveOut* methods from the old Windows multimedia API and handled playback from there.

Other options that I know about are to use waveOut directly, from this: http://windowsmedianet.sourceforge.net/ or write your own DirectShow source filter, but this may be too complicated as it needs to be written in C ++ .

If you are interested in trying my component, I can make it available to you for free, since I need to test it (I used it only in a few of my projects).

EDIT:

Since there are 6 questions to the question, I offer my component for free (if you find it useful) here: http://dl.dropbox.com/u/10020780/SimpleAudioPlayer.zip

Maybe you can think about it :)

+3
source

I use Audiere to accomplish this and find that it works very well.

This C ++ lib is valid, but there is a set of bindings available for C #.

For more information, see the question I asked .

+2
source

You should take a look at FMOD , which allows you to perform this type of operation and much more. It is also a cross platform that may be of interest if you also work on a Mac.

+2
source

Alvas.Audio has 3 audio players: Player

  player.FileName = "123.mp3"; player.Play(); 

Playerex

  public static void TestPlayerEx() { PlayerEx plex = new PlayerEx(); plex.Done += new PlayerEx.DoneEventHandler(plex_Done); Mp3Reader mr = new Mp3Reader(File.OpenRead("in.mp3")); IntPtr format = mr.ReadFormat(); byte[] data = mr.ReadData(); mr.Close(); plex.OpenPlayer(format); plex.AddData(data); plex.StartPlay(); } static void plex_Done(object sender, DoneEventArgs e) { if (e.IsEndPlaying) { ((PlayerEx)sender).ClosePlayer(); } } 

and RecordPlayer

  public static void TestRecordPlayer() { RecordPlayer rp = new RecordPlayer(); rp.PropertyChanged += new PropertyChangedEventHandler(rp_PropertyChanged); rp.Open(new Mp3Reader(File.OpenRead("in.mp3"))); rp.Play(); } static void rp_PropertyChanged(object sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case RecordPlayer.StateProperty: RecordPlayer rp = ((RecordPlayer)sender); if (rp.State == DeviceState.Stopped) { rp.Close(); } break; } } 
+1
source

All Articles