Exemplo n.º 1
0
 public void Resume()
 {
     if (IsPlaying && IsPaused)
     {
         player.resume();
         IsPaused = false;
         wavePlayer?.Play();
     }
 }
Exemplo n.º 2
0
        public void PlaySound()
        {
            if (_waveOut == null)
            {
                SetupSound();
            }

            _waveOut.Volume = 1.0F;
            _waveOut?.Play();
            _waveOut?.Pause();
            _waveOut?.Play();
        }
Exemplo n.º 3
0
        public PianoSynth()
        {
            mixer = new WaveMixerStream32();
            mixer.AutoStop = false;

            int i = 0;
            foreach (var note in noteFiles)
            {
                reader[i] = new WaveFileReader(note);

                offsetStream[i] = new WaveOffsetStream(reader[i]);
                channelSteam[i] = new WaveChannel32(offsetStream[i]);
                channelSteam[i].Position = channelSteam[i].Length;
                mixer.AddInputStream(channelSteam[i]);

                i++;
            }

            if (waveOutDevice == null)
            {
                waveOutDevice = new WaveOut {DeviceNumber = 0};
                waveOutDevice.Init(mixer);
                waveOutDevice.Volume = 0;
                waveOutDevice.Play();
                waveOutDevice.Volume = 100;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Lejátszik egy .mp3 fájlt
 /// </summary>
 /// <param name="audioFile">.mp3 fájl</param>
 public static void playWave(string audioFile)
 {
     thread = new WaveOut();
     stream = CreateInputStream(audioFile);
     thread.Init(stream);
     thread.Play();
 }
Exemplo n.º 5
0
        private void play_Click(object sender, EventArgs e)
        {
            if (playlist.SelectedItems.Count>0)
            {
                id = fn.IndexOf(playlist.SelectedItem.ToString());
                if (waveOutDevice.PlaybackState.ToString() != "Paused")
                {
                    t.Stop();
                    stp();
                    audioFileReader = new AudioFileReader(fp[id]);
                    waveOutDevice = new WaveOut();
                    waveOutDevice.Init(audioFileReader);
                    trackbar.Maximum = (int)audioFileReader.TotalTime.TotalSeconds + 1;
                    //deb.Items.Add(audioFileReader.TotalTime.Seconds.ToString());
                    audioFileReader.Volume = (float)vol.Value / 100;
                    waveOutDevice.Play();
                    t.Start();

                }
                else
                {
                    waveOutDevice.Play();
                    t.Start();
                }
            }
            
           
            
        }
Exemplo n.º 6
0
        private void Connect(IPEndPoint endPoint, int inputDeviceNumber, INetworkChatCodec codec)
        {
            waveIn = new WaveIn();
            waveIn.BufferMilliseconds = 50;
            waveIn.DeviceNumber = inputDeviceNumber;
            waveIn.WaveFormat = codec.RecordFormat;
            waveIn.DataAvailable += waveIn_DataAvailable;
            waveIn.StartRecording();

            udpSender = new UdpClient();
            udpListener = new UdpClient();

            // To allow us to talk to ourselves for test purposes:
            // http://stackoverflow.com/questions/687868/sending-and-receiving-udp-packets-between-two-programs-on-the-same-computer
            udpListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            udpListener.Client.Bind(endPoint);

            udpSender.Connect(endPoint);

            waveOut = new WaveOut();
            waveProvider = new BufferedWaveProvider(codec.RecordFormat);
            waveOut.Init(waveProvider);
            waveOut.Play();

            connected = true;
            var state = new ListenerThreadState { Codec = codec, EndPoint = endPoint };
            ThreadPool.QueueUserWorkItem(ListenerThread, state);
        }
Exemplo n.º 7
0
 public AudioPlaybackEngine(int sampleRate = 44100, int channelCount = 2)
 {
     outputDevice = new WaveOutEvent();
     mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channelCount));
     mixer.ReadFully = true;
     outputDevice.Init(mixer);
     outputDevice.Play();
 }
Exemplo n.º 8
0
 public void PlaySound()
 {
     if (_waveOut == null)
     {
         SetupSound();
     }
     _waveOut?.Play();
 }
Exemplo n.º 9
0
 public int PlayFile(string filename)
 {
     waveOutDevice = new WaveOut();
     mainOutputStream = CreateInputStream(filename);
     waveOutDevice.Init(mainOutputStream);
     waveOutDevice.Play();
     return 0;
 }
Exemplo n.º 10
0
 public void PlaySong()
 {
     // Instantiate audio player
     waveOutDevice = new WaveOut();
     // Set MP3 to play
     audioFileReader = new AudioFileReader(GetSong());
     // Init device and call play
     waveOutDevice.Init(audioFileReader);
     waveOutDevice.Play();
 }
 private void Play()
 {
     if (waveOut != null)
     {
         Stop();
     }
     waveOut = new WaveOut();
     this.patternSequencer = new DrumPatternSampleProvider(pattern);
     this.patternSequencer.Tempo = tempo;
     waveOut.Init(patternSequencer);
     waveOut.Play();
 }
Exemplo n.º 12
0
 private void BeginPlayback(string filename)
 {
     Debug.Assert(wavePlayer == null);
     wavePlayer = CreateWavePlayer();
     audioFileReader = new AudioFileReader(filename);
     audioFileReader.Volume = volumeSlider1.Volume;
     wavePlayer.Init(audioFileReader);
     wavePlayer.PlaybackStopped += OnPlaybackStopped;
     wavePlayer.Play();
     EnableButtons(true);
     timer1.Enabled = true; // timer for updating current time label
 }
Exemplo n.º 13
0
 /// <summary>
 /// Joue le morceau
 /// </summary>
 public void play()
 {
     if (this.data != null)
     {
         terminated = false;
         outer = new WaveOut();
         outer.Init(this.data);
         outer.Play();
         outer.PlaybackStopped += outer_PlaybackStopped;
     }
     else
         this.load(true);
 }
Exemplo n.º 14
0
 //Кнопка "Плей"
 private void button_play_Click(object sender, EventArgs e)
 {
     button_stop.Enabled = true;
     timer.Start();
     ind = 2;
     waveOutDevice = new WaveOut();
     mainOutputStream = CreateInputStream(outputFilename);
     waveOutDevice.Init(mainOutputStream);
     waveOutDevice.Play();
     button_play.Enabled = false;
     button_rec.Enabled = false;
     numeric.Enabled = false;
 }
Exemplo n.º 15
0
        public void Start()
        {
            _audioSource.Listening = true;
            if (_audioSource.WaveOutProvider != null)
            {
                _waveOut = new DirectSoundOut(100);
                _waveOut.Init(_audioSource.WaveOutProvider);
                _waveOut.Play();

                _audioSource.DataAvailable -= AudioSourceDataAvailable;
                _audioSource.DataAvailable += AudioSourceDataAvailable;
                _bTalking = true;
            }
        }
Exemplo n.º 16
0
        public IWavePlayer PlayKillStreak(string sfxName, string ext = "wav")
        {
            KillStreakDevice = KillStreakDevice ?? new WaveOutEvent();

            var path = SFXPath + sfxName + "." + ext;
            Wait(250);
            AudioFileReader audioFileReader = new AudioFileReader(path);
            audioFileReader.Volume = 0.6f * Volume;

            KillStreakDevice.Stop();
            KillStreakDevice.Init(audioFileReader);
            KillStreakDevice.Play();
            return KillStreakDevice;
        }
Exemplo n.º 17
0
 /// <summary>
 /// Joue le morceau
 /// </summary>
 public void play()
 {
     if (data != null || this.lastPlayed.AddMinutes(13) < DateTime.Now)
     {
         terminated = false;
         Console.WriteLine("Playing " + link);
         outer = new WaveOut();
         outer.Init(this.data);
         outer.Play();
         outer.PlaybackStopped += outer_PlaybackStopped;
     }
     else
         this.load(true);
 }
Exemplo n.º 18
0
        private void button_play_Click(object sender, EventArgs e)
        {
            if (!System.IO.File.Exists(textBox_filename.Text))
            {
                MessageBox.Show("Please select a valid file to play.");
                return;
            }

            waveOutDevice = new WaveOut();

            mainOutputStream = CreateInputStream(textBox_filename.Text);

            waveOutDevice.Init(mainOutputStream);
            waveOutDevice.Play();
        }
Exemplo n.º 19
0
        public override void Loop()
        {
            var length = Length();

            if (length > 0 && audioFileReader is WaveStream ws)
            {
                if (!IsPlaying())
                {
                    ws.CurrentTime = TimeSpan.FromSeconds(MusicData.LoopStart);
                    waveOutDevice?.Play();
                }
                else
                {
                    var loopStart = MusicData.LoopStart;
                    var loopEnd   = (MusicData.LoopEnd <= loopStart || MusicData.LoopEnd >= length) ? length : MusicData.LoopEnd;
                    var position  = Position();
                    var overrun   = position - loopEnd;
                    if (overrun >= 0)
                    {
                        ws.CurrentTime = TimeSpan.FromSeconds(loopStart + (overrun % (loopEnd - loopStart)));
                    }
                }
            }
            else
            {
                if (!IsPlaying())
                {
                    waveOutDevice?.Stop();
                    if (audioFileReader is WaveStream ws2)
                    {
                        ws2.Position = 0;
                    }
                    waveOutDevice?.Play();
                }
            }
        }
Exemplo n.º 20
0
 public void Pause()
 {
     if (waveOut.PlaybackState != PlaybackState.Stopped)
     {
         if (waveOut.PlaybackState == PlaybackState.Paused)
         {
             waveOut?.Play();
         }
         else
         {
             waveOut?.Pause();
             OnPause?.Invoke(new GenericEventArgs());
         }
     }
 }
Exemplo n.º 21
0
 public void PlayPauseStream()
 {
     if (waveOut != null)
     {
         if (_streamState == StreamState.Playing)
         {
             waveOut?.Pause();
             _streamState = StreamState.Paused;
         }
         else if (_streamState == StreamState.Paused)
         {
             waveOut?.Play();
             _streamState = StreamState.Playing;
         }
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// Setup Audio via NAudio. Defaults to using Asio for Audio Output.
        /// </summary>
        public void SetupAudio()
        {
            //Setup the Mixer
            mixer = new WaveMixerStream32();
            mixer.AutoStop = false;

            if (waveOutDevice == null)
            {
                //waveOutDevice = new AsioOut();

                waveOutDevice = new WaveOut(0, 300, false);
                
                waveOutDevice.Init(mixer);
                waveOutDevice.Play();
            }
        }
Exemplo n.º 23
0
        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 4; i++)
            {
                sampleLoaded[i] = "";

            }

            if (waveOutDevice == null)
            {

                waveOutDevice = new AsioOut();
                waveOutDevice.Init(mixer);

                waveOutDevice.Play();
            }
        }
Exemplo n.º 24
0
        public void romanPlay()
        {
            //FileStream fs = new FileStream(soundTmpTrack + "out.wav", FileMode.Open, FileAccess.Read);
            //System.Media.SoundPlayer sp = new System.Media.SoundPlayer(fs);
            //sp.Play();
            //fs.Close();

            if (!ok)
            {
                return;
            }

            Mp3FileReader audioFileReader = new Mp3FileReader(soundTmpTrack + fileOutputMP3Name);

            waveOutDevice = new WaveOut();
            waveOutDevice.Init(audioFileReader);
            waveOutDevice.Play();
            waveOutDevice.PlaybackStopped += delegate { endPlay(audioFileReader); };
        }
Exemplo n.º 25
0
        private void Ukuisi(Ezani ezan)
        {
            if (ukujisem)
            {
                return;
            }
            if (wavePlayer != null && wavePlayer.PlaybackState == PlaybackState.Playing)
            {
                return;
            }
            var cehcBox = (CheckBox)this.Controls.Find("ezani" + ezan.ToString(), true).FirstOrDefault();

            if (!cehcBox.Checked)
            {
                return;
            }

            string ezanProperti = "ezan" + ezan.ToString();
            string ezanFajla    = Properties.Settings.Default[ezanProperti].ToString();

            string sslider = "volumeSlider" + ezan.ToString();

            var slider = (NAudio.Gui.VolumeSlider) this.Controls.Find(sslider, false).FirstOrDefault();


            try
            {
                Debug.Assert(wavePlayer == null);
                wavePlayer                  = CreateWavePlayer();
                audioFileReader             = new AudioFileReader(ezanFajla);
                audioFileReader.Volume      = slider.Volume;
                wavePlayer.PlaybackStopped += WavePlayer_PlaybackStopped;
                wavePlayer.Init(audioFileReader);
                wavePlayer.Play();
                ukujisem = true;
                this.labelLastEvent.Text = "Ukujišem ezan za  namaz: " + ezan.ToString();
            }
            catch (Exception ex)
            {
                stopPlayer();
                this.labelLastEvent.Text = "Nisam upiejo ezaniti " + ezan.ToString() + " sa ex" + ex.Message;
            }
        }
Exemplo n.º 26
0
        private void startPlay()
        {
            if (upcoming.Count > 0)
            {
                isDirty         = true;
                audioFileReader = new AudioFileReader(upcoming[0].Path);
                waveOutDevice.Init(audioFileReader);
                waveOutDevice.Play();
                currentSong         = upcoming[0];
                Song_Status.Content = Properties.Resources.nowPlaying + currentSong.SongName + Properties.Resources.nowPlaying_transition + currentSong.Artist;
                if (upcoming.Count > 0)
                {
                    upcoming.RemoveAt(0);
                }
                Play_List.ItemsSource = upcoming;

                isDirty = true;
            }
        }
Exemplo n.º 27
0
 public void StartTrack()
 {
     try
     {
         audioFileReader = new AudioFileReader(musicPathes[new Random().Next(0, musicPathes.Length)])
         {
             Volume = 0.5f
         };
         waveOutDevice.Init(audioFileReader);
         waveOutDevice.Play();
         waveOutDevice.PlaybackStopped += new EventHandler <StoppedEventArgs>(onMusicStopped);
         musicPlaying = true;
     }
     catch (Exception)
     {
         musicPlaying = false;
         waveOutDevice.Stop();
     }
 }
Exemplo n.º 28
0
        private void StartPlayingSong()
        {
            try
            {
                int  index       = listBox_songs.SelectedIndex;
                Song currentSong = songs[index]; // get song from list by index

                wavePlayer      = new WaveOut();
                audioFileReader = new AudioFileReader(currentSong.Path);
                wavePlayer.Init(audioFileReader);
                wavePlayer.Play();

                trackBar_volume.Value = 10;
            }
            catch (ArgumentOutOfRangeException)
            {
                MessageBox.Show("Select song that you want to play");
            }
        }
Exemplo n.º 29
0
        public bool Stream()
        {
            if (waveStream != null)
            {
                waveStream.Dispose();
            }

            if (audioPlayer != null)
            {
                audioPlayer.Dispose();
            }

            if (audioPlaylist.Count < 1)
            {
                return(false);
            }

            if (!playlistManualState)
            {
                if (playlistPosition != audioPlaylist.Count - 1)
                {
                    playlistPosition++;
                }
                else
                {
                    playlistPosition = 0;
                }
            }
            else
            {
                playlistManualState = false;
            }

            audioPlayer = new WaveOutEvent();
            waveStream  = new AudioFileReader(audioPlaylist[playlistPosition]);
            audioPlayer.PlaybackStopped += (sender, evn) => { Stream(); };

            audioPlayer.Init(waveStream);
            audioPlayer.Play();
            onAudioChange.AudioChanged();

            return(true);
        }
Exemplo n.º 30
0
        public void PlaySound(Stream Sound)
        {
            if (Sound == null)
            {
                return;
            }

            wavePlayerSounds = new WaveOutEvent();
            wavePlayerSounds.PlaybackStopped += wavePlayerSounds_PlaybackStopped;

            WaveStream    sourceStreamSounds = new WaveFileReader(Sound);
            WaveChannel32 inputStreamSounds  = new WaveChannel32(sourceStreamSounds);

            inputStreamSounds.Volume        = (float)Convert.ToDouble(iSoundLautstaerke) / 100;
            inputStreamSounds.PadWithZeroes = false;

            wavePlayerSounds.Init(inputStreamSounds);
            wavePlayerSounds.Play();
        }
Exemplo n.º 31
0
        /// <summary>
        /// 播放歌曲
        /// </summary>
        internal static bool Play()
        {
            if (!playNotDone)
            {
                return(false);
            }
            if (waveout != null)
            {
                waveout.Play();
            }
            if (timer != null)
            {
                timer.Start();
            }

            Center.Mainw.setPlayPauseButtonIcon(!PlayControl.isPause);

            return(true);
        }
Exemplo n.º 32
0
        internal bool PlaySound()
        {
            StopSound();

            IsPlaying = true;
            //ShouldBePlaying = true;

            waveOutDevice = new WaveOutEvent();
            try
            {
                if (AudioFilePath != "")
                {
                    audioFileReader =
                        new MediaFoundationReader(AudioFilePath);
                }
                else
                {
                    audioFileReader =
                        new MediaFoundationReader(DefaultAudioPath);
                }

                ApplyMuteSetting();

                waveOutDevice.PlaybackStopped +=
                    WaveOutDevice_PlaybackStopped;
                waveOutDevice.Init(audioFileReader);
                waveOutDevice.Play();
            }
            catch (Exception)
            {
                HasError  = true;
                IsPlaying = false;
                //ShouldBePlaying = false;
                return(false);
            }
            finally
            {
            }

            // TODO: use more of the API NAudio: https://github.com/naudio/NAudio/wiki/Playing-an-Audio-File. Build a mini audio player UI and functionality.

            return(true);
        }
Exemplo n.º 33
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //Only for the first start after the Installation
            if (Properties.Settings.Default.PlatiniumClientPath == "")
            {
                Properties.Settings.Default.PlatiniumClientPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\PlatiniumLC_Client\";
                Properties.Settings.Default.Save();
            }
            PlatiniumClientPath = Properties.Settings.Default.PlatiniumClientPath;
            killSSH();
            waveOutDevice   = new WaveOut();
            audioFileReader = new AudioFileReader(@".\Sound\lc.mp3");
            waveOutDevice.Init(audioFileReader);
            waveOutDevice.PlaybackStopped += new EventHandler <StoppedEventArgs>(audio_loop);
            waveOutDevice.Play();
            //audioFileReader.Position = 45000000; // => beinahe Ende

            CopyFolder("./PlatiniumLC_Client", PlatiniumClientPath);


            Task.Factory.StartNew(() =>
            {
                try
                {
                    WebClient client    = new WebClient();
                    Stream stream       = client.OpenRead("http://lc.elderfun.ch/news.txt");
                    StreamReader reader = new StreamReader(stream);
                    Invoke((MethodInvoker) delegate()
                    {
                        News_richTextBox.Text = reader.ReadToEnd();
                    });
                }
                catch (WebException)
                {
                    Invoke((MethodInvoker) delegate()
                    {
                        News_richTextBox.Text = "Die Newsdatei konnte nich von http://lc.elderfun.ch/news.txt " +
                                                "hinuntergeladen werden." + Environment.NewLine + Environment.NewLine +
                                                "Sind Sie etwa offline?";
                    });
                }
            });
        }
Exemplo n.º 34
0
        private void StartRecording(int deviceNumber) {
            // Setup Incoming
            m_WaveIn = new WaveIn();
            m_WaveIn.BufferMilliseconds = 50; // This is very very important.
            m_WaveIn.DeviceNumber = deviceNumber;
            m_WaveIn.DataAvailable += WaveIn_DataAvailable;
            m_WaveIn.WaveFormat = m_waveFormat;
            m_WaveIn.StartRecording();

            // Setup Output


            waveOut = new WaveOut();
            waveProvider = new BufferedWaveProvider(m_waveFormat);
            waveOut.Init(waveProvider);
            waveOut.Play();


        }
Exemplo n.º 35
0
        private void PlaySoundBtn_Click(object sender, RoutedEventArgs e)
        {
            if (_isPlayback)
            {
                return;
            }
            _isPlayback = true;
            try
            {
                CreateWaveOut();
            }
            catch (Exception driverCreateException)
            {
                _isPlayback = false;
                MessageBox.Show(String.Format("{0}", driverCreateException.Message));
                return;
            }

            ISampleProvider sampleProvider;

            try
            {
                sampleProvider = CreateInputStream(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources/sound.mp3"));
            }
            catch (Exception createException)
            {
                _isPlayback = false;
                MessageBox.Show(String.Format("{0}", createException.Message), "Error Loading File");
                return;
            }
            try
            {
                waveOut.Init(sampleProvider);
            }
            catch (Exception initException)
            {
                _isPlayback = false;
                MessageBox.Show(String.Format("{0}", initException.Message), "Error Initializing Output");
                return;
            }
            waveOut.Play();
        }
Exemplo n.º 36
0
        public void PlayAlarm(Mp3FileReader fileReader)
        {
            if (this.isCurrentlyPlaying || !Default.EnableAlarms || !Default.EnableSoundAlarms)
            {
                // We don't want to play if there is already other players active
                // even if the other players are playing other alarms..
                return;
            }
            //alarms should not be sound if actively snoozed or workstation is locked
            if (this.IsPostponed() || (AppShared.IsWorkStationLocked && Default.DisableSoundAlarmsOnWorkstationLock))
            {
                return;
            }

            var loop = new LoopStream(fileReader);

            device.Init(loop);
            device.Play();
            this.isCurrentlyPlaying = true;
        }
Exemplo n.º 37
0
        public void TogglePauseSong()
        {
            if (wavePlayer != null)
            {
                if (wavePlayer.PlaybackState == PlaybackState.Playing)
                {
                    wavePlayer.Pause();
                    return;
                }

                if (wavePlayer.PlaybackState == PlaybackState.Paused)
                {
                    wavePlayer.Play();
                    return;
                }
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Exemplo n.º 38
0
 private void BtnPlay_Click(object sender, EventArgs e)
 {
     // wavePlayer already init
     if (wavePlayer != null)
     {
         //timer1.Enabled = !timer1.Enabled;
         if (wavePlayer.PlaybackState == PlaybackState.Playing)
         {
             wavePlayer.Pause();
         }
         else
         {
             wavePlayer.Play();
         }
     }
     else
     {
         SelectInputFile();
     }
 }
Exemplo n.º 39
0
        /// <summary>
        /// play an audio file
        /// </summary>
        public void Play()
        {
            if (wavePlayer != null)
            {
                try
                {
                    wavePlayer.Play();
                }
                catch (Exception)
                {
                    //throw;
                }
                if (PlaybackResumed != null)
                {
                    PlaybackResumed();
                }
            }

            //throw new NotImplementedException();
        }
Exemplo n.º 40
0
        public void Play(string filename)
        {
            this.filename = filename;

            if (run)
            {
                closeWaveOut();
                Play(filename);
            }
            else if (filename != null)
            {
                waveOutDevice = new WaveOut();
                waveOutDevice.PlaybackStopped += (s, e) => handler();

                audioFileReader = new AudioFileReader(filename);
                waveOutDevice.Init(audioFileReader);
                waveOutDevice.Play();
                run = true;
            }
        }
Exemplo n.º 41
0
        public void Play()
        {
            if (string.IsNullOrEmpty(FileName))
            {
                return;
            }

            if (isPlaying)
            {
                return;
            }

            wavePlayer             = new WaveOut();
            audioFileReader        = new AudioFileReader(FileName);
            audioFileReader.Volume = volume;
            wavePlayer.Init(audioFileReader);
            wavePlayer.PlaybackStopped += OnPlaybackStopped;
            wavePlayer.Play();
            isPlaying = true;
        }
Exemplo n.º 42
0
        private void Play()
        {
            if (player == null)
            {
                // Exclusive mode - fails with a weird buffer alignment error
                player = new WasapiOutRT(AudioClientShareMode.Shared, 200);
                player.Init(CreateReader);

                player.PlaybackStopped += PlayerOnPlaybackStopped;
            }

            if (player.PlaybackState != PlaybackState.Playing)
            {
                //reader.Seek(0, SeekOrigin.Begin);
                player.Play();
                StopCommand.IsEnabled  = true;
                PauseCommand.IsEnabled = true;
                LoadCommand.IsEnabled  = false;
            }
        }
Exemplo n.º 43
0
        private void Listen(object o = null)
        {
            if (listenable)
            {
                int l = server.Pull(bufferRaw, 0);
                while (Source.IsFull(bufferRaw.Length))
                {
                    Thread.Sleep(100);
                }
                if (l > 0)
                {
                    Source.AddSamples(bufferRaw, 0, l);
                    player.Play();
                }
            }

            if (service)
            {
                ThreadPool.QueueUserWorkItem(Listen);
            }
        }
Exemplo n.º 44
0
        private void OnButtonPlayClick(object sender, EventArgs e)
        {
            if (wavePlayer == null)
            {
                wavePlayer = new WaveOutEvent();
                wavePlayer.PlaybackStopped += WavePlayerOnPlaybackStopped;
            }
            if (speedControl == null)
            {
                LoadFile();
                if (speedControl == null)
                {
                    return;
                }
            }

            wavePlayer.Init(speedControl);

            wavePlayer.Play();
            EnableControls(true);
        }
Exemplo n.º 45
0
        private void Play()
        {
            if (player == null)
            {
                // Exclusive mode - fails with a weird buffer alignment error
                player = new WasapiOutRT(AudioClientShareMode.Shared, 200);
                //((WasapiOutRT)player).SetClientProperties(false, AudioStreamCategory.GameChat, AudioClientStreamOptions.None);
                player.Init(CreateReader);

                player.PlaybackStopped += PlayerOnPlaybackStopped;
            }

            if (player.PlaybackState != PlaybackState.Playing)
            {
                //reader.Seek(0, SeekOrigin.Begin);
                player.Play();
                StopCommand.IsEnabled  = true;
                PauseCommand.IsEnabled = true;
                LoadCommand.IsEnabled  = false;
            }
        }
Exemplo n.º 46
0
 private void SetupEngine()
 {
     //OutputDevice = new WaveOutEvent();
     //OutputDevice = new DirectSoundOut(40);
     //OutputDevice = new WasapiOut(AudioClientShareMode.Shared, true, 40);
     if (Constants.DefaultAudioDevice == Guid.Empty)
     {
         OutputDevice = new DirectSoundOut(100);
     }
     else
     {
         LastAudioDevice = Constants.DefaultAudioDevice;
         OutputDevice    = new DirectSoundOut(Constants.DefaultAudioDevice, 100);
     }
     Mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(SampleRate, ChannelCount))
     {
         ReadFully = true
     };
     OutputDevice.Init(Mixer);
     OutputDevice.Play();
 }
Exemplo n.º 47
0
        private void PlayNext()
        {
            waveOutDevice.Stop();
            waveOutDevice.Dispose();
            audioFileReader.Dispose();

            var song = GetNext();

            waveOutDevice        = new WaveOutEvent();
            audioFileReader      = new AudioFileReader(song.FilePath);
            sampleChannel        = new SampleChannel(audioFileReader);
            sampleChannel.Volume = 0.125f;
            waveOutDevice.Init(sampleChannel);
            waveOutDevice.PlaybackStopped += (sender, e) => { PlayNext(); };
            waveOutDevice.Play();
            ConsoleHelper.WriteLine($"Now Playing: \"{song.Title}\" by {song.Artist}");
            if (RequestedSongs.Count > 0)
            {
                DownloadNextInQueueAsync().GetAwaiter().GetResult();
            }
        }
Exemplo n.º 48
0
    public AudioPlayer()
    {
        //Setup the Mixer
        mixer = new WaveMixerStream32Custom();
        mixer.AutoStop = false;

        //initialize keys
        for (int i = 0; i < keyArray.Length; i++)
        {
            keyArray[i] = new Key(fileNames[i], audioSourcePath + fileNames[i] + ".wav");
            mixer.AddInputStream(keyArray[i].channelStream);
        }

        if (waveOutDevice == null)
        {
            waveOutDevice = new WaveOut();
            waveOutDevice.Init(mixer);
            mixer.Position = mixer.Length;
            waveOutDevice.Play();
        }
    }
Exemplo n.º 49
0
 protected void Init(IWaveProvider waveProvider)
 {
     @out = new WasapiOut();
     @out.Init(waveProvider);
     using (var en = new MMDeviceEnumerator())
     {
         SessionCollection sessions = en.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia).AudioSessionManager.Sessions;
         int id = System.Diagnostics.Process.GetCurrentProcess().Id;
         for (int i = 0; i < sessions.Count; i++)
         {
             AudioSessionControl session = sessions[i];
             if (session.GetProcessID == id)
             {
                 appVolume = session;
                 appVolume.RegisterEventClient(this);
                 break;
             }
         }
     }
     @out.Play();
 }
Exemplo n.º 50
0
		/**
		 * Constructor, initializes the audio system for
		 * 44100Hz 32-bit float stereo output.
		 */
		public AudioDevice()
		{
			// BufferedWaveProvider
			bufferedWaveProvider = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(44100, 2));
			bufferedWaveProvider.BufferDuration = TimeSpan.FromMinutes(10);
			bufferedWaveProvider.DiscardOnBufferOverflow = true;
			
			// waveOut
			/*
			 * This is the default and recommended approach if you are creating a WaveOut object
			 * from the GUI thread of a Windows Forms or WPF application.
			 * Whenever WaveOut wants more data it posts a message that is handled by the
			 * Windows message pump of an invisible new window.
			 * You get this callback model by default when you call the empty WaveOut constructor.
			 * However, it will not work on a background thread, since there is no message pump.
			 * */
			waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); // seems to be the best way
			//waveOut = new WaveOut();
			//waveOut.Volume = 0.5f;
			waveOut.Init(bufferedWaveProvider);
			waveOut.PlaybackStopped += new EventHandler<StoppedEventArgs>(_waveOutDevice_PlaybackStopped);
			waveOut.Play();
		}
Exemplo n.º 51
0
        public void Start()
        {
            _audioSource.Listening = true;
            _audioSource.DataAvailable -= AudioSourceDataAvailable;
            _audioSource.DataAvailable -= _audioSource_DataAvailablePipe;
            if (_audioSource.WaveOutProvider == null)
            {
                _bwp = new BufferedWaveProvider(_audioSource.RecordingFormat);
                _audioSource.DataAvailable += AudioSourceDataAvailable;

                _waveOut = new DirectSoundOut(100);
                _waveOut.Init(_bwp);
                _waveOut.Play();
                _bTalking = true;
            }
            else
            {
                _waveOut = new DirectSoundOut(100);
                _waveOut.Init(_audioSource.WaveOutProvider);
                _waveOut.Play();
                _bTalking = true;
                _audioSource.DataAvailable += _audioSource_DataAvailablePipe;
            }
        }
Exemplo n.º 52
0
 private AudioMixer()
 {
     mixer = new WaveMixerStream32 {
         AutoStop = false
     };
     player = new WasapiOut(AudioClientShareMode.Shared, 100);
     player.Init(mixer);
     player.Play();
 }
Exemplo n.º 53
0
 public void playVoiceSingle(string t)
 {
     try
     {
         waveOutDeviceS = new WaveOut();
         mainOutputStreamS = CreateInputStream(Path.Combine(Application.StartupPath, @"mp3\s\" + t + ".mp3"));
         waveOutDeviceS.Init(mainOutputStreamS);
         waveOutDeviceS.Play();
     }
     catch (Exception) { }
 }
Exemplo n.º 54
0
        /////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////
        public void playPress()
        {
            try
            {

                CloseWaveOut();

                waveOutDevice = new WaveOut();
                mainOutputStream = CreateInputStream(Path.Combine(Application.StartupPath, @"mp3\t.mp3"));
                waveOutDevice.Init(mainOutputStream);
                waveOutDevice.Play();

            }
            catch (Exception) { }
        }
Exemplo n.º 55
0
 public void playNum(string t)
 {
     try
     {
         CloseWaveOutS();
         CloseWaveOutN();
     }
     catch (Exception) { }
     try
     {
         waveOutDeviceN = new WaveOut();
         mainOutputStreamN = CreateInputStream(Path.Combine(Application.StartupPath, @"mp3\n\" + t + ".mp3"));
         waveOutDeviceN.Init(mainOutputStreamN);
         waveOutDeviceN.Play();
     }
     catch (Exception) { }
 }
Exemplo n.º 56
0
        private void Start(Audio.Codecs.INetworkChatCodec codec)
        {
            ShouldTryRestartOutput = false;

            Stop();

            waveOut = GetWavePlayer();

            waveProvider = new BufferedWaveProvider(codec.RecordFormat);

            sampleChannel = new SampleChannel(waveProvider, false);
            sampleStream = new NotifyingSampleProvider(sampleChannel);
            sampleStream.Sample += (s, e) => aggregator.Add(e.Left);
            waveOut.Init(sampleStream);
            waveOut.Play();

            if (LevelManager == null)
                LevelManager = new AudioLevelManagerDisconnected();

            OutputFormat = codec.RecordFormat.ToString();
        }
Exemplo n.º 57
0
        /// <summary>
        /// Opens the stream and starts playback.
        /// </summary>
        /// <param name="songName">The name of the song to be played.</param>
        public void Play(string songName)
        {
            if (m_dataSubscriber != null && m_metadata != null)
            {
                UnsynchronizedSubscriptionInfo info;

                StringBuilder filterExpression = new StringBuilder();
                DataTable deviceTable = m_metadata.Tables["DeviceDetail"];
                DataTable measurementTable = m_metadata.Tables["MeasurementDetail"];

                Dictionary<string, string> uriSettings;
                string dataChannel = null;
                int uriIndex = ConnectionUri.IndexOf(URI_SEPARATOR);

                m_channelIndexes = new ConcurrentDictionary<Guid, int>();
                m_sampleRate = DEFAULT_SAMPLE_RATE;
                m_numChannels = DEFAULT_NUM_CHANNELS;

                // Get sample rate from metadata.
                if (deviceTable != null)
                {
                    string sampleRate = deviceTable.Rows.Cast<DataRow>()
                        .Single(row => row["Acronym"].ToNonNullString() == songName)["FramesPerSecond"].ToNonNullString();

                    if (!string.IsNullOrEmpty(sampleRate))
                        m_sampleRate = int.Parse(sampleRate);
                }

                // Get measurements from metadata.
                if (measurementTable != null)
                {
                    IEnumerable<DataRow> measurementRows = measurementTable.Rows.Cast<DataRow>()
                        .Where(row => row["DeviceAcronym"].ToNonNullString() == songName)
                        .Where(row => row["SignalAcronym"].ToNonNullString() == "ALOG" || row["SignalAcronym"].ToNonNullString() == "VPHM")
                        .Where(row => row["Enabled"].ToNonNullString().ParseBoolean())
                        .OrderBy(row => row["ID"].ToNonNullString());

                    m_numChannels = 0;

                    foreach (DataRow row in measurementRows)
                    {
                        Guid measurementID = Guid.Parse(row["SignalID"].ToNonNullString());

                        if (m_numChannels > 0)
                            filterExpression.Append(';');

                        filterExpression.Append(measurementID);
                        m_channelIndexes[measurementID] = m_numChannels;
                        m_numChannels++;
                    }
                }

                // Create UDP data channel if specified.
                if (uriIndex >= 0)
                {
                    uriSettings = ConnectionUri.Substring(uriIndex + URI_SEPARATOR.Length).ParseKeyValuePairs('&');

                    if (uriSettings.ContainsKey("udp"))
                        dataChannel = string.Format("dataChannel={{port={0}; interface={1}}}", uriSettings["udp"], IPv6Enabled ? "::0" : "0.0.0.0");
                }

                m_buffer = new ConcurrentQueue<IMeasurement>();
                m_dumpTimer = CreateDumpTimer();
                m_statTimer = CreateStatTimer();
                m_waveProvider = new BufferedWaveProvider(new WaveFormat(m_sampleRate < MINIMUM_SAMPLE_RATE ? MINIMUM_SAMPLE_RATE : m_sampleRate, m_numChannels));
                m_wavePlayer = CreateWavePlayer(m_waveProvider);
                m_waveProvider.DiscardOnBufferOverflow = true;

                info = new UnsynchronizedSubscriptionInfo(false)
                {
                    FilterExpression = filterExpression.ToString(),
                    ExtraConnectionStringParameters = dataChannel
                };

                m_statTimer.Start();
                m_wavePlayer.Play();
                m_dataSubscriber.UnsynchronizedSubscribe(info);
                m_timeoutTimer.Start();
                OnStateChanged(PlaybackState.Buffering);
            }
        }
Exemplo n.º 58
0
        public IWavePlayer PlayKillStreak(string sfxName, string ext = "wav")
        {
            if (!RPGSettings.PlayKillstreaks) return null;

            KillStreakDevice = KillStreakDevice ?? new WaveOutEvent();

            var path = SFXPath + sfxName + "." + ext;
            Wait(250);
            if (!File.Exists(path))
            {
                RPGLog.Log("Did not find killstreak SFX to play");
                return KillStreakDevice;
            }
            AudioFileReader audioFileReader = new AudioFileReader(path);
            audioFileReader.Volume = 0.6f * Volume;

            KillStreakDevice.Stop();
            KillStreakDevice.Init(audioFileReader);
            KillStreakDevice.Play();
            return KillStreakDevice;
        }
Exemplo n.º 59
0
Arquivo: Jeu.cs Projeto: Heliex/Tetris
        // Constructeur par défaut
        public Jeu()
        {
            // Initialisation des variables

            resetEvent = new ManualResetEvent(true);
            randNum = new Random();
            plateau = new Case[NB_CASE_HAUTEUR, NB_CASE_LARGEUR];
            estPerdu = false;
            waveOutDevice = new WaveOut();
            audioFileReader = new AudioFileReader("Musiques/Tetris.mp3");
            LoopStream loop = new LoopStream(audioFileReader);
            waveOutDevice.Init(loop);
            waveOutDevice.Play();
            for (int i = 0; i < NB_CASE_HAUTEUR; i++)
            {
                for (int j = 0; j < NB_CASE_LARGEUR; j++)
                {
                    plateau[j, i] = new Case(j, i);
                }
            }
            pieceCourante = pieceSuivante(); // On récupére la pièce suivante
            pieceApres = pieceSuivante(); // Déclaration de l'évenement
        }
Exemplo n.º 60
0
 private void TryStartPlaying()
 {
     if (_player == null)
     {
         _player = new WasapiOutRT(AudioClientShareMode.Shared, 0);
         _player.Init(CreateReader);
         _player.Play();
     }
 }