public OscSoundEvent(double freq) : base() { _freq = freq; FMOD.RESULT r = MusicEngine.AudioEngine.createDSPByType(FMOD.DSP_TYPE.OSCILLATOR, ref _dsp); if (r == FMOD.RESULT.OK) { _dsp.setParameter((int)FMOD.DSP_OSCILLATOR.RATE, (float)freq); // freq in Hz. } }
private void sineWave_Click(object sender, System.EventArgs e) { FMOD.RESULT result; float pan = 0, frequency = 0; if (channel != null) { channel.stop(); } if (dsp != null) { dsp.release(); } /* * Create an oscillator DSP unit for the tone. */ result = system.createDSPByType(FMOD.DSP_TYPE.OSCILLATOR, ref dsp); ERRCHECK(result); result = dsp.setParameter((int)FMOD.DSP_OSCILLATOR.RATE, 440.0f); /* musical note 'A' */ ERRCHECK(result); result = system.playDSP(FMOD.CHANNELINDEX.REUSE, dsp, true, ref channel); ERRCHECK(result); channel.setVolume(0.5f); result = dsp.setParameter((int)FMOD.DSP_OSCILLATOR.TYPE, 0); ERRCHECK(result); channel.setPaused(false); channel.getFrequency(ref frequency); channel.getPan(ref pan); trackBarVolume.Value = 512; trackBarFrequency.Value = (int)frequency; trackBarPan.Value = (int)(pan * 512); }
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 void SetParameter(int param, double value) { _dsp.setParameter(param, (float)value); }