SubmitBuffer() public method

public SubmitBuffer ( byte buffer, int count ) : void
buffer byte
count int
return void
Exemplo n.º 1
0
        /// <summary>
        /// Plays the effect.
        /// </summary>
        /// <param name="asEffect">Set to false for music, true for sound effects.</param>
        public void Play(bool asEffect = true)
        {
            double now = UltimaGame.TotalMS;
            CullExpiredEffects(now);

            m_ThisInstance = GetNewInstance(asEffect);
            if (m_ThisInstance == null)
            {
                this.Dispose();
                return;
            }

            BeforePlay();

            byte[] buffer = GetBuffer();
            if (buffer != null && buffer.Length > 0)
            {

                m_ThisInstance.BufferNeeded += new EventHandler<EventArgs>(OnBufferNeeded);
                m_ThisInstance.SubmitBuffer(buffer);
                m_ThisInstance.Play();

                List<Tuple<DynamicSoundEffectInstance, double>> list = (asEffect) ? m_EffectInstances : m_MusicInstances;
                list.Add(new Tuple<DynamicSoundEffectInstance, double>(m_ThisInstance, now + (m_ThisInstance.GetSampleDuration(buffer.Length).Milliseconds)));
            }
        }
        public void PlaySound(int samplingRate, byte[] pcmData)
        {
            DynamicSoundEffectInstance playback = 
                new DynamicSoundEffectInstance(samplingRate, AudioChannels.Mono);

            playback.SubmitBuffer(pcmData);
            playback.Play();
        }
Exemplo n.º 3
0
            public void Play()
            {
                float now = UltimaVars.EngineVars.TheTime;

                // Check to see if any existing instances of this sound effect have stopped playing. If
                // they have, remove the reference to them so the garbage collector can collect them.
                for (int i = 0; i < m_instances.Count; i++)
                    if (m_instances[i].Item2 < now)
                    {
                        m_instances.RemoveAt(i);
                        i--;
                    }

                DynamicSoundEffectInstance instance = new DynamicSoundEffectInstance(22050, AudioChannels.Mono);
                instance.BufferNeeded += new EventHandler<EventArgs>(instance_BufferNeeded);
                instance.SubmitBuffer(m_waveBuffer);
                instance.Play();
                m_instances.Add(new Tuple<DynamicSoundEffectInstance, float>(instance,
                    now + (instance.GetSampleDuration(m_waveBuffer.Length).Milliseconds / 1000f)));
            }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Plays the effect.
        /// </summary>
        /// <param name="asEffect">Set to false for music, true for sound effects.</param>
        public void Play(bool asEffect, AudioEffects effect = AudioEffects.None, float volume = 1.0f)
        {
            double now = UltimaGame.TotalMS;
            CullExpiredEffects(now);

            m_ThisInstance = GetNewInstance(asEffect);
            if (m_ThisInstance == null)
            {
                this.Dispose();
                return;
            }

            switch (effect)
            {
                case AudioEffects.PitchVariation:
                    float pitch = (float)Utility.RandomValue(-5, 5) * .025f;
                    m_ThisInstance.Pitch = pitch;
                    break;
            }

            BeforePlay();

            byte[] buffer = GetBuffer();
            if (buffer != null && buffer.Length > 0)
            {
                m_ThisInstance.BufferNeeded += new EventHandler<EventArgs>(OnBufferNeeded);
                m_ThisInstance.SubmitBuffer(buffer);
                m_ThisInstance.Volume = volume;
                m_ThisInstance.Play();

                List<Tuple<DynamicSoundEffectInstance, double>> list = (asEffect) ? m_EffectInstances : m_MusicInstances;
                double ms = m_ThisInstance.GetSampleDuration(buffer.Length).TotalMilliseconds;
                list.Add(new Tuple<DynamicSoundEffectInstance, double>(m_ThisInstance, now + ms));
            }
        }
Exemplo n.º 6
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();
        }