Esempio n. 1
0
        public SoundPlayer(int maxChannels = 256)
        {
            MaxChannels = maxChannels;

            FMOD.FMODPreInit.DoFMODCopy();

            FMOD.Error.Check(FMOD.Factory.System_Create(out _system));
            FMOD.Error.Check(_system.init(maxChannels,
                                          FMOD.INITFLAGS.NORMAL, IntPtr.Zero));
            FMOD.Error.Check(_system.set3DNumListeners(1));
            FMOD.Error.Check(_system.createChannelGroup("Background Sounds", out _backgroundGroup));
            FMOD.Error.Check(_system.createChannelGroup("Voice Chat", out _voiceGroup));
            FMOD.Error.Check(_system.createChannelGroup("Sound Effects", out _effectsGroup));
            SoundDistanceScale = 20;
            Cache        = new SoundCache(this);
            ActiveSounds = new ActiveGameEffectContainer(this);
            MusicPlayer  = new MusicHelper(this);

            BackgroundVolume = 0f;
            EffectVolume     = .35f;
            VoiceVolume      = .35f;
        }
Esempio n. 2
0
        /// <summary>
        /// Create a channel group given a particular id.
        /// </summary>
        /// <param name="p_id"></param>
        /// <returns></returns>
        public FMOD.ChannelGroup GetChannelGroup(int p_id)
        {
            FMOD.ChannelGroup cg;

            if (m_ChannelGroups.ContainsKey(p_id))
            {
                cg = m_ChannelGroups[p_id];
            }
            else
            {
                m_fmodSystem.createChannelGroup(
                    string.Format("channelgroup{0}", p_id),
                    out cg
                    );
                m_ChannelGroups[p_id] = cg;
            }

            return(cg);
        }
Esempio n. 3
0
        public FModSounds()
        {
            Instance = this;
            FMOD.RESULT result = FMOD.Factory.System_Create(ref system);
            ERRCHECK(result);

            uint version = 0;

            result = system.getVersion(ref version);
            ERRCHECK(result);
            if (version < FMOD.VERSION.number)
            {
                System.Diagnostics.Trace.TraceError("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
            }

            result = system.init(32, FMOD.INITFLAGS.NORMAL, (System.IntPtr)null);
            ERRCHECK(result);

            system.createChannelGroup("channelGroup", ref channelGroup);
        }
Esempio n. 4
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            int  count   = 0;
            uint version = 0;

            FMOD.RESULT result;

            /*
             *  Create a System object and initialize.
             */
            result = FMOD.Factory.System_Create(ref system);
            ERRCHECK(result);

            result = system.getVersion(ref version);
            ERRCHECK(result);
            if (version < FMOD.VERSION.number)
            {
                MessageBox.Show("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
                Application.Exit();
            }

            result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
            ERRCHECK(result);

            result = system.createSound("../../../../../examples/media/drumloop.wav", FMOD.MODE.SOFTWARE | FMOD.MODE.LOOP_NORMAL, ref sound[0]);
            ERRCHECK(result);
            result = system.createSound("../../../../../examples/media/jaguar.wav", FMOD.MODE.SOFTWARE | FMOD.MODE.LOOP_NORMAL, ref sound[1]);
            ERRCHECK(result);
            result = system.createSound("../../../../../examples/media/c.ogg", FMOD.MODE.SOFTWARE | FMOD.MODE.LOOP_NORMAL, ref sound[2]);
            ERRCHECK(result);
            result = system.createSound("../../../../../examples/media/d.ogg", FMOD.MODE.SOFTWARE | FMOD.MODE.LOOP_NORMAL, ref sound[3]);
            ERRCHECK(result);
            result = system.createSound("../../../../../examples/media/e.ogg", FMOD.MODE.SOFTWARE | FMOD.MODE.LOOP_NORMAL, ref sound[4]);
            ERRCHECK(result);

            result = system.createChannelGroup("Group A", ref groupA);
            ERRCHECK(result);

            result = system.createChannelGroup("Group B", ref groupB);
            ERRCHECK(result);

            result = system.getMasterChannelGroup(ref masterGroup);
            ERRCHECK(result);

            result = masterGroup.addGroup(groupA);
            ERRCHECK(result);

            result = masterGroup.addGroup(groupB);
            ERRCHECK(result);

            /*
             *  Start all the sounds!
             */
            for (count = 0; count < 5; count++)
            {
                result = system.playSound(FMOD.CHANNELINDEX.FREE, sound[count], true, ref channel[count]);
                ERRCHECK(result);
                if (count < 2)
                {
                    result = channel[count].setChannelGroup(groupA);
                }
                else
                {
                    result = channel[count].setChannelGroup(groupB);
                }
                ERRCHECK(result);
                result = channel[count].setPaused(false);
                ERRCHECK(result);
            }

            /*
             *  Create the DSP effects we want to apply to our submixes.
             */
            result = system.createDSPByType(FMOD.DSP_TYPE.ECHO, ref dspecho);
            ERRCHECK(result);

            result = system.createDSPByType(FMOD.DSP_TYPE.FLANGE, ref dspflange);
            ERRCHECK(result);
            result = dspflange.setParameter((int)FMOD.DSP_FLANGE.RATE, 1.0f);
            ERRCHECK(result);

            result = system.createDSPByType(FMOD.DSP_TYPE.LOWPASS, ref dsplowpass);
            ERRCHECK(result);
            result = dsplowpass.setParameter((int)FMOD.DSP_LOWPASS.CUTOFF, 500.0f);
            ERRCHECK(result);
        }
Esempio n. 5
0
 /// <summary>
 /// Creates new channel group with given name.
 /// </summary>
 public static FMOD.ChannelGroup CreateChannelGroup(string name)
 {
     FMODSystem.createChannelGroup(name, out FMOD.ChannelGroup group);
     return(group);
 }
Esempio n. 6
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            int  count   = 0;
            uint version = 0;

            FMOD.RESULT result;

            /*
             *  Create a System object and initialize.
             */
            result = FMOD.Factory.System_Create(ref system);
            ERRCHECK(result);

            result = system.getVersion(ref version);
            ERRCHECK(result);
            if (version < FMOD.VERSION.number)
            {
                MessageBox.Show("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
                Application.Exit();
            }

            result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
            ERRCHECK(result);

            result = system.createSound("../../../../../examples/media/drumloop.wav", FMOD.MODE.LOOP_NORMAL, ref sound[0]);
            ERRCHECK(result);
            result = system.createSound("../../../../../examples/media/jaguar.wav", FMOD.MODE.LOOP_NORMAL, ref sound[1]);
            ERRCHECK(result);
            result = system.createSound("../../../../../examples/media/swish.wav", FMOD.MODE.LOOP_NORMAL, ref sound[2]);
            ERRCHECK(result);
            result = system.createSound("../../../../../examples/media/c.ogg", FMOD.MODE.LOOP_NORMAL, ref sound[3]);
            ERRCHECK(result);
            result = system.createSound("../../../../../examples/media/d.ogg", FMOD.MODE.LOOP_NORMAL, ref sound[4]);
            ERRCHECK(result);
            result = system.createSound("../../../../../examples/media/e.ogg", FMOD.MODE.LOOP_NORMAL, ref sound[5]);
            ERRCHECK(result);

            result = system.createChannelGroup("Group A", ref groupA);
            ERRCHECK(result);

            result = system.createChannelGroup("Group B", ref groupB);
            ERRCHECK(result);

            result = system.getMasterChannelGroup(ref masterGroup);
            ERRCHECK(result);

            /*
             *  Instead of being independent, set the group A and B to be children of the master group.
             */
            result = masterGroup.addGroup(groupA);
            ERRCHECK(result);

            result = masterGroup.addGroup(groupB);
            ERRCHECK(result);

            /*
             *  Start all the sounds!
             */
            for (count = 0; count < 6; count++)
            {
                result = system.playSound(FMOD.CHANNELINDEX.FREE, sound[count], true, ref channel[count]);
                ERRCHECK(result);
                if (count < 3)
                {
                    result = channel[count].setChannelGroup(groupA);
                }
                else
                {
                    result = channel[count].setChannelGroup(groupB);
                }
                ERRCHECK(result);

                result = channel[count].setPaused(false);
                ERRCHECK(result);
            }

            /*
             *  Change the volume of each group, just because we can!  (And makes it less noise).
             */
            result = groupA.setVolume(0.5f);
            ERRCHECK(result);
            result = groupB.setVolume(0.5f);
            ERRCHECK(result);
        }