private void Form1_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 | FMOD.MODE.LOOP_NORMAL, ref sound);
            ERRCHECK(result);

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

            /*
             *  Create DSP unit
             */

            cohar[] nameArray = new char[32];
            dspname.ToCharArray().CopyTo(nameArray, 0);

            dspdesc.name     = nameArray;
            dspdesc.channels = 0;
            dspdesc.read     = dspreadcallback;

            result = system.createDSP(ref dspdesc, ref mydsp);
            ERRCHECK(result);

            result = system.addDSP(mydsp, ref dspconnectiontemp);
            ERRCHECK(result);

            result = mydsp.setActive(true);
            ERRCHECK(result);

            result = mydsp.setBypass(true);
            ERRCHECK(result);
        }
Exemple #2
0
        /// <summary>
        /// Takes a media info object and plays it on an open channel
        /// </summary>
        /// <param name="media"></param>
        /// <returns></returns>
        private void PlayStream()
        {
            //result
            FMOD.RESULT result;

            //play the sound on the channel
            result = _system.playSound(_sound, null, true, out _channel);
            CheckError(result);

            //prepare the equalizer
            SetupEqualizer();

            //create the dsp, although it will not be active at this time
            result = _system.createDSP(ref _dspDesc, out _dsp);

            ////deactivate
            //_dsp.setBypass(true);

            //add to dsp chain
            _channel.addDSP(0, _dsp);

            //unpause when ready to begin playing
            result = _channel.setPaused(false);
            CheckError(result);

            ////activate
            //_dsp.setBypass(false);

            //fire PlaybackStatusChanged event
            OnPlaybackStatusChanged();

            //hold the thread hostage
            while (GetIsPlaying())
            {
                //check to see if playback should stop
                if (_playbackCts.IsCancellationRequested)
                {
                    //we requested to stop playback
                    break;
                }

                //get the current position
                InternalPosition = GetPosition();

                //update fmod
                Update();

                //sleep for a few miliseconds
                Thread.Sleep(25);
            }
        }