コード例 #1
0
    IEnumerator LoadAudioClips()
    {
        for (int i = 0; i < slots.Length; i++)
        {
            AudioDataSaver.LoadAudioClipFromDisk(slots[i].GetComponent <AudioSource>(), i.ToString() + ".dat");
        }

        //wait for end of frame so that all the Start() has been called
        yield return(new WaitForEndOfFrame());

        //finish loading
        stateChangedEvent(SoundboardState.Default);

        //deactivate loading sceen
        yield return(new WaitForEndOfFrame());

        loadingCanvas.SetActive(false);
    }
コード例 #2
0
    void EditStateTouchUp()
    {
        //if is not recording, return
        if (!Microphone.IsRecording(null))
        {
            return;
        }

        //change back the color of the inner circle
        innerCircle.color = transparentColor;

        //get mic position (in samples)
        int lastTime = Microphone.GetPosition(null);

        //end mic
        Microphone.End(null);

        //if too short, return
        if (lastTime == 0)
        {
            return;
        }

        //get the full samples and store them in an array
        float[] samples = new float[_audioSouce.clip.samples];
        _audioSouce.clip.GetData(samples, 0);

        //store the clipped samples to a new array
        float[] clipSamples = new float[lastTime];
        Array.Copy(samples, clipSamples, clipSamples.Length);

        //create a new AudioClip and set the data from the clipped samples
        _audioSouce.clip = AudioClip.Create("new", clipSamples.Length, 1, 44100, false);
        _audioSouce.clip.SetData(clipSamples, 0);

        //save (serialize) AudioClipq to local disk
        AudioDataSaver.SaveAudioClipToDisk(_audioSouce.clip, slotNum.ToString() + ".dat");

        //change state
        SoundboardManager.ChangeState(SoundboardManager.SoundboardState.Default);
    }