public void Initialize() { m_fmodSystem.init( 32, FMOD.INITFLAGS.NORMAL, IntPtr.Zero ); m_fmodSystem.getMasterChannelGroup(out m_masterChannelGroup); }
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); }
void DrawDebugOverlay(int windowID) { if (lastDebugUpdate + 0.25f < Time.unscaledTime) { if (initException != null) { lastDebugText = initException.Message; } else { if (!mixerHead.hasHandle()) { FMOD.ChannelGroup master; lowlevelSystem.getMasterChannelGroup(out master); master.getDSP(0, out mixerHead); mixerHead.setMeteringEnabled(false, true); } StringBuilder debug = new StringBuilder(); FMOD.Studio.CPU_USAGE cpuUsage; studioSystem.getCPUUsage(out cpuUsage); debug.AppendFormat("CPU: dsp = {0:F1}%, studio = {1:F1}%\n", cpuUsage.dspusage, cpuUsage.studiousage); int currentAlloc, maxAlloc; FMOD.Memory.GetStats(out currentAlloc, out maxAlloc); debug.AppendFormat("MEMORY: cur = {0}MB, max = {1}MB\n", currentAlloc >> 20, maxAlloc >> 20); int realchannels, channels; lowlevelSystem.getChannelsPlaying(out channels, out realchannels); debug.AppendFormat("CHANNELS: real = {0}, total = {1}\n", realchannels, channels); FMOD.DSP_METERING_INFO outputMetering; mixerHead.getMeteringInfo(IntPtr.Zero, out outputMetering); float rms = 0; for (int i = 0; i < outputMetering.numchannels; i++) { rms += outputMetering.rmslevel[i] * outputMetering.rmslevel[i]; } rms = Mathf.Sqrt(rms / (float)outputMetering.numchannels); float db = rms > 0 ? 20.0f * Mathf.Log10(rms * Mathf.Sqrt(2.0f)) : -80.0f; if (db > 10.0f) { db = 10.0f; } debug.AppendFormat("VOLUME: RMS = {0:f2}db\n", db); lastDebugText = debug.ToString(); lastDebugUpdate = Time.unscaledTime; } } GUI.Label(new Rect(10, 20, 290, 100), lastDebugText); GUI.DragWindow(); }
void Initialiase(bool forceNoNetwork) { UnityEngine.Debug.Log("FMOD Studio: Creating runtime system instance"); FMOD.RESULT result; result = FMOD.Studio.System.create(out studioSystem); CheckInitResult(result, "Creating System Object"); studioSystem.getLowLevelSystem(out lowlevelSystem); Settings fmodSettings = Settings.Instance; fmodPlatform = RuntimeUtils.GetCurrentPlatform(); #if UNITY_EDITOR || ((UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX) && DEVELOPMENT_BUILD) result = FMOD.Debug.Initialize(FMOD.DEBUG_FLAGS.LOG, FMOD.DEBUG_MODE.FILE, null, RuntimeUtils.LogFileName); if (result == FMOD.RESULT.ERR_FILE_NOTFOUND) { #if UNITY_5_X Debug.LogWarningFormat("FMOD Studio: Cannot open FMOD debug log file '{0}', logs will be missing for this session.", System.IO.Path.Combine(Application.dataPath, RuntimeUtils.LogFileName)); #else Debug.LogWarning(string.Format("FMOD Studio: Cannot open FMOD debug log file '{0}', logs will be missing for this session.", System.IO.Path.Combine(Application.dataPath, RuntimeUtils.LogFileName))); #endif } else { CheckInitResult(result, "Applying debug settings"); } #endif int realChannels = fmodSettings.GetRealChannels(fmodPlatform); realChannels = Math.Min(realChannels, 256); // Prior to 1.08.10 we didn't clamp this properly in the settings screen result = lowlevelSystem.setSoftwareChannels(realChannels); CheckInitResult(result, "Set software channels"); result = lowlevelSystem.setSoftwareFormat( fmodSettings.GetSampleRate(fmodPlatform), (FMOD.SPEAKERMODE)fmodSettings.GetSpeakerMode(fmodPlatform), 0 // raw not supported ); CheckInitResult(result, "Set software format"); // Setup up the platforms recommended codec to match the real channel count FMOD.ADVANCEDSETTINGS advancedsettings = new FMOD.ADVANCEDSETTINGS(); #if UNITY_EDITOR || UNITY_STANDALONE advancedsettings.maxVorbisCodecs = realChannels; #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8_1 || UNITY_PSP2 || UNITY_WII advancedsettings.maxFADPCMCodecs = realChannels; #elif UNITY_XBOXONE advancedsettings.maxXMACodecs = realChannels; #elif UNITY_PS4 advancedsettings.maxAT9Codecs = realChannels; #endif #if UNITY_5_0 || UNITY_5_1 if (fmodSettings.IsLiveUpdateEnabled(fmodPlatform) && !forceNoNetwork) { UnityEngine.Debug.LogWarning("FMOD Studio: Detected Unity 5, running on port 9265"); advancedsettings.profilePort = 9265; } #endif advancedsettings.randomSeed = (uint)DateTime.Now.Ticks; result = lowlevelSystem.setAdvancedSettings(ref advancedsettings); CheckInitResult(result, "Set advanced settings"); FMOD.INITFLAGS lowlevelInitFlags = FMOD.INITFLAGS.NORMAL; FMOD.Studio.INITFLAGS studioInitFlags = FMOD.Studio.INITFLAGS.NORMAL | FMOD.Studio.INITFLAGS.DEFERRED_CALLBACKS; if (fmodSettings.IsLiveUpdateEnabled(fmodPlatform) && !forceNoNetwork) { studioInitFlags |= FMOD.Studio.INITFLAGS.LIVEUPDATE; } FMOD.RESULT initResult = studioSystem.initialize( fmodSettings.GetVirtualChannels(fmodPlatform), studioInitFlags, lowlevelInitFlags, IntPtr.Zero ); CheckInitResult(initResult, "Calling initialize"); // Dummy flush and update to get network state studioSystem.flushCommands(); FMOD.RESULT updateResult = studioSystem.update(); // Restart without liveupdate if there was a socket error if (updateResult == FMOD.RESULT.ERR_NET_SOCKET_ERROR) { studioSystem.release(); UnityEngine.Debug.LogWarning("FMOD Studio: Cannot open network port for Live Update, restarting with Live Update disabled. Check for other applications that are running FMOD Studio"); Initialiase(true); } else { // Load plugins (before banks) #if (UNITY_IOS || UNITY_TVOS) && !UNITY_EDITOR FmodUnityNativePluginInit(lowlevelSystem.getRaw()); #else foreach (var pluginName in fmodSettings.Plugins) { string pluginPath = RuntimeUtils.GetPluginPath(pluginName); uint handle; result = lowlevelSystem.loadPlugin(pluginPath, out handle); #if UNITY_64 || UNITY_EDITOR_64 // Add a "64" suffix and try again if (result == FMOD.RESULT.ERR_FILE_BAD || result == FMOD.RESULT.ERR_FILE_NOTFOUND) { string pluginPath64 = RuntimeUtils.GetPluginPath(pluginName + "64"); result = lowlevelSystem.loadPlugin(pluginPath64, out handle); } #endif CheckInitResult(result, String.Format("Loading plugin '{0}' from '{1}'", pluginName, pluginPath)); loadedPlugins.Add(pluginName, handle); } #endif if (fmodSettings.ImportType == ImportType.StreamingAssets) { // Always load strings bank try { LoadBank(fmodSettings.MasterBank + ".strings", fmodSettings.AutomaticSampleLoading); } catch (BankLoadException e) { UnityEngine.Debug.LogException(e); } if (fmodSettings.AutomaticEventLoading) { try { LoadBank(fmodSettings.MasterBank, fmodSettings.AutomaticSampleLoading); } catch (BankLoadException e) { UnityEngine.Debug.LogException(e); } foreach (var bank in fmodSettings.Banks) { try { LoadBank(bank, fmodSettings.AutomaticSampleLoading); } catch (BankLoadException e) { UnityEngine.Debug.LogException(e); } } WaitForAllLoads(); } } }; FMOD.ChannelGroup master; lowlevelSystem.getMasterChannelGroup(out master); master.getDSP(0, out mixerHead); mixerHead.setMeteringEnabled(false, true); }
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); }
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.LOOP_NORMAL, ref sound[0]); ERRCHECK(result); result = system.createSound("../../../../../examples/media/jaguar.wav", FMOD.MODE.LOOP_NORMAL, ref sound[1]); ERRCHECK(result); result = system.createSound("../../../../../examples/media/swish.wav", FMOD.MODE.LOOP_NORMAL, ref sound[2]); ERRCHECK(result); result = system.createSound("../../../../../examples/media/c.ogg", FMOD.MODE.LOOP_NORMAL, ref sound[3]); ERRCHECK(result); result = system.createSound("../../../../../examples/media/d.ogg", FMOD.MODE.LOOP_NORMAL, ref sound[4]); ERRCHECK(result); result = system.createSound("../../../../../examples/media/e.ogg", FMOD.MODE.LOOP_NORMAL, ref sound[5]); 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); /* * Instead of being independent, set the group A and B to be children of the master group. */ result = masterGroup.addGroup(groupA); ERRCHECK(result); result = masterGroup.addGroup(groupB); ERRCHECK(result); /* * Start all the sounds! */ for (count = 0; count < 6; count++) { result = system.playSound(FMOD.CHANNELINDEX.FREE, sound[count], true, ref channel[count]); ERRCHECK(result); if (count < 3) { result = channel[count].setChannelGroup(groupA); } else { result = channel[count].setChannelGroup(groupB); } ERRCHECK(result); result = channel[count].setPaused(false); ERRCHECK(result); } /* * Change the volume of each group, just because we can! (And makes it less noise). */ result = groupA.setVolume(0.5f); ERRCHECK(result); result = groupB.setVolume(0.5f); ERRCHECK(result); }