Exemplo n.º 1
0
        /**
         * every 2 seconds, one out of 3 different sounds should play
         */
        public SoundEvent Test_MorphingSoundEvent()
        {
            SoundEvent soundScript = new SoundEvent("Test_MorphingSoundEvent");
            MorphingSoundEvent mEv = new MorphingSoundEvent();

            // component 1
            SampleSoundEvent evTwoPing = new SampleSoundEvent("synthetic_twoPing.wav");
            // component 2
            SampleSoundEvent evDing = new SampleSoundEvent("ding.wav");
            evDing.Amplitude = 0.5;
            // comp3
            SampleSoundEvent evEmerald = new SampleSoundEvent("tail_emerald2.wav");
            evEmerald.Amplitude = 0.2;

            // add comps to the morphing event
            mEv.AddEvent(0, evTwoPing);
            mEv.AddEvent(0, evDing);
            mEv.AddEvent(0, evEmerald);

            // repeat this event lots of times to test
            for(double t= 0; t < 300 ; t+=0.5 )
                soundScript.AddEvent(t, new MorphingSoundEvent(mEv ));

            return soundScript;
        }
Exemplo n.º 2
0
 /// <summary>
 /// simple sample play test
 /// </summary>
 /// <returns></returns>
 public SoundEvent Test_Sample()
 {
     SoundEvent soundScript = new SoundEvent("Test_Sample");
     SoundEvent evDing = new SampleSoundEvent("ambient-echoing-ding.wav");
     soundScript.AddEvent(0, evDing);
     return soundScript;
 }
Exemplo n.º 3
0
 public SoundEvent Test_OverlapInTime()
 {
     SoundEvent soundScript = new SoundEvent("Test_OverlapInTime");
     SampleSoundEvent evDing = new SampleSoundEvent("ding.wav");
     for (double t = 0; t < 300; t += 0.333333)
         soundScript.AddEvent(t, new SampleSoundEvent(evDing));
     return soundScript;
 }
Exemplo n.º 4
0
 /**
  * add a new soundevent to this track at specified beat count using ACID Music Studio Beat RUler notation
  * (shorthand notation method name)
  */
 public double b(double beatCount, SoundEvent ev)
 {
     // translate beats to time
     double t = Beat.BeatToTime(beatCount, bpm);
     // add event to track
     this.AddEvent(t, ev);
     return t;
 }
Exemplo n.º 5
0
        /**
         * add a new soundevent to this track at specified beat count using ACID Music Studio Beat RUler notation
         * (shorthand notation method name)
         */
        public double b(double beatCount, SoundEvent ev)
        {
            // translate beats to time
            double t = Beat.BeatToTime(beatCount, bpm);

            // add event to track
            this.AddEvent(t, ev);
            return(t);
        }
Exemplo n.º 6
0
 /**
  * copy constructor - single level is copied (children not copied)
  */
 public SoundEvent(SoundEvent ev)
 {
     CreateID();
     _ampl = ev._ampl;
     _children = ev._children.Clone();
     _duration = ev._duration;
     _isActive = ev._isActive;
     _pan = ev._pan;
     _repeats = ev._repeats;
 }
Exemplo n.º 7
0
 internal override void NotifyNewParent(SoundEvent parent)
 {
     base.NotifyNewParent(parent);
     if (parent is SampleSoundEvent)
     {
         // yes, we can attach effect here
         SampleSoundEvent ev = (SampleSoundEvent)parent;
         ev.AddDSP(_dsp);
     }
 }
Exemplo n.º 8
0
 /**
  * copy constructor - single level is copied (children not copied)
  */
 public SoundEvent(SoundEvent ev)
 {
     CreateID();
     _ampl     = ev._ampl;
     _children = ev._children.Clone();
     _duration = ev._duration;
     _isActive = ev._isActive;
     _pan      = ev._pan;
     _repeats  = ev._repeats;
 }
Exemplo n.º 9
0
 internal override void NotifyNewParent(SoundEvent parent)
 {
     base.NotifyNewParent(parent);
     if (parent is SampleSoundEvent)
     {
         // yes, we can attach effect here
         SampleSoundEvent ev = (SampleSoundEvent)parent;
         ev.AddDSP(_dsp);
     }
 }
Exemplo n.º 10
0
 public GameMusic()
 {
     //track = TTengineMaster.ActiveGame.Content.Load<Song>("A01");
     soundScript = new SoundEvent("GameMusic");
     SampleSoundEvent ev1 = new SampleSoundEvent("ductia.ogg");
     soundScript.AddEvent(2, ev1);
     soundScript.AddEvent(166, ev1);
     soundScript.AddEvent(332, ev1);
     soundScript.AddEvent(498, ev1);
     soundScript.AddEvent(664, ev1);
 }
        public override void AddEvent(double t, SoundEvent child)
        {
            if (t > 0) throw new Exception("MorphingSoundEvent does not support t > 0");
            base.AddEvent(t, child);
            // specific behaviour: _all_ child events are as long as the longest child already there.
            double longestChildDuration = this.Duration; // as a side effect of AddEvent, this.Duration is updated.

            // update _all_ children now
            foreach (KeyValuePair<double, List<SoundEvent>> pair in _children)
            {
                foreach (SoundEvent c in pair.Value)
                {
                    c.UpdateDuration(longestChildDuration);
                }
            }
        }
Exemplo n.º 12
0
 internal override void NotifyNewParent(SoundEvent parent)
 {
     base.NotifyNewParent(parent);
     if (_modif == Modifier.DSP_PARAM)
     {
         if (parent is DSPSoundEvent)
         {
             _parentsDSP = (DSPSoundEvent)parent;
         }
         if (parent is OscSoundEvent)
         {
             _parentsOsc = (OscSoundEvent)parent;
         }
     }
     // else TODO
 }
Exemplo n.º 13
0
        /**
         * simple test of generic Repeat feature - on a SoundEvent. Not directly applied on SampleSoundEvent here.
         */
        public SoundEvent Test_Repeat()
        {
            SoundEvent soundScript = new SoundEvent("Test_Repeat");
            // try a once event
            SampleSoundEvent evDing = new SampleSoundEvent("ambient-echoing-ding.wav");
            evDing.Repeat = 1;
            soundScript.AddEvent(1, evDing);

            SampleSoundEvent evDing2 = new SampleSoundEvent(evDing);
            SoundEvent dingHolderEv = new SoundEvent();
            dingHolderEv.AddEvent(0, evDing2);
            dingHolderEv.Repeat = 10;
            soundScript.AddEvent(5, dingHolderEv);

            soundScript.UpdateDuration(60);
            return soundScript;
        }
Exemplo n.º 14
0
 /** oscillator with varying frequency */
 public SoundEvent Test_OscFrequency()
 {
     SoundEvent soundScript = new SoundEvent("Test_OscFrequency");
     OscSoundEvent oscEv = new OscSoundEvent(320);
     oscEv.SetOscType(OscSoundEvent.OscType.SINE);
     //oscEv.SetParameter((int)FMOD.DSP_OSCILLATOR.TYPE, 1);
     oscEv.Amplitude = 0.15;
     oscEv.UpdateDuration(6);
     SignalSoundEvent sEv = new SignalSoundEvent(SignalSoundEvent.Modifier.AMPLITUDE,
         new Signal(new List<double>() { 0, 0,  5.5,  1.0, 6.0, 0, 7.0, 0 }));
     SignalSoundEvent sEv2 = new SignalSoundEvent(SignalSoundEvent.Modifier.DSP_PARAM,
         new Signal(new List<double>() { 0, 320, 1.0, 543, 2, 109, 2.5, 737.3, 6.0, 210 }), (int)FMOD.DSP_OSCILLATOR.RATE);
     oscEv.AddEvent(0.0, sEv);
     oscEv.AddEvent(0.0, sEv2);
     soundScript.AddEvent(1.0, oscEv);
     //soundScript.AddEvent(3.0, new OscSoundEvent(oscEv));
     soundScript.UpdateDuration(10);
     return soundScript;
 }
Exemplo n.º 15
0
        public override void AddEvent(double t, SoundEvent child)
        {
            if (t > 0)
            {
                throw new Exception("MorphingSoundEvent does not support t > 0");
            }
            base.AddEvent(t, child);
            // specific behaviour: _all_ child events are as long as the longest child already there.
            double longestChildDuration = this.Duration; // as a side effect of AddEvent, this.Duration is updated.

            // update _all_ children now
            foreach (KeyValuePair <double, List <SoundEvent> > pair in _children)
            {
                foreach (SoundEvent c in pair.Value)
                {
                    c.UpdateDuration(longestChildDuration);
                }
            }
        }
Exemplo n.º 16
0
        /**
         * called internally from Render() method, by any event that needs/wants to render its child events
         */
        internal override bool RenderChildren(RenderParams rp, RenderCanvas canvas)
        {
            if (_children.Count() == 0)
            {
                return(false);
            }

            // check if a child for rendering is already selected: if not, select one
            if (_childSelected == null)
            {
                // select one child effect random or in sequence, and see if it has to be played now
                double myRpTime = rp.Time;
                Random rnd      = new Random();
                int    idx      = rnd.Next(_children.Count());
                KeyValuePair <double, List <SoundEvent> > kvPair = _children.ElementAt(idx);
                List <SoundEvent> evs = kvPair.Value;
                idx            = rnd.Next(evs.Count());
                _childSelected = evs.ElementAt(idx);
            }

            SoundEvent ev = _childSelected;

            // check if we are in the time range where the effect can work
            double evEndTime = 0.0 + ev.Duration;               ///_timeSpeedupFactor ;

            if (evEndTime + RENDER_SAFETY_MARGIN_SEC > rp.Time) // if end time lies in the future...
            {
                // --render the child effect, shifted in time/pan/amplitude by use of rp.
                RenderParams rpChild = new RenderParams(rp);
                rpChild.Time = (rp.Time - 0.0);  // only time is set for each child separately. Rest is same.
                bool wasActive = ev.Render(rpChild, canvas);
                if (!wasActive)
                {
                    _childSelected = null; // reset back - next time, another event may be selected into _childSelected
                }
                return(wasActive);
            }
            else
            {
                _childSelected = null; // reset back - next time, another event may be selected into _childSelected
            }
            return(false);
        } // end method
        /**
        * called internally from Render() method, by any event that needs/wants to render its child events
        */
        internal override bool RenderChildren(RenderParams rp, RenderCanvas canvas)
        {
            if (_children.Count() == 0)
                return false;

            // check if a child for rendering is already selected: if not, select one
            if (_childSelected == null)
            {
                // select one child effect random or in sequence, and see if it has to be played now
                double myRpTime = rp.Time;
                Random rnd = new Random();
                int idx = rnd.Next(_children.Count());
                KeyValuePair<double, List<SoundEvent>> kvPair = _children.ElementAt(idx);
                List<SoundEvent> evs = kvPair.Value;
                idx = rnd.Next(evs.Count());
                _childSelected = evs.ElementAt(idx);
            }

            SoundEvent ev = _childSelected;

            // check if we are in the time range where the effect can work
            double evEndTime = 0.0 + ev.Duration; ///_timeSpeedupFactor ;
            if (evEndTime + RENDER_SAFETY_MARGIN_SEC > rp.Time)  // if end time lies in the future...
            {
                // --render the child effect, shifted in time/pan/amplitude by use of rp.
                RenderParams rpChild = new RenderParams(rp);
                rpChild.Time = (rp.Time - 0.0);  // only time is set for each child separately. Rest is same.
                bool wasActive= ev.Render(rpChild, canvas);
                if (!wasActive)
                {
                    _childSelected = null; // reset back - next time, another event may be selected into _childSelected
                }
                return wasActive;
            }
            else
            {
                _childSelected = null; // reset back - next time, another event may be selected into _childSelected
            }
            return false;
        }
Exemplo n.º 18
0
 protected void Play(int effect, float volume)
 {
     SoundEvent sev = new SoundEvent();
     sev.AddEvent(0f,soundsBank[effect]);
     sev.Amplitude = volume;
     soundScript.AddEvent(SimTime + 0.020f, sev);
 }
Exemplo n.º 19
0
 public GardenMusic()
 {
     soundScript = new SoundEvent("GardenMusic");
     rp.Ampl = 1;
     PlayDefaultSong();
 }
Exemplo n.º 20
0
 /** add a SoundEvent as a child at specified relative Time t */
 public virtual void AddEvent(double t, SoundEvent child)
 {
     _children.Add(t, child);
     child.NotifyNewParent(this);
     UpdateDuration(t + child.Duration);
 }
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (Keyboard.GetState().IsKeyDown(Keys.Escape) || GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // User can select one of the test methods to play
            if ( gameTime.TotalGameTime.TotalSeconds > timeLastSelected + 0.5)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.PageUp))
                {
                    testIndex++;
                    if (testIndex >= soundScripts.Count)
                        testIndex = 0;
                    timeLastSelected = gameTime.TotalGameTime.TotalSeconds;
                    rp.Time = 0;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.PageDown))
                {
                    testIndex--;
                    if (testIndex < 0)
                        testIndex = soundScripts.Count - 1;
                    timeLastSelected = gameTime.TotalGameTime.TotalSeconds;
                    rp.Time = 0;
                }
            }

            // select a sound script and render it.
            rp.Time += gameTime.ElapsedGameTime.TotalSeconds;
            soundScript = soundScripts[testIndex];
            musicEngine.Render(soundScript,rp);

            // call base update
            base.Update(gameTime);
        }
Exemplo n.º 22
0
 /**
  * called internally when adding this event as a child to a parent event
  */
 internal virtual void NotifyNewParent(SoundEvent parent)
 {
     _parent = parent;
 }
Exemplo n.º 23
0
 /**
  * add a new soundevent to this track at specified real time (shorthand notation method name)
  */
 public double t(double time, SoundEvent ev)
 {
     this.AddEvent(time, ev);
     return time;
 }
Exemplo n.º 24
0
        /**
         * simple test of Repeat feature for SampleSoundEvent - using the better audio-engine looping instead!
         * there is an audible difference - this one better than Test_Repeat.
         */
        public SoundEvent Test_RepeatForSampleSoundEvents()
        {
            SoundEvent soundScript = new SoundEvent("Test_RepeatForSampleSoundEvents");
            // try a once event
            SampleSoundEvent evDing = new SampleSoundEvent("ding.wav");
            evDing.Repeat = 1;
            soundScript.AddEvent(1, evDing);

            SampleSoundEvent evDing2 = new SampleSoundEvent(evDing);
            evDing2.Repeat = 10;
            soundScript.AddEvent(5, evDing2);

            soundScript.UpdateDuration(60);
            return soundScript;
        }
Exemplo n.º 25
0
 public AudioComp(SoundEvent script)
 {
     this.AudioScript = script;
 }
Exemplo n.º 26
0
        /**
         * complex script sequence for testing
         */
        public SoundEvent Test_Script1()
        {
            SoundEvent soundScript = new SoundEvent("Test_Script1");
            SampleSoundEvent evDing = new SampleSoundEvent("ding.wav");
            SampleSoundEvent evOrgan = new SampleSoundEvent("hammond-loop.wav");

            // dsp effects
            SoundEvent evEcho = new DSPSoundEvent(FMOD.DSP_TYPE.ECHO);
            //evEmerald.AddEvent(0,echo1);
            SoundEvent evChorus = new DSPSoundEvent(FMOD.DSP_TYPE.CHORUS);
            evChorus.UpdateDuration(10.0);
            evOrgan.AddEvent(evOrgan.Duration, evChorus);
            DSPSoundEvent evLP = new DSPSoundEvent(FMOD.DSP_TYPE.LOWPASS);
            evLP.UpdateDuration(10.0);
            Signal sigLP = new Signal(new List<double>() { 0,300, 3,1500, 7,300, 20,15050 });
            SignalSoundEvent evLPsig = new SignalSoundEvent(SignalSoundEvent.Modifier.DSP_PARAM, sigLP, (int)FMOD.DSP_LOWPASS.CUTOFF);
            evLP.AddEvent(0, evLPsig);
            evOrgan.AddEvent(0, evLP);

            evOrgan.Amplitude = 0.4;
            evOrgan.Repeat = 10;

            soundScript.AddEvent(0.5, evOrgan);

            // create an event defining a signal, which modifies amplitude - linear fade in!
            Signal sig = new Signal(new List<double>() {0,0, 4,1  } );
            SignalSoundEvent evsig = new SignalSoundEvent(SignalSoundEvent.Modifier.AMPLITUDE, sig);
            evOrgan.AddEvent(0.0, evsig);

            // composite event
            SoundEvent evc = new SoundEvent();
            evc.AddEvent(0, evDing);
            evDing = new SampleSoundEvent(evDing); evDing.Amplitude = 0.8; evDing.Pan = -0.5;
            evc.AddEvent(0.33, evDing);
            evDing = new SampleSoundEvent(evDing); evDing.Amplitude = 0.6; evDing.Pan = 0.5;
            evc.AddEvent(0.66, evDing);
            evDing = new SampleSoundEvent(evDing); evDing.Amplitude = 0.4; evDing.Pan = 0.0;
            evc.AddEvent(1.0, evDing);
            evDing = new SampleSoundEvent(evDing); evDing.Amplitude = 0.3;
            evc.AddEvent(1.33, evDing);
            evDing = new SampleSoundEvent(evDing); evDing.Amplitude = 0.25;
            evc.AddEvent(1.66, evDing);

            // add it to script
            soundScript.AddEvent(2.0, evc);
            soundScript.AddEvent(2.5, evc );

            evDing = new SampleSoundEvent(evDing); evDing.Amplitude = 0.91; evDing.Pan = -0.9;
            soundScript.AddEvent(0, evDing);
            evDing = new SampleSoundEvent(evDing); evDing.Amplitude = 0.92; evDing.Pan = +1;
            soundScript.AddEvent(0.5, evDing);
            evDing = new SampleSoundEvent(evDing); evDing.Amplitude = 0.93; evDing.Pan = -1;
            soundScript.AddEvent(1.0, evDing);

            // try oscillator
            OscSoundEvent oscEv = new OscSoundEvent(320);
            oscEv.Amplitude = 0.1;
            SignalSoundEvent sEv = new SignalSoundEvent( SignalSoundEvent.Modifier.AMPLITUDE ,
                new Signal( new List<double>() { 0,0 , 0.5,1 , 2,1 , 2.5,0 , 3.0,0 } ) );
            SignalSoundEvent sEv2 = new SignalSoundEvent(SignalSoundEvent.Modifier.DSP_PARAM,
                new Signal(new List<double>() { 0, 320, 0.5, 543, 2, 129, 2.5, 192.3, 3.0, 410 }), (int) FMOD.DSP_OSCILLATOR.RATE);
            oscEv.AddEvent(0.0, sEv);
            oscEv.AddEvent(0.0, sEv2);
            soundScript.AddEvent(3.0, oscEv);
            soundScript.AddEvent(7.0, oscEv);
            soundScript.AddEvent(11.0, oscEv);
            soundScript.AddEvent(15.0, oscEv);

            return soundScript;
        }
Exemplo n.º 27
0
 /**
  * called internally when adding this event as a child to a parent event
  */
 internal virtual void NotifyNewParent(SoundEvent parent)
 {
     _parent = parent;
 }
Exemplo n.º 28
0
 public SoundEvent Test_Speed()
 {
     SoundEvent soundScript = new SoundEvent("Test_Speed");
     SampleSoundEvent evDing = new SampleSoundEvent("synthetic_twoPing.wav");
     for (double t = 0; t < 100; t += 2.0)
         soundScript.AddEvent(t, new SampleSoundEvent(evDing));
     soundScript.Speed = 2.0; // twice as fast
     return soundScript;
 }
Exemplo n.º 29
0
 /**
  * add a new soundevent to this track at specified real time (shorthand notation method name)
  */
 public double t(double time, SoundEvent ev)
 {
     this.AddEvent(time, ev);
     return(time);
 }
Exemplo n.º 30
0
        /**
         * render audio in the script 'ev', with parameters 'rp'. Multiple rendered scripts may run
         * in parrallel.
         * Call for example once per frame per script, but no firm requirements posed for this.
         * See also: Update()
         */
        public RenderCanvas Render(SoundEvent ev, RenderParams rp)
        {
            rp.AbsTime = rp.Time;
            RenderCanvas canvas = new RenderCanvas(); // TODO option to recycle objects here, avoid creation?
            ev.Render(rp,canvas);

            return canvas;
        }
Exemplo n.º 31
0
 /// <summary>
 /// Create an Audiolet, which is an Entity that only contains an audio script
 /// </summary>
 /// <param name="soundScript"></param>
 /// <returns></returns>
 public static Entity CreateAudiolet(SoundEvent soundScript)
 {
     var e = CreateEntity();
     e.AddComponent(new AudioComp(soundScript));
     e.Refresh();
     return e;
 }
Exemplo n.º 32
0
        /** 2 overlapping oscillators - does not work */
        public SoundEvent Test_TwoOscillators()
        {
            SoundEvent soundScript = new SoundEvent("Test_TwoOscillators");
            OscSoundEvent oscEv = new OscSoundEvent(320);
            oscEv.Amplitude = 0.15;
            //oscEv.UpdateDuration(6);
            SignalSoundEvent sEv = new SignalSoundEvent(SignalSoundEvent.Modifier.AMPLITUDE,
                new Signal(new List<double>() { 0, 0, 0.5, 1.0, 6.5, 1.0, 7.0, 0 }));
            SignalSoundEvent sEv2 = new SignalSoundEvent(SignalSoundEvent.Modifier.DSP_PARAM,
                new Signal(new List<double>() { 0, 170, 7.0, 450 }), (int)FMOD.DSP_OSCILLATOR.RATE);
            oscEv.AddEvent(0.0, sEv);
            oscEv.AddEvent(0.0, sEv2);
            OscSoundEvent oscEv2 = new OscSoundEvent(oscEv);
            oscEv2.AddEvent(0.0, new SignalSoundEvent(sEv));
            oscEv2.AddEvent(0.0, new SignalSoundEvent(sEv2));
            soundScript.AddEvent(1.0, oscEv);
            soundScript.AddEvent(4.0, oscEv2);

            return soundScript;
        }
Exemplo n.º 33
0
 internal override void NotifyNewParent(SoundEvent parent)
 {
     base.NotifyNewParent(parent);
     if ( _modif == Modifier.DSP_PARAM )
     {
         if (parent is DSPSoundEvent )
             _parentsDSP = (DSPSoundEvent)parent;
         if (parent is OscSoundEvent)
             _parentsOsc = (OscSoundEvent)parent;
     }
     // else TODO
 }
Exemplo n.º 34
0
 /** add a SoundEvent as a child at specified relative Time t */
 public virtual void AddEvent(double t, SoundEvent child)
 {
     _children.Add(t, child);
     child.NotifyNewParent(this);
     UpdateDuration(t + child.Duration);
 }