コード例 #1
0
        public AudioCue GetCue(string name, GameThing thing)
        {
            AudioCue cue;

            if (spareCues.Count > 0)
            {
                // Reuse a spare AudioCue instance
                cue = spareCues[0];
                spareCues.RemoveAt(0);
            }
            else
            {
                // No spare AudioCue instances available, so create a new one
                cue = new AudioCue();
            }

            /// Ugly hack to disable 3d for non-positional sounds.
            /// Later we'll know whether a given sound is non-positional by examining its tag set.
            if (name.StartsWith("Mystery") || name.StartsWith("Driving") || name.StartsWith("Dramatic"))
            {
                thing = null;
            }

            // Initialize the sound cue
            cue.Set(SoundBank.GetCue(name), thing);

            // Apply initial 3D audio values
            cue.Apply3D(listener);

            // Keep track of the audio cue until it completes
            activeCues.Add(cue);

            return(cue);
        }
コード例 #2
0
//        PerfTimer updateTimer = new PerfTimer(">>> Update Audio ");

        public void Update()
        {
//            this.updateTimer.Start();

            // Limit audio updates to 60 fps
            if (Time.GameTimeTotalSeconds > lastFrameTimeSeconds &&
                Time.GameTimeTotalSeconds - lastFrameTimeSeconds < 1 / 60.0f)
            {
                return;
            }

            lastFrameTimeSeconds = Time.GameTimeTotalSeconds;

            engine.Update();

            // Update 3D audio listener values from camera state
            listener.Position = InGame.inGame.Camera.From;
            listener.Up       = InGame.inGame.Camera.Up;
            listener.Forward  = InGame.inGame.Camera.At;
            listener.Velocity = Vector3.Zero; // Camera doesn't expose a "Velocity" property

            // Loop through active audio cues, updating 3D values and recycling completed cues
            for (int cueIndex = 0; cueIndex < activeCues.Count; ++cueIndex)
            {
                AudioCue cue = activeCues[cueIndex];

                // If cue is done playing, recycle it. Because we create
                // and destroy AudioCue objects frequently, this helps avoid
                // unnecessary garbage collector activity.
                if (cue.IsComplete)
                {
                    cue.Reset();
                    spareCues.Add(cue);
                    activeCues.RemoveAt(cueIndex);
                    --cueIndex;
                    continue;
                }

                // Update cue's 3D audio values
                cue.Apply3D(listener);
            }

//            this.updateTimer.Stop();
        }