if (version < FMOD.VERSION.number)\r
throw new MediaException("You are using an old version of FMOD " + version.ToString("X") + ". This program requires " + FMOD.VERSION.number.ToString("X") + ".");\r
\r
- if (Environment.OSVersion.Platform == PlatformID.Unix)\r
+ // Assume no special hardware capabilities except 5.1 surround sound.\r
+ FMOD.CAPS caps = FMOD.CAPS.NONE;\r
+ FMOD.SPEAKERMODE speakermode = FMOD.SPEAKERMODE._5POINT1;\r
+\r
+ // Get the capabilities of the driver.\r
+ int minfrequency = 0, maxfrequency = 0;\r
+ StringBuilder name = new StringBuilder(128);\r
+ FMODExec(system.getDriverCaps(0, ref caps,\r
+ ref minfrequency, ref maxfrequency,\r
+ ref speakermode)\r
+ );\r
+\r
+ // Set FMOD speaker mode to what the driver supports.\r
+ FMODExec(system.setSpeakerMode(speakermode));\r
+\r
+ // Forcing the ESD sound system on Linux seems to avoid a CPU loop\r
+ if (System.Environment.OSVersion.Platform == PlatformID.Unix)\r
FMODExec(system.setOutput(FMOD.OUTPUTTYPE.ESD));\r
- FMODExec(system.init(100, FMOD.INITFLAG.NORMAL, (IntPtr)null));\r
- FMODExec(system.setStreamBufferSize(64 * 1024, FMOD.TIMEUNIT.RAWBYTES));\r
+\r
+ // The user has the 'Acceleration' slider set to off, which\r
+ // is really bad for latency. At 48khz, the latency between\r
+ // issuing an fmod command and hearing it will now be about 213ms.\r
+ if ((caps & FMOD.CAPS.HARDWARE_EMULATED) == FMOD.CAPS.HARDWARE_EMULATED)\r
+ {\r
+ FMODExec(system.setDSPBufferSize(1024, 10));\r
+ }\r
+\r
+ // Get driver information so we can check for a wierd one.\r
+ FMOD.GUID guid = new FMOD.GUID();\r
+ FMODExec(system.getDriverInfo(0, name, 128, ref guid));\r
+\r
+ // Sigmatel sound devices crackle for some reason if the format is pcm 16bit.\r
+ // pcm floating point output seems to solve it.\r
+ if (name.ToString().IndexOf("SigmaTel") != -1)\r
+ {\r
+ FMODExec(system.setSoftwareFormat(\r
+ 48000,\r
+ FMOD.SOUND_FORMAT.PCMFLOAT,\r
+ 0, 0,\r
+ FMOD.DSP_RESAMPLER.LINEAR)\r
+ );\r
+ }\r
+\r
+ // Try to initialize with all those settings, and Max 32 channels.\r
+ FMOD.RESULT result = system.init(32, FMOD.INITFLAG.NORMAL, (IntPtr)null);\r
+ if (result == FMOD.RESULT.ERR_OUTPUT_CREATEBUFFER)\r
+ {\r
+ // Can not handle surround sound - back to Stereo.\r
+ FMODExec(system.setSpeakerMode(FMOD.SPEAKERMODE.STEREO));\r
+\r
+ // And init again.\r
+ FMODExec(system.init(\r
+ 32,\r
+ FMOD.INITFLAG.NORMAL,\r
+ (IntPtr)null)\r
+ );\r
+ }\r
+\r
+ // Set real-world effect scales.\r
+ FMODExec(system.set3DSettings(\r
+ 1.0f, // Doppler scale\r
+ 1.0f, // Distance scale is meters\r
+ 1.0f) // Rolloff factor\r
+ );\r
\r
soundSystemAvailable = true;\r
Logger.Log("Initialized FMOD Ex", Helpers.LogLevel.Debug);\r
}\r
catch (Exception ex)\r
{\r
- Logger.Log("Failed to initialize the sound system", Helpers.LogLevel.Warning, ex);\r
+ Logger.Log("Failed to initialize the sound system: ", Helpers.LogLevel.Warning, ex);\r
}\r
}\r
\r