static void Main(string[] args) { string soundToPlay = "Airhorn.wav"; string currentDir = Environment.CurrentDirectory; if (args.Length < 1) { Console.WriteLine("Please specify which sound to play."); } else { soundToPlay = args[0]; } Console.WriteLine("Playing {0}", soundToPlay); //Get the list of installed sound devices. IrrKlang.ISoundDeviceList sdl = new IrrKlang.ISoundDeviceList(IrrKlang.SoundDeviceListType.PlaybackDevice); // start the sound engine int AudioDevice = 0; if (args.Length > 1) { int j; if (Int32.TryParse(args[1], out j)) { AudioDevice = j; } else { Console.WriteLine("String could not be parsed."); } } ISoundEngine engine = new ISoundEngine(IrrKlang.SoundOutputDriver.AutoDetect, IrrKlang.SoundEngineOptionFlag.DefaultOptions, sdl.getDeviceID(AudioDevice)); engine.Play2D("" + currentDir + "\\" + soundToPlay); do { //don't close me yet }while (engine.IsCurrentlyPlaying("" + currentDir + "\\" + soundToPlay)); }
public bool soundThreadStartup() { // populate device list, pulling default from config file ISoundDeviceList sdl = new IrrKlang.ISoundDeviceList(IrrKlang.SoundDeviceListType.PlaybackDevice); //Add each device to a combo box. for (int i = 0; i < sdl.DeviceCount; i++) { string desc = sdl.getDeviceDescription(i); cbDevices.Items.Add(desc); } // take the value in the config file and set the drop-down to that cbDevices.SelectedIndex = Settings.Default.DeviceID; // fire up sound processing thread SoundObject = new SoundEngine(); SoundThread = new Thread(SoundObject.Run); // Start the worker thread. SoundThread.Start(); Debug.WriteLine("Telemetry processing thread: Starting sound thread..."); while (!SoundThread.IsAlive); if (cbDevices.SelectedIndex == -1) { SoundObject.Initialize("0"); // using the default } else { string dev = sdl.getDeviceID(cbDevices.SelectedIndex); SoundObject.Initialize(dev); // using the selected value } return true; }
private void resetSound(bool on_connection) { if (!on_connection) { int cur_dev = Settings.Default.DeviceID; int new_dev = cbDevices.SelectedIndex; if ((new_dev != cur_dev) && (new_dev != -1)) { // update config file for next time Settings.Default.DeviceID = new_dev; Settings.Default.Save(); // get the proper dev id from the sound device list // populate device list, pulling default from config file ISoundDeviceList sdl = new IrrKlang.ISoundDeviceList(IrrKlang.SoundDeviceListType.PlaybackDevice); string dev_id = sdl.getDeviceID(new_dev); // kill curent sound process and start a new one with the new device SoundObject.appExit(); SoundObject.Initialize(dev_id); SoundObject.SetMasterVolume(MasterVol); } } else { ISoundDeviceList sdl = new IrrKlang.ISoundDeviceList(IrrKlang.SoundDeviceListType.PlaybackDevice); string dev_id = sdl.getDeviceID(Settings.Default.DeviceID); SoundObject.Initialize(dev_id); SoundObject.SetMasterVolume(MasterVol); } }