/// <summary> /// Check and fix any problem with hardware. /// </summary> private void CheckDriver() { //Get number of driver available int DriverNumber = 0; CheckError(m_System.getNumDrivers(ref DriverNumber)); //Driver checking #region Solve hardware problems //If there's 0 driver, no sound if (DriverNumber <= 0) { CheckError(m_System.setOutput(OUTPUTTYPE.NOSOUND)); } else { //Get driver capability int MinFreq = 0, MaxFreq = 0; CAPS Capability = CAPS.NONE; SPEAKERMODE Speakermode = SPEAKERMODE.STEREO; CheckError(m_System.getDriverCaps(0, ref Capability, ref MinFreq, ref MaxFreq, ref Speakermode)); //Set spearker mode according to the driver CheckError(m_System.setSpeakerMode(Speakermode)); //Set buffer if not using hardware accceleration if ((Capability & CAPS.HARDWARE_EMULATED) == CAPS.HARDWARE_EMULATED) { CheckError(m_System.setDSPBufferSize(Global.EMULATED_BUFFERSIZE, Global.EMULATED_BUFFERCOUNT)); } //Get user driver data GUID Guid = new GUID(); StringBuilder DriverName = new StringBuilder(Global.MAX_DRIVERNAME); CheckError(m_System.getDriverInfo(0, DriverName, Global.MAX_DRIVERNAME, ref Guid)); //If driver is sigmatel if (DriverName.Equals(new StringBuilder((Global.SIGMATEL_DRIVERNAME)))) { //Fix crackling CheckError(m_System.setSoftwareFormat( Global.SIGMATEL_SAMPLERATE, SOUND_FORMAT.PCMFLOAT, 0, 0, DSP_RESAMPLER.LINEAR)); } } #endregion }
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 Init() { FMOD.RESULT result; CONTROLS[(int)CONTROLTYPE.DIRECT] = new ControlInfo(new PointF(0.0f, 1.0f), new PointF(0.5f, 0.0f), new PointF(1.0f, 0.6f), new PointF(-0.5f, 0.0f)); CONTROLS[(int)CONTROLTYPE.REVERB] = new ControlInfo(new PointF(0.0f, 0.3f), new PointF(0.5f, 0.0f), new PointF(1.0f, 0.0f), new PointF(-0.5f, 0.0f)); CONTROLS[(int)CONTROLTYPE.LOWPASS] = new ControlInfo(new PointF(0.0f, 1.0f), new PointF(0.5f, 0.0f), new PointF(1.0f, 0.0f), new PointF(-0.5f, 0.0f)); CONTROLS[(int)CONTROLTYPE.ROLLOFF] = new ControlInfo(new PointF(0.0f, 1.0f), new PointF(0.5f, 0.0f), new PointF(1.0f, 0.7f), new PointF(-0.5f, 0.0f)); CONTROLS[(int)CONTROLTYPE.PANLEVEL] = new ControlInfo(new PointF(0.0f, 0.0f), new PointF(0.5f, 0.0f), new PointF(0.7f, 1.0f), new PointF(-0.5f, 0.0f)); result = FMOD.Factory.System_Create(ref system); ERRCHECK(result); uint version = 0; 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 minfrequency = 0, maxfrequency = 0; StringBuilder name = new StringBuilder(128); result = system.getDriverCaps(0, ref caps, ref minfrequency, ref maxfrequency, ref speakermode); ERRCHECK(result); result = system.setSpeakerMode(speakermode); ERRCHECK(result); if ((caps & FMOD.CAPS.HARDWARE_EMULATED) == FMOD.CAPS.HARDWARE_EMULATED) { result = system.setDSPBufferSize(1024, 10); ERRCHECK(result); } FMOD.GUID guid = new FMOD.GUID(); result = system.getDriverInfo(0, name, 256, ref guid); ERRCHECK(result); if (name.ToString().IndexOf("SigmaTel") != -1) { result = system.setSoftwareFormat(48000, FMOD.SOUND_FORMAT.PCMFLOAT, 0, 0, FMOD.DSP_RESAMPLER.LINEAR); ERRCHECK(result); } result = system.init(32, FMOD.INITFLAGS.NORMAL | FMOD.INITFLAGS._3D_RIGHTHANDED, (IntPtr)null); if (result == FMOD.RESULT.ERR_OUTPUT_CREATEBUFFER) { result = system.setSpeakerMode(FMOD.SPEAKERMODE.STEREO); ERRCHECK(result); result = system.init(32, FMOD.INITFLAGS.NORMAL | FMOD.INITFLAGS._3D_RIGHTHANDED, (IntPtr)null); ERRCHECK(result); } result = system.set3DSettings(2.0f, 100.0f, 1.0f); ERRCHECK(result); result = system.set3DRolloffCallback(ROLLOFFCALLBACK); ERRCHECK(result); 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; FMOD.VECTOR dir; dir.x = 0.0f; dir.y = 1.0f; dir.z = 0.0f; FMOD.VECTOR up; up.x = 0.0f; up.y = 0.0f; up.z = 1.0f; result = system.get3DListenerAttributes(0, ref pos, ref vel, ref dir, ref up); ERRCHECK(result); FMOD.PRESET preset = new FMOD.PRESET(); REVERB[(int)REVERBTYPE.OFF] = preset.OFF(); REVERB[(int)REVERBTYPE.GENERIC] = preset.GENERIC(); REVERB[(int)REVERBTYPE.PADDEDCELL] = preset.PADDEDCELL(); REVERB[(int)REVERBTYPE.ROOM] = preset.ROOM(); REVERB[(int)REVERBTYPE.BATHROOM] = preset.BATHROOM(); REVERB[(int)REVERBTYPE.LIVINGROOM] = preset.LIVINGROOM(); REVERB[(int)REVERBTYPE.STONEROOM] = preset.STONEROOM(); REVERB[(int)REVERBTYPE.AUDITORIUM] = preset.AUDITORIUM(); REVERB[(int)REVERBTYPE.CONCERTHALL] = preset.CONCERTHALL(); REVERB[(int)REVERBTYPE.CAVE] = preset.CAVE(); REVERB[(int)REVERBTYPE.ARENA] = preset.ARENA(); REVERB[(int)REVERBTYPE.HANGAR] = preset.HANGAR(); REVERB[(int)REVERBTYPE.CARPETTEDHALLWAY] = preset.CARPETTEDHALLWAY(); REVERB[(int)REVERBTYPE.HALLWAY] = preset.HALLWAY(); REVERB[(int)REVERBTYPE.STONECORRIDOR] = preset.STONECORRIDOR(); REVERB[(int)REVERBTYPE.ALLEY] = preset.ALLEY(); REVERB[(int)REVERBTYPE.FOREST] = preset.FOREST(); REVERB[(int)REVERBTYPE.CITY] = preset.CITY(); REVERB[(int)REVERBTYPE.MOUNTAINS] = preset.MOUNTAINS(); REVERB[(int)REVERBTYPE.QUARRY] = preset.QUARRY(); REVERB[(int)REVERBTYPE.PLAIN] = preset.PLAIN(); REVERB[(int)REVERBTYPE.PARKINGLOT] = preset.PARKINGLOT(); REVERB[(int)REVERBTYPE.SEWERPIPE] = preset.SEWERPIPE(); REVERB[(int)REVERBTYPE.UNDERWATER] = preset.UNDERWATER(); SetReverb(REVERBTYPE.OFF); return(true); }