public void UpdateSpeakerAttributes() { FMOD.RESULT result; FMOD.VECTOR positionFmodVect; positionFmodVect.x = gameObject.transform.position.X; positionFmodVect.y = gameObject.transform.position.Y; positionFmodVect.z = gameObject.transform.position.Z; // TODO: add true velocity of speaker FMOD.VECTOR velocityFmodVect; velocityFmodVect.x = 0.0f; velocityFmodVect.y = 0.0f; velocityFmodVect.z = 0.0f; FMOD.VECTOR panFmodVect; panFmodVect.x = 0.0f; panFmodVect.y = 0.0f; panFmodVect.z = 0.0f; result = _channel.set3DAttributes(ref positionFmodVect, ref velocityFmodVect, ref panFmodVect); if (result != FMOD.RESULT.OK) { Console.WriteLine("[SpeakerComponent Update] FMOD set3DAttributes failed : " + result); } }
public void SetPosition(float posx, float posy) { FMOD.RESULT result; mPos.x = posx; mPos.y = posy; mPos.z = 0; result = mChannel.set3DAttributes(ref mPos, ref mVel); VirtualVoices.ERRCHECK(result); }
public void SetPositionAndVelocity(Vector3 position, Vector3 velocity) { if (channel == null) { return; } FMOD.VECTOR pos = new FMOD.VECTOR(); pos.x = position.x; pos.y = position.y; pos.z = position.z; FMOD.VECTOR vel = new FMOD.VECTOR(); vel.x = velocity.x; vel.y = velocity.y; vel.z = velocity.z; CheckRetCode(channel.set3DAttributes(ref pos, ref vel)); }
private void threeD_Load(object sender, System.EventArgs e) { uint version = 0; FMOD.RESULT result; trackBarPosition.Enabled = false; /* * 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(); } FMOD.CAPS caps = FMOD.CAPS.NONE; FMOD.SPEAKERMODE speakermode = FMOD.SPEAKERMODE.STEREO; int outputrate = 0; StringBuilder name = new StringBuilder(128); result = system.getDriverCaps(0, ref caps, ref outputrate, ref speakermode); ERRCHECK(result); result = system.setSpeakerMode(speakermode); /* Set the user selected speaker mode. */ ERRCHECK(result); if ((caps & FMOD.CAPS.HARDWARE_EMULATED) == FMOD.CAPS.HARDWARE_EMULATED) /* The user has the 'Acceleration' slider set to off! This is really bad for latency!. */ { /* You might want to warn the user about this. */ result = system.setDSPBufferSize(1024, 10); /* At 48khz, the latency between issuing an fmod command and hearing it will now be about 213ms. */ ERRCHECK(result); } FMOD.GUID guid = new FMOD.GUID(); result = system.getDriverInfo(0, name, 256, ref guid); ERRCHECK(result); if (name.ToString().IndexOf("SigmaTel") != -1) /* Sigmatel sound devices crackle for some reason if the format is pcm 16bit. pcm floating point output seems to solve it. */ { result = system.setSoftwareFormat(48000, FMOD.SOUND_FORMAT.PCMFLOAT, 0, 0, FMOD.DSP_RESAMPLER.LINEAR); ERRCHECK(result); } result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null); if (result == FMOD.RESULT.ERR_OUTPUT_CREATEBUFFER) { result = system.setSpeakerMode(FMOD.SPEAKERMODE.STEREO); /* Ok, the speaker mode selected isn't supported by this soundcard. Switch it back to stereo... */ ERRCHECK(result); result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null); /* Replace with whatever channel count and flags you use! */ ERRCHECK(result); } /* * Set the distance units. (meters/feet etc). */ result = system.set3DSettings(1.0f, DISTANCEFACTOR, 1.0f); ERRCHECK(result); /* * Load some sounds */ result = system.createSound("../../../../../examples/media/drumloop.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._3D), ref sound1); ERRCHECK(result); result = sound1.set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR); ERRCHECK(result); result = sound1.setMode(FMOD.MODE.LOOP_NORMAL); ERRCHECK(result); result = system.createSound("../../../../../examples/media/jaguar.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._3D), ref sound2); ERRCHECK(result); result = sound2.set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR); ERRCHECK(result); result = sound2.setMode(FMOD.MODE.LOOP_NORMAL); ERRCHECK(result); result = system.createSound("../../../../../examples/media/swish.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._2D), ref sound3); ERRCHECK(result); /* * Play sounds at certain positions */ { FMOD.VECTOR pos1 = new FMOD.VECTOR(); pos1.x = -10.0f * DISTANCEFACTOR; pos1.y = -0.0f; pos1.z = 0.0f; FMOD.VECTOR vel1 = new FMOD.VECTOR(); vel1.x = 0.0f; vel1.y = 0.0f; vel1.z = 0.0f; result = system.playSound(FMOD.CHANNELINDEX.FREE, sound1, true, ref channel1); ERRCHECK(result); result = channel1.set3DAttributes(ref pos1, ref vel1); ERRCHECK(result); result = channel1.setPaused(false); ERRCHECK(result); } { FMOD.VECTOR pos2 = new FMOD.VECTOR(); pos2.x = 15.0f * DISTANCEFACTOR; pos2.y = -0.0f; pos2.z = -0.0f; FMOD.VECTOR vel2 = new FMOD.VECTOR(); vel2.x = 0.0f; vel2.y = 0.0f; vel2.z = 0.0f; result = system.playSound(FMOD.CHANNELINDEX.FREE, sound2, true, ref channel2); ERRCHECK(result); result = channel2.set3DAttributes(ref pos2, ref vel2); ERRCHECK(result); result = channel2.setPaused(false); ERRCHECK(result); } lastpos.x = 0.0f; lastpos.y = 0.0f; lastpos.z = 0.0f; listenerpos.x = 0.0f; listenerpos.y = 0.0f; listenerpos.z = -1.0f * DISTANCEFACTOR; }
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); }