Пример #1
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);
    }
Пример #2
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);
        }
    }