internal bool IsChannelPlaying(FMOD.Channel channel) { if (channel == null) { return(false); } bool playing = false; bool paused = false; FMOD.RESULT result = channel.isPlaying(ref playing); if (result != FMOD.RESULT.OK) { return(false); } if (playing == false) { return(playing); } if (channel.getPaused(ref paused) == FMOD.RESULT.OK) { return(!paused); } channel = null; return(false); }
/// <summary> /// Initializes a new <see cref="FMODChannel"/> and sets it's values to the ones specified /// </summary> /// <param name="channel">The FMOD.Channel to wrap around</param> /// <param name="sound">The FMOD.Sound to wrap</param> /// <param name="context">The SynchronizationContext to use for callbacks</param> /// <param name="id">the ID of this container</param> /// <param name="system">The <see cref="FMODSystem"/> that contains this channel</param> internal FMODChannel(FMODSystem system, FMOD.Channel channel, FMOD.Sound sound, Guid id) { this.system = system; this.id = id; this.Channel = channel; this.sound = sound; }
void StopFMODSound() { if (channel != null) { result = channel.stop(); // ERRCHECK(result, "channel.stop", false); } channel = null; System.Threading.Thread.Sleep(50); if (sound != null) { result = sound.release(); // ERRCHECK(result, "sound.release", false); } sound = null; if (this.pcmReadCallbackBuffer != null) { this.pcmReadCallbackBuffer[0].Clear(); this.pcmReadCallbackBuffer[1].Clear(); } }
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); }
private void FMODrelease() { if (channel != null) { FMOD.Sound currentSound; FMOD.RESULT result = channel.getCurrentSound(out currentSound); if (result != FMOD.RESULT.ERR_CHANNEL_STOLEN) { ERRCHECK(result, "channel.getCurrentSound", false); if (currentSound == sound || currentSound == subSound) { result = channel.stop(); if (result != FMOD.RESULT.ERR_CHANNEL_STOLEN) { ERRCHECK(result, "channel.stop", false); } } } channel = null; } if (subSound != null) { FMOD.RESULT result = subSound.release(); ERRCHECK(result, "subSound.release", false); subSound = null; } if (sound != null) { FMOD.RESULT result = sound.release(); ERRCHECK(result, "sound.release", false); sound = null; } }
private void button1_Click(object sender, System.EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); if (sound != null) { if (channel != null) { channel.stop(); channel = null; } sound.release(); sound = null; } if (dialog.ShowDialog() == DialogResult.OK) { FMOD.RESULT result; result = system.createStream(dialog.FileName, FMOD.MODE.SOFTWARE | FMOD.MODE._2D, ref sound); ERRCHECK(result); textBox.Text = dialog.FileName; } playButton.Text = "Play"; }
/// <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); }
public SoundSystem() { var ret = FMOD.Result.OK; system = null; try { FMOD.Factory.CreateSystem(ref system); } catch (DllNotFoundException) { return; } if (ret != FMOD.Result.OK) { return; } ret = system.Initialize(8, FMOD.InitFlags.Normal, IntPtr.Zero); if (ret != FMOD.Result.OK) { system = null; return; } sounds = new Dictionary <string, Sound>(); music = null; musicChannel = null; }
private void playButton_Click(object sender, System.EventArgs e) { FMOD.RESULT result; bool isplaying = false; if (channel != null) { channel.isPlaying(ref isplaying); } if (sound != null && !isplaying) { result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel); ERRCHECK(result); playButton.Text = "Stop"; } else { if (channel != null) { channel.stop(); channel = null; } playButton.Text = "Play"; } }
public SoundSystem() { var ret = FMOD.Result.OK; system = null; Program.WriteLine("SoundSystem: _ctor"); if (!IniFile.GetValue("audio", "enabled", true)) { return; } musicVolume = IniFile.GetValue("audio", "musicvolume", 100) / 100f; soundVolume = IniFile.GetValue("audio", "soundvolume", 100) / 100f; Program.Write("SoundSystem: trying to create FMOD system..."); try { FMOD.Factory.CreateSystem(ref system); } catch (DllNotFoundException) { Program.WriteLine(" Library not found. Disabling sound."); return; } Program.WriteLine(" " + ret.ToString()); if (ret != FMOD.Result.OK) { return; } Program.Write("SoundSystem: system.init..."); ret = system.Initialize(8, FMOD.InitFlags.Normal, IntPtr.Zero); Program.WriteLine(" " + ret.ToString()); if (ret != FMOD.Result.OK) { system = null; return; } music = null; musicChannel = null; sounds = new Dictionary <string, Sound>(); Program.WriteLine("SoundSystem: loading libraries..."); musicLibrary = Mix.GetTokenTree("music.tml"); soundLibrary = Mix.GetTokenTree("sound.tml"); Program.WriteLine("SoundSystem: _ctor DONE"); Program.WriteLine("Null report:"); if (system == null) { Program.WriteLine(" * system"); } if (music == null) { Program.WriteLine(" * music"); } if (musicChannel == null) { Program.WriteLine(" * musicChannel"); } }
/// <summary> /// Frees channel, sound and DSP resources /// </summary> private void FreeChannelResources() { //stop any playing channels if (_channel != null) { _channel.stop(); _channel = null; } //release sound if (_sound != null) { _sound.release(); _sound = null; } //free waveform DSP if (_dsp != null) { _dsp.release(); _dsp = null; } //destroy the equalizer DestroyEqualizer(); }
/** * adapt a running sample according to renderparams and canvas result */ internal void AdaptChannelSettings(FMOD.Channel channel, RenderParams rp, RenderCanvas canvas) { double a = rp.Ampl * canvas.AmplMultiply + canvas.AmplAdd; double p = rp.Pan + canvas.Pan; channel.setVolume((float)a); channel.setPan((float)p); }
public FMODChannel(FMOD.Channel channel, bool looping) { this.channel = channel; FMODManager.Instance.SetChannelMapping(channel.getRaw().ToInt32(), this); FMODManager.ERRCHECK(channel.setCallback(ChannelCallback)); if (looping) channel.setMode(FMOD.MODE.LOOP_NORMAL); }
public static void Play(int index) { if (index < 0 || index >= sounds.Length) { return; } FMOD.Channel channel = null; sys.playSound(FMOD.CHANNELINDEX.FREE, sounds[index], false, ref channel); }
public static void Stop() { if (SoundEngine.IsPlaying()) { FMODChannel.stop(); FMODSound.release(); FMODChannel = null; FMODSound = null; } }
public FMODChannel(FMOD.Channel channel, bool looping) { this.channel = channel; FMODManager.Instance.SetChannelMapping(channel.getRaw().ToInt32(), this); FMODManager.ERRCHECK(channel.setCallback(ChannelCallback)); if (looping) { channel.setMode(FMOD.MODE.LOOP_NORMAL); } }
private FMOD.Channel PlaySound(FMOD.Sound sound, bool play) { FMOD.Channel channel = null; FMOD.RESULT result = this.system.playSound(FMOD.CHANNELINDEX.FREE, sound, !play, ref channel); if (result != FMOD.RESULT.OK) { throw new FMODException("Unable to play sound", result); } return(channel); }
/// <summary> /// Play a loaded sound on a specified channel. /// </summary> /// <param name="p_sound">A loaded sound.</param> /// <param name="p_channelGroup">The channel group to play on.</param> /// <param name="o_channel">The channel created.</param> /// <returns></returns> public bool PlaySound(FMOD.Sound p_sound, FMOD.ChannelGroup p_channelGroup, out FMOD.Channel o_channel) { FMOD.RESULT r = m_fmodSystem.playSound( p_sound, p_channelGroup, false, out o_channel ); return(r == FMOD.RESULT.OK); }
public void Play() { if (InnerSound == null) { return; } var chan = Channel; SoundSystem.CheckError(system.PlaySound(InnerSound, false, ref chan)); Channel = chan; }
/// <summary> /// Initializes a new instance of <see cref="FMODChannel"/> and attempts to load all other values automatically /// <para/> /// The <see cref="FMODChannel.Sound"/> property is set to the one found via FMOD.Channel.getCurrentSound(ref FMOD.Sound) /// <para/> /// The <see cref="FMODChannel.Context"/> property is set to either the current context, or a new SynchronizationContext (if the current is not valid) /// </summary> /// <param name="channel"></param> /// <param name="id">The id of the channel</param> /// <param name="system">The <see cref="FMODSystem"/> that contains this channel</param> internal FMODChannel(FMODSystem system, FMOD.Channel channel, Guid id) { this.system = system; this.id = id; this.Channel = channel; FMOD.RESULT result = channel.getCurrentSound(ref this.sound); if (result != FMOD.RESULT.OK) { throw new FMODException("Unable to get current sound for Container", result); } }
public static FMOD.RESULT channel_callback(IntPtr channelraw, FMOD.CHANNEL_CALLBACKTYPE type, IntPtr commanddata1, IntPtr commanddata2) { if (type == FMOD.CHANNEL_CALLBACKTYPE.END) { if (channel.getRaw() == channelraw) { sound.release(); channel = null; } } return(0); }
float _volume = 1.0f; // Główna głośność dźwięków i muzyki zmieniana przez Volume, wartości: <0, 1.0f> #endregion Fields #region Constructors public SoundManager() { Result = FMOD.Factory.System_Create(ref System); Result = System.init(4, FMOD.INITFLAGS.NORMAL, IntPtr.Zero); // 4 oznacza maksymalną ilość dźwięków naraz // 1-bgm, 2-odgłosy chodzenia, 3-dźwięki otoczenia, 4-głosy postaci. Może coś jeszcze? BGMPlaylist = new List<string>(); ChannelBGM = new FMOD.Channel(); ChannelDialog = new FMOD.Channel(); ChannelSound = new FMOD.Channel(); }
private void stopButton_Click(object sender, System.EventArgs e) { FMOD.RESULT result; result = system.recordStop(selected); ERRCHECK(result); if (channel != null) { channel.stop(); channel = null; } }
public SoundManager() { Result = FMOD.Factory.System_Create(ref System); Result = System.init(4, FMOD.INITFLAGS.NORMAL, IntPtr.Zero); // 4 oznacza maksymalną ilość dźwięków naraz // 1-bgm, 2-odgłosy chodzenia, 3-dźwięki otoczenia, 4-głosy postaci. Może coś jeszcze? BGMPlaylist = new List <string>(); ChannelBGM = new FMOD.Channel(); ChannelDialog = new FMOD.Channel(); ChannelSound = new FMOD.Channel(); }
internal void RenderOsc(RenderParams rp, RenderCanvas canvas) { //Util.Log("RenOsc HID=" + rp.HierarchyID + " T=" + Math.Round(rp.Time, 3) + " AbsT=" + Math.Round(rp.AbsTime, 3) + " A=" + Math.Round(rp.Ampl, 3) + "\n"); bool wasPlaying = nowPlayingList.ContainsKey(rp.HierarchyID); FMOD.Channel channel = null; FMOD.RESULT r; if (wasPlaying) { channel = nowPlayingList[rp.HierarchyID]; // check if still playing now bool isPlayingNow = false; r = channel.isPlaying(ref isPlayingNow); if (isPlayingNow) { // check if should be stopped now if (rp.Time >= Duration) { channel.stop(); nowPlayingList.Remove(rp.HierarchyID); } else { // if still validly playing, adapt channel properties only. AdaptChannelSettings(channel, rp, canvas); //Util.Log(" rp.A=" + Math.Round(rp.Ampl, 3) + " canv.A=" + canvas.AmplMultiply + "\n"); } } else { // if not anymore, remove from list nowPlayingList.Remove(rp.HierarchyID); } } else { // was not playing but should be rendered - hence, initiate playing now if (rp.Time < Duration - 0.100) // extra safety margin - do not start if close to end. { channel = PlayOsc(rp, canvas); if (channel != null) { // store playing sound in the table nowPlayingList[rp.HierarchyID] = channel; } else { // } } } }
public IChannelGlue PlaySound(ISoundGlue sound, bool paused, bool looping) { FMOD.Channel channel = null; var result = system.playSound(FMOD.CHANNELINDEX.FREE, (FMOD.Sound)sound.InnerSoundObject, paused, ref channel); if (result == FMOD.RESULT.ERR_NOTREADY) { return(null); } FMODManager.ERRCHECK(result); var fmodChannel = new FMODChannel(channel, looping); return(fmodChannel); }
public void Initialize() { if (system == null) { result = FMOD.Factory.System_Create(out system); result = system.init(512, FMOD.INITFLAGS.NORMAL, IntPtr.Zero); } PlayList = new List <string>(); ChannelGroup = new FMOD.ChannelGroup(IntPtr.Zero); Channel = new FMOD.Channel(IntPtr.Zero); spectrum = new float[512]; previousSpectrum = spectrum; EnableFFT(); }
// Function to Play a FMOD Sound static public FMOD.Channel PlaySound(FMOD.Sound sFMODSound, bool bForcePlaySound) { // Dummy Channel Handle FMOD.Channel sFMODChannelHandle = new FMOD.Channel(); // If Sounds should be played if (mbSoundOn || bForcePlaySound) { // Play Sound CFMOD.CheckResult(CFMOD.GetSystem().playSound(FMOD.CHANNELINDEX.FREE, sFMODSound, false, ref sFMODChannelHandle), "FMOD Play Sound Error"); } // Return the Channel the sound is playing on return(sFMODChannelHandle); }
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 override void Clear() { if (m_bOpened) { 播放中 = false; if (m_FMODChannel != null) { m_FMODChannel.stop(); } m_FMODChannel = null; ((SoundPlayer_FMOD)m_HostPlayer).OnChannelCleared(this); m_bOpened = false; m_bPlaying = false; m_bPaused = false; m_strFileName = ""; } }
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); }
public ISoundEngine StopMusic() { if (this.analyzeChannel != null) { try { this.analyzeChannel.stop(); } catch (Exception) { // Do nothing } this.analyzeChannel = null; } if (this.playChannel != null) { try { this.playChannel.stop(); } catch (Exception) { // Do nothing } this.playChannel = null; } if (this.analyzeSound != null) { this.analyzeSound.release(); this.analyzeSound = null; } if (this.playSound != null) { this.playSound.release(); this.playSound = null; } return this; }
// instances only dispose of streaming audio public void Dispose() { #if !NO_FMOD if (Playing && mChannel != null) { mChannel.stop(); } if (mSound != null) { AudioEngine audioengine = GSGE.AudioManager.GetAudioManager().GetAudioEngine(); audioengine.FmodSounds.Remove(this); } if (mOwnSound && mSound != null) { FMOD.RESULT result = mSound.release(); ERRCHECK(result); } mOwnSound = false; mSound = null; mChannel = null; if (mStreamRequested != mStreamStarted) mAbortStream = true; else { mStreamBytes = null; mStreamRequested = false; mStreamStarted = false; } #endif }
private void TTRUnloadSound() { if (TTRChannel != null) { // Bugfix: sound now only unloads if stopped if (GAPT_CurrentPlaybackState == "Stopped") { TTRSound.release(); TTRUpdateText_Row3_Sub("No track is currently loaded."); TTRUpdateText_Row1_Sub(" "); TTRUpdateText_Row2_Sub(" "); TTRSound = null; TTRChannel = null; TTRLength = 0; GAPT_LastPROCESSEDName = ""; GAPT_LastTrackName = ""; } } }
public FmodChannel(FMOD.Channel c) { channel = c; }
private void stopButton_Click(object sender, System.EventArgs e) { FMOD.RESULT result; result = system.recordStop(); ERRCHECK(result); if (channel != null) { channel.stop(); channel = null; } }
private bool StopInternal() { FMOD.RESULT result; FMOD.Sound sound = null; if (channel == null) return false; bool playing = IsPlaying(); if (!playing) return false; result = channel.getCurrentSound(ref sound); ErrorCheck(result, "channel.getCurrentSound"); result = channel.stop(); ErrorCheck(result, "channel.stop"); channel = null; result = sound.release(); ErrorCheck(result, "sound.release"); return true; }
private void timer_Tick(object sender, System.EventArgs e) { FMOD.RESULT result; FMOD.OPENSTATE openstate = 0; if (soundcreated) { uint percentbuffered = 0; bool starving = false; bool busy = false; result = sound.getOpenState(ref openstate, ref percentbuffered, ref starving, ref busy); ERRCHECK(result); if (openstate == FMOD.OPENSTATE.READY && channel == null) { result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel); ERRCHECK(result); } } if (channel != null) { uint ms = 0; bool playing = false; bool paused = false; int tagsupdated = 0; int numtags = 0; result = sound.getNumTags(ref numtags, ref tagsupdated); ERRCHECK(result); if (tagsupdated != 0) { for (;;) { FMOD.TAG tag = new FMOD.TAG(); if (sound.getTag(null, -1, ref tag) != FMOD.RESULT.OK) { break; } if (tag.datatype == FMOD.TAGDATATYPE.STRING) { FMOD.SOUND_FORMAT format = FMOD.SOUND_FORMAT.NONE; int channels = 0; int bits = 0; sound.getFormat(ref gSoundType, ref format, ref channels, ref bits); if (tag.name == "ARTIST") { if (Marshal.PtrToStringAnsi(tag.data) != gCurrentTrackArtist) { gCurrentTrackArtist = Marshal.PtrToStringAnsi(tag.data); gUpdateFileName = true; } } if (tag.name == "TITLE") { if (Marshal.PtrToStringAnsi(tag.data) != gCurrentTrackTitle) { gCurrentTrackTitle = Marshal.PtrToStringAnsi(tag.data); gUpdateFileName = true; } } break; } else { break; } } } result = channel.isPlaying(ref playing); if (result != FMOD.RESULT.OK || !playing) { sound.release(); sound = null; channel = null; } else { result = channel.getPaused(ref paused); ERRCHECK(result); result = channel.getPosition(ref ms, FMOD.TIMEUNIT.MS); ERRCHECK(result); statusBar.Text = "Time " + (ms /1000 / 60) + ":" + (ms / 1000 % 60) + ":" + (ms / 10 % 100) + (paused ? " Paused " : playing ? " Playing" : " Stopped"); } } if (sound != null) { uint percentbuffered = 0; bool starving = false; bool busy = false; sound.getOpenState(ref openstate, ref percentbuffered, ref starving, ref busy); if (openstate == FMOD.OPENSTATE.ERROR) { sound.release(); sound = null; channel = null; } } if (openstate == FMOD.OPENSTATE.ERROR) { statusBar.Text = "Error occurred or stream ended. Restarting stream.."; result = system.createSound(url, (FMOD.MODE.HARDWARE | FMOD.MODE._2D | FMOD.MODE.CREATESTREAM | FMOD.MODE.NONBLOCKING), ref exinfo, ref sound); ERRCHECK(result); } if (system != null) { system.update(); } }
private void button1_Click(object sender, System.EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); if (sound != null) { if (channel != null) { channel.stop(); channel = null; } sound.release(); sound = null; } if(dialog.ShowDialog() == DialogResult.OK) { FMOD.RESULT result; result = system.createStream(dialog.FileName, FMOD.MODE.SOFTWARE | FMOD.MODE._2D, ref sound); ERRCHECK(result); textBox.Text = dialog.FileName; } playButton.Text = "Play"; }
private void ResetEverything() { // Stopping Music if(fmodChannel != null) fmodChannel.stop(); fmodSystem = null; fmodChannel = null; theSong = null; szSongName = ""; nCurrentPositionMS = 0; nLengthMS = 0; bPlaying = false; bIsFastforwarding = false; bIsRewinding = false; bPaused = false; //bFreq = false; bRunning = true; bListChanged = false; listBeats = new List<Beat>(); MouseAddBeat = new Beat(); szClickedEventEdit = ""; nMouseScroll = 0; MouseSelectStartPoint = new Point(); MouseSelectRect = Rectangle.Empty; SelectedBeats.Clear(); CopiedBeats.Clear(); TimeCurrentLabel.Text = "0(s)"; TimeLengthLabel.Text = "0(s)"; BeatCountLabel.Text = "0"; BPMCurrentLabel.Text = "0"; // Clean shit up RIGHT NAO!!! GC.Collect(); }