Beispiel #1
0
        public void Init(AudioDevice audioDevice, Vector2 minMaxDistance, int nSoundChannels, JMOD.CustomReadFileMethodDelegate customReadFileMethodDelegate)
        {
            // NOTE: Ignore customReadFileMethodDelegate for now... This is getting messy...

            // NOTE: This isn't implemented, but we'll just ignore the choice of audio device (you're not supposed to use FMOD anyway)
            //if (AudioDevice.DeviceID.Length > 0)
            //    throw new NotImplementedException();

            uint version = 0;

            FMOD.RESULT result;
            FMOD.System system = null;
            this.minMaxDistance = minMaxDistance;

            LogInit("Init() running with arguments ({0}, {1})", minMaxDistance, nSoundChannels);

            LogInit(false, "Creating system... ");
            result = FMOD.Factory.System_Create(ref system);
            LogInit(result.ToString());
            ERRCHECK(result);

            FMODSystem = system;
            SystemGlue = new FMODSystem(system);
            LogInit("Created SystemGlue");

            result = FMODSystem.getVersion(ref version);
            LogInit("FMOD version {0}, {1} required", version.ToString("X"), FMOD.VERSION.number.ToString("X"));
            ERRCHECK(result);
            if (version < FMOD.VERSION.number)
            {
                LogInit("ERROR: Version mismatch");
                throw new Exception("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
            }

            result = FMODSystem.setHardwareChannels(0, 0, 0, 0);        // Skip EAX probe which can crash/corrupt some bad drivers
            LogInit("Disabling hardware channels. {0}", result.ToString());
            ERRCHECK(result);

            int nDrivers = -1;

            LogInit(false, "Checking number of drivers... ");
            result = FMODSystem.getNumDrivers(ref nDrivers);
            LogInit("{0} ({1})", result.ToString(), nDrivers);
            ERRCHECK(result);
            if (nDrivers == 0)
            {
                result = FMODSystem.setOutput(FMOD.OUTPUTTYPE.NOSOUND);
                LogInit("Output set to NOSOUND. " + result.ToString());
                ERRCHECK(result);
            }
            else
            {
                driverCaps = FMOD.CAPS.NONE;
                int minfrequency = 0, maxfrequency = 0;
                FMOD.SPEAKERMODE speakermode = FMOD.SPEAKERMODE.STEREO;

                result = FMODSystem.getDriverCaps(0, ref driverCaps, ref minfrequency, ref maxfrequency, ref speakermode);
                LogInit("Checking driver caps... " + result.ToString());
                ERRCHECK(result);
                LogInit("\tDriver caps: " + driverCaps);
                LogInit("\tFrequency range: {0}-{1}", minfrequency, maxfrequency);
                LogInit("\tSpeaker mode: {0}", speakermode);

                result = FMODSystem.setSpeakerMode(speakermode);
                LogInit("Set speaker mode to {0}. {1}", speakermode, result.ToString());
                ERRCHECK(result);

                if ((driverCaps & FMOD.CAPS.HARDWARE_EMULATED) == FMOD.CAPS.HARDWARE_EMULATED)      // The user has the 'Acceleration' slider set to off!  This is really bad for latency!
                {
                    LogInit("WARNING: Acceleration slider set to off");
                    result = FMODSystem.setDSPBufferSize(1024, 10);
                    LogInit("Set DSP buffer size to 10 * 1024. {0}", result.ToString());
                    ERRCHECK(result);
                }

                StringBuilder name = new StringBuilder(256);
                FMOD.GUID     guid = new FMOD.GUID();

                result = FMODSystem.getDriverInfo(0, name, 256, ref guid);
                LogInit("Fetching driver 0. {0}", result.ToString());
                ERRCHECK(result);
                LogInit("\tName: " + name);

                string tmpGuidStr = "";
                for (int i = 0; i < guid.Data4.Length; i++)
                {
                    tmpGuidStr += guid.Data4[i].ToString("X");
                    if (i == 1)
                    {
                        tmpGuidStr += "-";
                    }
                }

                LogInit("\tGUID: {0}-{1}-{2}-{3}", guid.Data1.ToString("X"), guid.Data2.ToString("X"), guid.Data3.ToString("X"), tmpGuidStr);

                if (name.ToString().IndexOf("SigmaTel") != -1)
                {
                    result = FMODSystem.setSoftwareFormat(48000, FMOD.SOUND_FORMAT.PCMFLOAT, 0, 0, FMOD.DSP_RESAMPLER.LINEAR);
                    LogInit("Set SigmaTel-specific software format settings. {0}", result.ToString());
                    ERRCHECK(result);
                }

                if (nDrivers > 1)
                {
                    LogInit("======================================");
                    LogInit("Drivers:");
                    for (int i = 0; i < nDrivers; i++)
                    {
                        LogInit("--------------------------------------");
                        LogDeviceInformation(i);
                    }
                    LogInit("======================================");
                }
            }

            result = FMODSystem.init(nSoundChannels, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
            LogInit("Running init({0}, {1}, null). {2}", nSoundChannels, FMOD.INITFLAGS.NORMAL, result.ToString());
            if (result == FMOD.RESULT.ERR_OUTPUT_CREATEBUFFER)
            {
                LogInit("ERROR: Could not create buffer");
                result = FMODSystem.setSpeakerMode(FMOD.SPEAKERMODE.STEREO);
                LogInit("Set speaker mode to STEREO. {0}", result.ToString());
                ERRCHECK(result);

                result = FMODSystem.init(nSoundChannels, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
                LogInit("Running init({0}, {1}, null). {2}", nSoundChannels, FMOD.INITFLAGS.NORMAL, result.ToString());

                if (result == FMOD.RESULT.ERR_OUTPUT_CREATEBUFFER)
                {
                    LogInit("ERROR: Could not create buffer");
                    result = FMODSystem.setOutput(FMOD.OUTPUTTYPE.WINMM);
                    LogInit("Set output to WINMM. {0}", result.ToString());
                    ERRCHECK(result);

                    result = FMODSystem.init(nSoundChannels, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
                    LogInit("Running init({0}, {1}, null). {2}", nSoundChannels, FMOD.INITFLAGS.NORMAL, result.ToString());
                    ERRCHECK(result);
                }
            }

            result = FMODSystem.set3DSettings(1f, 1f, 1f);
            LogInit("Set 3D-settings to (1, 1, 1). {0}", result.ToString());
            ERRCHECK(result);

            NonBlockCallback = new FMOD.SOUND_NONBLOCKCALLBACK(NonBlockCallbackMethod);
        }