Example #1
0
        protected void addPeriodic(InitTable config)
        {
            SoundDescriptor desc = new SoundDescriptor();

            desc.filename  = config.findData <string>("sound");
            desc.is3d      = true;
            desc.isLooping = false;
            desc.priority  = Priority.BACKGROUND_FX;

            Sound snd = new Sound(desc);

            snd.relativePosition = true;

            Periodic pr = new Periodic(this);

            pr.sound = snd;

            Random rand = new Random();

            pr.minPitch = config.findDataOr <float>("pitch.min", 0.8f);
            pr.maxPitch = config.findDataOr <float>("pitch.max", 1.2f);
            pr.minDelay = config.findDataOr <float>("delay.min", 1.0f);
            pr.maxDelay = config.findDataOr <float>("delay.min", 5.0f);
            pr.maxRange = config.findDataOr <Vector3>("maxRange", new Vector3(20, 20, 20));

            pr.nextTime = rand.randomInRange(pr.minDelay, pr.maxDelay);

            myPeriodics.Add(pr);
        }
Example #2
0
        protected void addBackground(InitTable config)
        {
            SoundDescriptor desc = new SoundDescriptor();

            desc.filename  = config.findData <string>("sound");
            desc.is3d      = false;
            desc.isLooping = true;
            desc.priority  = Priority.BACKGROUND_FX;
            Sound snd = new Sound(desc);

            Background bg = new Background(this);

            bg.sound = snd;

            Random rand = new Random();

            bg.pitch.minVal     = config.findDataOr <float>("pitch.minVal", 0.8f);
            bg.pitch.maxVal     = config.findDataOr <float>("pitch.maxVal", 1.2f);
            bg.pitch.currentVal = rand.randomInRange(bg.pitch.minVal, bg.pitch.maxTime);
            bg.pitch.minTime    = config.findDataOr <float>("pitch.minTime", 1.0f);
            bg.pitch.maxTime    = config.findDataOr <float>("pitch.maxTime", 5.0f);
            bg.pitch.reset();

            bg.volume.minVal     = config.findDataOr <float>("volume.minVal", 0.8f);
            bg.volume.maxVal     = config.findDataOr <float>("volume.maxVal", 1.2f);
            bg.volume.currentVal = rand.randomInRange(bg.volume.minVal, bg.volume.maxTime);
            bg.volume.minTime    = config.findDataOr <float>("volume.minTime", 1.0f);
            bg.volume.maxTime    = config.findDataOr <float>("volume.maxTime", 5.0f);
            bg.volume.reset();

            myBackgrounds.Add(bg);
        }
Example #3
0
        public void playSoundOnetime(SoundDescriptor sd)
        {
            Sound snd = new Sound(sd);

            snd.transient = true;
            snd.play();
        }
Example #4
0
        public void transitionMusic(SoundDescriptor music, double transitionTime)
        {
            //cleanup if we transition before we're done with a transition
            if (myNextMusic != null)
            {
                if (music.source.filename != myNextMusic.source.filename)
                {
                    myNextMusic.stop();
                    myNextMusic = null;
                }
                else
                {
                    return; //don't transition to the same song
                }
            }

            //don't transition to the same song
            if (myCurrentMusic != null && myCurrentMusic.source.filename == music.source.filename)
            {
                return;
            }

            //transition to new song
            Sound snd = new Sound(music);

            myNextMusic        = snd;
            myNextMusic.volume = 0.0f;
            myNextMusic.play();
            myMusicTransitionTime        = transitionTime;
            myCurrentMusicTransitionTime = 0.0;
        }
Example #5
0
        public Sound(SoundDescriptor desc)
            : base()
        {
            is3d              = desc.is3d;
            isLooping         = desc.isLooping;
            position          = desc.position;
            velocity          = desc.velocity;
            coneOrientation   = new Vector3();
            referenceDistance = desc.falloffDistance;
            relativePosition  = desc.isRelative;
            mySource          = desc.source;
            priority          = desc.priority;

            myVoice           = null;
            myNextBufferIndex = 0;
        }
Example #6
0
        public void playSoundOneTime(string filename, Vector3 pos, bool relative, Vector3 vel, float falloffDistance, AbstractAudio.Priority priority)
        {
            SoundDescriptor desc = new SoundDescriptor();

            desc.filename  = filename;
            desc.is3d      = true;
            desc.isLooping = false;
            desc.priority  = priority;

            Sound snd = new Sound(desc);

            snd.position         = pos;
            snd.velocity         = vel;
            snd.relativePosition = relative;
            snd.transient        = true;

            snd.play();
        }
Example #7
0
        public Sound(SoundDescriptor desc)
            : base()
        {
            myNextBufferIndex = 0;
            is3d              = desc.is3d;
            isLooping         = desc.isLooping;
            myVoice           = null;
            relativePosition  = false;
            referenceDistance = 1.0f;

            if (desc.source != null)
            {
                mySource = desc.source;
            }

            position          = new Vector3();
            velocity          = new Vector3();
            coneOrientation   = new Vector3();
            myNextBufferIndex = 0;
        }