Example #1
0
        public SpeexCodex(BandMode mode)
        {
            this.mode = mode;

            encoder = new NSpeex.SpeexEncoder(SpeedxMode);
            decoder = new NSpeex.SpeexDecoder(SpeedxMode, false);

            encoder.VBR     = true;
            encoder.Quality = 4;

            dataSize = encoder.FrameSize * (mode == BandMode.Narrow ? 8 : mode == BandMode.Wide ? 4 : 2);

            encodingBuffer = new short[dataSize];
            encodedBuffer  = new byte[dataSize];
            decodeBuffer   = new short[dataSize];
            decodedBuffer  = new float[dataSize];

            int frequency = AudioUtils.GetFrequency(mode);
            var time      = frequency / (float)dataSize;

            UnityEngine.Debug.Log("SpeedCodex created mode:" + mode + " dataSize:" + dataSize + " time:" + time);
        }
Example #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;
        }