예제 #1
0
 //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);
     }
 }
예제 #2
0
    public List <ImageSource> calculateNoise(NoiseController controller, NoiseSource src, noiseParameters vehicleParams)
    {
        currController = controller;
        currSource     = src;
        currVehicle    = vehicleParams;
        images         = new List <ImageSource>();
        List <propagationStep> start = new List <propagationStep>();

        //turn propagation paths into image sources
        //Recursively work through to the leafs, then add to images
        foreach (TreeNode <NoiseSource> node in src.node.Children)
        {
            pathFromTo(src.node, src.node, node, 0, 0, start);
        }
        //After this loop, the list of images is populated
        return(images);
    }
예제 #3
0
    private void generateAudio(GameObject noiseObject, NoiseSource noiseTree, noiseParameters vehicleParams)
    {
        //Save tree
        currTrees.Add(noiseTree);

        //Convert tree of noise propagation paths into list of image sources for audio playback
        NMBP2008           noiseModel   = new NMBP2008();
        List <ImageSource> audioSources = noiseModel.calculateNoise(this, noiseTree, vehicleParams);

        //Check if sound is already running
        NoisePlayer nP = noiseObject.GetComponent <NoisePlayer>();

        if (nP == null)
        {
            nP = noiseObject.AddComponent <NoisePlayer>();
        }
        nP.play(audioSources, audioSourceObject);
    }
예제 #4
0
    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);
        }
    }