public void Play() { _owner.Play(); }
void _initAudioPlayers() { _audioCreated = true; _configReceived = false; //Create audio playback if (AudioStream) { string audioPorts = ""; GstAudioPlayer.SourceChannel[] channels; if (!_isSpatialAudio) { channels = new GstAudioPlayer.SourceChannel[1] { GstAudioPlayer.SourceChannel.Both }; for (int i = AudioLocation.Count; i < _audioSourceCount; ++i) { AudioLocation.Add(Vector3.zero); } } else { //check number of audio locations for (int i = AudioLocation.Count; i < 2 * _audioSourceCount; ++i) { AudioLocation.Add(Vector3.zero); } channels = new GstAudioPlayer.SourceChannel[2] { GstAudioPlayer.SourceChannel.Right, GstAudioPlayer.SourceChannel.Left }; /* * // AudioLocation = new Vector3[_audioSourceCount * 2]; * float angle = 0; * float step = Mathf.Deg2Rad* 360.0f / (float)AudioLocation.Count; * float r = 0.1f; * for (int i = 0; i < AudioLocation.Count; ++i) { * AudioLocation [i] = new Vector3 (Mathf.Cos (angle)*r, 0, Mathf.Sin (angle)*r); * angle += step; * }*/ } int idx = 0; for (int i = 0; i < _audioSourceCount; ++i) { GstNetworkAudioPlayer aplayer; GstAudioPacketGrabber grabber; aplayer = new GstNetworkAudioPlayer(); aplayer.SetSampleRate(AudioSettings.outputSampleRate); aplayer.SetUseCustomOutput(true); int audioPort = Settings.Instance.GetPortValue("AudioPort", 0); string ip = Settings.Instance.GetValue("Ports", "ReceiveHost", _ifo.IP); aplayer.SetIP(ip, audioPort, false); aplayer.CreateStream(); aplayer.Play(); _audioPort = aplayer.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 grabber = new GstAudioPacketGrabber(); grabber.Player = aplayer.AudioWrapper; _audioGrabbers.Add(grabber); //finally create sound object(s)-- for (int j = 0; j < channels.Length; ++j) { //Create Sound Object GameObject audioObj = new GameObject("AudioObject" + i.ToString() + "_" + TargetNode.name + "_" + channels[j].ToString()); audioObj.transform.parent = TargetNode.transform; audioObj.transform.position = AudioLocation[idx]; AudioSource asrc = audioObj.AddComponent <AudioSource> (); asrc.loop = true; _player = audioObj.AddComponent <GstAudioPlayer> (); _player.Player = aplayer.AudioWrapper; _player.TargetSrc = asrc; _player.grabber = grabber; _player.SupportSpatialAudio = _isSpatialAudio; _player.Channel = channels [j]; grabber.AttachedPlayers.Add(_player); AudioObjects.Add(asrc); ++idx; } _audioPlayer.Add(aplayer); } RobotConnector.Connector.SendData(TxKitEars.ServiceName, "AudioPort", audioPorts, true); } }