using System;
using Microsoft.DirectX.DirectSound;
using BufferMicrosoft.DirectX.DirectSound.SecondaryBuffer;
using Microsoft.DirectX;
using Global;
using Global.GlobalClass;
using System.IO;
using System.Windows.Forms;
namespace KillerInstinct.DirectX{
public class SoundClass
{
// EFFECTS CONSTANTS /////////////////////////////////////////////////////////////////
public const string SOUND_GAMESTART = CONST.DIR_SOUND + "GameStart.wav";
public const string SOUND_GAMEEXIT = CONST.DIR_SOUND + "GameExit.wav";
public const string SOUND_SHOT = CONST.DIR_SOUND + "Shot";
public const string SOUND_SHOTEMPTY = CONST.DIR_SOUND + "ShotEmpty.wav";
public const string SOUND_EXPLOSION = CONST.DIR_SOUND + "Explosion.wav";
public const string SOUND_WIND = CONST.DIR_SOUND + "Wind.wav";
public const string SOUND_ALTHIT = CONST.DIR_SOUND + "AltHit.wav";
public const string SOUND_MENUNEXT = CONST.DIR_SOUND + "MenuNext.wav";
public const string SOUND_MENUSELECT = CONST.DIR_SOUND + "MenuSelect.wav";
public const string SOUND_LOWENERGY = CONST.DIR_SOUND + "LowEnergy.wav";
public const string SOUND_POWERUP = CONST.DIR_SOUND + "Powerup";
public const string SOUND_LOSER1 = CONST.DIR_SOUND + "loser1.wav";
// VOICE CONSTANTS ///////////////////////////////////////////////////////////////////
public const string VOICE_AWCRAP = CONST.DIR_VOICE + "aw_crap.wav";
public const string VOICE_BREATHIN = CONST.DIR_VOICE + "breathe_in.wav";
public const string VOICE_BREATHOUT = CONST.DIR_VOICE + "breathe_out.wav";
public const string VOICE_COMEONYO = CONST.DIR_VOICE + "comeon_yo.wav";
public const string VOICE_FEELSGOOD = CONST.DIR_VOICE + "it_feels_so_good.wav";
public const string VOICE_NOWORD = CONST.DIR_VOICE + "no_word_bout_it.wav";
public const string VOICE_STEREOBENEFITS= CONST.DIR_VOICE + "stereo_benefits.wav";
public const string VOICE_STOPPED = CONST.DIR_VOICE + "stopped.wav";
public const string VOICE_STUPID = CONST.DIR_VOICE + "stupid.wav";
public const string VOICE_SUCK = CONST.DIR_VOICE + "suck_my.wav";
//...
private SecondaryBuffer ApplicationBuffer = null;
private Device SoundDevice = null;
public bool bMute;
private int Volume;
private Control Window;
public SoundClass(Control window, bool mute, int volume)
{
Window = window;
bMute = mute;
Volume = volume;
SoundDevice = new Device();
SoundDevice.SetCooperativeLevel(Window, CooperativeLevel.Priority);
}
// returns a random resource file (.WAV) based on searchText
public static string GetRandomSound(string searchText)
{
global.dbg.Out(Debug.DBG2, "GetRandomSound searching for [" + searchText + "].");
string resourceName = "";
try
{
// get array of Tank*.bmp files
string[] files = Directory.GetFiles(CONST.DIR_SOUND, searchText);
if (files.Length > 0)
{
global.dbg.Out(Debug.DBG2, "Found [" + files.Length + "] resource files.");
// return random resource file name, e.g. ".\Bitmaps\Win1.bmp"
resourceName = files[global.random(0, files.Length-1)];
global.dbg.Out(Debug.DBG2, "Using random resource file from resource: [" + resourceName + "]");
}
else
{
global.dbg.Out(Debug.ERR, "No resources were found to load.");
}
}
catch (Exception e)
{
global.dbg.Out(Debug.ERR, "An error occurred trying to read list of resources: " + e);
MessageBox.Show("An error occurred trying to read list of resources: " + e, "Unable to find resources");
}
return (resourceName);
}
public void PlayRandomIntro()
{
global.SC.Play(GetRandomSound("Intro*.wav"), true);
}
public void Play(string file, bool loop)
{
if (!bMute)
{
if (File.Exists(file))
{
//DirectXException.IgnoreExceptions();
BufferDescription desc = new BufferDescription();
//desc.ControlFrequency = true;
//desc.ControlPan = true;
//desc.ControlVolume = true;
ApplicationBuffer = new SecondaryBuffer(file, desc, SoundDevice);
BufferPlayFlags PlayFlags = loop ? BufferPlayFlags.Looping : 0;
if (null != ApplicationBuffer)
ApplicationBuffer.Play(0, PlayFlags);
//DirectXException.EnableExceptions();
}
else
global.dbg.Out(Debug.ERR, "Cannot open file " + file);
}
}
public void Stop()
{
if (!bMute)
{
if (null != ApplicationBuffer)
{
global.dbg.Out(Debug.DBG2, "SOUND stop");
//ApplicationBuffer.Stop();
//ApplicationBuffer.SetCurrentPosition(0);
//ApplicationBuffer.Dispose();
//ApplicationBuffer = null;
SoundDevice.Dispose();
SoundDevice = new Device();
SoundDevice.SetCooperativeLevel(Window, CooperativeLevel.Normal);
}
}
}
public void ChangeVolume(int diff)
{
if (!bMute)
{
/*if ((Volume+diff <= 0) && (Volume+diff >= -50))
Volume += diff;
ApplicationBuffer.Volume = Volume * 100;*/
}
}
}
}
|