Пример #1
0
        private void Update()
        {
            CheckForErrorOnCall(MicStream.MicSetGain(InputGain));

            if (Input.GetKeyDown(KeyCode.Q))
            {
                CheckForErrorOnCall(MicStream.MicStartStream(KeepAllData, false));
            }
            else if (Input.GetKeyDown(KeyCode.W))
            {
                CheckForErrorOnCall(MicStream.MicStopStream());
            }
            else if (Input.GetKeyDown(KeyCode.A))
            {
                CheckForErrorOnCall(MicStream.MicStartRecording(SaveFileName, false));
            }
            else if (Input.GetKeyDown(KeyCode.S))
            {
                string outputPath = MicStream.MicStopRecording();
                Debug.Log("Saved microphone audio to " + outputPath);
                CheckForErrorOnCall(MicStream.MicStopStream());
            }

            this.gameObject.transform.localScale = new Vector3(minSize + averageAmplitude, minSize + averageAmplitude, minSize + averageAmplitude);
        }
Пример #2
0
 // on device, deal with all the ways that we could suspend our program in as few lines as possible
 private void OnApplicationPause(bool pause)
 {
     if (pause)
     {
         CheckForErrorOnCall(MicStream.MicPause());
     }
     else
     {
         CheckForErrorOnCall(MicStream.MicResume());
     }
 }
Пример #3
0
        private void OnAudioFilterRead(float[] buffer, int numChannels)
        {
            // this is where we call into the DLL and let it fill our audio buffer for us
            CheckForErrorOnCall(MicStream.MicGetFrame(buffer, buffer.Length, numChannels));

            float sumOfValues = 0;

            // figure out the average amplitude from this new data
            for (int i = 0; i < buffer.Length; i++)
            {
                sumOfValues += Mathf.Abs(buffer[i]);
            }
            averageAmplitude = sumOfValues / buffer.Length;
        }
Пример #4
0
        private void Awake()
        {
            CheckForErrorOnCall(MicStream.MicInitializeCustomRate((int)StreamType, AudioSettings.outputSampleRate));
            CheckForErrorOnCall(MicStream.MicSetGain(InputGain));

            if (!ListenToAudioSource)
            {
                this.gameObject.GetComponent <AudioSource>().volume = 0; // can set to zero to mute mic monitoring
            }

            if (AutomaticallyStartStream)
            {
                CheckForErrorOnCall(MicStream.MicStartStream(KeepAllData, false));
            }

            print("MicStream selector demo");
            print("press Q to start stream to audio source, W will stop that stream");
            print("It will start a recording and save it to a wav file. S will stop that recording.");
            print("Since this all goes through the AudioSource, you can mute the mic while using it there, or do anything else you would do with an AudioSource");
            print("In this demo, we start the stream automatically, and then change the size of the gameobject based on microphone signal amplitude");
        }
Пример #5
0
 private void OnDestroy()
 {
     CheckForErrorOnCall(MicStream.MicDestroy());
 }
Пример #6
0
 private void CheckForErrorOnCall(int returnCode)
 {
     MicStream.CheckForErrorOnCall(returnCode);
 }