// TODO: Check for more effective way of clearing removed drivers and adding new ones
        /// <summary>
        /// Called if the number of recording drivers is not equal to the number of drivers we have reference to.
        /// Will completely clear and refill our dictionary of drivers.
        /// Plus, it will stop all recording sounds.
        /// </summary>
        void RefreshRecordingDrivers()
        {
            if (OnDriverRefresh != null)
            {
                OnDriverRefresh.Invoke();
            }

            // Remove all our previous drivers as they're going to probably be in the wrong order or just not there anymore
            allRecordDrivers.Clear();

            // Get number of drivers
            RESULT result = RESULT.OK;

            result = LowLevelSystem.getRecordNumDrivers(out NumberOfDrivers, out NumberOfConnectedDrivers);
            CheckResult(result, "FMOD.GetRecordNumDrivers");

            // Add our new list of drivers
            for (int i = 0; i < NumberOfDrivers; i++)
            {
                RecordDriver tempDriver = new RecordDriver();
                LowLevelSystem.getRecordDriverInfo(i, out tempDriver.name, Settings.Instance.DriverNameLength, out tempDriver.guid, out tempDriver.systemRate, out tempDriver.speakerMode, out tempDriver.speakerModeChannels, out tempDriver.state);
                tempDriver.id = i;
                allRecordDrivers.Add(tempDriver.id, tempDriver);
            }

            // If there are sounds recording, stop them.
            // (Assumption) FMOD will stop recording anyway as connections will be lost
            if (recordingSounds.Count > 0)
            {
                foreach (KeyValuePair <int, RecordingSound> entry in recordingSounds)
                {
                    entry.Value.Stop();
                }
            }
        }
        /// <summary>
        /// Called when Extensions is initalised. Will not update removed or added drivers
        /// </summary>
        void GetRecordingInformation()
        {
            RESULT result = RESULT.OK;

            result = LowLevelSystem.getRecordNumDrivers(out NumberOfDrivers, out NumberOfConnectedDrivers);
            CheckResult(result, "FMOD.GetRecordNumDrivers");

            if (NumberOfDrivers == 0)
            {
                UnityEngine.Debug.LogWarning("FMOD Extensions: No recording drivers found!");
                return;
            }

            for (int i = 0; i < NumberOfDrivers; i++)
            {
                RecordDriver tempDriver = new RecordDriver();
                LowLevelSystem.getRecordDriverInfo(i, out tempDriver.name, Settings.Instance.DriverNameLength, out tempDriver.guid, out tempDriver.systemRate, out tempDriver.speakerMode, out tempDriver.speakerModeChannels, out tempDriver.state);
                tempDriver.id = i;

                if (!allRecordDrivers.ContainsKey(i))
                {
                    allRecordDrivers.Add(i, tempDriver);
                }
            }
        }
        /// <summary>
        /// Record what is coming in from the given driver
        /// </summary>
        /// <returns>The record.</returns>
        /// <param name="driver">Driver.</param>
        public static RecordingSound StartRecording(RecordDriver driver, ChannelGroup channelgroup = new ChannelGroup())
        {
            if (driver.id == -1)
            {
                return(new RecordingSound());
            }

            RESULT result = RESULT.OK;

            CREATESOUNDEXINFO exInfo = new CREATESOUNDEXINFO();

            exInfo.cbsize           = Marshal.SizeOf(exInfo);
            exInfo.numchannels      = driver.speakerModeChannels;
            exInfo.format           = SOUND_FORMAT.PCM16;
            exInfo.defaultfrequency = driver.systemRate;
            exInfo.length           = (uint)driver.systemRate * (uint)driver.speakerModeChannels * 16; // (FROM FMOD EXAMPLES): nativeRate * sizeof(short) * nativeChannels
                                                                                                       // I'm just saying 16 as that's the size of a short
            Sound sound;

            result = Instance.LowLevelSystem.createSound(IntPtr.Zero, MODE.LOOP_NORMAL | MODE.OPENUSER, ref exInfo, out sound);
            Instance.CheckResult(result, "FMOD.CreateSound");

            result = Instance.LowLevelSystem.recordStart(driver.id, sound, true);
            Instance.CheckResult(result, "FMOD.RecordStart");

            uint soundLength = 0;

            result = sound.getLength(out soundLength, TIMEUNIT.PCM);
            Instance.CheckResult(result, "Sound.GetLength");

            // Add our currently recording sound to our dictionary so we can check its record position and do stuff to it in update
            RecordingSound recordingSound = new RecordingSound
            {
                driver = driver,
                sound  = sound
            };

            if (channelgroup.hasHandle())
            {
                recordingSound.channelGroup = channelgroup;
            }

            RecordingSound temp = new RecordingSound();

            if (Instance.recordingSounds.TryGetValue(driver.id, out temp))
            {
                return(temp);
            }

            Instance.recordingSounds.Add(driver.id, recordingSound);
            return(recordingSound);
        }