Stop() public method

public Stop ( ) : void
return void
Esempio n. 1
0
        private static void PlayThings(Context ctx, Node srcNode)
        {
            FrameworkDispatcher.Update();
            using (var aud = new DynamicSoundEffectInstance(48000, AudioChannels.Mono))
            {
                SampleSize = aud.GetSampleSizeInBytes(new TimeSpan(0, 0, 0, 0, SampleTimeMs));

                var sub = ctx.Socket(SocketType.SUB);
                sub.Subscribe(new byte[0]);
                sub.Connect(srcNode.Url);

                mBar.SignalAndWait();

                bool bufferNeeded = true;
                aud.BufferNeeded += (_, __) => bufferNeeded = true;

                while (isRunning)
                {
                    if (bufferNeeded)
                    {
                        foreach (var n in mNodes.Where(n => n is GeneratorNode).Cast<GeneratorNode>())
                        {
                            n.SignalForData();
                        }
                        bufferNeeded = false;
                    }

                    var bytes = sub.Recv(SampleTimeMs / 2);

                    if (bytes != null)
                    {
                        aud.SubmitBuffer(bytes);
                        if (aud.State == SoundState.Stopped)
                            aud.Play();
                    }

                    FrameworkDispatcher.Update();

                    //running = false;
                }

                aud.Stop();
                sub.Dispose();
            }
        }
Esempio n. 2
0
        private static void PlaybackSpeech()
        {
            // trace the operation
            TraceHelper.AddMessage("About to playback speech");

            // create a sound effect instance
            DynamicSoundEffectInstance effect = new DynamicSoundEffectInstance(mic.SampleRate, AudioChannels.Mono);

            // submit all the buffers to the instance
            foreach (var buf in speechBufferList)
                if (buf.Length > 0)
                    effect.SubmitBuffer(buf);
            speechBufferList.Clear();

            // create an event handler to stop playback when all the buffers have been consumed
            effect.BufferNeeded += delegate
            {
                if (effect.PendingBufferCount == 0)
                {
                    effect.Stop();
                    TraceHelper.AddMessage("Finished playing back speech");
                }
            };

            // play the speech
            FrameworkDispatcher.Update();
            effect.Play();
        }