public void InitiateLoadedSound(SoundResource soundResource) { float dummy = 0f; int dummyI = 0; float baseFrequency = 0; FMOD.Sound sound = (FMOD.Sound)soundResource.SoundGlue.InnerSoundObject; ERRCHECK(sound.set3DMinMaxDistance(minMaxDistance.X, minMaxDistance.Y)); ERRCHECK(sound.getDefaults(ref baseFrequency, ref dummy, ref dummy, ref dummyI)); ERRCHECK(sound.setDefaults(soundResource.PlaybackSpeed * baseFrequency, soundResource.Volume, 0f, (int)soundResource.Priority)); soundResource.BaseFrequency = baseFrequency; if (soundResource.SoundGroupEnum != SoundGroups.Default) { ERRCHECK(sound.setSoundGroup((FMOD.SoundGroup)SoundManager.Instance.GetSoundGroup(soundResource.SoundGroupEnum).SoundGroupGlue.InnerSoundGroupObject)); } }
public Sound Load(Stream s) { byte[] buffer = new byte[s.Length]; s.Read(buffer, 0, (int)s.Length); FMOD.RESULT result; FMOD.Sound sound1 = null; FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO(); exinfo.cbsize = Marshal.SizeOf(exinfo); exinfo.length = (uint)s.Length; //result = system.createSound(buffer, (FMOD.MODE.HARDWARE | FMOD.MODE._3D | FMOD.MODE.OPENMEMORY), ref exinfo, ref sound1); result = system.createSound(buffer, (FMOD.MODE.HARDWARE | FMOD.MODE._3D | FMOD.MODE.OPENMEMORY | FMOD.MODE._3D_LINEARROLLOFF), ref exinfo, ref sound1); ERRCHECK(result); sound1.set3DMinMaxDistance(500, 5000); return(new FmodSound(this, sound1, false)); }
private void VirtualVoices_Load(object sender, System.EventArgs e) { FMOD.RESULT result; /* * Create a System object and initialize. */ result = FMOD.Factory.System_Create(ref system); ERRCHECK(result); result = system.setSoftwareChannels(NUMREALCHANNELS); ERRCHECK(result); result = system.init(NUMCHANNELS, FMOD.INITFLAGS.NORMAL, (IntPtr)null); ERRCHECK(result); result = system.createSound("../../../../../examples/media/drumloop.wav", (FMOD.MODE.SOFTWARE | FMOD.MODE._3D | FMOD.MODE.LOOP_NORMAL), ref sound); ERRCHECK(result); result = sound.set3DMinMaxDistance(4.0f, 10000.0f); ERRCHECK(result); /* * Create a listener in the middle of the window */ mListener = new Listener(system, WIDTH / 2, HEIGHT / 2); /* * Initialise all of the sound sources */ Random r = new Random(); mSoundSource = new SoundSource[NUMCHANNELS]; for (int count = 0; count < NUMCHANNELS; count++) { mSoundSource[count] = new SoundSource(system, sound, r.Next(this.Width), r.Next(this.Height)); } }
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; }