Example #1
0
        public TestSoundIO(IVoiceHandler c0)
        {
            hand = c0;

            Thread tt = new Thread(TestThread);

            tt.Start();
        }
Example #2
0
        public void StartReceiving(IVoiceHandler v0)
        {
            playback = v0;

            // Start voice connection
            // todo: binding causes error: The requested address is not valid in its context
            //if (!clientSocket.IsBound)
            //    clientSocket.Bind(localEndPoint);

            udpReceiveThread = new Thread(ReceiveThread);
            udpReceiveThread.Start();
        }
Example #3
0
        public VoiceInput(IVoiceHandler c0, int devin)
        {
            micHandler       = c0;
            InputAudioDevice = devin;

            sourceStream = new WaveInEvent
            {
                DeviceNumber       = InputAudioDevice,
                WaveFormat         = new WaveFormat(8000, 16, WaveIn.GetCapabilities(0).Channels),
                BufferMilliseconds = 30
            };

            sourceStream.DataAvailable += sourceStream_DataAvailable;
            sourceStream.StartRecording();
        }
    /// <summary>
    /// Adds the handler
    /// </summary>
    /// <param name="handler">handler to add</param>
    public void AddVoiceHandler(IVoiceHandler handler)
    {
        //check if workflow is initialized
        if (manipulator == null)
        {
            throw new Exception("The current manipulator is null, be sure to initialize the workflow properly before any other action");
        }

        //Compatibility check between handler to add and manipulator
        AudioDataTypeFlag res = manipulator.AvailableTypes & handler.AvailableTypes;

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

        //handler is added and callback for when mic data is available is set on the handler
        handlers.Add(handler.Identity.NetworkId, handler);
        handler.SetOnMicDataProcessed(OnMicDataProcessed);
    }
Example #5
0
 public void StartReceiving(IVoiceHandler v0)
 {
     tcpReceiveThread = new Thread(ReceiveThread);
     tcpReceiveThread.Start();
 }
Example #6
0
 void Awake()
 {
     SteamCallbackReceiver.ChatUpdateEvent += OnLobbyUpdate;
     handler = GetComponent <IVoiceHandler>();
 }
 /// <summary>
 /// Removes the handler
 /// </summary>
 /// <param name="handler">handler to remove</param>
 public void RemoveVoiceHandler(IVoiceHandler handler)
 {
     //handler and callback are removed
     handlers.Remove(handler.Identity.NetworkId);
     handler.SetOnMicDataProcessed(null);
 }
    private void OnMicDataProcessed(IVoiceHandler handler)
    {
        //throw exception if workflow is not initialized correctly
        if (manipulator == null || transport == null)
        {
            throw new Exception("The current manipulator or transport is null, be sure to initialize the workflow properly before any other action");
        }

        //If voice chat is disabled or if the given handler is not a recorder do nothing
        if (!Settings.VoiceChatEnabled || Settings.MuteSelf || !handler.IsRecorder)
        {
            return;
        }

        //Compatibility check between manipulator and handler. If they are incompatible throw exception
        AudioDataTypeFlag res = handler.AvailableTypes & manipulator.AvailableTypes;

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

        VoicePacketInfo info;

        //determine which data format to use. Gives priority to Single format
        bool useSingle = (res & AudioDataTypeFlag.Single) != 0;

        //Retrive data from handler input
        uint count;

        if (useSingle)
        {
            info = handler.GetMicData(micDataBuffer, 0, micDataBuffer.Length, out count);
        }
        else
        {
            info = handler.GetMicDataInt16(micDataBufferInt16, 0, micDataBufferInt16.Length, out count);
        }

        //if data is valid go on
        if (info.ValidPacketInfo)
        {
            //packet buffer used to create the final packet is prepared
            packetSender.ResetSeekLength();

            //data recovered from input is manipulated and stored into the gamepacket
            if (useSingle)
            {
                manipulator.FromAudioDataToPacket(micDataBuffer, 0, (int)count, ref info, packetSender);
            }
            else
            {
                manipulator.FromAudioDataToPacketInt16(micDataBufferInt16, 0, (int)count, ref info, packetSender);
            }

            //if packet is valid send to transport
            if (info.ValidPacketInfo)
            {
                transport.SendToAllOthers(packetSender, info);
            }
        }
    }
    private void OnPacketAvailable()
    {
        //throw exception if workflow is not initialized correctly
        if (manipulator == null || transport == null)
        {
            throw new Exception("The current manipulator or transport is null, be sure to initialize the workflow properly before any other action");
        }

        //If voice chat is disabled do nothing
        if (!Settings.VoiceChatEnabled)
        {
            return;
        }

        //Cycle that iterates as long as there are packets available in the transport
        while (transport.IsPacketAvailable)
        {
            //resets packet buffer
            packetReceiver.ResetSeekLength();
            //receive packet
            VoicePacketInfo info = transport.Receive(packetReceiver);

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

            IVoiceHandler handler = handlers[info.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. Gives priority to Single format
            bool useSingle = (res & AudioDataTypeFlag.Single) != 0;

            int count;
            //packet received Seek to zero to prepare for data manipulation
            packetReceiver.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)
            {
                manipulator.FromPacketToAudioData(packetReceiver, ref info, receivedDataBuffer, 0, out count);
                if (info.ValidPacketInfo)
                {
                    handler.ReceiveAudioData(receivedDataBuffer, 0, count, info);
                }
            }
            else
            {
                manipulator.FromPacketToAudioDataInt16(packetReceiver, ref info, receivedDataBufferInt16, 0, out count);
                if (info.ValidPacketInfo)
                {
                    handler.ReceiveAudioDataInt16(receivedDataBufferInt16, 0, count, info);
                }
            }
        }
    }