示例#1
0
 void ApplyGain(float[] data)
 {
     targetGain = TargetEqualizeVolume / AudioUtils.GetMaxAmplitude(data);;
     if (targetGain > MaxEqualization)
     {
         targetGain = MaxEqualization;
     }
     if (targetGain < currentGain)
     {
         currentGain = targetGain;
     }
     AudioUtils.ApplyGain(data, currentGain);
 }
示例#2
0
        void Update()
        {
            if (recording == null)
            {
                Setup();
                return;
            }

            var now    = Microphone.GetPosition(null);
            var length = now - lastPos;

            if (now < lastPos)
            {
                lastPos = 0;
                length  = now;
            }

            Profiler.BeginSample("Voip Encode");
            while (length >= recordingBuffer.Length)
            {
                if (recording.GetData(recordingBuffer, lastPos))
                {
                    //Send..
                    var amplitude = AudioUtils.GetMaxAmplitude(recordingBuffer);
                    if (amplitude >= minAmplitude)
                    {
                        index++;
                        if (OnAudioGenerated != null)
                        {
                            chunkCount++;

                            //Downsample if needed.
                            if (recordingBuffer != resampleBuffer)
                            {
                                AudioUtils.Downsample(recordingBuffer, resampleBuffer);
                            }

                            var data = encoder.Encode(resampleBuffer);
                            bytes += data.Length + 11;
                            OnAudioGenerated(new VoipFragment(index, data, encoder.mode));
                        }
                    }
                }
                length  -= recordingBuffer.Length;
                lastPos += recordingBuffer.Length;
            }
            Profiler.EndSample();

            UpdateStats();
        }