/// <summary> /// Frees channel, sound and DSP resources /// </summary> private void FreeChannelResources() { //stop any playing channels if (_channel != null) { _channel.stop(); _channel = null; } //release sound if (_sound != null) { _sound.release(); _sound = null; } //free waveform DSP if (_dsp != null) { _dsp.release(); _dsp = null; } //destroy the equalizer DestroyEqualizer(); }
public string RecognizeByAudioSource(FMOD.DSP m_FFTDsp, int rate) { string result = null; IntPtr unmanagedData; uint length; m_FFTDsp.getParameterData((int)FMOD.DSP_FFT.SPECTRUMDATA, out unmanagedData, out length); FMOD.DSP_PARAMETER_FFT fftData = (FMOD.DSP_PARAMETER_FFT)Marshal.PtrToStructure(unmanagedData, typeof(FMOD.DSP_PARAMETER_FFT)); if (fftData.spectrum != null && fftData.spectrum.Length > 0) { playingAudioSpectrum = fftData.spectrum[0]; Recognize(ref result, rate); } return(result); }
// Initializes and returns the FMOD Resonance Audio Listener Plugin. private static FMOD.DSP Initialize() { // Search through all busses on in banks. int numBanks = 0; FMOD.DSP dsp = new FMOD.DSP(); FMOD.Studio.Bank[] banks = null; RuntimeManager.StudioSystem.getBankCount(out numBanks); RuntimeManager.StudioSystem.getBankList(out banks); for (int currentBank = 0; currentBank < numBanks; ++currentBank) { int numBusses = 0; FMOD.Studio.Bus[] busses = null; banks[currentBank].getBusCount(out numBusses); banks[currentBank].getBusList(out busses); RuntimeManager.StudioSystem.flushCommands(); for (int currentBus = 0; currentBus < numBusses; ++currentBus) { // Make sure the channel group of the current bus is assigned properly. string busPath = null; busses[currentBus].getPath(out busPath); RuntimeManager.StudioSystem.getBus(busPath, out busses[currentBus]); RuntimeManager.StudioSystem.flushCommands(); FMOD.ChannelGroup channelGroup; busses[currentBus].getChannelGroup(out channelGroup); RuntimeManager.StudioSystem.flushCommands(); if (channelGroup.hasHandle()) { int numDsps = 0; channelGroup.getNumDSPs(out numDsps); for (int currentDsp = 0; currentDsp < numDsps; ++currentDsp) { channelGroup.getDSP(currentDsp, out dsp); string dspNameSb; int unusedInt = 0; uint unusedUint = 0; dsp.getInfo(out dspNameSb, out unusedUint, out unusedInt, out unusedInt, out unusedInt); if (dspNameSb.ToString().Equals(listenerPluginName) && dsp.hasHandle()) { return(dsp); } } } } } Debug.LogError(listenerPluginName + " not found in the FMOD project."); return(dsp); }
public static void Update() { if (system == null) { return; } // Update sound if (channel != null) { FMOD.MODE mode = FMOD.MODE.DEFAULT; channel.getMode(ref mode); if ((mode & FMOD.MODE._3D) == FMOD.MODE._3D) { FMOD.VECTOR pos; pos.x = 0.0f; pos.y = 0.0f; pos.z = 0.0f; FMOD.VECTOR vel; vel.x = 0.0f; vel.y = 0.0f; vel.z = 0.0f; channel.get3DAttributes(ref pos, ref vel); float distance = (float)Math.Sqrt((double)(pos.x * pos.x + pos.y * pos.y)); float minDist = 0.0f, maxDist = 1000.0f; channel.get3DMinMaxDistance(ref minDist, ref maxDist); float distRatio = distance / maxDist; if (ignorefod == false) { // Set direct and reverb occlusion float direct = 1.0f - GetDistanceRatioValue(CONTROLTYPE.DIRECT, distRatio); float reverb = 1.0f - GetDistanceRatioValue(CONTROLTYPE.REVERB, distRatio); channel.set3DOcclusion(direct, reverb); // Set lowpass FMOD.DSP head = null; channel.getDSPHead(ref head); if (head != null) { int inputs = 0; head.getNumInputs(ref inputs); for (int i = 0; i < inputs; i++) { FMOD.DSP dsp = null; FMOD.DSPConnection dspcon = null; head.getInput(i, ref dsp, ref dspcon); if (dsp == null) { continue; } FMOD.DSP_TYPE type = FMOD.DSP_TYPE.UNKNOWN; dsp.getType(ref type); if (type == FMOD.DSP_TYPE.LOWPASS_SIMPLE) { float hrtf = 1.0f; FMOD.VECTOR dir; dir.x = pos.x; dir.y = pos.y; dir.z = 0.0f; float length = (float)Math.Sqrt((double)(dir.x * dir.x + dir.y * dir.y)); if (length > 0.0001f) { length = 1.0f / length; dir.x *= length; dir.y *= length; float _angle = (float)Math.Acos((double)dir.y); hrtf = 1.0f - HRTFDATA.Scale * Math.Min(1.0f, Math.Max(0.0f, (_angle - HRTFDATA.MinAngle) / (HRTFDATA.MaxAngle - HRTFDATA.MinAngle))); } float lowpass = 21990.0f * GetDistanceRatioValue(CONTROLTYPE.LOWPASS, distRatio) * hrtf + 10.0f; dsp.setParameter((int)FMOD.DSP_LOWPASS_SIMPLE.CUTOFF, lowpass); break; } } } // Set pan level float panlevel = GetDistanceRatioValue(CONTROLTYPE.PANLEVEL, distRatio); channel.set3DPanLevel(panlevel); } else { channel.set3DPanLevel(0.0f); } } } system.update(); }
public static bool Play(string strRootPath, SoundItemProperty prop) { FMOD.RESULT result; if (channel != null) { channel.stop(); } string name = strRootPath + prop.FileName; FMOD.MODE mode = FMOD.MODE.DEFAULT; if (prop.Type == SoundItemProperty.typeSound[0]) { mode |= FMOD.MODE._2D | FMOD.MODE.CREATESAMPLE | FMOD.MODE.SOFTWARE; } else if (prop.Type == SoundItemProperty.typeSound[1]) { mode |= FMOD.MODE._3D | FMOD.MODE.CREATESAMPLE | FMOD.MODE.SOFTWARE | FMOD.MODE._3D_LINEARROLLOFF | FMOD.MODE._3D_WORLDRELATIVE | FMOD.MODE._3D_IGNOREGEOMETRY; } else if (prop.Type == SoundItemProperty.typeSound[2]) { mode |= FMOD.MODE._2D | FMOD.MODE.CREATESTREAM | FMOD.MODE.SOFTWARE; } if (prop.Loop == true) { mode |= FMOD.MODE.LOOP_NORMAL; } result = system.createSound(name, mode, ref sound); ERRCHECK(result); result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, true, ref channel); ERRCHECK(result); if (prop.Type == SoundItemProperty.typeSound[1]) { channel.set3DMinMaxDistance(100.0f, prop.MaxDistance); FMOD.VECTOR pos = new FMOD.VECTOR(); pos.x = 0.0f; pos.y = 0.0f; pos.z = 0.0f; FMOD.VECTOR vel = new FMOD.VECTOR(); vel.x = 0.0f; vel.y = 0.0f; vel.z = 0.0f; channel.set3DAttributes(ref pos, ref vel); FMOD.DSP dsp = null; result = system.createDSPByType(FMOD.DSP_TYPE.LOWPASS_SIMPLE, ref dsp); ERRCHECK(result); dsp.setParameter((int)FMOD.DSP_LOWPASS_SIMPLE.CUTOFF, 22000.0f); FMOD.DSPConnection dspcon = null; channel.addDSP(dsp, ref dspcon); } channel.setVolume((float)prop.Volume * 0.01f); channel.setCallback(CHANNELCALLBACK); channel.setPaused(false); return(true); }
public DSPSoundEvent(DSPSoundEvent ev) : base(ev) { _dsp = ev._dsp; }
private void SetEqualizerBand(FMOD.DSP eqDsp, float gain) { FMOD.RESULT result; //set the gain for the specified eq band result = eqDsp.setParameterFloat((int)FMOD.DSP_PARAMEQ.GAIN, gain); }
internal void AddDSP(FMOD.DSP dsp) { _dspList.Add(dsp); }
/// <summary> /// Method responsible for disposing the variables that play the songs /// </summary> private void DisposeSound() { timer1.Stop(); FMOD.RESULT result; if (sound != null) { result = sound.release(); ERRCHECK(result); } sound = null; if (system != null) { result = system.close(); ERRCHECK(result); result = system.release(); ERRCHECK(result); } mydsp = null; }