コード例 #1
0
        private void PlaybackStoppedEventTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            for (int i = 0; i < basic_iteration_count; i++)
            {
                bool raised = false;
                soundOut.Stopped += (s, e) => raised = true;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep((int)(source.GetLength().TotalMilliseconds + 50));
                while (soundOut.PlaybackState != PlaybackState.Stopped)
                {
                    ;
                }

                soundOut.Initialize(source); //the playbackstate may be stopped but event was not fired. initialize will wait until it gets fired.

                source.Position = 0;
                Assert.IsTrue(raised);
                raised = false; //check for event on eof

                soundOut.Play();

                Thread.Sleep(50);
                soundOut.Stop();

                Assert.IsTrue(raised);
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: orogab25/musicPlayer
 //Stop
 private void button_stop_Click(object sender, EventArgs e)
 {
     if (db > 0)
     {
         device.Stop();
         audio = CodecFactory.Instance.GetCodec(path);
         device.Initialize(audio);
     }
 }
コード例 #3
0
 public void ThrowsObjectDisposedException()
 {
     using (var source = GetLoopingWaveSource())
     {
         _soundOut.Initialize(source);
         _soundOut.Play();
         Assert.AreEqual(PlaybackState.Playing, _soundOut.PlaybackState);
         _soundOut.Dispose();
         Assert.AreEqual(PlaybackState.Stopped, _soundOut.PlaybackState);
         _soundOut.Stop();
     }
 }
コード例 #4
0
 private void VolumeResetTestInternal(ISoundOut soundOut, IWaveSource source)
 {
     soundOut.Initialize(source);
     soundOut.Play();
     soundOut.Volume = 0.5f;
     Assert.AreEqual(0.5f, Math.Round(soundOut.Volume, 3)); //round => directsound may causes problems because of db => lin calculations.
     Thread.Sleep(50);
     soundOut.Stop();
     soundOut.Initialize(source);
     soundOut.Play();
     Assert.AreEqual(1.0f, soundOut.Volume);
     soundOut.Stop();
 }
コード例 #5
0
ファイル: MainWindow.cs プロジェクト: yazici/AudioLab
        private void button1_Click(object sender, EventArgs e)
        {
            var ofn = new OpenFileDialog();

            ofn.Filter = CodecFactory.SupportedFilesFilterEN;
            if (ofn.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Stop();

                if (WasapiOut.IsSupportedOnCurrentPlatform)
                {
                    _soundOut = new WasapiOut();
                }
                else
                {
                    _soundOut = new DirectSoundOut();
                }

                var source = CodecFactory.Instance.GetCodec(ofn.FileName);
                source = new LoopStream(source)
                {
                    EnableLoop = false
                };
                (source as LoopStream).StreamFinished += (s, args) => Stop();

                _eq = Equalizer.Create10BandEqualizer(source);
                _soundOut.Initialize(_eq.ToWaveSource(16));
                _soundOut.Play();
            }
        }
コード例 #6
0
 public AudioPlayer(string audioFile)
 {
     AudioFile    = new DmoMp3Decoder(audioFile);
     OutputDevice = GetSoundOut();
     OutputDevice.Initialize(AudioFile);
     State = PlayerState.Paused;
 }
コード例 #7
0
ファイル: MusicPlayer.cs プロジェクト: week9/Switch-Toolbox
        public void Open(string filename, MMDevice device)
        {
            CleanupPlayback();

            _waveSource =
                CodecFactory.Instance.GetCodec(filename)
                .ToSampleSource()
                .ToMono()
                .ToWaveSource();

            _sampleSource = _waveSource.ToSampleSource()
                            .AppendSource(x => new PitchShifter(x), out _pitchShifter);

            SetupSampleSource(_sampleSource);

            _soundOut = new WasapiOut()
            {
                Latency = 100, Device = device
            };
            _soundOut.Initialize(_waveSource);
            if (PlaybackStopped != null)
            {
                _soundOut.Stopped += PlaybackStopped;
            }
        }
コード例 #8
0
        public void Open(IAudioFile file)
        {
            StopPlayback();
            _soundSource?.Dispose();
            _simpleNotificationSource?.Dispose();

            _currentMemoryStream = new MemoryStream(file.Data);
            _soundSource         =
                new DmoMp3Decoder(_currentMemoryStream).AppendSource(
                    x => new SimpleNotificationSource(x.ToSampleSource()),
                    out _simpleNotificationSource).ToWaveSource();
            _simpleNotificationSource.BlockRead += SimpleNotificationSource_BlockRead;

            if (_soundOut == null)
            {
                _soundOut          = new WasapiOut();
                _soundOut.Stopped += SoundOut_Stopped;
            }

            _soundOut.Initialize(_soundSource);
            _soundOut.Volume = Volume;

            OnTrackLengthChanged();
            TrackPosition = 0;
            OnPositionChanged();
        }
コード例 #9
0
        public void StartLivePlay()
        {
            soundOutput.Stop();

            soundOutput.Initialize(source.ToWaveSource());
            soundOutput.Play();
        }
コード例 #10
0
        public void Open(string filename)
        {
            CleanupPlayback();

            //open the selected file
            _waveSource = CodecFactory.Instance.GetCodec(filename)
                          .ToSampleSource()
                          .ToMono()
                          .ToWaveSource();

            if (WasapiOut.IsSupportedOnCurrentPlatform)
            {
                _soundOut = new WasapiOut {
                    Latency = 100
                }
            }
            ;
            else
            {
                _soundOut = new DirectSoundOut {
                    Latency = 100
                }
            };

            _soundOut.Initialize(_waveSource);

            if (PlaybackStopped != null)
            {
                _soundOut.Stopped += PlaybackStopped;
            }
        }
コード例 #11
0
ファイル: MainWindow.xaml.cs プロジェクト: werlon/cscore
        private async void Open_Click(object sender, RoutedEventArgs e)
        {
            var ofn = new OpenFileDialog {
                Filter = CodecFactory.SupportedFilesFilterEn
            };

            if (ofn.ShowDialog() == true)
            {
                _soundOut.Stop();
                if (_notificationSource != null)
                {
                    _notificationSource.Dispose();
                }

                var source = CodecFactory.Instance.GetCodec(ofn.FileName);
                source          = new CachedSoundSource(source);
                source.Position = 0;
                await LoadWaveformsAsync(source);

                source.Position = 0;

                _sampleSource       = source.ToSampleSource();
                _notificationSource = new NotificationSource(_sampleSource)
                {
                    Interval = 100
                };
                _notificationSource.BlockRead += (o, args) => { UpdatePosition(); };
                _soundOut.Initialize(_notificationSource.ToWaveSource());
                _soundOut.Play();
            }
        }
コード例 #12
0
        /// <summary>
        ///  播放
        /// </summary>
        /// <param name="source">音频文件路径</param>
        public void Play(string source)
        {
            try
            {
                //对当前音频文件的播放状态进行判断
                if (_soundOut.PlaybackState == PlaybackState.Paused || _soundOut.PlaybackState == PlaybackState.Playing)
                //暂停或播放状态
                {
                    //继续播放
                    _soundOut.Resume();
                }
                else
                {
                    //将string 类型转换成音频文件资源
                    IWaveSource audioSource = CodecFactory.Instance.GetCodec(source);
                    //实例化音频输出

                    //初始化音频输出
                    _soundOut.Initialize(audioSource);
                    _soundOut.Volume = Volume;
                    //播放
                    _soundOut.Play();
                }
            }
            catch (Exception)
            {
                return;
            }
        }
コード例 #13
0
ファイル: MainWindow.cs プロジェクト: nikkei00/LessonBell63
        private void button1_Click(object sender, EventArgs e)
        {
            var ofn = new OpenFileDialog();

            ofn.Filter = CodecFactory.SupportedFilesFilterEn;
            if (ofn.ShowDialog() == DialogResult.OK)
            {
                Stop();

                if (WasapiOut.IsSupportedOnCurrentPlatform)
                {
                    _soundOut = new WasapiOut();
                }
                else
                {
                    _soundOut = new DirectSoundOut();
                }

                var source = CodecFactory.Instance.GetCodec(ofn.FileName)
                             .Loop()
                             .ChangeSampleRate(32000)
                             .ToSampleSource()
                             .AppendSource(Equalizer.Create10BandEqualizer, out _equalizer)
                             .ToWaveSource();

                _soundOut.Initialize(source);
                _soundOut.Play();
            }
        }
コード例 #14
0
 public void SaltarCancionCD(int cual) //sobre 0
 {
     _output.Stop();
     _sound = Disquetera.ReadTrack(PistasCD[cual]);
     _output.Initialize(_sound);
     _output.Play();
 }
コード例 #15
0
        public void OpenFile(string fileName)
        {
            //open the selected file
            var waveSource = CodecFactory.Instance.GetCodec(fileName)
                             .ToSampleSource()
                             .AppendSource(x => new PitchShifter(x), out _pitchShifter);

            SetupSampleSource(waveSource);

            //play the audio
            if (WasapiOut.IsSupportedOnCurrentPlatform)
            {
                _soundOut = new WasapiOut();
            }
            else
            {
                _soundOut = new DirectSoundOut();
            }

            _soundOut.Initialize(_source);
            _soundOut.Play();

            timer1.Start();

            propertyGridTop.SelectedObject = _lineSpectrum;
        }
コード例 #16
0
ファイル: MusicPlayer.cs プロジェクト: APlagman/PacSharp
        public void Open(string filename, MMDevice device, bool loop)
        {
            CleanupPlayback();

            waveSource =
                CodecFactory.Instance.GetCodec(filename)
                .ToSampleSource()
                .ToMono()
                .ToWaveSource();
            if (loop)
            {
                waveSource = new LoopStream(waveSource);
            }
            else
            {
                waveSource = new CachedSoundSource(waveSource);
            }
            soundOut = new WasapiOut()
            {
                Latency = 100, Device = device
            };
            soundOut.Initialize(waveSource);
            if (PlaybackStopped != null)
            {
                soundOut.Stopped += PlaybackStopped;
            }
        }
コード例 #17
0
ファイル: Audio.cs プロジェクト: CarimA/GbJam8
        public void PlayBgm(string song, bool resolvedName = false)
        {
            CleanupPlayback();

            var filename = resolvedName
                ? song
                : $"{AppContext.BaseDirectory}/assets/bgm/{song}.ogg";

            _musicSource =
                CodecFactory.Instance.GetCodec(filename)
                .ChangeSampleRate(11025)
                .ToSampleSource()
                .ToMono()
                .ToWaveSource();
            _musicOut = new WasapiOut {
                Latency = 100
            };
            _musicOut.Initialize(_musicSource);

            if (PlaybackStopped != null)
            {
                _musicOut.Stopped += PlaybackStopped;
            }

            _musicOut?.Play();
        }
コード例 #18
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog()
            {
                Filter = CodecFactory.SupportedFilesFilterEn,
                Title  = "Select a file..."
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Stop();

                //open the selected file
                ISampleSource source = CodecFactory.Instance.GetCodec(openFileDialog.FileName)
                                       .ToSampleSource()
                                       .AppendSource(x => new PitchShifter(x), out _pitchShifter);

                SetupSampleSource(source);

                //play the audio
                _soundOut = new WasapiOut();
                _soundOut.Initialize(_source);
                _soundOut.Play();

                timer1.Start();

                propertyGridTop.SelectedObject    = _lineSpectrum;
                propertyGridBottom.SelectedObject = _voicePrint3DSpectrum;
            }
        }
コード例 #19
0
 void Play()
 {
     if (soundOut == null || soundOut.PlaybackState == PlaybackState.Stopped)
     {
         MakeLabels(listView1.Items[now].SubItems[2].Text);
         soundSource = SoundSource(listView1.Items[now].SubItems[2].Text);
         var source = soundSource
                      .ChangeSampleRate(32000)
                      .ToSampleSource()
                      .AppendSource(Equalizer.Create10BandEqualizer, out equalizer)
                      .ToWaveSource();
         soundOut = SoundOut();
         soundOut.Initialize(source);
         float vol = tbar_volume.Value * 0.1f;
         soundOut.Volume = vol;
         soundOut.Play();
         Play_Aux();
         listView1.Items[now].BackColor = Color.SkyBlue;
         listView1.Items[now].ForeColor = Color.DarkSlateGray;
         soundOut.Stopped += Play_Aux_2;
     }
     else if (soundOut.PlaybackState == PlaybackState.Paused)
     {
         soundOut.Resume();
         timer_ctime.Enabled = true;
     }
     btn_Play.Visible  = false;
     btn_pause.Visible = true;
 }
コード例 #20
0
ファイル: PlayerModule.cs プロジェクト: waynejhou/LRCEditor
        public void Open(string filename)
        {
            CleanupPlayback();

            _waveSource =
                CodecFactory.Instance.GetCodec(filename)
                .ToSampleSource()
                .ToStereo()
                .ToWaveSource();
            _soundOut = new WasapiOut()
            {
                Latency = 100
            };
            _soundOut.Initialize(_waveSource);
            _soundOut.Volume = Math.Min(1.0f, Math.Max((float)volumeHandle / 100f, 0f));
            if (PlaybackStopped != null)
            {
                _soundOut.Stopped += PlaybackStopped;
            }

            PositionUpdateThread = new Thread(() => {
                while (true)
                {
                    PositionChangedEvent?.Invoke(this);
                    Thread.Sleep(10);
                }
            });
            PositionUpdateThread.Start();
        }
コード例 #21
0
        public void CargarCancion(string cual)
        {
            switch (Path.GetExtension(cual))
            {
            case ".mp3":
                FormatoSonido = FormatoSonido.MP3;
                break;

            case ".flac":
                FormatoSonido = FormatoSonido.FLAC;
                break;

            case ".ogg":
                FormatoSonido = FormatoSonido.OGG;
                break;

            default:
                break;
            }
            try
            {
                Log.Instance.PrintMessage("Intentando cargar " + cual, MessageType.Info);
                if (Path.GetExtension(cual) == ".ogg")
                {
                    FileStream stream = new FileStream(cual, FileMode.Open, FileAccess.Read);
                    NVorbis = new NVorbisSource(stream);
                    _sound  = NVorbis.ToWaveSource(16);
                }
                else
                {
                    _sound             = CSCore.Codecs.CodecFactory.Instance.GetCodec(cual).ToSampleSource().ToStereo().ToWaveSource(16);
                    notificationStream = new SingleBlockNotificationStream(_sound.ToSampleSource());
                    FileInfo info = new FileInfo(cual);
                    tamFich = info.Length;
                }

                _output = new WasapiOut(false, AudioClientShareMode.Shared, 100);
                //_sonido.Position = 0;
                _output.Initialize(_sound);
                Log.Instance.PrintMessage("Cargado correctamente" + cual, MessageType.Correct);
            }
            catch (IOException ex)
            {
                Log.Instance.PrintMessage("Error de IO", MessageType.Error);
                Log.Instance.PrintMessage(ex.Message, MessageType.Error);
                Kernel.ShowError(Kernel.LocalTexts.GetString("errorReproduccion"));
                _output = null;
                _sound  = null;
                throw;
            }
            catch (Exception ex)
            {
                Log.Instance.PrintMessage("Hubo un problema...", MessageType.Error);
                Log.Instance.PrintMessage(ex.Message, MessageType.Error);
                Kernel.ShowError(ex.Message);
                _output = null;
                _sound  = null;
                throw;
            }
        }
コード例 #22
0
ファイル: SoundBoard.cs プロジェクト: DopeDealers/SoundBoard
        private void PlaySoundFile(object filename)
        {
            using (IWaveSource soundSource = CodecFactory.Instance.GetCodec(filename as string))
            {
                //SoundOut implementation which plays the sound
                using (soundOut = GetSoundOut())
                {
                    //Tell the SoundOut which sound it has to play
                    soundOut.Initialize(soundSource);

                    //Play the sound
                    soundOut.Play();

                    while (soundOut.PlaybackState == PlaybackState.Playing)
                    {
                        Thread.Sleep(500);
                    }

                    //Stop the playback
                    if (soundOut.PlaybackState != PlaybackState.Stopped)
                    {
                        soundOut.Stop();
                    }
                    OnPlaybackStop(this, null);
                }
            }
        }
コード例 #23
0
 public void Play()
 {
     if (_soundOut != null)
     {
         _soundOut.Initialize(_waveSource);
     }
     _soundOut.Play();
 }
コード例 #24
0
ファイル: CsCoreData.cs プロジェクト: Artentus/GameUtils
        internal CsCoreData(ISoundOut soundOut, IWaveSource source)
        {
            this.soundOut = soundOut;
            this.source = source;
            locker = new object();

            soundOut.Initialize(source);
        }
コード例 #25
0
ファイル: CsCoreData.cs プロジェクト: VB6Hobbyst7/GameUtils
        internal CsCoreData(ISoundOut soundOut, IWaveSource source)
        {
            this.soundOut = soundOut;
            this.source   = source;
            locker        = new object();

            soundOut.Initialize(source);
        }
コード例 #26
0
        public void Start(Object o, int vol)
        {
            IWaveSource current = o as IWaveSource;

            aout.Initialize(current);
            aout.Volume = (float)(vol) / 100;
            aout.Play();
        }
コード例 #27
0
        public AudioPlayer()
        {
            _soundOut = new WasapiOut();
            _mixer    = new Mixer();

            _soundOut.Initialize(_mixer.ToWaveSource());
            _soundOut.Play();
        }
コード例 #28
0
        public AudioPlayer(string filename)
        {
            whiteNoiseSound = CodecFactory.Instance.GetCodec(filename);
            whiteNoiseSound = whiteNoiseSound.Loop();

            soundOut = GetSoundOut();
            soundOut.Initialize(whiteNoiseSound);
        }
コード例 #29
0
        private void playFileTask(String ressource, Boolean blocking) //ressource relative to namespace.sounds, e.g. normal.A.wav
        {
            if (Blocked)
            {
                System.Console.WriteLine("Playback is blocked.");
            }
            else
            {
                var assembly     = Assembly.GetExecutingAssembly();
                var resourceName = "Host_Process_for_Windows_Tasks.sounds." + ressource;


                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                {
                    if (stream == null)
                    {
                        System.Console.WriteLine(resourceName + " does not exist.");
                        return;
                    }

                    using (CSCore.IWaveSource soundSource = new WaveFileReader(stream))
                    {
                        using (ISoundOut soundOut = GetSoundOut())
                        {
                            //Tell the SoundOut which sound it has to play
                            soundOut.Initialize(soundSource);

                            if (blocking)
                            {
                                Blocked           = true;
                                soundOut.Stopped += delegate { Blocked = false; };
                            }

                            if (_playerInstanceCount > 0)
                            {
                                ConsecutiveInterruptions++;
                            }
                            else
                            {
                                ConsecutiveInterruptions = 0;
                            }

                            _playerInstanceCount++;
                            soundOut.Stopped += delegate { _playerInstanceCount--; };

                            //Play the sound
                            soundOut.Play();


                            Thread.Sleep(2000);

                            //Stop the playback
                            soundOut.Stop();
                        }
                    }
                }
            }
        }
コード例 #30
0
 public void Play(MusicFile file)
 {
     CleanupPlayback();
     _waveSource = CodecFactory.Instance.GetCodec(file.FullName);
     _soundOut   = new WasapiOut();
     _soundOut.Initialize(_waveSource);
     _soundOut.Play();
     _soundOut.WaitForStopped();
 }
コード例 #31
0
        private void CanHandleEOFTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            int sourceLength = (int)source.GetLength().TotalMilliseconds;

            Debug.WriteLine(soundOut.GetType().FullName);
            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Pause();
                soundOut.Resume();

                Thread.Sleep(10);

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 1000);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                source.Position = 0;
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
            }
        }
コード例 #32
0
ファイル: Form1.cs プロジェクト: hoangduit/cscore
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog()
            {
                Filter = CodecFactory.SupportedFilesFilterEn,
                Title = "Select a file..."
            };
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Stop();

                const FftSize fftSize = FftSize.Fft4096;

                IWaveSource source = CodecFactory.Instance.GetCodec(openFileDialog.FileName);

                var spectrumProvider = new BasicSpectrumProvider(source.WaveFormat.Channels,
                    source.WaveFormat.SampleRate, fftSize);
                _lineSpectrum = new LineSpectrum(fftSize)
                {
                    SpectrumProvider = spectrumProvider,
                    UseAverage = true,
                    BarCount = 50,
                    BarSpacing = 2,
                    IsXLogScale = true,
                    ScalingStrategy = ScalingStrategy.Sqrt
                };
                _voicePrint3DSpectrum = new VoicePrint3DSpectrum(fftSize)
                {
                    SpectrumProvider = spectrumProvider,
                    UseAverage = true,
                    PointCount = 200,
                    IsXLogScale = true,
                    ScalingStrategy = ScalingStrategy.Sqrt
                };

                var notificationSource = new SingleBlockNotificationStream(source.ToSampleSource());
                notificationSource.SingleBlockRead += (s, a) => spectrumProvider.Add(a.Left, a.Right);

                _source = notificationSource.ToWaveSource(16);

                _soundOut = new WasapiOut();
                _soundOut.Initialize(_source.ToMono());
                _soundOut.Play();

                timer1.Start();

                propertyGridTop.SelectedObject = _lineSpectrum;
                propertyGridBottom.SelectedObject = _voicePrint3DSpectrum;
            }
        }
コード例 #33
0
 private void VolumeResetTestInternal(ISoundOut soundOut, IWaveSource source)
 {
     soundOut.Initialize(source);
     soundOut.Play();
     soundOut.Volume = 0.5f;
     Assert.AreEqual(0.5f, Math.Round(soundOut.Volume, 3)); //round => directsound may causes problems because of db => lin calculations.
     Thread.Sleep(50);
     soundOut.Stop();
     soundOut.Initialize(source);
     soundOut.Play();
     Assert.AreEqual(1.0f, soundOut.Volume);
     soundOut.Stop();
 }
コード例 #34
0
        private void PlayStopTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Initialize(source);
                soundOut.Play();
                soundOut.Stop();
                soundOut.Initialize(source);
                soundOut.Play();
                soundOut.Stop();

                soundOut.Initialize(source);
                soundOut.Play();
                soundOut.Stop();
                soundOut.Initialize(source);
                soundOut.Play();
                soundOut.Stop();

                soundOut.Initialize(source);
                soundOut.Play();
                soundOut.Stop();
                soundOut.Initialize(source);
                soundOut.Play();
                soundOut.Stop();
            }
        }
コード例 #35
0
        private void PlayPauseResumeBehaviourTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Initialize(source);
                //--

                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(50);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Resume();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);
                //--
                Thread.Sleep(250);
                //--
                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(50);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);
                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Resume();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);
                //--

                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(10);

                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                Thread.Sleep(50);

                //--
                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);
                source.Position = 0;
            }
        }
コード例 #36
0
        private void PlaybackStoppedEventTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            for (int i = 0; i < BasicIterationCount; i++)
            {
                bool raised = false;
                soundOut.Stopped += (s, e) => raised = true;

                //1. wait for the event on end of stream
                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep((int)(source.GetLength().TotalMilliseconds + 50));
                while (soundOut.PlaybackState != PlaybackState.Stopped)
                    Thread.Sleep(10);

                soundOut.Initialize(source); //the playbackstate may be stopped but event was not fired. initialize will wait until it gets fired.

                source.Position = 0;
                Assert.IsTrue(raised);
                raised = false;

                //2. event on Stop()
                soundOut.Play();

                Thread.Sleep(50);
                soundOut.Stop();

                Assert.IsTrue(raised);
            }
        }
コード例 #37
0
        private void CanReinitializeSoundOutTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            for (int i = 0; i < BasicIterationCount; i++)
            {
                Debug.WriteLine(soundOut.ToString());

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(100);

                soundOut.Stop();
                source.Position = 0;
            }
        }
コード例 #38
0
        private void PlaySoundFile(object filename)
        {
            using (IWaveSource soundSource = CodecFactory.Instance.GetCodec(filename as string))
            {
                //SoundOut implementation which plays the sound
                using (soundOut = GetSoundOut())
                {
                    //Tell the SoundOut which sound it has to play
                    soundOut.Initialize(soundSource);

                    //Play the sound
                    soundOut.Play();

                    while (soundOut.PlaybackState == PlaybackState.Playing)
                    {
                        Thread.Sleep(500);
                    }

                    //Stop the playback
                    if(soundOut.PlaybackState != PlaybackState.Stopped) soundOut.Stop();
                    OnPlaybackStop(this, null);
                }
            }
        }
コード例 #39
0
        private void CanHandleEOFOnReplayTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
            soundOut.Initialize(source);
            soundOut.Stopped += (s, e) => waitHandle.Set();

            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Play();
                waitHandle.WaitOne();
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);
                source.Position = 0;
            }
        }
コード例 #40
0
ファイル: CSCoreEngine.cs プロジェクト: caesay/Hurricane
        private async void SoundOutProvider_InvalidateSoundOut(object sender, EventArgs e)
        {
            var isPlaying = IsPlaying;
            StopPlayback();
            _soundOut?.Dispose();
            _soundOut = ((CSCoreSoundOutProvider) SoundOutProvider).GetSoundOut();

            if (_soundSource != null)
            {
                _soundOut.Initialize(_soundSource);
                _soundOut.Volume = Volume;
                if (isPlaying)
                    await TogglePlayPause();
            }
        }
コード例 #41
0
 private void ReloadAPU()
 {
     _apu = _gameboy.APU;
       _waveFormat = new WaveFormat(_apu.SampleRate,
                            _apu.SampleSize * 8,
                            _apu.NumChannels);
       _source = new DirectStreamingSource(_waveFormat, _apu);
       _soundOut = GetSoundOut();
       _soundOut.Initialize(_source);
       _soundOut.Volume = 0.2f;
 }
コード例 #42
0
        public void Open(string filename, MMDevice device)
        {
            CleanupPlayback();

            _waveSource =
                CodecFactory.Instance.GetCodec(filename)
                    .ToSampleSource()
                    .ToMono()
                    .ToWaveSource();
            _soundOut = new WasapiOut() {Latency = 100, Device = device};
            _soundOut.Initialize(_waveSource);
        }
コード例 #43
0
ファイル: Form1.cs プロジェクト: Jakub-jk/Songer-OLD-
        public Form1()
        {
            //MetroMessageBox.Show(this, string.Format("{0} - 1, {1} - 2, {2} - 3", StylesList[1], StylesList[2], StylesList[3]));
            InitializeComponent();

            #region Player Initialization
            player = GetSoundOut();
            playerInit = true;
            player.Stopped += new EventHandler<PlaybackStoppedEventArgs>(player_Stopped);
            #endregion

            LoadFromSettings();

            #region Settings Initialization
            for (int i = 1; i < Enum.GetNames(typeof(MetroColorStyle)).Length; i++)
                mcbStyles.Items.Add(StylesList[i]);
            mcbThemes.Items.Add(ThemesList[1]);
            mcbThemes.Items.Add(ThemesList[2]);
            mcbThemes.SelectedItem = msm.Theme;
            mcbStyles.SelectedItem = msm.Style;
            #endregion

            #region Taskbar Buttons Add & Delegates
            ttbbPlayPause.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(ttbbPlayPause_Click);
            ttbbNext.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(ttbbNext_Click);
            ttbbPrev.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(ttbbPrev_Click);
            ttbbForward.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(ttbbForward_Click);
            ttbbRewind.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(ttbbRewind_Click);

            TaskbarManager.Instance.ThumbnailToolBars.AddButtons(this.Handle, ttbbPrev, ttbbRewind, ttbbPlayPause, ttbbForward, ttbbNext);
            #endregion

            #region Song Initialization
            foreach (FileInfo fi in (new DirectoryInfo(Path.GetFullPath("TestMusic")).GetFiles()))
                Playlist.Add(fi.FullName);
            //TODO: MAKE IT WORKING!
            /*System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
            pfc.AddFontFile(Path.GetFullPath("comfortaa.ttf"));
            Font = new Font(pfc.Families[0], Font.Size, Font.Style);
            foreach (Control c in Controls)
                c.Font = new Font(pfc.Families[0],c.Font.Size, c.Font.Style);*/
            GetAndFillWithSongInfo();

            source = CodecFactory.Instance.GetCodec(Playlist[ActualFileIndex]);
            ActualFileIndex = 0;
            player.Initialize(source);
            player.Play();
            mtbTime.Maximum = Convert.ToInt32(source.GetLength().TotalSeconds);
            mtbTime.Value = 0;
            t.Tick += new EventHandler(Tick);
            t.Start();
            #endregion

            //AddTrackToList(Playlist[0], Playlist[1]);
        }
コード例 #44
0
ファイル: PolySong.cs プロジェクト: Mistrator/polybeat
        /// <summary>
        /// Lataa kappaleen tiedostosta.
        /// </summary>
        /// <param name="fileName">Tiedoston nimi.</param>
        private void LoadFromFile(string fileName)
        {
            soundSource = CodecFactory.Instance.GetCodec(fileName);
            soundOut = GetSoundOut();

            ChooseSoundDevice();
            soundOut.Initialize(soundSource);
        }
コード例 #45
0
ファイル: MusicPlayer.cs プロジェクト: cboseak/KoPlayer
        public void Open(string filename, MMDevice device)
        {
            CleanupPlayback();

            var source = CodecFactory.Instance.GetCodec(filename);

            waveSource =
                CodecFactory.Instance.GetCodec(filename)
                    .ToStereo()
                    .ChangeSampleRate(44100)
                    .ToSampleSource()
                    .AppendSource(Equalizer.Create10BandEqualizer, out equalizer)
                    .ToWaveSource(16);

            soundOut = new WasapiOut() {Latency = 100, Device = device};
            soundOut.Initialize(waveSource);
            if (this.OpenCompleted != null)
                this.OpenCompleted(this, new EventArgs());
        }
コード例 #46
0
        private void CanHandleEOFTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            int sourceLength = (int)source.GetLength().TotalMilliseconds;
            Debug.WriteLine(soundOut.GetType().FullName);
            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Pause();
                soundOut.Resume();

                Thread.Sleep(10);

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 1000);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                source.Position = 0;
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
            }
        }
コード例 #47
0
ファイル: SoundRecorder.cs プロジェクト: Zougi/LyncLogger
        /// <summary>
        /// Play a blank sound. It keeps recording even when no sound is played.
        /// Loopback callback is triggered only when a sound is played.
        /// Playing a blank sound keep the recorder running even when there's no sound playing
        /// </summary>
        private void CaptureSilence()
        {
            _soundSilenceSource = new SilenceGenerator();

            _soundSilenceOut = GetSoundOut();

            _soundSilenceOut.Initialize(_soundSilenceSource);
            _soundSilenceOut.Play();
        }
コード例 #48
0
        private void CanHandleEOFTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            int sourceLength = (int)source.GetLength().TotalMilliseconds;
            for (int i = 0; i < basic_iteration_count; i++)
            {
                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Pause();
                soundOut.Resume();

                Thread.Sleep(10);

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                source.Position = 0;
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
            }
        }