public bool StartRecording()
    {
        if (NetworkId == -1 && !VoiceChatSettings.Instance.LocalDebug)
        {
            Debug.LogError("NetworkId is -1");
            return(false);
        }

        if (recording)
        {
            Debug.LogError("Already recording");
            return(false);
        }

        targetFrequency  = VoiceChatSettings.Instance.Frequency;
        targetSampleSize = VoiceChatSettings.Instance.SampleSize;

        int minFreq;
        int maxFreq;

        Microphone.GetDeviceCaps(Device, out minFreq, out maxFreq);

        recordFrequency  = minFreq == 0 && maxFreq == 0 ? 44100 : maxFreq;
        recordSampleSize = recordFrequency / (targetFrequency / targetSampleSize);

        clip         = Microphone.Start(Device, true, 1, recordFrequency);
        sampleBuffer = new float[recordSampleSize];
        fftBuffer    = new float[VoiceChatUtils.ClosestPowerOfTwo(targetSampleSize)];
        recording    = true;

        return(recording);
    }
Exemple #2
0
    public bool StartRecording()
    {
        if (NetworkId == -1 && !VoiceChatSettings.Instance.LocalDebug)
        {
            Debug.LogError("NetworkId is -1");
            return(false);
        }

        if (recording)
        {
            Debug.LogError("Already recording");
            return(false);
        }

        if (Microphone.devices.Length == 0)
        {
            if (!reportedInitErrors)
            {
                Debug.LogError("No Microphone found");
                AnnouncementManager.Inst.Announce("Warning", "No Microphone Found on this computer, your voice will not be heard by others");
                UpdateUserMicHWI("(none)");
                reportedInitErrors = true;
            }
            return(false);
        }

        targetFrequency  = VoiceChatSettings.Instance.Frequency;
        targetSampleSize = VoiceChatSettings.Instance.SampleSize;

        int minFreq;
        int maxFreq;

        Microphone.GetDeviceCaps(Device, out minFreq, out maxFreq);

        recordFrequency  = minFreq == 0 && maxFreq == 0 ? 44100 : maxFreq;
        recordSampleSize = recordFrequency / (targetFrequency / targetSampleSize);

        clip         = Microphone.Start(Device, true, 1, recordFrequency);
        sampleBuffer = new float[recordSampleSize];
        fftBuffer    = new float[VoiceChatUtils.ClosestPowerOfTwo(targetSampleSize)];
        recording    = true;

        return(recording);
    }