Exemplo n.º 1
0
        private void outputBufferTimerCheck(object sender, EventArgs e)
        {
            if (outputBuffer.BufferedDuration < TimeSpan.FromMilliseconds(40) && output.PlaybackState != PlaybackState.Paused)
            {
                output.Pause();
                Logger.WriteLine(DateTime.Now.TimeOfDay + ": OUTPUT PAUSED");
            }
            else if (outputBuffer.BufferedDuration > TimeSpan.FromMilliseconds(40) && output.PlaybackState != PlaybackState.Playing)
            {
                output.Play();
                Logger.WriteLine(DateTime.Now.TimeOfDay + ": OUTPUT PLAYING");
            }

            // UPDATE OUTPUT STATE INDICATORS
            switch (output.PlaybackState)
            {
            case PlaybackState.Playing:
                outputPlayingIndicator.turnOnUpper();
                outputPausedIndicator.turnOffUpper();
                outputStoppedIndicator.turnOffUpper();
                break;

            case PlaybackState.Paused:
                outputPlayingIndicator.turnOffUpper();
                outputPausedIndicator.turnOnUpper();
                outputStoppedIndicator.turnOffUpper();
                break;

            case PlaybackState.Stopped:
                outputPlayingIndicator.turnOffUpper();
                outputPausedIndicator.turnOffUpper();
                outputStoppedIndicator.turnOnUpper();
                break;
            }
        }
Exemplo n.º 2
0
        private void AudioOutput_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (output != null && output.PlaybackState != PlaybackState.Stopped)
            {
                output.Pause();
            }

            output = new WasapiOut(outputs[audioOutputSelector.SelectedIndex], AudioClientShareMode.Shared, true, outputLatency);

            bitsPrSample = output.OutputWaveFormat.BitsPerSample;
            sampleRate   = output.OutputWaveFormat.SampleRate;
            channels     = output.OutputWaveFormat.Channels;


            // Set the WaveFormat
            outputFormat = WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channels);

            pflBuffer           = new BufferedWaveProvider(internalFormatStereo);
            pflBuffer.ReadFully = true;
            pflBuffer.DiscardOnBufferOverflow = true;

            WdlResamplingSampleProvider resampler = new WdlResamplingSampleProvider(pflBuffer.ToSampleProvider(), outputFormat.SampleRate);



            output.Init(resampler);
            output.Play();

            Logger.WriteLine("SET OUTPUT FORMAT: "
                             + "Sample Rate: " + sampleRate
                             + ", BitsPrSasmple: " + bitsPrSample
                             + ", Channels: " + channels);
        }
Exemplo n.º 3
0
 public void Pause()
 {
     _output.Pause();
     oscPanel.Pause();
     mixerView.Pause();
     fftView.Pause();
     toggleButton.Content = "Play";
 }
Exemplo n.º 4
0
 /// <summary>
 /// Pause a sound.
 /// </summary>
 public void Pause()
 {
     _wasapiOut.Pause();
     if (PlaybackChanged != null)
     {
         PlaybackChanged(this, EventArgs.Empty);
     }
 }
Exemplo n.º 5
0
 // Write buffer to output
 public Task Clip(Stream dest)
 {
     _dest   = dest;
     _action = PauseAction.Clip;
     _task   = new TaskCompletionSource <bool>();
     _capture.StopRecording();
     _renderFix?.Pause();
     return(_task.Task);
 }
Exemplo n.º 6
0
 public void Pause()
 {
     if (IsPlaying && CanPause)
     {
         waveOutDevice.Pause();
         IsPlaying = false;
         CanPlay   = true;
         CanPause  = false;
     }
 }
Exemplo n.º 7
0
 private void button2_Click(object sender, RoutedEventArgs e)
 {
     if (audioOutput.PlaybackState == PlaybackState.Playing)
     {
         audioOutput.Pause();
     }
     else if (audioOutput.PlaybackState == PlaybackState.Paused || audioOutput.PlaybackState == PlaybackState.Stopped)
     {
         audioOutput.Play();
     }
 }
Exemplo n.º 8
0
        static void StartSubscriber()
        {
            // create client instance
            client = new MqttClient(MQTT_BROKER_ADDRESS);

            /* Setup audio buffer */
            sourceWaveData = new BufferedWaveProvider(new WaveFormat(16000, 1));
            sourceWaveData.BufferDuration = System.TimeSpan.FromMilliseconds(1000); // 20 "blocks"; 32kb

            // register to message received
            client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

            string clientId = Guid.NewGuid().ToString();

            client.Connect(clientId);

            client.Subscribe(
                new string[] { "/audio/stream" },
                new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }
                );

            Console.WriteLine("Listening for data...");

            WasapiOut player = new WasapiOut();

            //WaveOut player = new WaveOut();
            player.Init(sourceWaveData);

            // while buffer is less than 200ms
            // wait for the buffer to grow
            // otherwise
            // play buffer

            for (;;)
            {
                if (sourceWaveData.BufferedDuration < System.TimeSpan.FromMilliseconds(25))
                {
                    if (player.PlaybackState == PlaybackState.Playing)
                    {
                        Console.WriteLine("Buffer underrun // no data, pausing playback...");
                        player.Pause();
                    }
                }

                if (player.PlaybackState != PlaybackState.Playing && sourceWaveData.BufferedDuration > System.TimeSpan.FromMilliseconds(200))
                {
                    player.Play();
                    Console.WriteLine("(re-)starting playback...");
                }
            }
        }
 /// <inheritdoc />
 public void Pause()
 {
     _context.Pause();
 }
Exemplo n.º 10
0
        private async Task Cmd(string cmd)
        {
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BackgroundColor = ConsoleColor.Black;
            if (cmd.StartsWith("vol "))
            {
                float.TryParse(cmd.Substring(4), out targetVolume);
                Console.Write("set volume to " + targetVolume.ToString());
                return;
            }
            if (cmd.StartsWith("pos"))
            {
                Console.Write("current pos is " + wasapiOut.WaveSource.GetPosition().ToString());
                return;
            }
            if (cmd.StartsWith("playlist "))
            {
                if (initialized)
                {
                    wasapiOut.Stop();
                    initialized = false;
                }
                string path       = cmd.Substring(9);
                bool   onComputer = true;
                if (!File.Exists(@path))
                {
                    onComputer = false;
                }
                Stream stream = Stream.Null;
                if (onComputer)
                {
                    stream = File.OpenRead(@path);
                }
                else
                {
                    try
                    {
                        HttpWebRequest  req      = (HttpWebRequest)WebRequest.Create(path);
                        HttpWebResponse response = (HttpWebResponse)req.GetResponse();
                        stream = response.GetResponseStream();
                    } catch { }
                }
                if (stream == Stream.Null)
                {
                    Console.Write("couldn't read " + path);
                    return;
                }
                string extension = Path.GetExtension(path);
                IPlaylistParser <IBasePlaylist> parser = PlaylistParserFactory.GetPlaylistParser(extension);
                IBasePlaylist playlist = parser.GetFromStream(stream);
                foreach (string str in playlist.GetTracksPaths())
                {
                    currentStream = new Mp3WebStream(str, false);
                    ISampleSource source             = currentStream.ToSampleSource().AppendSource(x => new PitchShifter(x), out pitchShifter);
                    var           notificationSource = new SingleBlockNotificationStream(source);
                    notificationSource.SingleBlockRead += (s, a) =>
                    {
                        leftPitch  = Math.Abs(a.Left) * 10;
                        rightPitch = Math.Abs(a.Right) * 10;
                    };
                    currentStream = notificationSource.ToWaveSource();
                    currentPath   = path;
                    wasapiOut.Initialize(currentStream);
                    wasapiOut.Volume = 0.0f;
                    initialized      = true;
                }
                Console.Write("set playlist to " + path);
                return;
            }
            if (cmd.StartsWith("thread"))
            {
                string board = "a";
                if (cmd.Length > 6)
                {
                    board = cmd.Substring(7);
                }

                Dictionary <int, int> a_threads    = new Dictionary <int, int>();
                Dictionary <int, int> smug_threads = new Dictionary <int, int>();
                using (HttpClient a_client = new HttpClient())
                    using (HttpResponseMessage a_response = await a_client.GetAsync("https://8ch.net/" + board + "/catalog.html"))
                        using (HttpContent a_content = a_response.Content)
                        {
                            string soykaf = await a_content.ReadAsStringAsync();

                            string pattern = "data-reply=\"";
                            for (int i = 0; i < soykaf.Length - pattern.Length; ++i)
                            {
                                if (soykaf.Substring(i, pattern.Length) == pattern)
                                {
                                    int    replyCountEnd   = FindNext(soykaf.Substring(i + pattern.Length), "\"");
                                    string replyCount      = soykaf.Substring(i + pattern.Length, replyCountEnd);
                                    int    threadIdBegin   = i + pattern.Length + FindNext(soykaf.Substring(i + pattern.Length), "data-id=\"");
                                    string threadId        = soykaf.Substring(threadIdBegin + 9, FindNext(soykaf.Substring(threadIdBegin + 9), "\""));
                                    int    threadNameBegin = threadIdBegin + 9 + FindNext(soykaf.Substring(threadIdBegin + 9), "data-subject=\"");
                                    string threadName      = soykaf.Substring(threadNameBegin + 14, FindNext(soykaf.Substring(threadNameBegin + 14), "\""));

                                    if (FindNext(threadName.ToLower(), "r/a/dio") >= 0 || FindNext(threadName.ToLower(), "radio") >= 0)
                                    {
                                        int.TryParse(threadId, out int ID);
                                        int.TryParse(replyCount, out int REPLY);
                                        a_threads.Add(ID, REPLY);
                                    }
                                }
                            }
                        }
                Console.Write("got " + a_threads.Count + " r/a/dio thread" + (a_threads.Count > 1 ? "s" : "") + " from 8/" + board + "/");
                if (board == "a")
                {
                    using (HttpClient smug_client = new HttpClient())
                        using (HttpResponseMessage smug_response = await smug_client.GetAsync("https://smuglo.li/a/catalog.html"))
                            using (HttpContent smug_content = smug_response.Content)
                            {
                                string soykaf = await smug_content.ReadAsStringAsync();

                                string pattern = "data-reply=\"";
                                for (int i = 0; i < soykaf.Length - pattern.Length; ++i)
                                {
                                    if (soykaf.Substring(i, pattern.Length) == pattern)
                                    {
                                        int    replyCountEnd   = FindNext(soykaf.Substring(i + pattern.Length), "\"");
                                        string replyCount      = soykaf.Substring(i + pattern.Length, replyCountEnd);
                                        int    threadIdBegin   = i + pattern.Length + FindNext(soykaf.Substring(i + pattern.Length), "data-id=\"");
                                        string threadId        = soykaf.Substring(threadIdBegin + 9, FindNext(soykaf.Substring(threadIdBegin + 9), "\""));
                                        int    threadNameBegin = threadIdBegin + 9 + FindNext(soykaf.Substring(threadIdBegin + 9), "data-subject=\"");
                                        string threadName      = soykaf.Substring(threadNameBegin + 14, FindNext(soykaf.Substring(threadNameBegin + 14), "\""));

                                        if (FindNext(threadName.ToLower(), "r/a/dio") >= 0 || FindNext(threadName.ToLower(), "radio") >= 0)
                                        {
                                            if (int.TryParse(threadId, out int ID) && int.TryParse(replyCount, out int REPLY))
                                            {
                                                smug_threads.Add(ID, REPLY);
                                            }
                                        }
                                    }
                                }
                            }
                    Console.Write("\ngot " + smug_threads.Count + " r/a/dio thread" + (smug_threads.Count > 1 ? "s" : "") + " from the bunker");
                }
                Thread.Sleep(500);
                Console.Write("\nopening the most active thread(s)");
                Thread.Sleep(1000);
                foreach (var x in a_threads)
                {
                    Process.Start("https://8ch.net/a/res/" + x.Key + ".html");
                    break;
                }
                foreach (var x in smug_threads)
                {
                    Process.Start("https://smuglo.li/a/res/" + x.Key + ".html");
                    break;
                }
                return;
            }
            if (cmd.StartsWith("play"))
            {
                if (M3uCheck())
                {
                    return;
                }

                wasapiOut.Play();
                Console.Write("started playing");
                return;
            }
            if (cmd.StartsWith("stop"))
            {
                if (M3uCheck())
                {
                    return;
                }

                wasapiOut.Stop();
                Console.Write("stopped playing");
                return;
            }
            if (cmd.StartsWith("pause"))
            {
                if (M3uCheck())
                {
                    return;
                }

                wasapiOut.Pause();
                Console.Write("paused playing");
                return;
            }
            if (cmd.StartsWith("resume"))
            {
                if (M3uCheck())
                {
                    return;
                }

                wasapiOut.Resume();
                Console.Write("resumed playing");
                return;
            }
            if (cmd.StartsWith("help"))
            {
                Console.Write(HELP_MESSAGE);
                return;
            }

            Console.ForegroundColor = ConsoleColor.Black;
            Console.BackgroundColor = ConsoleColor.Red;
            Console.Write("nANI!?");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.Write("?");
            return;
        }
Exemplo n.º 11
0
 public void Pause()
 {
     audioOut.Pause();
 }