public void Play(string audioPath, bool loop = false, int loopCount = -1) { if (!Game.dummyAudioOn) { return; } Stop(); FMOD.Sound sound = _audioMaster.LoadSound(audioPath); if (loop) { sound.setMode(FMOD.MODE.LOOP_NORMAL); sound.setLoopCount(loopCount - 1); } else { sound.setMode(FMOD.MODE.LOOP_OFF); } FMOD.RESULT result; result = _audioMaster.GetFmodSystem().playSound(sound, null, true, out _channel); // 3rd parameter : paused if (result != FMOD.RESULT.OK) { Console.WriteLine("[SpeakerComponent Play] FMOD playSound failed : " + result); } UpdateSpeakerAttributes(); setVolume(100.0f); PauseResume(); }
public void UpdateSound(string name, ref FMOD.Sound s, Boolean Loop) { FMOD.RESULT result; string strNameSpace = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString(); Stream str = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(strNameSpace + ".Sounds." + name); //Block = new Bitmap(str); byte[] Arr = new byte[str.Length]; str.Read(Arr, 0, (int)str.Length); FMOD.CREATESOUNDEXINFO inf = new FMOD.CREATESOUNDEXINFO(); inf.cbsize = Marshal.SizeOf(inf); inf.length = (uint)str.Length; result = soundsystem.createSound(Arr, FMOD.MODE.SOFTWARE | FMOD.MODE.OPENMEMORY | FMOD.MODE._3D, ref inf, ref s); ERRCHECK(result); if (!Loop) { s.setMode(FMOD.MODE.LOOP_OFF); } else { s.setMode(FMOD.MODE.LOOP_NORMAL); } ERRCHECK(result); }
private void PlaySound_Load(object sender, System.EventArgs e) { uint version = 0; FMOD.RESULT result; /* * 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(); } result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null); ERRCHECK(result); result = system.createSound("../../../../../examples/media/drumloop.wav", FMOD.MODE.HARDWARE, ref sound1); ERRCHECK(result); result = sound1.setMode(FMOD.MODE.LOOP_OFF); ERRCHECK(result); result = system.createSound("../../../../../examples/media/jaguar.wav", FMOD.MODE.SOFTWARE, ref sound2); ERRCHECK(result); result = system.createSound("../../../../../examples/media/swish.wav", FMOD.MODE.HARDWARE, ref sound3); ERRCHECK(result); }
void createFMODSound(string fn) { // load the _sound FMOD.RESULT r; r = MusicEngine.AudioEngine.createSound(fn, FMOD.MODE.SOFTWARE, ref _sound); if (Util.ERRCHECK(r)) { throw new ContentLoadException(Util.ERRMSG(r)); } else { if (_sound != null) { r = _sound.setMode(FMOD.MODE.LOOP_NORMAL); // enable loop functionality, Util.ERRCHECK(r); r = _sound.setLoopCount(0); // but do not loop by default Util.ERRCHECK(r); // determine sample duration uint l = 0; r = _sound.getLength(ref l, FMOD.TIMEUNIT.MS); if (!Util.ERRCHECK(r)) { _soundDuration = ((double)l) / 1000.0; } } else { Util.Log("AudioSample.createFMODSound(): Error, _sound is null."); } } }
private void playButton_Click(object sender, System.EventArgs e) { FMOD.RESULT result; if (looping) { result = sound.setMode(FMOD.MODE.LOOP_NORMAL); } else { result = sound.setMode(FMOD.MODE.LOOP_OFF); } ERRCHECK(result); result = system.playSound(FMOD.CHANNELINDEX.REUSE, sound, false, ref channel); ERRCHECK(result); }
public override void Initialize() { base.Initialize(); GameContainer.SoundSystem.createSound("nectar\\sounds\\wind_med.ogg", FMOD.MODE.HARDWARE, ref windGust1); GameContainer.SoundSystem.createSound("nectar\\sounds\\wind_quiet.ogg", FMOD.MODE.HARDWARE, ref windGust2); GameContainer.SoundSystem.createSound("nectar\\sounds\\wind_quiet2.ogg", FMOD.MODE.HARDWARE, ref windGust3); windGust1.setMode(FMOD.MODE.DEFAULT); windGust2.setMode(FMOD.MODE.DEFAULT); windGust3.setMode(FMOD.MODE.DEFAULT); }
public void SetLoop(bool Loop) { if (!SoundSystem.AudioFound) { return; } RESULT result = RESULT.OK; if (Loop) { result = _sound.setMode(FMOD.MODE.LOOP_NORMAL); } else { result = _sound.setMode(FMOD.MODE.LOOP_OFF); } if (result != RESULT.OK) { throw new Exception("Loop Count Set Failed\r\n" + result.ToString()); } }
public override void Initialize() { base.Initialize(); GameContainer.SoundSystem.createSound("Content\\Sounds\\hit1.wav", FMOD.MODE.HARDWARE, ref hit1); GameContainer.SoundSystem.createSound("Content\\Sounds\\hit2.wav", FMOD.MODE.HARDWARE, ref hit2); GameContainer.SoundSystem.createSound("Content\\Sounds\\hit3.wav", FMOD.MODE.HARDWARE, ref hit3); hit1.setMode(FMOD.MODE.LOOP_OFF); hit2.setMode(FMOD.MODE.LOOP_OFF); hit3.setMode(FMOD.MODE.LOOP_OFF); GameContainer.SoundSystem.createSound("Content\\Sounds\\score.wav", FMOD.MODE.HARDWARE, ref score); score.setMode(FMOD.MODE.LOOP_OFF); }
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { FMOD.RESULT result; int selected = comboBox1.SelectedIndex; result = systemA.setDriver(selected); ERRCHECK(result); result = systemA.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null); ERRCHECK(result); comboBox1.Enabled = false; playA.Enabled = true; /* * Load a sample into soundcard */ result = systemA.createSound("../../../../../examples/media/drumloop.wav", FMOD.MODE.HARDWARE, ref soundA); ERRCHECK(result); result = soundA.setMode(FMOD.MODE.LOOP_OFF); ERRCHECK(result); }
private void MultiSpeakerOutput_Load(object sender, System.EventArgs e) { uint version = 0; FMOD.RESULT result; /* * 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(); } /* * Choose the highest mode possible. * If the user doesn't have 7.1 speakers, then only the speakers they have will be audible. */ system.setSpeakerMode(FMOD.SPEAKERMODE._7POINT1); ERRCHECK(result); result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null); ERRCHECK(result); result = system.createSound("../../../../../examples/media/drumloop.wav", (FMOD.MODE.SOFTWARE | FMOD.MODE._2D), ref sound1); ERRCHECK(result); result = sound1.setMode(FMOD.MODE.LOOP_OFF); ERRCHECK(result); result = system.createSound("../../../../../examples/media/stereo.ogg", (FMOD.MODE.SOFTWARE | FMOD.MODE._2D), ref sound2); ERRCHECK(result); }
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; }