Ejemplo n.º 1
0
        /// <summary>Switch the audio source.</summary>
        /// <param name="source">Where to load the sound from.</param>
        /// <param name="cueName">The cue name to play.</param>
        private void SetAudio(ContentSource source, string cueName)
        {
            if (source == this.Source && cueName == this.CueName)
            {
                return;
            }

            // remove last sound
            this.Cue?.Stop(AudioStopOptions.Immediate);

            // set new sound
            this.Source  = source;
            this.CueName = cueName;
            if (cueName != null)
            {
                switch (source)
                {
                case ContentSource.GameContent:
                    this.Cue = Game1.soundBank.GetCue(cueName);
                    break;

                case ContentSource.ModFolder:
                {
                    IModCue sound = this.Helper.Content.ExtendedLoad <IModCue>($"assets/{cueName}.ogg");
                    sound.IsLooped = true;
                    this.Cue       = sound;
                }
                break;
                }
            }
            else
            {
                this.Cue = null;
            }
        }
Ejemplo n.º 2
0
        /*********
        ** Private methods
        *********/
        /// <summary>The method invoked when the player presses a button.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void Input_ButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            switch (e.Button)
            {
            // toggle audio source
            case SButton.Tab:
                this.SetAudio(this.Source == ContentSource.GameContent ? ContentSource.ModFolder : ContentSource.GameContent, this.CueName);
                break;

            // set audio clip
            case SButton.D1:
                this.SetAudio(this.Source, null);
                break;

            case SButton.D2:
                this.SetAudio(this.Source, "SinWave.ogg");     // supports Pitch
                break;

            case SButton.D3:
                this.SetAudio(this.Source, "wind.ogg");     // supports Frequency; GameContent cue only works after loading a save
                if (this.Source == ContentSource.ModFolder)
                {
                    IModCue cue = (IModCue)this.Cue;
                    cue.EnableFilter(FilterType.LowPass, 3000, 0.707);
                }
                break;

            case SButton.D4:
                this.SetAudio(this.Source, "stillnessInTheRain.ogg");     // mod sound only
                break;

            case SButton.D5:
                this.SetAudio(this.Source, "flute.ogg");
                break;

            case SButton.D6:
                this.SetAudio(this.Source, "rain.ogg");
                if (this.Source == ContentSource.ModFolder)
                {
                    IModCue cue = (IModCue)this.Cue;
                    cue.EnableFilter(FilterType.LowPass, 20000, 2.90);
                }
                break;

            case SButton.D7:
                this.SetAudio(this.Source, "stillnessInTheRain.wav");     // Support wav reading.
                break;

            // set frequency
            case SButton.Up:
            case SButton.Down:
            {
                int change = e.Button == SButton.Up ? 10 : -10;
                this.Frequency = (int)MathHelper.Clamp(this.Frequency + change, 0, 100);
            }
            break;

            // set pitch
            case SButton.Left:
            case SButton.Right:
            {
                int change = e.Button == SButton.Right ? 240 : -240;
                this.Pitch = (int)MathHelper.Clamp(this.Pitch + change, 0, 2400);
            }
            break;
            }
        }