How do I play nsf music in C#? (making a game) - c#

I'm making a game with some friends for our last highschool project .
I'm having trouble finding out how to play the music I've written in c# and I'm turning here for answers.
We're using Microsoft Visual studio 2010, and I've mainly been writing music for the game during this time so I'm quite a beginner at programming in C#.
The Music I've made is made in a program called Famitracker don't know if your familiar with it but I can export the files to NSF which is good since they take up low disk space.
So my real question is how do I make our game play the music and loop it until the play gets to the next stage?

NSF, or the Nintendo Sound Format is not something that Windows nor .NET supports natively... instead you would have to either write or find your own player for it... or redo your music in something more common like MP3 or WAV.
If you want to stick with NSF, I'd suggest looking at one of the open source NES emulators out there and see if you can't use of of their code. (Example 1) (Example 2) (Example 3)

Your easiest solution would probably be to output is as a wav and play it using XNA as Matthew describes. The file size may be larger, but unless you are having file size issues, I think that will by far be the easiest way to go. There doesn't seem to be any easy implementation of a nsf player in C#, although you might look into how NES emulators are doing it.

Use the XNA framework for audio, etc in games.
Here is a good starting point: http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=xna+framework+play+audio

Related

How to control HD video play position and speed in XNA?

I am developing a game for Windows in C# using Visual Studio 2010 and XNA 4.0. I would like to be able to set and change the play position of an HD video and also play the video in reverse, depending on user input.
I am having trouble finding where to start. XNA's videoPlayer class does not provide these type of functions. I've read that XNA DirectShow is now out of date and slow when using HD video.
I don't quite understand how I would be able to use or implement tools such as ffmpeg with my project. It seems some people have had similar questions and posted solutions but without much detail. These are below.
interop out to talk to the core DX functionality.
write a managed c++ wrapper to interop ffmpeg.
write an mpeg decoder.
I am not sure what would be best and where to begin.
Thanks!
The VideoPlayer class has a "PlayPosition" property, which you should be able to play with.
Otherwise (and I don't know how big your video file is nor how long) try an image sequence and animate the current image sequence and control that with user input. Of course working with image sequences would make audio reversal (if there is audio) etc very complicated.
Last but not least, you can see if you can figure anything out from this mpeg decoder here:
https://www.box.com/shared/ojzfv0qzfx
Something else that might help with mpeg decoding:
http://chrisa.wordpress.com/2007/11/21/decoding-mpeg2-information/

How can I play a .wav file using SharpDX DirectSound in a C# WPF project?

I want to be able to precisely control the timing of .wav files played in my program. I also want to be able to play more than one .wav file at the same time. The SoundPlayer was not good enough because I can't play two sounds at once, and even when I play different sounds consecutively, there is about a 1/8th second delay between each sound, which is unacceptable for what I am doing. I cannot find a way to add a Device using SharpDX.
You have a directsound sample in sharpdx, should get you started.
Also you can have a look at NAudio , which should also fit your needs and be a bit easier to use.

Playing video in a .NET application

Lately, I've been trying to setup a media center PC. I've played around with all the common media center applications like XBMC, Plex, Boxee, and WMC. But all of them have one issue or another. So I was thinking about writing my own application from scratch.
My problem is I have no experience with developing software that plays media such as videos or music. I'm also not interested in spending a huge amount of time trying to figure this out, considering all the different file formats and codecs out there. I'm really more interested in developing the database and library interface for my application and reusing someone else's control or code for actually playing the media.
One option I was thinking was to just control an existing media player externally. So for example you may browse for a video to play in my application, and then when you hit play it would fire up VideoLAN or some other popular video player.
However, I was wondering if there was an easy way to play video inside a .NET application. I'm looking for something that is capable of playing a wide variety of formats such as MKV files, and DVD ISOs. I'm more experience with WinForms, but was also thinking about using this project as an opportunity to learn WPF.
i've spent many years looking at playing video under wpf.
The short answer
There is no easy way to guarantee to be able to play a variety of formats under wpf ( mkv,dvd etc etc ) or under windows for that matter.
the long answer
If you are looking just to run this at home and not release it, install all the codecs you need and most of the formats will run via mediaelement in wpf.
Getting all the codecs to cooperate can sometimes be frustrating.
Now moving into slightly harder territory.
if you want to play DVD then you need to replace mediaelement with wpfmediakit
http://wpfmediakit.codeplex.com/
wpfmediakit gives a base library to get access to the low level directshow functionality.
There is already a code base for playing DVDs based on wpfmediakit.
Now moving onto the very hard territory.
if you want to distribute your application and have users be able to "just watch" most/all media formats means you need to be able to completely control their codecs, which generally means distributing the codecs with your package and building the directshow filter graph in code rather than let windows build it.
The easiest way is to use the existing .Net hooks to Microsoft's standard MediaPlayer:
http://msdn.microsoft.com/en-us/library/system.windows.media.mediaplayer.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/dd562851%28v=vs.85%29.aspx
was trying myself a while ago for something to play media in winforms, and found out there is vlc wrappers for .Net, dunno how good they are as i gave up, but you can try
here is one them:
http://vlcdotnet.codeplex.com/
Thanks for all the great answers. But just found out that VLC can actually be controlled through HTTP. So I think I'm just going to use that to point an instance of VLC running with the HTTP interface at whatever file I want to play.

So I want to make a basic music visualizer in C# as practice. Is there a library that lets me handle sound files easily in C#?

What is a sound library I can use to easily manipulate sound files (mp3, ogg, wav, etc.).
I'm doing this as a leasure project and as such I'm more than willing to read a bit because I want this to be a little learning experience.
Any help, SO? :D
If you need more than just .wav files, as it appears you do, and you're using .NET 3.0 or higher, have a look at:
MediaPlayer Class
It's basically a wrapper around Windows Media Player, and will let you do in code most (if not all) of what WMP can do.
If you're still in .NET 2.0, have a look at the Windows Media Player SDK, which is a significantly uglier wrapper around Windows Media Player. See this answer.
SoundPlayer class for wav. At the bottom of that documentation there is a link to a page explaining how to also play mp3 and wma.

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