示例#1
0
        private void PrepareSound()
        {
            try
            {
                //オーディオ初期化
                using (DeviceManager manager = new DeviceManager())
                {
                    manager.ReadyRenderDeviceCollection();
                    device = manager.GetDefaultDevice(DeviceManager.Render, DeviceManager.Console);
                }

                //音声ファイル読み込み
                using (Client client = device.GetAudioClient())
                {
                    client.SharedMode(false, false);
                    client.EventDriven();

                    ReadWavFile(client, "bound.wav", ref bound_wav);
                    ReadWavFile(client, "demolish.wav", ref demolish_wav);
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(string.Format("オーディオが正しく初期化されませんでした.例外情報:{0}", e.ToString()));
            }
        }
示例#2
0
        private void PlaySync(IStream stream, string soundName)
        {
            using (Client client = device.GetAudioClient())
            {
                client.SharedMode(false, false);
                client.EventDriven();
                client.Initialize(stream.PCMParam, 0, false);

                using (Driver render = client.StartUpRenderer(stream))
                {
                    client.GetReady();
                    client.Start();
                    try
                    {
                        client.Drive();
                        Trace.WriteLine(soundName + " stopped.");
                    }
                    catch (RenderingException)
                    {
                        Trace.WriteLine(soundName + " stopped in midstream.");
                    }
                }
            }
        }