00001 namespace Tests
00002 {
00003 using System;
00004 using System.Text;
00005 using System.Threading;
00006 using Microsoft.VisualStudio.TestTools.UnitTesting;
00007 using NewGamePhysics.Utilities;
00008 using Microsoft.DirectX.DirectSound;
00009
00013 [TestClass]
00014 public class UnitTestDirectXAudio
00015 {
00016 public UnitTestDirectXAudio()
00017 {
00018 }
00019
00020 private TestContext testContextInstance;
00021
00026 public TestContext TestContext
00027 {
00028 get
00029 {
00030 return testContextInstance;
00031 }
00032 set
00033 {
00034 testContextInstance = value;
00035 }
00036 }
00037
00038 [TestMethod]
00039 public void NullPlayback()
00040 {
00041 DirectXAudio player = new DirectXAudio((Device)null, 44100, (short)16, (short)2);
00042 player.Play(new PullAudioCallback(NullFiller));
00043 System.Threading.Thread.Sleep(1000);
00044 player.Stop();
00045 }
00046
00047 [TestMethod]
00048 public void RandomPlayback()
00049 {
00050 DirectXAudio player = new DirectXAudio((Device)null, 44100, (short)16, (short)2);
00051 player.Play(new PullAudioCallback(RandomFiller));
00052 System.Threading.Thread.Sleep(1000);
00053 player.Stop();
00054 }
00055
00056 #region sample_filler_callbacks
00057
00058 private void NullFiller(IntPtr dest, int size)
00059 {
00060 int samples = size / 2;
00061
00062 short[] buffer = new short[samples];
00063
00064 for (int i = 0; i < samples; i++)
00065 {
00066 buffer[i] = 0;
00067 }
00068
00069 System.Runtime.InteropServices.Marshal.Copy(buffer, 0, dest, samples);
00070 }
00071
00072 private void RandomFiller(IntPtr dest, int size)
00073 {
00074 Random rand = new Random();
00075 int samples = size / 2;
00076 short[] buffer = new short[samples];
00077 for (int i = 0; i < samples; i++)
00078 {
00079 buffer[i] = Convert.ToInt16(rand.Next(short.MinValue, short.MaxValue));
00080 }
00081
00082 System.Runtime.InteropServices.Marshal.Copy(buffer, 0, dest, samples);
00083 }
00084
00085 #endregion
00086 }
00087 }