Example #1
0
 private static void UpdateVolume(SoundData sData, MyAudioEffect.SoundEffect effect, float effPosition)
 {
     if (effect.VolumeCurve != null)
     {
         sData.Sound.SetVolume(sData.OrigVolume * effect.VolumeCurve.Evaluate(effPosition));
     }
 }
Example #2
0
 private static void UpdateFilter(SoundData sData, MyAudioEffect.SoundEffect effect)
 {
     if (effect.Filter != MyAudioEffect.FilterType.None)
     {
         if (!sData.CurrentFilter.HasValue)
         {
             sData.CurrentFilter = new FilterParameters()
             {
                 Frequency = effect.Frequency,
                 OneOverQ  = effect.OneOverQ,
                 Type      = (FilterType)effect.Filter
             };
         }
         sData.Sound.Voice.SetFilterParameters(sData.CurrentFilter.Value);
     }
 }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            var ob = builder as MyObjectBuilder_AudioEffectDefinition;

            Effect.EffectId = Id.SubtypeId;
            foreach (var soundsEffects in ob.Sounds)
            {
                var soundsEffects2 = new List <MyAudioEffect.SoundEffect>();
                foreach (var effect in soundsEffects.SoundEffects)
                {
                    var seff = new MyAudioEffect.SoundEffect();
                    MyCurveDefinition def;
                    if (!MyDefinitionManager.Static.TryGetDefinition <MyCurveDefinition>(new MyDefinitionId(typeof(MyObjectBuilder_CurveDefinition), effect.VolumeCurve), out def))
                    {
                        seff.VolumeCurve = null;
                    }
                    else
                    {
                        seff.VolumeCurve = def.Curve;
                    }
                    seff.Duration  = effect.Duration;
                    seff.Filter    = effect.Filter;
                    seff.Frequency = (float)(2 * Math.Sin(3.14 * effect.Frequency / 44100));

                    seff.OneOverQ  = 1 / effect.Q;
                    seff.StopAfter = effect.StopAfter;
                    soundsEffects2.Add(seff);
                }
                Effect.SoundsEffects.Add(soundsEffects2);
            }
            if (ob.OutputSound == 0)
            {
                Effect.ResultEmitterIdx = Effect.SoundsEffects.Count - 1;
            }
            else
            {
                Effect.ResultEmitterIdx = ob.OutputSound - 1;
            }
        }
Example #4
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            MyObjectBuilder_AudioEffectDefinition definition = builder as MyObjectBuilder_AudioEffectDefinition;

            this.Effect.EffectId = base.Id.SubtypeId;
            using (List <MyObjectBuilder_AudioEffectDefinition.SoundList> .Enumerator enumerator = definition.Sounds.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    List <MyAudioEffect.SoundEffect> item = new List <MyAudioEffect.SoundEffect>();
                    foreach (MyObjectBuilder_AudioEffectDefinition.SoundEffect effect in enumerator.Current.SoundEffects)
                    {
                        MyCurveDefinition         definition2;
                        MyAudioEffect.SoundEffect effect2 = new MyAudioEffect.SoundEffect {
                            VolumeCurve = MyDefinitionManager.Static.TryGetDefinition <MyCurveDefinition>(new MyDefinitionId(typeof(MyObjectBuilder_CurveDefinition), effect.VolumeCurve), out definition2) ? definition2.Curve : null,
                            Duration    = effect.Duration,
                            Filter      = effect.Filter,
                            Frequency   = (float)(2.0 * Math.Sin((3.14 * effect.Frequency) / 44100.0)),
                            OneOverQ    = 1f / effect.Q,
                            StopAfter   = effect.StopAfter
                        };
                        item.Add(effect2);
                    }
                    this.Effect.SoundsEffects.Add(item);
                }
            }
            if (definition.OutputSound == 0)
            {
                this.Effect.ResultEmitterIdx = this.Effect.SoundsEffects.Count - 1;
            }
            else
            {
                this.Effect.ResultEmitterIdx = definition.OutputSound - 1;
            }
        }