示例#1
0
        // private int _packetsSent;

        private void PrepareAndSendAudioPacket(AudioContext audioContext, short[] audioBuffer)
        {
            // Apply any custom filters.
            ApplyAudioInputFilter(audioBuffer);

            //if (++_packetsSent % 100 == 0)
            //{
            //    DebugHelper.AnalyzeAudioFrame("MediaController_PrepareAndSendAudioPacket", audioBuffer, 0, audioBuffer.Length);
            //}

            if (MediaConfig.EnableDenoise)
            {
                audioContext.DtxFilter.Filter(audioBuffer);
            }

            // Check to see if we've succeeded in sending some audio.
            if (!AudioSentSuccessfully)
            {
                AudioSentSuccessfully = !audioContext.DtxFilter.IsSilent;
            }

            // Set the volume.
            if (MediaConfig.ApplyVolumeFilterToRecordedSound)
            {
                ApplyVolumeFilter(MicrophoneVolume, audioBuffer, 0, audioBuffer.Length);
            }

            // Compress the audio onto the audioEncodeBuffer.
            LastAudioEncoder = audioContext.Encoder.CodecType;
            int length = audioContext.Encoder.Encode(audioBuffer, 0, audioBuffer.Length, audioContext.SendBuffer, audioContext.DtxFilter.IsSilent);

            // Send the packet
            MediaConnection.SendAudioPacket(audioContext.SendBuffer, length, audioContext.Encoder.CodecType, audioContext.DtxFilter.IsSilent, (int)_mediaEnvironment.LocalProcessorLoad);
            Logger.LogAudioFrameTransmitted(audioContext.DtxFilter.IsSilent);
        }