/**
         * 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;
        }
 /// <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;
 }
 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;
 }
示例#4
0
 /**
  * create the item that is able to play the level's music based on the music script.
  * If a mainSoundTrack=null is passed, no time syncing to a main sound track is used.
  */
 public LevelMusic( SoundTrackEvent musicScript, SampleSoundEvent mainSoundTrack)
     : base()
 {
     musicRp = new RenderParams();
     musicRp.RenderAheadTime = 15.0;
     this.musicScript = musicScript;
     this.mainSoundTrack = mainSoundTrack;
 }
示例#5
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);
     }
 }
示例#6
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);
 }
示例#7
0
        public GameSound()
        {
            MusicEngine.GetInstance();

            soundsBank[0] = new SampleSoundEvent("sword-unsheathe.wav");
            soundsBank[1] = new SampleSoundEvent("swing.wav");
            soundsBank[2] = new SampleSoundEvent("swing2.wav");
            soundsBank[3] = new SampleSoundEvent("swing3.wav");
            soundsBank[4] = new SampleSoundEvent("hit_1.wav");
            soundsBank[5] = new SampleSoundEvent("hit_2.wav");
            soundsBank[6] = new SampleSoundEvent("hit_3.wav");
        }
        /**
         * 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;
        }
        public override void CreateMusicScript()
        {
            musicScript = new SoundTrackEvent(BPM);
            wTrk = new SampleSoundEvent("Sublime/drumnbass.ogg");
            wVox = new SampleSoundEvent("Sublime/vox.ogg");
            wLead = new SampleSoundEvent("Sublime/leads.ogg");
            wBeat = new SampleSoundEvent("Sublime/beat.ogg");
            wHat  = new SampleSoundEvent("Sublime/revhat.ogg");
            wStr = new SampleSoundEvent("Sublime/strings.ogg");
            wBeep = new SampleSoundEvent("Sublime/beeps.ogg");

            musicScript.AddEvent(0, wTrk);
            musicScript.AddEvent(0, wVox);
            musicScript.AddEvent(0, wLead);
            musicScript.AddEvent(0, wBeat);
            musicScript.AddEvent(0, wHat);
            musicScript.AddEvent(0, wStr);
            musicScript.AddEvent(0, wBeep);

            double N = Math.Sqrt(musicScript.Children.Count);
            wTrk.Amplitude = 1 / N;
            wVox.Amplitude = 1 / N;
            wLead.Amplitude = 1 / N;
            wBeat.Amplitude = 1 / N;
            wHat.Amplitude = 1 / N;
            wStr.Amplitude = 1 / N;
            wBeep.Amplitude = 1 / N;

            // attach a events soundtrack to each sampled wave track
            tLead = new SoundTrackEvent(BPM);
            wLead.AddEvent(0, tLead);
            tVox = new SoundTrackEvent(BPM);
            wVox.AddEvent(0, tVox);
            tTrk = new SoundTrackEvent(BPM);
            wTrk.AddEvent(0, tTrk);
            tBeat = new SoundTrackEvent(BPM);
            wTrk.AddEvent(0, tBeat);
            tHat = new SoundTrackEvent(BPM);
            wTrk.AddEvent(0, tHat);
            tStr = new SoundTrackEvent(BPM);
            wTrk.AddEvent(0, tStr);
            tBeep = new SoundTrackEvent(BPM);
            wBeep.AddEvent(0, tBeep);

            // volume-decrease events
            // vol( measure.beat-nr,  which-track, measures-duration, game-item )
            for (double t = 3; t < 20; t++)
            {
                Ball b = crBall(0.3f, 0.4f);
                vol(t+0.1, tBeat, 1.0, b);
                if (t == 12)
                {
                    /*
                    // FIXME component does not get inited now?
                    VortexEffect ve = new VortexEffect("CurvedVortex", "clouds");
                    b.Add(ve);
                    //ve.Position = new Vector2(2.1f, 0.43f);
                    ve.VortexVelocity = 0.04f;
                    ve.NoiseLevel = 0.03f;
                    ve.Paused = false;
                    ve.Duration = 10f;
                     */
                }
            }
            /*
            vol(5.1, tBeat, 4.0, crBall(0.5f, 1.26f));
            vol(7.2, tBeat, 4.0, crBall(0.7f, 1.18f));
            vol(9.2, tBeat, 4.0, crBall(0.7f, 1.18f));
            vol(11.2, tBeat, 4.0, crBall(0.7f, 1.18f));
            vol(13.2, tBeat, 4.0, crBall(0.7f, 1.18f));
             */
        }
            protected override void StartInternal()
            {
                try
                {
                    if (isAbort)
                    {
                        status = ITaskStatus.FAIL;
                        statusMsg = "Task aborted";
                        return;
                    }

                    // check file
                    if (!System.IO.File.Exists(musicFile))
                    {
                        status = ITaskStatus.FAIL;
                        statusMsg = "File not found: " + musicFile;
                        return;
                    }

                    SampleSoundEvent ev = new SampleSoundEvent(musicFile);
                    ev.Amplitude = volume;
                    parent.soundScript.AddEvent(parent.rp.Time - musicStartTime, ev);
                    if (isAbort)
                    {
                        status = ITaskStatus.FAIL;
                        statusMsg = "Task aborted";
                        return;
                    }

                    lock (parent.songChangeLock)
                    {
                        if (parent.currentSong != null)  // if needed, fade out a current playing song
                        {
                            parent.oldSongs.Add(parent.currentSong);
                        }
                        parent.currentSong = ev;
                        parent.currentSong.Amplitude = 0;
                        parent.currentSongStartTime = parent.rp.Time;
                        parent.FadeIn();
                    }

                    // if all ok, record this as last song played
                    parent.lastMusicFile = musicFile;

                }
                catch (Exception ex)
                {
                    status = ITaskStatus.FAIL;
                    statusMsg = "Failed: " + ex.Message;
                }
            }
        protected override void OnUpdate(ref UpdateParams p)
        {
            base.OnUpdate(ref p);

            lock (songChangeLock)
            {
                List<SampleSoundEvent> songsToRemove = new List<SampleSoundEvent>();
                foreach (SampleSoundEvent ev in oldSongs)
                {
                    ev.Amplitude -= fadeSpeed * p.Dt;

                    // remove songs from list if completely faded out.
                    if (ev.Amplitude <= 0)
                    {
                        ev.Active = false;
                        songsToRemove.Add(ev);
                    }
                }
                foreach (SampleSoundEvent ev in songsToRemove)
                {
                    oldSongs.Remove(ev);
                }

                // check if current song is still on list
                if (currentSong != null)
                {

                    if (isFadeIn)
                    {
                        currentSong.Amplitude += fadeSpeed * p.Dt;
                        if (currentSong.Amplitude >= 1)
                        {
                            currentSong.Amplitude = 1;
                            isFadeIn = false;
                        }
                    }

                    if (isFadeOut)
                    {
                        currentSong.Amplitude -= fadeSpeed * p.Dt;
                        if (currentSong.Amplitude <= 0)
                        {
                            currentSong.Amplitude = 0;
                            isFadeOut = false;
                        }
                    }

                    // advance time only if volume nonzero
                    if (currentSong.Amplitude > 0)
                        rp.Time += p.Dt;

                    // remove current song if done playing
                    if (rp.Time - currentSongStartTime > currentSong.Duration + 0.3)
                        currentSong = null;
                }
            }

            if (currentSong != null && currentSong.Amplitude > 0)
                MusicEngine.GetInstance().Render(soundScript, rp);
        }
 /**
  * constructor that saves memory by re-using the internal AudioSample obj
  * of another SampleSoundEvent
  */
 public SampleSoundEvent(SampleSoundEvent ev)
     : base(ev)
 {
     _audio = ev._audio;
     UpdateDuration(_audio.Duration);
 }
 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;
 }
        /**
         * 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;
        }
        /**
         * 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;
        }
示例#16
0
 /**
  * constructor that saves memory by re-using the internal AudioSample obj
  * of another SampleSoundEvent
  */
 public SampleSoundEvent(SampleSoundEvent ev) : base(ev)
 {
     _audio = ev._audio;
     UpdateDuration(_audio.Duration);
 }