示例#1
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO();
            FMOD.RESULT            result;
            uint version = 0;

            /*
             *  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(1, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
            ERRCHECK(result);

            /*
             *  Set up the FMOD_CREATESOUNDEXINFO structure for the user stream with room for 2 subsounds. (our subsound double buffer)
             */

            exinfo.cbsize           = Marshal.SizeOf(exinfo);
            exinfo.defaultfrequency = 44100;
            exinfo.numsubsounds     = 2;
            exinfo.numchannels      = 1;
            exinfo.format           = FMOD.SOUND_FORMAT.PCM16;

            /*
             *  Create the 'parent' stream that contains the substreams.  Set it to loop so that it loops between subsound 0 and 1.
             */
            result = system.createStream("", FMOD.MODE.LOOP_NORMAL | FMOD.MODE.OPENUSER, ref exinfo, ref sound);
            ERRCHECK(result);

            /*
             *  Add 2 of our streams as children of the parent.  They should be the same format (ie mono/stereo and bitdepth) as the parent sound.
             *  When subsound 0 has finished and it is playing subsound 1, we will swap subsound 0 with a new sound, and the same for when subsound 1 has finished,
             *  causing a continual double buffered flip, which means continuous sound.
             */
            result = system.createStream(soundname[0], FMOD.MODE.DEFAULT, ref subsound[0]);
            ERRCHECK(result);

            result = system.createStream(soundname[1], FMOD.MODE.DEFAULT, ref subsound[1]);
            ERRCHECK(result);

            result = sound.setSubSound(0, subsound[0]);
            ERRCHECK(result);

            result = sound.setSubSound(1, subsound[1]);
            ERRCHECK(result);

            /*
             *  Set up the gapless sentence to contain these first 2 streams.
             */
            {
                int[] soundlist = { 0, 1 };

                result = sound.setSubSoundSentence(soundlist, 2);
                ERRCHECK(result);
            }

            subsoundid = 0;
            sentenceid = 2;     /* The next sound to be appeneded to the stream. */

            /*
             *  Play the sound.
             */

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