views:

682

answers:

3

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.

+3  A: 

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
Presidenten
It's quite possible to play sounds/music without using XACT, and can be much simpler too if you don't need XACT's features. You can load many audio formats (WAV, MP3, WMA just to name a few) via Content.Load() directly, using the classes Audio.SoundEffect and/or Media.Song to manage them. :)
rmz
Does this also apply to reading from the line-in? I don't really need to much playback functionality
srand
+2  A: 

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.

Joel Martinez
+2  A: 

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.

Raumornie
Yeah, I'll use NAudio (http://www.codeplex.com/naudio) along with XNA. Portability is not a concern for my game for now.
srand
@srand Nice library! I've used MixDiff and didn't realize that this was what they were using for audio output. I'm going to look into it myself; thanks for the link.
Raumornie