/// <summary>
    /// Raises the audio filter read event.
    /// </summary>
    /// <param name="data">Data.</param>
    /// <param name="channels">Channels.</param>
    void OnAudioFilterRead(float[] data, int channels)
    {
        // Do not spatialize if we are not initialized, or if there is no
        // audio source attached to game object
        if ((OVRVoiceMod.IsInitialized() != OVRVoiceMod.ovrVoiceModSuccess) || audioSource == null)
        {
            return;
        }

        // increase the gain of the input to get a better signal input
        for (int i = 0; i < data.Length; ++i)
        {
            data[i] = data[i] * gain;
        }

        // Send data into VoiceMod context for processing (if context is not 0)
        lock (this)
        {
            if (context != 0)
            {
                OVRVoiceMod.ProcessFrameInterleaved(context, data);
            }
        }

        // Turn off output (so that we don't get feedback from a mic too close to speakers)
        if (audioMute == true)
        {
            for (int i = 0; i < data.Length; ++i)
            {
                data[i] = data[i] * 0.0f;
            }
        }
    }
    // * * * * * * * * * * * * *
    // Public Functions

    /// <summary>
    /// Sends the parameter.
    /// </summary>
    /// <returns>The parameter.</returns>
    /// <param name="parameter">Parameter.</param>
    /// <param name="value">Value.</param>
    public int SendParameter(ovrVoiceModParams parameter, int value)
    {
        if (OVRVoiceMod.IsInitialized() != OVRVoiceMod.ovrVoiceModSuccess)
        {
            return((int)OVRVoiceMod.ovrVoiceModError.Unknown);
        }

        return(OVRVoiceMod.SendParameter(context, (int)parameter, value));
    }
    /// <summary>
    /// Gets the average abs volume.
    /// </summary>
    /// <returns>The average abs volume.</returns>
    public float GetAverageAbsVolume()
    {
        if (context == 0)
        {
            return(0.0f);
        }

        float V = prevVol * 0.8f + OVRVoiceMod.GetAverageAbsVolume(context) * 0.2f;

        prevVol = V;

        return(V);
    }
 /// <summary>
 /// Raises the destroy event.
 /// </summary>
 void OnDestroy()
 {
     // Create the context that we will feed into the audio buffer
     lock (this)
     {
         if (context != 0)
         {
             if (OVRVoiceMod.DestroyContext(context) != OVRVoiceMod.ovrVoiceModSuccess)
             {
                 Debug.Log("OVRVoiceModContext.OnDestroy ERROR: Could not delete VoiceMod context.");
             }
         }
     }
 }
    /// <summary>
    /// Start this instance.
    /// Note: make sure to always have a Start function for classes that have editor scripts.
    /// </summary>
    void Start()
    {
        // Create the context that we will feed into the audio buffer
        lock (this)
        {
            if (context == 0)
            {
                if (OVRVoiceMod.CreateContext(ref context) != OVRVoiceMod.ovrVoiceModSuccess)
                {
                    Debug.Log("OVRVoiceModContext.Start ERROR: Could not create VoiceMod context.");
                    return;
                }
            }
        }

        // Add a listener to the OVRMessenger for touch events
        OVRMessenger.AddListener <OVRTouchpad.TouchEvent>("Touchpad", LocalTouchEventCallback);

        // VoiceMod: Set the current state of the voice mod as set in the inspector
        SendVoiceModUpdate();
    }
Example #6
0
    // * * * * * * * * * * * * *
    // MonoBehaviour overrides

    /// <summary>
    /// Awake this instance.
    /// </summary>
    void Awake()
    {
        // We can only have one instance of OVRLipSync in a scene (use this for local property query)
        if (sInstance == null)
        {
            sInstance = this;
        }
        else
        {
            Debug.LogWarning(System.String.Format("OVRVoiceMod Awake: Only one instance of OVRVoiceMod can exist in the scene."));
            return;
        }

        int samplerate;
        int bufsize;
        int numbuf;

        // Get the current sample rate
        samplerate = AudioSettings.outputSampleRate;
        // Get the current buffer size and number of buffers
        AudioSettings.GetDSPBufferSize(out bufsize, out numbuf);

        String str = System.String.Format
                         ("OvrVoiceMod Awake: Queried SampleRate: {0:F0} BufferSize: {1:F0}", samplerate, bufsize);

        Debug.LogWarning(str);

        sOVRVoiceModInit = ovrVoiceModDll_Initialize(samplerate, bufsize);

        if (sOVRVoiceModInit != ovrVoiceModSuccess)
        {
            Debug.LogWarning(System.String.Format
                                 ("OvrVoiceMod Awake: Failed to init VoiceMod library"));
        }

        // Important: Use the touchpad mechanism for input, call Create on the OVRTouchpad helper class
        OVRTouchpad.Create();
    }