示例#1
0
        public override void PlayElement(MusicalSymbol element)
        {
            if (!(element is NoteOrRest))
            {
                return;
            }
            OnElementPlayed(element);
            if (element is Rest)
            {
                return;
            }

            Note note = element as Note;

            if (note == null)
            {
                return;
            }
            if (note.MidiPitch > 92 || note.MidiPitch < 56)
            {
                return;
            }

            int octaveModifier = 0;

            if (note.MidiPitch > 79)
            {
                octaveModifier = 1;
            }
            if (note.MidiPitch < 68)
            {
                octaveModifier = -1;
            }

            SoundEffect effect;
            string      soundUri = string.Format("Manufaktura.Controls.WindowsPhoneSilverlight;component/piano-{0}.wav", _stepNames[note.MidiPitch]);

            lock (_soundEffectsCache)
            {
                if (_soundEffectsCache.ContainsKey(soundUri))
                {
                    effect = _soundEffectsCache[soundUri];
                }
                else
                {
                    var resourceStream = Application.GetResourceStream(new Uri(soundUri, UriKind.RelativeOrAbsolute));
                    effect = SoundEffect.FromStream(resourceStream.Stream);
                    _soundEffectsCache.Add(soundUri, effect);
                }
            }

            var firstNoteInMeasure = note.Staff.Peek <Note>(element, PeekType.BeginningOfMeasure);

            FrameworkDispatcher.Update();
            effect.Play(element == firstNoteInMeasure ? 0.4f : 0.3f, octaveModifier, 0);
        }
示例#2
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     startAcc();
     StartBackGround();
     stream = TitleContainer.OpenStream("Sound/footstep.wav");
     effect = SoundEffect.FromStream(stream);
     FrameworkDispatcher.Update();
     txtNuts.Text = nutAmount.ToString();
     //.base.OnNavigatedTo(e);
 }
示例#3
0
        public override void LoadContent()
        {
            base.LoadContent();
            startUp.Location = new Point(size.Width / 2 - startUp.Size.Width / 2, size.Height * 2 / 3);
            StreamReader streamReader = new StreamReader("./Sound/loading.wav");
            SoundEffect  tse          = SoundEffect.FromStream(streamReader.BaseStream);

            sounds.Add("loading", new Sound(tse));
            sounds["loading"].Play();
        }
示例#4
0
 private void PlaySoundEffect(string effect)
 {
     if (App.AppSettings.SoundEnabled == true)
     {
         var         info        = App.GetResourceStream(new Uri(@"/SQSinglePlayer;Component/Resources/Sound/" + effect + ".wav", UriKind.Relative));
         SoundEffect Soundeffect = SoundEffect.FromStream(info.Stream);
         FrameworkDispatcher.Update();
         Soundeffect.Play();
     }
 }
        /// <summary>
        /// Plays a sound effect
        /// </summary>
        /// <param name="wavResource">The uri of the resource containing the .wav file</param>
        public void Play(Uri wavResource)
        {
            var res = Application.GetResourceStream(wavResource);

            using (var stream = res.Stream)
            {
                var effect = SoundEffect.FromStream(stream);
                effect.Play();
            }
        }
示例#6
0
        private SoundEffectInstance MakeSoundEffect(string soundPath)
        {
            SoundEffect sfx = null;

            using (System.IO.Stream fileStream = System.IO.File.OpenRead(soundPath))
            {
                sfx = SoundEffect.FromStream(fileStream);
            }
            return(sfx.CreateInstance());
        }
        private void storyCompletedBreadTop(object sender, EventArgs e)
        {
            this.countTickPigletEat = 0;
            this.currentBackground  = 1;
            this.timerPigletEat.Start();

            SoundEffectInstance instance = SoundEffect.FromStream(Application.GetResourceStream(new Uri("Sound/piglet_feed/sandwich_eat.wav", UriKind.Relative)).Stream).CreateInstance();

            instance.Play();
        }
示例#8
0
 public override void Build()
 {
     using (var fs = File.OpenRead(UIC_FILE)) {
         uic = new UICMainMenu();
         ZXParser.ParseInto(new StreamReader(fs).ReadToEnd(), uic);
     }
     using (var s = File.OpenRead(uic.SoundClick)) {
         seClick = SoundEffect.FromStream(s);
     }
 }
        private static void LoadBreatheSound()
        {
            string filePath = $"{Helper.DirectoryPath}\\assets\\breathe.wav";

            if (File.Exists(filePath))
            {
                breatheEffect = SoundEffect.FromStream(new FileStream(filePath, FileMode.Open));
                Monitor.Log("Loaded breathing sound.");
            }
        }
示例#10
0
        private void PlatformInitialize(string fileName)
        {
#if MONOMAC || (WINDOWS && OPENGL) || WEB
            using (var s = File.OpenRead(_name))
            {
                var soundEffect = SoundEffect.FromStream(s);
                _sound = soundEffect.CreateInstance();
            }
#endif
        }
 private void PlayFocusLockedSoundIfEnabled()
 {
     if (this.isShutterSoundEnabledByUser)
     {
         Stream      soundFile      = Application.GetResourceStream(new Uri(autofocusLockSoundPath, UriKind.Relative)).Stream;
         SoundEffect autoFocusSound = SoundEffect.FromStream(soundFile);
         Microsoft.Xna.Framework.FrameworkDispatcher.Update();
         autoFocusSound.Play();
     }
 }
 public SoundEffectHelper(string path)
 {
     using (Stream stream = TitleContainer.OpenStream(path))
     {
         SoundEffect effect = SoundEffect.FromStream(stream);
         this.Duration    = effect.Duration;
         this.soundEffect = effect.CreateInstance();
         FrameworkDispatcher.Update();
     }
 }
示例#13
0
 /// <summary>
 /// Load SoundEffect from files
 /// </summary>
 /// <param name="path">File .mp3 path</param>
 /// <param name="sound">Result sound</param>
 static public void SoundFromMp3(string path, ref SoundEffect sound)
 {
     if (File.Exists(path))
     {
         using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
         {
             sound = SoundEffect.FromStream(fileStream);
         }
     }
 }
示例#14
0
        /// <summary>
        ///   Plays a sound effect
        /// </summary>
        /// <param name="wavResource"> The uri of the resource containing the .wav file </param>
        public void Play(Uri wavResource)
        {
            var type = updater.GetType(); // dummy call so updater is created
            var res  = Application.GetResourceStream(wavResource);

            using (var stream = res.Stream) {
                var effect = SoundEffect.FromStream(stream);
                effect.Play();
            }
        }
示例#15
0
        public void Play(Note note, int bpm)
        {
            Stop();

            using (var s = soundGenerator.NoteToWaveStream(note, bpm))
            {
                var effect = SoundEffect.FromStream(s);
                player = effect.CreateInstance();
                player.Play();
            }
        }
示例#16
0
        public void Play(Tune tune)
        {
            Stop();

            using (var s = soundGenerator.TuneToWaveStream(tune))
            {
                var effect = SoundEffect.FromStream(s);
                player = effect.CreateInstance();
                player.Play();
            }
        }
示例#17
0
        /// <summary>
        /// Loads a <see cref="SoundEffect"/> from a file.
        /// </summary>
        /// <param name="soundPath">The path to the sound file.</param>
        public SoundEffect GetSound(string soundPath)
        {
            using (var soundStream = _reader.GetFileStream(soundPath)) {
                if (soundStream != null)
                {
                    return(SoundEffect.FromStream(soundStream));
                }
            }

            return(null);
        }
示例#18
0
 public static void AlarmSound()
 {
     if (alarmNoice)
     {
         StreamResourceInfo _stream      = Application.GetResourceStream(new Uri("PivotApp1;component/Sound/miley.wav", UriKind.Relative));
         SoundEffect        _soundeffect = SoundEffect.FromStream(_stream.Stream);
         App.soundInstance = _soundeffect.CreateInstance();
         FrameworkDispatcher.Update();
         App.soundInstance.Play();
     }
 }
示例#19
0
 public static SoundEffect SoundEffectFromOgg(string path)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         WavStreamFromOgg(path, ms);
         ms.Position = 0;
         SoundEffect fx = SoundEffect.FromStream(ms);
         //ms.Dispose();
         return(fx);
     }
 }
示例#20
0
        void translator_SpeakCompleted(object sender, TTSService.SpeakCompletedEventArgs e)
        {
            var client = new WebClient();

            client.OpenReadCompleted += ((s, args) =>
            {
                SoundEffect se = SoundEffect.FromStream(args.Result);
                se.Play();
            });
            client.OpenReadAsync(new Uri(e.Result));
        }
示例#21
0
 public static SafeSoundEffect FromFile(string path)
 {
     if (!AudioDevice.Available)
     {
         return(new SafeSoundEffect());
     }
     using (var fs = File.OpenRead(path))
     {
         return(new SafeSoundEffect(SoundEffect.FromStream(fs)));
     }
 }
示例#22
0
 private void LoadSound(bool loop)
 {
     using (var stream = File.OpenRead(Filename))
     {
         Effect                  = SoundEffect.FromStream(stream);
         EffectInstance          = Effect.CreateInstance();
         EffectInstance.Volume   = Volume / 100.0f;
         EffectInstance.Pitch    = ((Pitch - 100) * 2) / 100.0f;
         EffectInstance.IsLooped = loop;
     }
 }
示例#23
0
        public static SoundEffect GetSoundEffect(string pPathToFile)
        {
            if (!File.Exists(pPathToFile))
            {
                throw new FileNotFoundException("File " + pPathToFile + " not found!");
            }

            var soundEffect = SoundEffect.FromStream(File.OpenRead(pPathToFile));

            return(soundEffect);
        }
        private void PlaySound(string path)
        {
            //PlaySound("Assets/CancelledEarcon.wav");
            //PlaySound("Assets/ListeningEarcon.wav");

            var stream = TitleContainer.OpenStream(path);
            var effect = SoundEffect.FromStream(stream);

            FrameworkDispatcher.Update();
            effect.Play();
        }
示例#25
0
 private SoundEffect GetSoundEffect(SoundType Type)
 {
     if (!_effects.ContainsKey(Type))
     {
         using (FileStream fs = File.Open((string.Format("Content\\{0}.wav", Type)), FileMode.Open))
         {
             _effects.Add(Type, SoundEffect.FromStream(fs));
         }
     }
     return(_effects[Type]);
 }
示例#26
0
 public static SoundEffect GetSoundFromPath(string path)
 {
     if (File.Exists(path))
     {
         return(SoundEffect.FromStream(new FileStream(path, FileMode.Open)));
     }
     else
     {
         return(null);
     }
 }
示例#27
0
        public T FromStream <T>(Stream stream) where T : class
        {
            if (typeof(T) != typeof(SoundEffect))
            {
                throw AssetLoadException.FromInvalidReader <WavReader, T>();
            }

            //if (!stream.CanSeek)
            //	stream = new MemoryStream(stream.ReadBytes(stream.Length));

            return(SoundEffect.FromStream(stream) as T);
        }
示例#28
0
            /// <summary>
            /// Get SoundEffect from WAV file
            /// </summary>
            public static SoundEffect GetSoundEffect(GraphicsDevice graphicsDevice, ContentManager contentManager, string soundName, string folder = "")
            {
                string absolutePath = new DirectoryInfo(Path.Combine(Path.Combine(contentManager.RootDirectory, folder), $"{soundName}.wav")).ToString();

                FileStream fileStream = new FileStream(absolutePath, FileMode.Open);

                SoundEffect result = SoundEffect.FromStream(fileStream);

                fileStream.Dispose();

                return(result);
            }
示例#29
0
        public AudioPlayer(ISfxrSynth synth)
        {
            var wavData = synth.GenerateWav();

            using (var stream = new MemoryStream(wavData))
            {
                _soundEffect = SoundEffect.FromStream(stream);
            }

            // may make these on a per-play instance at some point
            _soundEffectInstance = _soundEffect.CreateInstance();
        }
        private void FeedGamePage_gamePlay()
        {
            this.textBlockLevel.Text             = String.Format(AppResources.FeedGamePageTextBlockLevelTextLevelNum, this.currentLevel, this.maxLevel) + Environment.NewLine + AppResources.FeedGamePageTextBlockLevelTextHint;
            this.ImageBackgroundLevel.Visibility = Visibility.Visible;
            this.textBlockLevel.Visibility       = Visibility.Visible;

            SoundEffectInstance instance = SoundEffect.FromStream(Application.GetResourceStream(new Uri("Sound/piglet_feed/new_level.wav", UriKind.Relative)).Stream).CreateInstance();

            instance.Play();

            this.timerStartLevel.Start();
        }