コード例 #1
0
        private void UpdateAudio(AudioBuffer audio)
        {
            var format = audio.Format;

            if (format.Channels != 1 ||
                format.SamplesPerSec != 48000 ||
                (format.FormatTag != WaveFormatTag.WAVE_FORMAT_IEEE_FLOAT &&
                 format.FormatTag != WaveFormatTag.WAVE_FORMAT_EXTENSIBLE) ||
                format.BitsPerSample != 32)
            {
                throw new ArgumentException("Expected 1-channel, 48kHz, float32 audio format.");
            }

            using var stream = new MemoryStream(audio.Data, 0, audio.Length);
            using var reader = new BinaryReader(stream);
            var count   = audio.Length / 4;
            var samples = new float[count];

            for (var i = 0; i < count; i++)
            {
                samples[i] = reader.ReadSingle();
            }

            this.sound.WriteSamples(samples);
            if (!this.playing)
            {
                this.soundInst = this.sound.Play(this.position, this.volume);
                this.playing   = true;
            }
        }
コード例 #2
0
        void StepWand()
        {
            if (wandStream == null)
            {
                wandStream = Sound.CreateStream(5f); wandStreamInst = wandStream.Play(wandTipPrev);
            }
            if (wandModel == null)
            {
                wandModel = Model.FromFile("Wand.glb", Shader.UI);
            }
            if (wandFollow == null)
            {
                wandFollow = new LinePoint[10]; for (int i = 0; i < wandFollow.Length; i += 1)
                {
                    wandFollow[i] = new LinePoint(Vec3.Zero, new Color(1, 1, 1, i / (float)wandFollow.Length), (i / (float)wandFollow.Length) * 0.01f + 0.001f);
                }
            }

            UI.HandleBegin("wand", ref wandPose, wandModel.Bounds);
            wandModel.Draw(Matrix.Identity);
            UI.HandleEnd();

            Vec3  wandTip   = wandPose.ToMatrix() * (wandModel.Bounds.center + wandModel.Bounds.dimensions.y * 0.5f * Vec3.Up);
            Vec3  wandVel   = (wandTip - wandTipPrev) * Time.Elapsedf;
            float wandSpeed = wandVel.Magnitude * 100;

            int count = Math.Max(0, (int)(0.1f * 48000) - (wandStream.TotalSamples - wandStream.CursorSamples));

            if (wandSamples.Length < count)
            {
                wandSamples = new float[count];
            }
            for (int i = 0; i < count; i++)
            {
                wandIntensity  = Math.Min(1, SKMath.Lerp(wandIntensity, wandSpeed, 0.001f));
                wandTime      += (1 / 48000.0) * (30000 * wandIntensity + 2000);
                wandSamples[i] = (float)Math.Sin(wandTime) * wandIntensity;
            }

            wandStreamInst.Position = wandTip;
            wandStream.WriteSamples(wandSamples, count);

            for (int i = 0; i < wandFollow.Length - 1; i++)
            {
                wandFollow[i].pt = wandFollow[i + 1].pt;
            }
            wandFollow[wandFollow.Length - 1].pt = wandTip;
            Lines.Add(wandFollow);
            wandTipPrev = wandTip;
        }
コード例 #3
0
ファイル: AudioQueue.cs プロジェクト: meds/ChicksnVixens
        SoundInst GetInst(string dir)
        {
            for (int i = 0; i < soundInstances.Count; i++)
            {
                if (soundInstances[i].SoundDir == dir)
                {
                    return(soundInstances[i]);
                }
            }

            SoundInst s = AudioManager.CreateSound(dir);

            soundInstances.Add(s);
            return(s);
        }
コード例 #4
0
ファイル: DemoNodes.cs プロジェクト: studentutu/StereoKit
    public void Initialize()
    {
        radioPowerPose     = radio.FindNode("Power").ModelTransform.Pose;
        radioSpeakerPose   = radio.FindNode("Speaker").ModelTransform.Pose;
        radioDisplayPose   = radio.FindNode("DisplayStart").ModelTransform.Pose;
        radioDisplaySize   = radio.FindNode("DisplayEnd").LocalTransform.Translation.XY;
        radioDisplaySize   = V.XY(Math.Abs(radioDisplaySize.x), Math.Abs(radioDisplaySize.y));
        radioInterfacePose = radio.FindNode("InterfaceStart").ModelTransform.Pose;
        radioInterfaceSize = radio.FindNode("InterfaceEnd").LocalTransform.Translation.XY;
        radioInterfaceSize = V.XY(Math.Abs(radioInterfaceSize.x), Math.Abs(radioInterfaceSize.y));

        UpdateLine(radioFreqLine, radioFreq);

        radioSound     = Sound.CreateStream(1);
        radioSoundInst = radioSound.Play(Vec3.Zero);
    }
コード例 #5
0
        public Fan(JabWorld world)
            : base("misc")
        {
            this.world = world;

            Rot   = 0.24f * JabMath.PI;
            Layer = SpriteLayer.LAYER8;

            world.MakeEntityGroup(FanEntitySpaceGroup);
            EventManager.Get.RegisterListner(this);

            //++NumFans;
            //  if (FanSound == null)
            {
                FanSound        = AudioManager.CreateSound("Sounds/Fan_Blowing_2", true);
                FanSound.Volume = 0.0f;
            }
            FanSound.Play(1.0f);
        }
コード例 #6
0
ファイル: Chicken.cs プロジェクト: meds/ChicksnVixens
        public override void Initialize(ContentManager Content)
        {
            base.Initialize(Content);

            AsType.CreateFramesFromXML("Chickens_Frames");

            //  PosY = 500;

            AsType.CurrentFrame = "bird-chicken-00000";

            AsType.Width  = 128;
            AsType.Height = 128;

            AsType.Animation = AccelerateAnimation;

            launchInst = AudioManager.CreateSound("Sounds/Chicken_Launch_0" + BaseGame.Random.Next(1, 7));
            launchInst.Play(1.0f);

            Sprite.Layer = SpriteLayer.LAYER10;


            World.BeginContact += OnContact;
            World.EndContact   += EndContact;
        }
コード例 #7
0
ファイル: AudioQueue.cs プロジェクト: meds/ChicksnVixens
        public override void Update(GameTime dt)
        {
            if (NumSlide > 0)
            {
                slide.Volume = JabMath.MoveTowards(slide.Volume, 1.0f, gttf(dt) * 2.0f);
            }
            else
            {
                slide.Volume = JabMath.MoveTowards(slide.Volume, 0.0f, gttf(dt) * 2.0f);
            }
            base.Update(dt);
            for (int i = 0; i < breakSounds.Count; i++)
            {
                breakSounds[i].lastPlayed -= gttf(dt);
                if (breakSounds[i].lastPlayed < 0)
                {
                    breakSounds.RemoveAt(i); --i;
                }
            }
            for (int i = 0; i < hitSounds.Count; i++)
            {
                hitSounds[i].lastPlayed -= gttf(dt);
                if (hitSounds[i].lastPlayed < 0)
                {
                    hitSounds.RemoveAt(i); --i;
                }
            }
            breakSounds.Clear();
            hitSounds.Clear();
            // if an explosion sfx is playing don't play any other sfx!
            bool AnyExplosion = false;

            for (int i = 0; i < ToPlay.Count; i++)
            {
                String dir = ToPlay[i].Dir;
                if (dir == "Sounds/Explode_Chicken" || dir == "Sounds/Explosion")
                {
                    SoundInst inst = GetInst(dir);
                    if (!inst.IsPlaying)
                    {
                        inst.Play(ToPlay[i].Volume);
                    }
                    else
                    {
                        AudioManager.PlayOnce(dir);
                    }
                    AnyExplosion = true;
                    break;
                }
            }

            if (!AnyExplosion)
            {
                for (int i = 0; i < ToPlay.Count; i++)
                {
                    String dir = ToPlay[i].Dir;

                    if (ShouldSoundPlay(dir))
                    {
                        SoundInst inst = GetInst(dir);
                        if (!inst.IsPlaying)
                        {
                            inst.Play(ToPlay[i].Volume);
                        }
                    }
                }
            }

            ToPlay.Clear();
        }
コード例 #8
0
ファイル: AudioManager.cs プロジェクト: meds/ChicksnVixens
 public static SoundInst CreateSound(string dir, bool looped)
 {
     SoundInst s = new SoundInst(dir, looped);
     sounds.Add(s);
     return s;
 }