Exemplo n.º 1
0
 private void OnAudioGenerated(VoipFragment audio)
 {
     if (Random.value >= packetLoss)
     {
         queue.Add(new NetworkContainer()
         {
             fragment  = audio,
             releaseAt = Time.time + networkDelaySec + Random.Range(networkStutterSec, networkStutterSec)
         });
     }
 }
Exemplo n.º 2
0
        public void Recieve(VoipFragment audio)
        {
            bytes += audio.data.Length + 11;
            chunkCount++;

            //If params have changed or decoder not set..
            if (decoder == null || decoder.mode != audio.mode)
            {
                //Create decoder.
                decoder = SpeexCodex.Create(audio.mode);
                //Create a buffer.
                buffer = new VoipBuffer(decoder.dataSize, BufferChunks);
                //Create clip.
                var frequency = AudioUtils.GetFrequency(audio.mode);
                recording = AudioClip.Create("Inbound", frequency * 10, 1, frequency, false);
                //Create source.
                source = gameObject.GetComponent <AudioSource>();
                if (source == null)
                {
                    source = gameObject.AddComponent <AudioSource>();
                }
                source.clip = recording;
                source.Play();
                source.loop = true;
            }

            //Decode.
            var decoded = decoder.Decode(audio.data);

            //Apply effects.
            if (Equalize)
            {
                ApplyGain(decoded);
            }
            //Write to voip buffer.
            buffer.Write(audio.index, decoded);
            //Update write cursor.
            lastWrittenCursor = audio.index > lastWrittenCursor ? audio.index : lastWrittenCursor;
        }