using System; using System.Collections.Generic; using System.Text; using Microsoft.DirectX; using Microsoft.DirectX.DirectSound; namespace SalsaModel.Sound { class Sound1 : IDisposable, IScene { private Device dSound; private SecondaryBuffer snd_clave; private SecondaryBuffer snd_tom_hi; private SecondaryBuffer snd_tom_lo; private SecondaryBuffer snd_bass; private SecondaryBuffer snd_guiro; private Random _rand = new Random(); private Timing _timing; readonly string soundDir = findSoundDir(); private static string findSoundDir() { string assloc = System.Reflection.Assembly.GetExecutingAssembly().Location; string topdir = System.IO.Path.GetDirectoryName(assloc); topdir = System.IO.Path.GetDirectoryName(topdir); topdir = System.IO.Path.GetDirectoryName(topdir); return topdir + "/Sound"; } public Sound1(System.Windows.Forms.Control form, Timing timing) { dSound = new Device(); dSound.SetCooperativeLevel(form.Handle, CooperativeLevel.Priority); // Create the sound snd_clave = new SecondaryBuffer(soundDir + "/Clave.wav", dSound); snd_tom_hi = new SecondaryBuffer(soundDir + "/congah.wav", dSound); snd_tom_lo = new SecondaryBuffer(soundDir + "/congal.wav", dSound); snd_bass = new SecondaryBuffer(soundDir + "/bass.wav", dSound); snd_guiro = new SecondaryBuffer(soundDir + "/CR-8000 Guiro.wav", dSound); snd_tom_hi.Volume = -8000; _timing = timing; } public void Dispose() { } public void Setup(Microsoft.DirectX.Direct3D.Device dev) { } int lastBeat = -11111; public void Draw() { int halfBeat = (_timing.Beat() - 1) * 2 + (_timing.Percent() < 0.5 ? 0 : 1); if (lastBeat != halfBeat) { switch (halfBeat % 8) { case 0: case 4: //snd_tom_lo.Play(0, BufferPlayFlags.Default); break; case 2: //snd_tom_hi.Play(0, BufferPlayFlags.Default); break; } // clave switch (halfBeat) { case 2: case 4: case 8: case 11: case 14: snd_clave.Play(0, BufferPlayFlags.Default); break; } // tumbao switch (halfBeat) { case 2: case 10: snd_tom_hi.Play(0, BufferPlayFlags.Default); //snd_tom_lo.SetCurrentPosition(0); //snd_tom_lo.Play(0, BufferPlayFlags.Default); break; case 6: case 7: case 14: case 15: snd_tom_lo.SetCurrentPosition(0); snd_tom_lo.Play(0, BufferPlayFlags.Default); break; default: //snd_tom_lo.SetCurrentPosition(0); //snd_tom_lo.Play(0, BufferPlayFlags.Default); break; } if (halfBeat % 4 == 0) { //snd_tom_lo.SetCurrentPosition(0); //snd_tom_lo.Play(0, BufferPlayFlags.Default); } if (halfBeat == 0 && _rand.NextDouble() < 0.3) { snd_guiro.Play(0, BufferPlayFlags.Default); } lastBeat = halfBeat; } } } }