Example #1
0
    // Initializes the source.
    private bool InitializeSource()
    {
        if (id < 0)
        {
            id = GvrAudio.CreateAudioSource(hrtfEnabled);
            if (id >= 0)
            {
                GvrAudio.UpdateAudioSource(id, this, currentOcclusion);
                audioSource.spatialize = true;
                audioSource.SetSpatializerFloat((int)GvrAudio.SpatializerData.Type,
                                                (float)GvrAudio.SpatializerType.Source);
                audioSource.SetSpatializerFloat((int)GvrAudio.SpatializerData.Gain,
                                                GvrAudio.ConvertAmplitudeFromDb(gainDb));
                audioSource.SetSpatializerFloat((int)GvrAudio.SpatializerData.MinDistance,
                                                sourceMinDistance);
                audioSource.SetSpatializerFloat((int)GvrAudio.SpatializerData.ZeroOutput, 0.0f);

                // Source id must be set after all the spatializer parameters, to ensure that the source is
                // properly initialized before processing.
                audioSource.SetSpatializerFloat((int)GvrAudio.SpatializerData.Id, (float)id);
            }
        }

        return(id >= 0);
    }
 void Update()
 {
     // Update occlusion state.
     if (!occlusionEnabled)
     {
         currentOcclusion = 0.0f;
     }
     else if (Time.time >= nextOcclusionUpdate)
     {
         nextOcclusionUpdate = Time.time + GvrAudio.occlusionDetectionInterval;
         currentOcclusion    = GvrAudio.ComputeOcclusion(transform);
     }
     // Update source.
     if (!isPlaying && !isPaused)
     {
         Stop();
     }
     else
     {
         audioSource.SetSpatializerFloat((int)GvrAudio.SpatializerData.Gain,
                                         GvrAudio.ConvertAmplitudeFromDb(gainDb));
         audioSource.SetSpatializerFloat((int)GvrAudio.SpatializerData.MinDistance,
                                         sourceMinDistance);
         GvrAudio.UpdateAudioSource(id, this, currentOcclusion);
     }
 }
Example #3
0
 // Initializes given channel set of the soundfield.
 private void InitializeChannelSet(AudioSource source, int channelSet)
 {
     source.spatialize = true;
     source.SetSpatializerFloat((int)GvrAudio.SpatializerData.Type,
                                (float)GvrAudio.SpatializerType.Soundfield);
     source.SetSpatializerFloat((int)GvrAudio.SpatializerData.NumChannels,
                                (float)GvrAudio.numFoaChannels);
     source.SetSpatializerFloat((int)GvrAudio.SpatializerData.ChannelSet, (float)channelSet);
     source.SetSpatializerFloat((int)GvrAudio.SpatializerData.Gain,
                                GvrAudio.ConvertAmplitudeFromDb(gainDb));
     source.SetSpatializerFloat((int)GvrAudio.SpatializerData.ZeroOutput, 0.0f);
     // Soundfield id must be set after all the spatializer parameters, to ensure that the soundfield
     // is properly initialized before processing.
     source.SetSpatializerFloat((int)GvrAudio.SpatializerData.Id, (float)id);
 }
 void Update()
 {
     // Update soundfield.
     if (!isPlaying && !isPaused)
     {
         Stop();
     }
     else
     {
         for (int channelSet = 0; channelSet < audioSources.Length; ++channelSet)
         {
             audioSources[channelSet].SetSpatializerFloat((int)GvrAudio.SpatializerData.Gain,
                                                          GvrAudio.ConvertAmplitudeFromDb(gainDb));
         }
     }
 }