public override int FromPacketToAudioDataInt16(BytePacket packet, ref VoicePacketInfo info, byte[] out_audioData, int out_audioDataOffset)
    {
        //reads audio data length
        int count = packet.ReadInt();

        //Restarts packet buffer to use
        decompressBuffer.ResetSeekLength();

        //fills buffer with only audio data from given packet
        decompressBuffer.WriteByteData(packet.Data, packet.CurrentSeek, count);

        EVoiceResult res = EVoiceResult.k_EVoiceResultUnsupportedCodec;

        //number of bytes written
        uint b = 0;

        //audio data is decompressed
        res = SteamUser.DecompressVoice(decompressBuffer.Data, (uint)decompressBuffer.CurrentLength, out_audioData, (uint)out_audioData.Length, out b, info.Frequency);

        //if an error occurred packet is invalid
        if (res != EVoiceResult.k_EVoiceResultOK)
        {
            info.ValidPacketInfo = false;
        }

        return((int)b);
    }
示例#2
0
        /// <summary>
        /// Process the received packet data.
        /// </summary>
        /// <param name="receivedData">received raw data</param>
        /// <param name="startIndex">received raw data start index</param>
        /// <param name="length">received raw data length</param>
        /// <param name="netId">sender net id</param>
        public override void ProcessReceivedPacket(byte[] receivedData, int startIndex, int length, ulong netId)
        {
            //If voice chat is disabled do nothing
            if (!Settings.VoiceChatEnabled)
            {
                return;
            }

            //resets packet buffer
            packetBuffer.ResetSeekLength();

            //receive packet
            VoicePacketInfo info = Transport.ProcessReceivedData(packetBuffer, receivedData, startIndex, length, netId);

            //if packet is invalid or if there is not an handler for the given netid discard the packet received
            if (!info.ValidPacketInfo || !handlers.ContainsKey(netId))
            {
                return;
            }

            VoiceHandler handler = handlers[netId];

            //Do nothing if handler is either muted or if it is a recorder
            if (handler.IsOutputMuted || handler.IsRecorder)
            {
                return;
            }

            //Compatibility check between manipulator, handler and packet; if incompatible throw exception
            AudioDataTypeFlag res = Manipulator.AvailableTypes & handler.AvailableTypes & info.Format;

            if (res == AudioDataTypeFlag.None)
            {
                throw new ArgumentException("the given handler type is incompatible with the current audio data manipulator and the received packet format");
            }

            //determine which data format to use.
            if (res == AudioDataTypeFlag.Both)
            {
                res = formatToUse;
            }

            bool useSingle = res == AudioDataTypeFlag.Single;

            //packet received Seek to zero to prepare for data manipulation
            packetBuffer.CurrentSeek = 0;

            //Different methods between Int16 and Single format. Data manipulation is done and, if no error occurred, audio data is sent to the handler in order to be used as output sound
            if (useSingle)
            {
                int count = Manipulator.FromPacketToAudioData(packetBuffer, ref info, dataBuffer, 0);
                if (info.ValidPacketInfo)
                {
                    handler.ReceiveAudioData(dataBuffer, 0, count, info);
                }
            }
            else
            {
                int count = Manipulator.FromPacketToAudioDataInt16(packetBuffer, ref info, dataBufferInt16, 0);
                if (info.ValidPacketInfo)
                {
                    handler.ReceiveAudioDataInt16(dataBufferInt16, 0, count, info);
                }
            }
        }