Example #1
0
    void _CreateRTPAudio()
    {
        GstAudioSource a;

        if (_audioSource != null)
        {
            _audioSource.Close();
        }
        _audioSource = (a = new GstAudioSource());

        //a._audioSourceCount = _audioSourceCount;
        //a._isSpatialAudio = _isSpatialAudio;
        //		a.TargetNode = gameObject;

        var grabber = new GstNetworkAudioGrabber();

        Output.SamplingRate = AudioSettings.outputSampleRate;
        grabber.Init(0, 2, AudioSettings.outputSampleRate);
        grabber.Start();
        a.AudioGrabber = grabber;
        a.Output       = Output;
        //a.RobotConnector = RobotConnector;
        a.Init();

        RobotConnector.Connector.DataCommunicator.OnAudioConfig += OnAudioConfig;
        RobotConnector.Connector.SendData(TxKitEars.ServiceName, "Parameters", "", false, true);
        RobotConnector.Connector.SendData(TxKitEars.ServiceName, "Port", grabber.GetAudioPort().ToString(), true);
        if (OnAudioSourceCreated != null)
        {
            OnAudioSourceCreated(this, _audioSource);
        }
    }
Example #2
0
    void _initAudioPlayers()
    {
        _audioCreated   = true;
        _configReceived = false;
        //Create audio playback
        if (AudioStream)
        {
            string audioPorts = "";
            TxEarsOutput.SourceChannel[] channels;
            if (!_isSpatialAudio)
            {
                channels = new TxEarsOutput.SourceChannel[1] {
                    TxEarsOutput.SourceChannel.Both
                };
                for (int i = 0; i < _audioSourceCount; ++i)
                {
                    var c = Output.GetChannel(i, true);
                    c.AudioLocation = Vector3.zero;
                }
            }
            else
            {
                //check number of audio locations
                for (int i = 0; i < 2 * _audioSourceCount; ++i)
                {
                    var c = Output.GetChannel(i, true);
                    c.AudioLocation = Vector3.zero;
                }

                channels = new TxEarsOutput.SourceChannel[2] {
                    TxEarsOutput.SourceChannel.Right, TxEarsOutput.SourceChannel.Left
                };
            }

            int idx          = 0;
            int channelIndex = 0;
            for (int i = 0; i < _audioSourceCount; ++i)
            {
                GstNetworkAudioGrabber  grabber;
                GstAudioPacketProcessor processor;

                grabber = new GstNetworkAudioGrabber();

                uint   audioPort = (uint)Settings.Instance.GetPortValue("AudioPort", 0);
                string ip        = Settings.Instance.GetValue("Ports", "ReceiveHost", _ifo.IP);
                grabber.Init(audioPort, 2, AudioSettings.outputSampleRate);
                grabber.Start();

                audioPort = grabber.GetAudioPort();
                Debug.Log("Playing audio from port:" + audioPort.ToString());
                audioPorts += audioPort.ToString();
                if (i != _audioSourceCount - 1)
                {
                    audioPorts += ",";
                }

                // next create the audio grabber to encapsulate the audio player
                processor         = new GstAudioPacketProcessor();
                processor.Grabber = grabber;
                _audioProcessor.Add(processor);

                //link processor with the channels
                for (int j = 0; j < channels.Length; ++j, ++channelIndex)
                {
                    var c = Output.GetChannel(channelIndex, true);
                    c.channel = channels [j];
                    processor.AttachedPlayers.Add(c);
                }

                _audioGrabber.Add(grabber);
            }
            RobotConnector.Connector.SendData(TxKitEars.ServiceName, "AudioPort", audioPorts, true);
        }
    }