public Server.Services.IAudioSource CreateSource(BroadcastSettings settings) { SoundInSourceWrapper source = new SoundInSourceWrapper( new SoundInSource(AudioCapturer.WasapiCapture) { FillWithZeros = false }, settings); return(source); }
public void SetBroadcastSettings(BroadcastSettings settings) { if (settings.BroadcastRadius <= 0) { throw new InvalidSettingsException("The broadcast radius must be greater than 0"); } if (settings.AgentTag == null || settings.AgentTag.Length == 0) { throw new InvalidSettingsException("You must supply a proper agent tag"); } BroadcastSettings = settings; }
public void StartAudioStream( [MidgeParameter("port", true)] int port, [MidgeParameter("sample_rate", false)] int?sampleRate = null, [MidgeParameter("bit_depth", false)] int?bitDepth = null, [MidgeParameter("channel", false)] AudioChannel?channel = null) { if (sampleRate == null) { sampleRate = 44100; } if (bitDepth == null) { bitDepth = 16; } if (channel == null) { channel = AudioChannel.Mono; } var settings = new BroadcastSettings(sampleRate.Value, channel.Value, bitDepth.Value); IAudioSource audioSource = _audioStreamService.CreateSource(settings); IEncrypter encrypter = AesEncrypter.Create(); BroadcastPoint point = new BroadcastPoint(audioSource, encrypter, Context.CurrentConnection.Ip, port); Context.AudioBroadcaster.Register(point); string base64Key = Convert.ToBase64String(encrypter.Key); string base64Iv = Convert.ToBase64String(encrypter.IV); Response = new JObject( new JProperty("crypt_key", base64Key), new JProperty("crypt_iv", base64Iv), new JProperty("sample_rate", settings.SampleRate), new JProperty("channel", (int)settings.Channel), new JProperty("alg", "aes32")); }
public SoundInSourceWrapper(SoundInSource soundIn, BroadcastSettings settings) { Settings = settings; _soundIn = soundIn; _convertedSource = soundIn.ChangeSampleRate(Settings.SampleRate).ToSampleSource().ToWaveSource(Settings.BitDepth); if (settings.Channel == AudioChannel.Mono) { _convertedSource = _convertedSource.ToMono(); } else { _convertedSource = _convertedSource.ToStereo(); } _audioChunks = new ConcurrentQueue <byte[]>(); _soundIn.DataAvailable += SoundInDataAvailable; }
void Start() { // Timers lifeTime = new Stopwatch(); takeHealthTimer = new Stopwatch(); lifeTime.Start(); takeHealthTimer.Start(); // Setting up the startup state state = new AgentState { hydrationLevel = 35, foodSupply = 50, happy = false, isAtDisco = false }; // Creating the default strategy behaviours walkAround = new WalkAroundBehaviour(GetComponent <NavMeshAgent>()); eatFood = new EatNearbyFoodBehaviour(GetComponent <NavMeshAgent>(), transform, state); findWater = new GetWaterBehaviour(GetComponent <NavMeshAgent>(), transform, state); awayFromMonster = new RunAwayFromMonster(GetComponent <NavMeshAgent>(), transform); List <AgentBehaviour> behaviours = new List <AgentBehaviour> { walkAround, eatFood, findWater, awayFromMonster }; homeAndRest = new GetHomeAndRestBehaviour(GetComponent <NavMeshAgent>(), restingPlace, state); // Added later to the default strategy defaultStrategy = new BehaviourStrategy(behaviours, (state) => { return(true); }); ControlCenter = new ControlCenter(gameObject, defaultStrategy); ControlCenter.SetStateObject(state); // Making additional strategies IStrategyManager strategyManager = ControlCenter.StrategyManager; strategyManager.EnableMultipleStrategies = true; AgentBehaviour goToDisco = new GoToDiscoBehaviour(GetComponent <NavMeshAgent>(), disco); AgentBehaviour dance = new DanceBehaviour(ControlCenter.CommunicationManager, GetComponent <NavMeshAgent>(), gameObject, state); AgentBehaviour goHomeAndSleep = new GetHomeAndSleepBehaviour(GetComponent <NavMeshAgent>(), restingPlace, state); List <AgentBehaviour> nightTimeStrategy = new List <AgentBehaviour> { goToDisco, dance, goHomeAndSleep }; BehaviourStrategy strategy = new BehaviourStrategy(nightTimeStrategy, (state) => { if (GameManager.isNight) { return(true); } else { return(false); } }); strategyManager.AddAdditionalStrategy(strategy); // Setting up the communication manager ICommunicationManager communicationManager = ControlCenter.CommunicationManager; communicationManager.EnableBroadcasting = true; BroadcastSettings settings = new BroadcastSettings { AgentTag = "Agent", BroadcastRadius = 20 }; settings.SetSuppressibleBehaviours(new List <AgentBehaviour> { dance, goToDisco }); communicationManager.SetBroadcastSettings(settings); // Add arbitration rules ControlCenter.ArbitrationManager.EnableArbitrationRules = true; ControlCenter.ArbitrationManager.AddArbitrationRule((inputBehaviors) => { if (inputBehaviors.Contains(findWater) && inputBehaviors.Contains(awayFromMonster)) { List <AgentBehaviour> toExecute = new List <AgentBehaviour> { findWater }; return(new ArbitrationRule(toExecute, true)); } return(default);