示例#1
0
        /// <summary>
        /// SharpDX XACT3 sample. Plays a sound.
        /// </summary>
        static void Main(string[] args)
        {
            // Loading settings
            var settings = File.OpenRead("TestWithSharpDX.xgs");
            var xact3    = new AudioEngine(CreationFlags.DebugMode, settings);

            // Loads WaveBank
            var waveBankStream = File.OpenRead("Ergon.xwb");
            var waveBank       = new WaveBank(xact3, waveBankStream);

            // Loads SoundBank
            var soundBankStream = File.OpenRead("Ergon.xsb");
            var soundBank       = new SoundBank(xact3, soundBankStream);

            // Prepare a cue
            var cue = soundBank.Prepare(soundBank.GetCueIndex("ergon"));

            // Register Notification for testing purpose
            cue.OnNotification += ((from, notif) => Console.WriteLine("Received event {0}", notif.Type));
            cue.RegisterNotification(NotificationType.CueStop);

            // Plays the cue
            cue.Play();

            // Log a message
            Console.WriteLine("Playing ergon cue");

            // Wait until its done
            int count = 0;

            while (cue.State != CueState.Stopped && !IsKeyPressed(ConsoleKey.Escape))
            {
                xact3.DoWork();
                Thread.Sleep(10);
                if (count == 50)
                {
                    Console.Write(".");
                    Console.Out.Flush();
                    count = 0;
                }
                Thread.Sleep(10);
                count++;
            }

            Thread.Sleep(2000);

            xact3.Dispose();
        }