/// <summary>
 /// Creates a new instance of the <see cref="SoundEffectInstance"/> class.
 /// </summary>
 /// <param name="soundEffect">The source effect whose instance needs to be created.</param>
 /// <param name="sourceVoice">The source voice to play the created instance.</param>
 /// <param name="isFireAndForget">A value indicating whether this instance is not monitored after it is being send to playback.</param>
 internal SoundEffectInstance(SoundEffect soundEffect, SourceVoice sourceVoice, bool isFireAndForget)
 {
     Effect = soundEffect;
     voice = sourceVoice;
     IsFireAndForget = isFireAndForget;
     paused = false;
     IsLooped = false;
     volume = 1.0f;
     pan = 0.0f;
     pitch = 0.0f;
     outputMatrix = null;
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WaveBank"/> class and loads the wave data from the provided stream.
        /// </summary>
        /// <param name="audioManager">The associated audio manager.</param>
        /// <param name="stream">The stream from which to read the wave data.</param>
        /// <exception cref="ArgumentNullException">Is thrown when either <paramref name="audioManager"/> or <paramref name="stream"/> are null.</exception>
        private WaveBank(AudioManager audioManager, Stream stream)
        {
            if (audioManager == null)
                throw new ArgumentNullException("audioManager");

            if (stream == null)
                throw new ArgumentNullException("stream");

            using (var reader = new WaveBankReader(stream))
            {
                effects = new SoundEffect[reader.Count];
                effectsByName = new Dictionary<string, SoundEffect>();

                for (uint i = 0; i < reader.Count; i++)
                {
                    var format = reader.GetWaveFormat(i);
                    var metadata = reader.GetMetadata(i); // why it is not used?
                    var name = reader.GetName(i);
                    var data = reader.GetWaveData(i);
                    uint[] decodedPacketsInfo = null;

                    if (format.Encoding == Multimedia.WaveFormatEncoding.Wmaudio2 || format.Encoding == Multimedia.WaveFormatEncoding.Wmaudio3)
                    {
                        Multimedia.WaveFormatEncoding tag;
                        decodedPacketsInfo = reader.GetSeekTable(i, out tag);
                    }

                    var buffer = DataStream.Create<byte>(data, true, false);

                    var effect = effects[i] = new SoundEffect(audioManager, name, format, buffer, decodedPacketsInfo);

                    if (!string.IsNullOrEmpty(name))
                        effectsByName.Add(name, effect);
                }
            }
        }
Esempio n. 3
0
        protected override void LoadContent()
        {
            spritebatch = new SpriteBatch(GraphicsDevice);

            menuSoundEffect = GameContent.Load<SoundEffect>("Music and Sounds/Menus");
            creditsSoundEffect = GameContent.Load<SoundEffect>("Music and Sounds/Credits");
            menuSound = menuSoundEffect.Create();
            creditsSound = creditsSoundEffect.Create();
            creditsSound.IsLooped = true;
            creditsSound.Volume = vol;
            menuSound.IsLooped = true;
            menuSound.Volume = vol;
            currentSound = creditsSound;
            currentSound.Play();
            GameState = GameStates.MainMenu;

            base.LoadContent();
        }
        /// <summary>
        /// Resets the current instance to be reused in an instance pool.
        /// </summary>
        /// <param name="soundEffect">The new parent sound effect.</param>
        /// <param name="sourceVoice">The new source voice.</param>
        /// <param name="isFireAndForget">The new <see cref="IsFireAndForget"/> value.</param>
        internal void Reset(SoundEffect soundEffect, SourceVoice sourceVoice, bool isFireAndForget)
        {
            Effect = soundEffect;
            voice = sourceVoice;
            IsFireAndForget = isFireAndForget;

            if (soundEffect != null && sourceVoice != null)
                Reset();
        }
Esempio n. 5
0
        public void LoadContent()
        {
            #region Load Rescources
            background = Main.GameContent.Load<Texture2D>("Menus/Background 2");
            font = Main.GameContent.Load<SpriteFont>("Font/Font1");
            title = Main.GameContent.Load<Texture2D>("Menus/Logo");
            highScoresUnPressed = Main.GameContent.Load<Texture2D>("Menus/High Scores");
            highScoresPressed = Main.GameContent.Load<Texture2D>("Menus/High Scores Pressed");
            optionsUnPressed = Main.GameContent.Load<Texture2D>("Menus/Options");
            optionsPressed = Main.GameContent.Load<Texture2D>("Menus/Options Pressed");
            menuUnPressed = Main.GameContent.Load<Texture2D>("Menus/Menu");
            menuPressed = Main.GameContent.Load<Texture2D>("Menus/Menu Pressed");
            creditsUnPressed = Main.GameContent.Load<Texture2D>("Menus/CreditsUnPressed");
            creditsPressed = Main.GameContent.Load<Texture2D>("Menus/CreditsPressed");
            soundUnPressed = Main.GameContent.Load<Texture2D>("Menus/Sound");
            soundPressed = Main.GameContent.Load<Texture2D>("Menus/SoundPressed");
            fullscreenUnPressed = Main.GameContent.Load<Texture2D>("Menus/FullScreen");
            fullscreenPressed = Main.GameContent.Load<Texture2D>("Menus/FullScreenPressed");
            inGameMenu = Main.GameContent.Load<Texture2D>("Menus/InGameMenu");
            exitUnHighLighted = Main.GameContent.Load<Texture2D>("Menus/Exit");
            exitHighLighted = Main.GameContent.Load<Texture2D>("Menus/ExitHighlight");
            resumeHighlighted = Main.GameContent.Load<Texture2D>("Menus/ResumeHighlight");
            resumeUnHighlighted = Main.GameContent.Load<Texture2D>("Menus/Resume");
            startUnPressed = Main.GameContent.Load<Texture2D>("Menus/Start");
            startPressed = Main.GameContent.Load<Texture2D>("Menus/Start Pressed");
            testKartUnPressed = Main.GameContent.Load<Texture2D>("Menus/TestKartUnPressed");
            testKartPressed = Main.GameContent.Load<Texture2D>("Menus/TestKartPressed");
            tifighterUnPressed = Main.GameContent.Load<Texture2D>("Menus/TiFighter");
            tifighterPressed = Main.GameContent.Load<Texture2D>("Menus/TiFighterPressed");
            shoppingCartUnPressed = Main.GameContent.Load<Texture2D>("Menus/ShoppingCart");
            shoppingCartPressed = Main.GameContent.Load<Texture2D>("Menus/ShoppingCartPressed");
            guminKartUnPressed = Main.GameContent.Load<Texture2D>("Menus/GuminKart");
            guminKartPressed = Main.GameContent.Load<Texture2D>("Menus/GuminKartPressed");
            Untitled = Main.GameContent.Load<Texture2D>("Menus/Untitled");
            pressed = Main.GameContent.Load<SoundEffect>("Music and Sounds/Button Press");
            pressedSound = pressed.Create();
            pressedSound.Volume = .25f;
            pressedSound.IsLooped = false;

            scores = new ScoreBoard("Scores", "Scores", 10);
            scores.retrieveScores();
            #endregion

            switch (type)
            {
                case MenuType.MainMenu:
                    kartSelect = new Button(new Vector2(310, 380), 173, 53, 1, Main.CurrentMouse, startUnPressed, startPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    highScores = new Button(new Vector2(9, 536), 324, 55, 2, Main.CurrentMouse, highScoresUnPressed, highScoresPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    options = new Button(new Vector2(280, 469), 233, 42, 3, Main.CurrentMouse, optionsUnPressed, optionsPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    credits = new Button(new Vector2(600, 545), 191, 47, 7, Main.CurrentMouse, creditsUnPressed, creditsPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    exit = new Button(new Vector2(720, 9), 71, 29, 9, Main.CurrentMouse, exitUnHighLighted, exitHighLighted, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);

                    credits.ButtonPressed += ButtonPressed;
                    kartSelect.ButtonPressed += ButtonPressed;
                    options.ButtonPressed += ButtonPressed;
                    highScores.ButtonPressed += ButtonPressed;
                    exit.ButtonPressed += ButtonPressed;
                    break;

                case MenuType.Options:
                    highScores = new Button(new Vector2(467, 536), 324, 55, 2, Main.CurrentMouse, highScoresUnPressed, highScoresPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    menu = new Button(new Vector2(9, 537), 168, 54, 4, Main.CurrentMouse, menuUnPressed, menuPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    sound = new Button(new Vector2(100, 100), 164, 53, 5, Main.CurrentMouse, soundUnPressed, soundPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    fullscreen = new Button(new Vector2(100, 200), 248, 45, 6, Main.CurrentMouse, fullscreenUnPressed, fullscreenPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);

                    menu.ButtonPressed += ButtonPressed;
                    highScores.ButtonPressed += ButtonPressed;
                    sound.ButtonPressed += ButtonPressed;
                    fullscreen.ButtonPressed += ButtonPressed;
                    break;

                case MenuType.HighScores:
                    menu = new Button(new Vector2(9, 537), 168, 54, 4, Main.CurrentMouse, menuUnPressed, menuPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);

                    menu.ButtonPressed += ButtonPressed;
                    break;

                case MenuType.Pause:
                    start = new Button(new Vector2(325, 200), 123, 38, 8, Main.CurrentMouse, resumeUnHighlighted, resumeHighlighted, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    menu = new Button(new Vector2(350, 300), 79, 29, 4, Main.CurrentMouse, exitUnHighLighted, exitHighLighted, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);

                    start.ButtonPressed += ButtonPressed;
                    menu.ButtonPressed += ButtonPressed;
                    break;

                case MenuType.KartSelect:
                    start = new Button(new Vector2(500, 500), 173, 53, 8, Main.CurrentMouse, startUnPressed, startPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    testKart = new Button(new Vector2(100, 100), 165, 23, 10, Main.CurrentMouse, testKartUnPressed, testKartPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    tieFighter = new Button(new Vector2(100, 200), 173, 26, 11, Main.CurrentMouse, tifighterUnPressed, tifighterPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    shoppingCart = new Button(new Vector2(100, 300), 255, 32, 12, Main.CurrentMouse, shoppingCartUnPressed, shoppingCartPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    guminKart = new Button(new Vector2(100, 400), 205, 25, 13, Main.CurrentMouse, guminKartUnPressed, guminKartPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    menu = new Button(new Vector2(100, 500), 168, 54, 4, Main.CurrentMouse, menuUnPressed, menuPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);

                    menu.ButtonPressed += ButtonPressed;
                    start.ButtonPressed += ButtonPressed;
                    testKart.ButtonPressed += ButtonPressed;
                    tieFighter.ButtonPressed += ButtonPressed;
                    shoppingCart.ButtonPressed += ButtonPressed;
                    guminKart.ButtonPressed += ButtonPressed;
                    break;

                case MenuType.Credits:
                    menu = new Button(new Vector2(9, 537), 168, 54, 4, Main.CurrentMouse, menuUnPressed, menuPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);

                    menu.ButtonPressed += ButtonPressed;
                    break;

                case MenuType.Publisher:
                    timer = new Timer(4000);
                    timer.Elapsed += TimeElapsed;
                    timer.Start();
                    break;

                default:
                    break;
            }
        }
Esempio n. 6
0
        protected override void LoadContent()
        {
            ergonWave = Content.Load<SoundEffect>("ergon.adpcm");
            ergonWaveInstance = ergonWave.Create();
            ergonWaveInstance.IsLooped = true;
            waveBank = Content.Load<WaveBank>("TestBank");
            //waveBankXbox = Content.Load<WaveBank>("TestBankXbox.xwb"); //does not play correctly

            // SpriteFont supports the following font file format:
            // - DirectX Toolkit MakeSpriteFont or SharpDX Toolkit tkfont
            // - BMFont from Angelcode http://www.angelcode.com/products/bmfont/
            arial16BMFont = Content.Load<SpriteFont>("Arial16");

            // Instantiate a SpriteBatch
            spriteBatch = new SpriteBatch(GraphicsDevice);

            primitiveBatch = new PrimitiveBatch<VertexPositionColor>(GraphicsDevice);
            primitiveBatchEffect = new BasicEffect(GraphicsDevice);
            primitiveBatchEffect.VertexColorEnabled = true;


            // setup tests
            tiles = new List<SoundTile>();
            Rectangle border = new Rectangle();
            border.X = SoundTile.Padding.X;
            border.Y = SoundTile.Padding.Y;

            AddTile(ref border, "Click to play looped SoundEffectInstance of " + ergonWave.Name, PlayMusic, PauseMusic);
            AddTile(ref border, "Click to play 'PewPew' wave bank entry", () => waveBank.Play("PewPew"));
            AddTile(ref border, "Click to play 'PewPew' wave bank entry with random pitch and pan", () => waveBank.Play("PewPew", 1, random.NextFloat(-1, 1), random.NextFloat(-1, 1)));
            AddTile(ref border, "Click to play 'PewPew' with 3D audio", PlayAudio3D, StopAudio3D);

            // setup 3D
            geometryEffect = ToDisposeContent(new BasicEffect(GraphicsDevice)
            {
                View = Matrix.LookAtRH(new Vector3(0, 10, 20), new Vector3(0, 0, 0), Vector3.UnitY),
                Projection = Matrix.PerspectiveFovRH((float)Math.PI / 4.0f, (float)GraphicsDevice.BackBuffer.Width / GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f),
                World = Matrix.Identity
            });

            cube = ToDisposeContent(GeometricPrimitive.Cube.New(GraphicsDevice));

            // Load the texture
            listenerTexture = Content.Load<Texture2D>("listen");
            emitterTexture = Content.Load<Texture2D>("speaker");
            geometryEffect.TextureEnabled = true;

            base.LoadContent();

        }