//Called on teleport, so that the noise levels for the listener can be recalculated void updateListener() { currTrees.Clear(); foreach (Transform child in transform) { noiseParameters vehicleParams = child.GetComponent <noiseParameters>(); if (vehicleParams == null) { continue; } ; //Skip this object if parameters are missing NoiseSource noise = new NoiseSource(); noise.debug = debugMode; noise.origin = child.position; noise.controller = this; noise.node = new TreeNode <NoiseSource>(noise); noise.fireAt(listener, maximumDistance); if (reflections) { noise.reflectToward(listener, maximumDistance); } //Transform tree into audio generateAudio(child.gameObject, noise, vehicleParams); } }
Color calculateNoiseLevelColor(GameObject dataPoint) { List <float> pathSoundLevels = new List <float>(); foreach (Transform child in transform) { noiseParameters vehicleParams = child.GetComponent <noiseParameters>(); if (vehicleParams == null) { return(Color.white); } ; //Skip this object if parameters are missing NoiseSource noise = new NoiseSource(); noise.debug = false; noise.origin = child.position; noise.controller = this; noise.node = new TreeNode <NoiseSource>(noise); noise.fireAt(dataPoint, maximumDistance); if (reflections) { noise.reflectToward(dataPoint, maximumDistance); } NMBP2008 noiseModel = new NMBP2008(); List <ImageSource> images = noiseModel.calculateNoise(this, noise, vehicleParams); foreach (ImageSource img in images) { pathSoundLevels.Add(aWeighting(img)); } } if (pathSoundLevels.Count == 0) { return(Color.white); } //Long term sound level float finalSoundLevel = 0; foreach (float dezibel in pathSoundLevels) { finalSoundLevel = finalSoundLevel + Mathf.Pow(10.0f, (dezibel / 10)); } finalSoundLevel = 10.0f * Mathf.Log10(finalSoundLevel); //Map value to something between 0 and 1, then map to color //Same mapping as in NoisePlayer.cs //float value = Mathf.Pow(10f, finalSoundLevel / 20f) * 0.00002f / 2f; //float minHue = 60f / 360; //corresponds to green //float maxHue = 1f / 360; //corresponds to red //float hue = value * maxHue + (1 - value) * minHue; //return Color.HSVToRGB(hue, 1, 0.7f); //Debug.Log("Soundlevel: " + finalSoundLevel + " Value: " + value + " Hue: " + hue); //Map to different danger levels if (finalSoundLevel < 65) { return(Color.green); } else if (finalSoundLevel < 80) { return(Color.yellow); } else { return(Color.red); } }