How to interpolate multiple sounds depending on float value

Hi. So, there is a variable number of car engine sounds (array). I would like to make the sounds smoothly flow from one to the other, depending on the engine RPM (a number from 0 to 1, where 0 = 0 RPM, 1 = for example 7000), like the way the FMOD program does it.


I have already written the basis of the script, but I have stalled on the calculations of the transitions. I hope someone can give me the magic formula…


I have attached a picture and my code for better understanding.



public class Car_Audio : MonoBehaviour
    {
        private CarController carController;

        [SerializeField] private AudioClip[] engineRPMSoundClips;

        [SerializeField, Range(0.35f, 0.75f)] private float minEngineVolume = 0.65f;
        [SerializeField, Range(0.75f, 1)] private float maxEngineVolume = 1;

        [HideInInspector] public List<AudioSource> engineRPMSoundSources;

        private float acceleration;

        private float verticalInput;
        private float currRPM;
        private float maxRPM;
        private int currGear;
        private bool isGearShifting;
        private bool isBraking;

        private void Start()
        {
            carController = FindObjectOfType<CarController>();
            maxRPM = carController.maxRPM;

            for (int i = 0; i < engineRPMSoundClips.Length; i++)
            {
                AudioSource tempSource = EngineAudioSourceSetUp(engineRPMSoundClips[i]);
                engineRPMSoundSources.Add(tempSource);
            }
        }

        private void FixedUpdate()
        {
            verticalInput = carController.verticalInput;
            currRPM = carController.currRPM;
            currGear = carController.currGear;
            isGearShifting = carController.isGearShifting;
            isBraking = carController.isBraking;

            if (verticalInput != 0 && !isGearShifting && !isBraking) acceleration = Mathf.Abs(Mathf.Clamp(verticalInput, minEngineVolume, maxEngineVolume));
            else acceleration = Mathf.Lerp(acceleration, minEngineVolume / 2, 0.1f);

            float currEngineRPMPosition = Mathf.Clamp(currRPM / maxRPM, 0, 1);

            foreach (AudioSource audSrc in engineRPMSoundSources)
            {
               audSrc.volume = ...
            }
        }

        private AudioSource EngineAudioSourceSetUp(AudioClip clip)
        {
            AudioSource source = gameObject.AddComponent<AudioSource>();
            source.clip = clip;
            source.volume = 0;
            source.spatialBlend = 1;
            source.loop = true;
            source.dopplerLevel = 0;
            source.time = Random.Range(0f, clip.length);
            source.minDistance = 50;
            source.maxDistance = 250;
            source.Play();
            return source;
        }
    }