Exemple #1
0
        public static void EnableFFT()
        {
            FFTEnabled = true;
            system.getMasterChannelGroup(out ChannelGroup);
            system.createDSPByType(FMOD.DSP_TYPE.FFT, out MyDSP);
            ChannelGroup.addDSP(1, MyDSP);

            MyDSP.setActive(true);
        }
Exemple #2
0
        private void sineWave_Click(object sender, System.EventArgs e)
        {
            FMOD.RESULT result;
            float       pan = 0, frequency = 0;

            if (channel != null)
            {
                channel.stop();
            }

            if (dsp != null)
            {
                dsp.release();
            }

            /*
             *  Create an oscillator DSP unit for the tone.
             */
            result = system.createDSPByType(FMOD.DSP_TYPE.OSCILLATOR, ref dsp);
            ERRCHECK(result);
            result = dsp.setParameter((int)FMOD.DSP_OSCILLATOR.RATE, 440.0f);       /* musical note 'A' */
            ERRCHECK(result);

            result = system.playDSP(FMOD.CHANNELINDEX.REUSE, dsp, true, ref channel);
            ERRCHECK(result);
            channel.setVolume(0.5f);
            result = dsp.setParameter((int)FMOD.DSP_OSCILLATOR.TYPE, 0);
            ERRCHECK(result);
            channel.setPaused(false);

            channel.getFrequency(ref frequency);
            channel.getPan(ref pan);

            trackBarVolume.Value    = 512;
            trackBarFrequency.Value = (int)frequency;
            trackBarPan.Value       = (int)(pan * 512);
        }
Exemple #3
0
        private void effects_Load(object sender, System.EventArgs e)
        {
            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, ref sound);
            ERRCHECK(result);

            result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel);
            ERRCHECK(result);

            /*
             *  Create some effects to play with.
             */
            result = system.createDSPByType(FMOD.DSP_TYPE.LOWPASS, ref dsplowpass);
            ERRCHECK(result);
            result = system.createDSPByType(FMOD.DSP_TYPE.HIGHPASS, ref dsphighpass);
            ERRCHECK(result);
            result = system.createDSPByType(FMOD.DSP_TYPE.ECHO, ref dspecho);
            ERRCHECK(result);
            result = system.createDSPByType(FMOD.DSP_TYPE.FLANGE, ref dspflange);
            ERRCHECK(result);
            result = system.createDSPByType(FMOD.DSP_TYPE.DISTORTION, ref dspdistortion);
            ERRCHECK(result);
            result = system.createDSPByType(FMOD.DSP_TYPE.CHORUS, ref dspchorus);
            ERRCHECK(result);
            result = system.createDSPByType(FMOD.DSP_TYPE.PARAMEQ, ref dspparameq);
            ERRCHECK(result);
        }
Exemple #4
0
        /// <summary>
        /// Add the DSP units to the channel
        /// </summary>
        private void SetupEqualizer()
        {
            FMOD.RESULT result;

            foreach (var eq in EqualizerBands)
            {
                FMOD.DSP eqDsp;

                //create the equalizer dps effects
                result = _system.createDSPByType(FMOD.DSP_TYPE.PARAMEQ, out eqDsp);

                //set up the dsp unit
                result = eqDsp.setParameterFloat((int)FMOD.DSP_PARAMEQ.CENTER, eq.Center);

                //set the gain to the current gain
                SetEqualizerBand(eqDsp, eq.Gain);

                //prepare the equalizer on the channel
                result = _channel.addDSP(0, eqDsp);

                //add dsp to list
                _eq.Add(eqDsp);
            }
        }
Exemple #5
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);
        }
Exemple #6
0
        public static bool Play(string strRootPath, SoundItemProperty prop)
        {
            FMOD.RESULT result;

            if (channel != null)
            {
                channel.stop();
            }

            string name = strRootPath + prop.FileName;

            FMOD.MODE mode = FMOD.MODE.DEFAULT;
            if (prop.Type == SoundItemProperty.typeSound[0])
            {
                mode |= FMOD.MODE._2D | FMOD.MODE.CREATESAMPLE | FMOD.MODE.SOFTWARE;
            }
            else if (prop.Type == SoundItemProperty.typeSound[1])
            {
                mode |= FMOD.MODE._3D | FMOD.MODE.CREATESAMPLE | FMOD.MODE.SOFTWARE | FMOD.MODE._3D_LINEARROLLOFF | FMOD.MODE._3D_WORLDRELATIVE | FMOD.MODE._3D_IGNOREGEOMETRY;
            }
            else if (prop.Type == SoundItemProperty.typeSound[2])
            {
                mode |= FMOD.MODE._2D | FMOD.MODE.CREATESTREAM | FMOD.MODE.SOFTWARE;
            }

            if (prop.Loop == true)
            {
                mode |= FMOD.MODE.LOOP_NORMAL;
            }

            result = system.createSound(name, mode, ref sound);
            ERRCHECK(result);

            result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, true, ref channel);
            ERRCHECK(result);

            if (prop.Type == SoundItemProperty.typeSound[1])
            {
                channel.set3DMinMaxDistance(100.0f, prop.MaxDistance);

                FMOD.VECTOR pos = new FMOD.VECTOR();
                pos.x = 0.0f; pos.y = 0.0f; pos.z = 0.0f;
                FMOD.VECTOR vel = new FMOD.VECTOR();
                vel.x = 0.0f; vel.y = 0.0f; vel.z = 0.0f;
                channel.set3DAttributes(ref pos, ref vel);

                FMOD.DSP dsp = null;
                result = system.createDSPByType(FMOD.DSP_TYPE.LOWPASS_SIMPLE, ref dsp);
                ERRCHECK(result);

                dsp.setParameter((int)FMOD.DSP_LOWPASS_SIMPLE.CUTOFF, 22000.0f);
                FMOD.DSPConnection dspcon = null;
                channel.addDSP(dsp, ref dspcon);
            }

            channel.setVolume((float)prop.Volume * 0.01f);
            channel.setCallback(CHANNELCALLBACK);
            channel.setPaused(false);

            return(true);
        }
Exemple #7
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            uint version = 0;

            FMOD.RESULT        result;
            FMOD.DSPConnection dspconnectiontemp = null;

            /*
             *  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);
            ERRCHECK(result);

            result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel);
            ERRCHECK(result);

            /*
             *  Create the DSP effects.
             */
            result = system.createDSPByType(FMOD.DSP_TYPE.LOWPASS, ref dsplowpass);
            ERRCHECK(result);

            result = system.createDSPByType(FMOD.DSP_TYPE.CHORUS, ref dspchorus);
            ERRCHECK(result);

            /*
             *  Connect up the DSP network
             */

            /*
             *  When a sound is played, a subnetwork is set up in the DSP network which looks like this.
             *  Wavetable is the drumloop sound, and it feeds its data from right to left.
             *
             *  [DSPHEAD]<------------[DSPCHANNELMIXER]
             */
            result = system.getDSPHead(ref dsphead);
            ERRCHECK(result);

            result = dsphead.getInput(0, ref dspchannelmixer, ref dspconnectiontemp);
            ERRCHECK(result);

            /*
             *  Now disconnect channeldsp head from wavetable to look like this.
             *
             *  [DSPHEAD]             [DSPCHANNELMIXER]
             */
            result = dsphead.disconnectFrom(dspchannelmixer);
            ERRCHECK(result);

            /*
             *  Now connect the 2 effects to channeldsp head.
             *
             *            [DSPLOWPASS]
             *           /
             *  [DSPHEAD]             [DSPCHANNELMIXER]
             \
             \            [DSPCHORUS]
             */
            result = dsphead.addInput(dsplowpass, ref dsplowpassconnection);
            ERRCHECK(result);
            result = dsphead.addInput(dspchorus, ref dspchorusconnection);
            ERRCHECK(result);

            /*
             *  Now connect the wavetable to the 2 effects
             *
             *            [DSPLOWPASS]
             *           /           \
             *  [DSPHEAD]             [DSPCHANNELMIXER]
             \           /
             \            [DSPCHORUS]
             */
            result = dsplowpass.addInput(dspchannelmixer, ref dspconnectiontemp);
            ERRCHECK(result);
            result = dspchorus.addInput(dspchannelmixer, ref dspconnectiontemp);
            ERRCHECK(result);

            /*
             *  Now the drumloop will be twice as loud, because it is being split into 2, then recombined at the end.
             *  What we really want is to only feed the dspchannelmixer->dsplowpass through the left speaker, and
             *  dspchannelmixer->dspchorus to the right speaker.
             *  We can do that simply by setting the pan, or speaker levels of the connections.
             *
             *            [DSPLOWPASS]
             *           /1,0        \
             *  [DSPHEAD]             [DSPCHANNELMIXER]
             \0,1        /
             *            [DSPCHORUS]
             */
            {
                float[] leftinputon  = { 1.0f, 0.0f };
                float[] rightinputon = { 0.0f, 1.0f };
                float[] inputsoff    = { 0.0f, 0.0f };

                result = dsplowpassconnection.setLevels(FMOD.SPEAKER.FRONT_LEFT, leftinputon, 2);
                ERRCHECK(result);
                result = dsplowpassconnection.setLevels(FMOD.SPEAKER.FRONT_RIGHT, inputsoff, 2);
                ERRCHECK(result);

                result = dsplowpassconnection.setLevels(FMOD.SPEAKER.FRONT_LEFT, inputsoff, 2);
                ERRCHECK(result);
                result = dsplowpassconnection.setLevels(FMOD.SPEAKER.FRONT_RIGHT, rightinputon, 2);
                ERRCHECK(result);
            }

            result = dsplowpass.setBypass(true);
            result = dspchorus.setBypass(true);

            result = dsplowpass.setActive(true);
            result = dspchorus.setActive(true);
        }