public bool Create(SoundSystemConfig config) { uint version = 0; int samplerate = 44100; FMOD.SOUND_FORMAT format = FMOD.SOUND_FORMAT.PCM16; FMOD.RESULT result = FMOD.Factory.System_Create(ref m_system); if (ERRCHECK(result, "Create") == false) { return(false); } result = m_system.getVersion(ref version); if (!ERRCHECK(result)) { return(false); } if (version < FMOD.VERSION.number) { Console.WriteLine("INCORRECT DLL VERSION!!", "FMOD ERROR"); return(false); } result = m_system.setDriver(config.SoundCard); ERRCHECK(result); switch (config.Output) { case RASOUNDAUSGABE.WINMM: m_system.setOutput(FMOD.OUTPUTTYPE.WINMM); break; case RASOUNDAUSGABE.WASAPI: m_system.setOutput(FMOD.OUTPUTTYPE.WASAPI); break; case RASOUNDAUSGABE.DSOUND: m_system.setOutput(FMOD.OUTPUTTYPE.DSOUND); break; case RASOUNDAUSGABE.ASIO: m_system.setOutput(FMOD.OUTPUTTYPE.ASIO); break; } ; switch (config.Format) { case RASOUNDFORMAT.PCM16_44100: samplerate = 44100; format = FMOD.SOUND_FORMAT.PCM16; break; case RASOUNDFORMAT.PCM16_48000: samplerate = 48000; format = FMOD.SOUND_FORMAT.PCM16; break; case RASOUNDFORMAT.PCM16_96000: samplerate = 96000; format = FMOD.SOUND_FORMAT.PCM16; break; case RASOUNDFORMAT.PCM24_44100: samplerate = 44100; format = FMOD.SOUND_FORMAT.PCM24; break; case RASOUNDFORMAT.PCM24_48000: samplerate = 48000; format = FMOD.SOUND_FORMAT.PCM24; break; case RASOUNDFORMAT.PCM24_96000: samplerate = 96000; format = FMOD.SOUND_FORMAT.PCM24; break; case RASOUNDFORMAT.PCM24_192000: samplerate = 192000; format = FMOD.SOUND_FORMAT.PCM24; break; case RASOUNDFORMAT.PCMFLOAT_44100: samplerate = 44100; format = FMOD.SOUND_FORMAT.PCMFLOAT; break; case RASOUNDFORMAT.PCMFLOAT_48000: samplerate = 48000; format = FMOD.SOUND_FORMAT.PCMFLOAT; break; case RASOUNDFORMAT.PCMFLOAT_96000: samplerate = 96000; format = FMOD.SOUND_FORMAT.PCMFLOAT; break; case RASOUNDFORMAT.PCMFLOAT_192000: samplerate = 192000; format = FMOD.SOUND_FORMAT.PCMFLOAT; break; case RASOUNDFORMAT.PCM32_44100: samplerate = 44100; format = FMOD.SOUND_FORMAT.PCM32; break; case RASOUNDFORMAT.PCM32_48000: samplerate = 48000; format = FMOD.SOUND_FORMAT.PCM32; break; case RASOUNDFORMAT.PCM32_96000: samplerate = 96000; format = FMOD.SOUND_FORMAT.PCM32; break; case RASOUNDFORMAT.PCM32_192000: samplerate = 192000; format = FMOD.SOUND_FORMAT.PCM32; break; } m_system.setSoftwareFormat(samplerate, format, 0, 0, FMOD.DSP_RESAMPLER.LINEAR); switch (config.Channel) { case RACHANNELMODE.Mono: result = m_system.setSpeakerMode(FMOD.SPEAKERMODE.MONO); break; case RACHANNELMODE.Stereo: result = m_system.setSpeakerMode(FMOD.SPEAKERMODE.STEREO); break; case RACHANNELMODE.Quad: result = m_system.setSpeakerMode(FMOD.SPEAKERMODE.QUAD); break; case RACHANNELMODE.FiveDotOne: result = m_system.setSpeakerMode(FMOD.SPEAKERMODE._5POINT1); break; case RACHANNELMODE.SevenDotOne: result = m_system.setSpeakerMode(FMOD.SPEAKERMODE._7POINT1); break; case RACHANNELMODE.Surround: result = m_system.setSpeakerMode(FMOD.SPEAKERMODE.SURROUND); break; } ; result = m_system.init(32, FMOD.INITFLAGS._3D_RIGHTHANDED | FMOD.INITFLAGS.DTS_NEURALSURROUND, IntPtr.Zero); if (!ERRCHECK(result)) { return(false); } m_system.set3DSettings(1.0f, 1.0f, 1.0f); Console.WriteLine("[FMOD] SoundSystem created"); m_system.get3DListenerAttributes(0, ref pos, ref vel, ref forward, ref up); return(true); }
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); }