/// <summary> /// Find the microphone to use and return it's sample rate /// </summary> /// <returns>New Mic's sample rate</returns> internal int GetCurrentMicSampleRate() { //Make sure the requested mic index exists if (Microphone.devices.Length <= MicNumberToUse) { return(-1); } int minFreq; int maxFreq; Microphone.GetDeviceCaps(_currentMic, out minFreq, out maxFreq); int micSampleRate = MumbleClient.GetNearestSupportedSampleRate(maxFreq); NumSamplesPerOutgoingPacket = MumbleConstants.NUM_FRAMES_PER_OUTGOING_PACKET * micSampleRate / 100; print("Device: " + _currentMic + " has freq: " + minFreq + " to " + maxFreq + " setting to: " + micSampleRate); _currentMic = Microphone.devices[MicNumberToUse]; _voiceHoldSamples = Mathf.RoundToInt(micSampleRate * VoiceHoldSeconds); if (SendAudioOnStart && (VoiceSendingType == MicType.AlwaysSend || VoiceSendingType == MicType.Amplitude)) { StartSendingAudio(micSampleRate); } return(micSampleRate); }
/// <summary> /// Find the microphone to use and return it's sample rate /// </summary> /// <returns>New Mic's sample rate</returns> internal int InitializeMic() { //Make sure the requested mic index exists if (Microphone.devices.Length <= MicNumberToUse) { Debug.LogWarning("No microphone connected!"); return(-1); } _currentMic = Microphone.devices[MicNumberToUse]; int minFreq; int maxFreq; Microphone.GetDeviceCaps(_currentMic, out minFreq, out maxFreq); int micSampleRate = MumbleClient.GetNearestSupportedSampleRate(maxFreq); NumSamplesPerOutgoingPacket = MumbleConstants.NUM_FRAMES_PER_OUTGOING_PACKET * micSampleRate / 100; if (micSampleRate != 48000) { Debug.LogWarning("Using a possibly unsupported sample rate of " + micSampleRate + " things might get weird"); } Debug.Log("Device: " + _currentMic + " has freq: " + minFreq + " to " + maxFreq + " setting to: " + micSampleRate); _voiceHoldSamples = Mathf.RoundToInt(micSampleRate * VoiceHoldSeconds); if (SendAudioOnStart && (VoiceSendingType == MicType.AlwaysSend || VoiceSendingType == MicType.Amplitude)) { StartSendingAudio(micSampleRate); } return(micSampleRate); }