public static void Play() { if (CurrentSong != null && !IsSongPlaying()) { Channel.setPaused(false); } }
private void frontLeft_Click(object sender, System.EventArgs e) { FMOD.RESULT result; result = system.playSound(FMOD.CHANNELINDEX.FREE, sound1, true, ref channel); ERRCHECK(result); result = channel.setSpeakerMix(1.0f, 0, 0, 0, 0, 0, 0, 0); ERRCHECK(result); result = channel.setPaused(false); ERRCHECK(result); }
/// <summary> /// Takes a media info object and plays it on an open channel /// </summary> /// <param name="media"></param> /// <returns></returns> private void PlayStream() { //result FMOD.RESULT result; //play the sound on the channel result = _system.playSound(_sound, null, true, out _channel); CheckError(result); //prepare the equalizer SetupEqualizer(); //create the dsp, although it will not be active at this time result = _system.createDSP(ref _dspDesc, out _dsp); ////deactivate //_dsp.setBypass(true); //add to dsp chain _channel.addDSP(0, _dsp); //unpause when ready to begin playing result = _channel.setPaused(false); CheckError(result); ////activate //_dsp.setBypass(false); //fire PlaybackStatusChanged event OnPlaybackStatusChanged(); //hold the thread hostage while (GetIsPlaying()) { //check to see if playback should stop if (_playbackCts.IsCancellationRequested) { //we requested to stop playback break; } //get the current position InternalPosition = GetPosition(); //update fmod Update(); //sleep for a few miliseconds Thread.Sleep(25); } }
//Use this to pause or resume sound public void PauseResume() { bool isPaused; _channel.getPaused(out isPaused); _channel.setPaused(!isPaused); }
public static void Pause(bool paused) { if (SoundEngine.IsPlaying()) { FMODChannel.setPaused(paused); } }
FMOD.Channel PlayOsc(RenderParams rp, RenderCanvas canvas) { FMOD.Channel channel = null; FMOD.RESULT r = MusicEngine.AudioEngine.playDSP(FMOD.CHANNELINDEX.FREE, _dsp, true, ref channel); if (r == FMOD.RESULT.OK && channel != null) { // set regular play properties AdaptChannelSettings(channel, rp, canvas); // set optional DSP unit(s) on channel if (r == FMOD.RESULT.OK) { FMOD.DSPConnection conn = null; foreach (FMOD.DSP d in _dspList) { r = channel.addDSP(d, ref conn); // TODO errcheck } // go - start playing if (r == FMOD.RESULT.OK) { r = channel.setPaused(false); } } } // if return(channel); }
public override void Play() { CheckChannel(); //FMOD_Audio.CheckFMODResult(); FMOD_Audio.CheckFMODResult(mChannel.setPaused(false)); }
public SoundSource(FMOD.System system, FMOD.Sound sound, int posx, int posy) { FMOD.RESULT result; mPos.x = posx; mPos.y = posy; mPos.z = 0; mVel.x = 0; mVel.y = 0; mVel.z = 0; mSystem = system; result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, true, ref mChannel); VirtualVoices.ERRCHECK(result); SetPosition(mPos.x, mPos.y); Random r = new Random(posx); result = mChannel.setFrequency(r.Next(22050, 44100)); VirtualVoices.ERRCHECK(result); result = mChannel.setPaused(false); VirtualVoices.ERRCHECK(result); mBrushBlue = new SolidBrush(Color.Blue); mBrushRed = new SolidBrush(Color.Red); }
/// <summary> /// volume은 0 ~ 1 /// </summary> public static void Play(int index, float volume) { FMOD.Channel channel = null; sys.playSound(FMOD.CHANNELINDEX.FREE, sounds[index], true, ref channel); channel.setVolume(volume); channel.setPaused(false); }
private void pause_Click(object sender, System.EventArgs e) { bool paused = false; if (channel != null) { channel.getPaused(ref paused); channel.setPaused(!paused); } }
public void PlayDialog(string path) { if (path != null) { string play; play = "Media/Sounds/Dialogs/" + path; LastDialog = play; Result = System.createStream(play, FMOD.MODE.DEFAULT, ref SoundDialog); Result = System.playSound(FMOD.CHANNELINDEX.REUSE, SoundDialog, false, ref ChannelDialog); Volume = _volume; } else { Result = ChannelDialog.setPaused(false); } }
private void pause_Click(object sender, System.EventArgs e) { FMOD.RESULT result; bool paused = false; result = channel.getPaused(ref paused); ERRCHECK(result); result = channel.setPaused(!paused); ERRCHECK(result); }
/// <summary> /// 暂停 /// </summary> public void pause() { if (channelMusic == null) { return; } try { channelMusic.setPaused(true); //mciSendString("pause media", "", 0, 0); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
public void Pause(bool paused) { if (IsPlaying) { if (mciCDEngine != null) { mciCDEngine.Pause(paused); } else { currentChannel.setPaused(paused); } } }
public void TogglePauseBGM() { if (IsBGMPlaying) { IsBGMPlaying = false; } else { IsBGMPlaying = true; } Result = ChannelBGM.setPaused(!IsBGMPlaying); Volume = _volume; }
private void sineWave_Click(object sender, System.EventArgs e) { FMOD.RESULT result; float pan = 0, frequency = 0; if (channel != null) { channel.stop(); } if (dsp != null) { dsp.release(); } /* * Create an oscillator DSP unit for the tone. */ result = system.createDSPByType(FMOD.DSP_TYPE.OSCILLATOR, ref dsp); ERRCHECK(result); result = dsp.setParameter((int)FMOD.DSP_OSCILLATOR.RATE, 440.0f); /* musical note 'A' */ ERRCHECK(result); result = system.playDSP(FMOD.CHANNELINDEX.REUSE, dsp, true, ref channel); ERRCHECK(result); channel.setVolume(0.5f); result = dsp.setParameter((int)FMOD.DSP_OSCILLATOR.TYPE, 0); ERRCHECK(result); channel.setPaused(false); channel.getFrequency(ref frequency); channel.getPan(ref pan); trackBarVolume.Value = 512; trackBarFrequency.Value = (int)frequency; trackBarPan.Value = (int)(pan * 512); }
private bool PlaySound(FMOD.Sound sound) { try { FMOD.Channel channel = null; FMOD.RESULT result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, true, ref channel); if (result == FMOD.RESULT.OK && channel != null) { channel.setVolume(volume); channel.setPaused(false); } return(FMOD.ERROR.ERRCHECK(result)); } catch { return(false); } }
private bool PlayMusicCallback(FMOD.Sound sound) { FMOD.RESULT result; lock (syncMusicCallback) { bool isPlaying = false; manualMusicEnd = false; if (channel != null) { channel.isPlaying(ref isPlaying); } else { isPlaying = false; } if (isPlaying && channel != null) { manualMusicEnd = true; InfoLog.WriteInfo(DateTime.Now.ToString() + " | Music is playing, Manual music end: " + manualMusicEnd, EPrefix.AudioEngine); channel.setMute(true); channel.stop(); channel = null; } else { InfoLog.WriteInfo(DateTime.Now.ToString() + " | Music is not playing, Manual music end: " + manualMusicEnd, EPrefix.AudioEngine); } result = system.playSound(FMOD.CHANNELINDEX.REUSE, sound, true, ref channel); if (result == FMOD.RESULT.OK && channel != null) { channel.setVolume(volume); channel.setCallback(FMOD.CHANNEL_CALLBACKTYPE.END, endPlayCallback, 0); InfoLog.WriteInfo(DateTime.Now.ToString() + " | Before Play music begin", EPrefix.AudioEngine); channel.setPaused(false); } } InfoLog.WriteInfo(DateTime.Now.ToString() + " | After Play music begin, result: " + result, EPrefix.AudioEngine); return(FMOD.ERROR.ERRCHECK(result)); }
public Channel Play(Sound sound, Vector3 pos, bool loop) { FMOD.Channel channel = null; FMOD.RESULT result; result = system.playSound(FMOD.CHANNELINDEX.FREE, ((FmodSound)sound).sound, true, ref channel); ERRCHECK(result); FmodChannel c = new FmodChannel(channel); SetPosition(c, pos); if (loop) { channel.setLoopCount(-1); } channel.setPaused(false); return(c); }
private void pauseButton_Click(object sender, System.EventArgs e) { if (channel != null) { bool ispaused = false; channel.getPaused(ref ispaused); channel.setPaused(!ispaused); if (ispaused) { pauseButton.Text = "Pause"; } else { pauseButton.Text = "Resume"; } } }
FMOD.Channel PlaySample(RenderParams rp, RenderCanvas canvas, List <FMOD.DSP> dspList) { FMOD.Channel channel = null; FMOD.RESULT r = MusicEngine.AudioEngine.playSound(FMOD.CHANNELINDEX.FREE, _sound, true, ref channel); if (r == FMOD.RESULT.OK && channel != null) { // set regular play properties AdaptChannelSettings(channel, rp, canvas); // set play position uint tMs = (uint)Math.Round(rp.Time * 1000.0); if (tMs > 0) { // only set position if there is a need r = channel.setPosition(tMs, FMOD.TIMEUNIT.MS); #if DEBUG Util.Log(" setPos(" + tMs + ")"); #endif } // set optional DSP unit(s) on channel if (r == FMOD.RESULT.OK) { FMOD.DSPConnection conn = null; foreach (FMOD.DSP d in dspList) { r = channel.addDSP(d, ref conn); // TODO errcheck } // go - start playing if (r == FMOD.RESULT.OK) { r = channel.setPaused(false); } } } // if Util.ERRCHECK(r); return(channel); }
public void Play() { #if !NO_FMOD if (Playing && mChannel != null) { bool paused = false; mChannel.getPaused(ref paused); if (paused) { mChannel.setPaused(false); return; } else { throw new InvalidOperationException(); } } else { if (data._streamIndex >= 0) { if (mStreamBytes != null) { mAbortStream = false; return; } // if this isn't true, we may have 2 async requests to play, which would be super bad GSGE.Debug.assert(mStreamBytes == null); GSGE.Debug.assert(mAbortStream == false); } if (mSound != null) { Dispose(); } FMOD.RESULT result; FMOD.CREATESOUNDEXINFO exinfo = SoundData.exinfo; exinfo.cbsize = Marshal.SizeOf(exinfo); // allocate streaming? if (data._size > 0) { mStreamRequested = true; mStreamBytes = new byte[data._size]; string file = "Content/Audio/"; if (data._persist) { file += "Deferred/"; } else { file += "Streaming/"; } file += data._streamIndex; file += ".mp3"; //GSGE.Debug.logMessage("streaming audio " + file); NaCl.AsyncFS.FileStream fs = new NaCl.AsyncFS.FileStream(file, System.IO.FileMode.Open); fs.BeginRead(mStreamBytes, 0, mStreamBytes.Length, delegate(IAsyncResult aresult) { int bytesRead; try { bytesRead = fs.EndRead(aresult); } catch (System.IO.FileNotFoundException) { bytesRead = -1; } fs.Close(); if (bytesRead != data._size) { GSGE.Debug.logMessage("Error streaming in sound " + data._streamIndex); mStreamStarted = true; Dispose(); return; } if (data._persist) { byte[] audiodata = mStreamBytes; mStreamBytes = null; mStreamRequested = false; mStreamStarted = false; // reconfigure parent Sound to be persistent now. data.setPersistent(audiodata); if (mAbortStream) { Dispose(); } else { Play(); } } else { mStreamStarted = true; if (mAbortStream) { Dispose(); } else { exinfo.length = (uint)mStreamBytes.Length; FMOD.MODE mode = FMOD.MODE.OPENMEMORY_POINT | FMOD.MODE.CREATECOMPRESSEDSAMPLE | FMOD.MODE.SOFTWARE; if (data._looping) { mode |= FMOD.MODE.LOOP_NORMAL; } result = FMOD.Framework.system.createSound(mStreamBytes, mode, ref exinfo, ref mSound); mOwnSound = true; ERRCHECK(result); AudioEngine audioengine = GSGE.AudioManager.GetAudioManager().GetAudioEngine(); audioengine.FmodSounds.Add(this); result = FMOD.Framework.system.playSound(FMOD.CHANNELINDEX.FREE, mSound, false, ref mChannel); if (mSound == null) { Dispose(); } else { GSGE.Debug.assert(mSound != null); ERRCHECK(result); mChannel.getFrequency(ref mBaseFrequency); } } } // all streaming sounds need to assign these asap Volume = _volume; Pitch = _pitch; LowPassCutoff = _lowPassCutoff; Reverb = _reverb; mAbortStream = false; }, null); } else { if (data.mSound == null) { data.createSound(); } //exinfo.length = (uint)data.data.Length; //FMOD.MODE mode = FMOD.MODE.OPENMEMORY_POINT | FMOD.MODE.CREATECOMPRESSEDSAMPLE | FMOD.MODE.SOFTWARE; //if (data._looping) // mode |= FMOD.MODE.LOOP_NORMAL; //result = FMOD.Framework.system.createSound(data.data, mode, ref exinfo, ref mSound); //ERRCHECK(result); mSound = data.mSound; if (mSound == null) { Dispose(); return; } GSGE.Debug.assert(mSound != null); AudioEngine audioengine = GSGE.AudioManager.GetAudioManager().GetAudioEngine(); audioengine.FmodSounds.Add(this); result = FMOD.Framework.system.playSound(FMOD.CHANNELINDEX.FREE, mSound, false, ref mChannel); GSGE.Debug.assert(mSound != null); ERRCHECK(result); mChannel.getFrequency(ref mBaseFrequency); } } #endif }
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); }
public static void Play(string key, int speaker, float volume = 1f, bool loop = false) { #if NO_AUDIO return; #endif // play audio FMOD.RESULT result = system.playSound(FMOD.CHANNELINDEX.FREE, sounds[key], true, ref channel); ERRCHECK(result); result = channel.setVolume(volume); ERRCHECK(result); int index = 0; channel.getIndex(ref index); channelIDs.Add(index); FMOD.MODE loopAudio = (loop) ? FMOD.MODE.LOOP_NORMAL : FMOD.MODE.LOOP_OFF; result = channel.setMode(loopAudio); //SPEAKER 1 (Satelite Audio, Side Specific) if (speaker == 0) { result = channel.setSpeakerMix(0, 0, 0, 0, 0, 0, 1.0f, 0); ERRCHECK(result); } //SPEAKER 2 (Satelite Audio, Side Specific) if (speaker == 1) { result = channel.setSpeakerMix(0, 0, 0, 0, 0, 0, 0, 1.0f); ERRCHECK(result); } //SPEAKER 3 (Satelite Audio, Side Specific) if (speaker == 2) { result = channel.setSpeakerMix(0, 0, 0, 0, 1.0f, 0, 0, 0); ERRCHECK(result); } //SPEAKER (Satelite Audio, Side Specific) if (speaker == 3) { result = channel.setSpeakerMix(0, 0, 0, 0, 0, 1.0f, 0, 0); ERRCHECK(result); } //SPEAKER 5 (Subwoofer) if (speaker == 4) { result = channel.setSpeakerMix(0, 0, 1.0f, 0, 0, 0, 0, 0); ERRCHECK(result); } if (isMuted) { channel.setMute(isMuted); } result = channel.setPaused(false); ERRCHECK(result); }