Using XNA Sound in Forms App
Tuesday, November 29 2011 - work, xna, code, c - 8 comments
At work we had a need to create a Win Forms Application that needed to use 3D audio and I wanted to use XNA to do it, it was pretty simple to do but there was no good example to do just this on the net. You could also do something like this to create a Console App or Library.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using System.Windows.Threading;
namespace SoundTest
{
public partial class Form1 : Form
{
ServiceContainer service;
SoundEffect soundEffect;
ContentManager content;
SoundEffectInstance soundEffectInstance;
AudioEmitter emitter = new AudioEmitter();
AudioListener listener = new AudioListener();
public Form1()
{
InitializeComponent();
service = new ServiceContainer();
content = new ContentManager(service, "Content");
soundEffect = content.Load<SoundEffect>("sound");
soundEffectInstance = soundEffect.CreateInstance();
}
private void button1_Click(object sender, EventArgs e)
{
// This plays a sound in a 3D space but at this point you can use any of the other sound functions in the XNA API
// Right
SoundEffectInstance i = soundEffect.CreateInstance();
emitter.Position = new Vector3(1, 0, 0);
i.Apply3D(listener, emitter);
i.Play();
}
}
public class ServiceContainer : IServiceProvider
{
Dictionary<Type, object> services = new Dictionary<Type, object>();
private DispatcherTimer frameworkDispatcherTimer;
/// <summary>
/// Adds a new service to the collection.
/// </summary>
public void AddService<T>(T service)
{
services.Add(typeof(T), service);
}
/// <summary>
/// Looks up the specified service.
/// </summary>
public object GetService(Type serviceType)
{
object service;
services.TryGetValue(serviceType, out service);
return service;
}
public ServiceContainer()
{
this.frameworkDispatcherTimer = new DispatcherTimer();
this.frameworkDispatcherTimer.Interval = TimeSpan.FromTicks(333333);
this.frameworkDispatcherTimer.Tick += frameworkDispatcherTimer_Tick;
FrameworkDispatcher.Update();
}
void frameworkDispatcherTimer_Tick(object sender, EventArgs e) { FrameworkDispatcher.Update(); }
}
}
Intro To Silverlight
Saturday, October 24 2009 - my-life, events - 30 comments
I gave a talk at Twin Cities Code Camp 7 an Intro to Silverlight 3.0 and here are the slides, source code and my notes. Thanks ot anyone who attended.
Where is the DeepZoom Community?
Wednesday, April 29 2009 - my-life, projects - 13 comments
I am a little frustrated with the lack of advanced information about DeepZoom. For the past few weeks I have been motivated to work on a personal project and since I am still waiting on getting Sketch Flow I have been thinking about DeepZoom. I have found a ton of examples on how to create a panoramic or layout images but not much on how interact with those images or on how to show and hide images a different zoom levels. I think I found the info I need and if I can keep motivated I will write up some more blog posts about what I got done and how I did it. If it works out it should be a use of DeepZoom that nobody else has done yet.
Happy Birthday Lisa
Wednesday, April 08 2009 - my-life - 15 comments
I just wanted to say happy birthday to my wife of almost 10 years Lisa. As with most years I have no idea what I am getting you but I now understand why I never know. It’s because when I know you want something I can’t make you wait for it. So now instead of trying to stay up and think of something smart or funny to add to this post I will just go and join you in the bed and tell you that I love you.
What is an HP Engine Room Bundle?
Tuesday, April 07 2009 - my-life, work - 6 comments
A few people have asked me what I got from winning the Microsoft PhizzPop challenges and I did not really know for sure until recently. For the regional in
Time to dust this place off
Tuesday, February 03 2009 - 1 comments
Been a while since I posted time to get back on it and make some posts.
Most Gamefest Presentations up for download.
Friday, September 05 2008 - 6 comments
If you are into game development Microsoft has released the audio from this years Gamefest there is a special section on XNA. That should be full of information about the next version of XNA 3.0 but the sessions on Certification is what I really want to know more about. What does it take to get a game through cert and just what does Microsoft require of its games.
I just found that the talks on Certification are only for people with XDS accounts, that sucks. I still hope that MajorNelson will do an interview with someone on the Cert team at Xbox sometime soon.
Thanks to The XNA Team Blog for the info about the presentations.
Not too Caffeinated just messy
Thursday, August 28 2008 - 7 comments
A blog post from Blogus Maximus (aka Chris Williams (aka Charity Fragathon guy)) inspired me to take some pictures.

Its good to know I am not the only one who cant be bothered to throw their cans away.

It does not have to be caffeinated, and hey I though we stopped stocking water.

Super caffeinated

Programmers love Red Bull

Fish + Red Bull = Fail
Events I think are cool
Thursday, August 14 2008 - events - 9 comments
There are two events coming up in September that I will be attending that you may want to check out.
The Charity Frag-a-thon is an event being hosted by the Twin Cities XNA User Group. Along with helping Children's Hospitals and Clinics of Minnesota the event will have a Halo 3 tournament with prizes. I am not the best Halo 3 player but I am hoping that the people that show up are not to great. For me this is also an chance to bring a non programmer friend of mine to meet some of the people I know from work and the user groups.
Wednesday, September 24, 2008 (6-10PM)
Microsoft
8300 Norman Center Dr, Suite 950
Bloomington, MN 55437
The other event is the Minnesota Developer Conference on September 9th. For me this is the first paid conference that I will be attending I am hope that this event will provide more than the free Twin Cities Code Camp coming up in October. There are still spots open for both MDC and Code Camp, the code camp is free and an event not to miss and right not you can get a big discount on the last of the MDC tickets.
Bravo Move
Tuesday, July 29 2008 - work - 0 comments
Over the last weekend the company I work for Sierra Bravo moved to a new office. It was a experience that I hope not to repeat any time soon. Moving all the stuff took 3 large moving trucks, a team of 9 movers and 2 trips for each truck and that does not even cover moving the data center. The internet connection is still a little flaky so the blog may be down from time to time over the next few days.
