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";
            }
        }
Example #2
0
        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);
        }
Example #3
0
        private void timer_Tick(object sender, System.EventArgs e)
        {
            if (system != null && sound != null)
            {
                uint recordpos = 0;
                uint playpos   = 0;
                bool recording = false;
                bool playing   = false;

                system.isRecording(selected, ref recording);
                system.getRecordPosition(selected, ref recordpos);

                if (channel != null)
                {
                    channel.isPlaying(ref playing);;

                    channel.getPosition(ref playpos, FMOD.TIMEUNIT.PCM);
                }

                statusBar.Text = "State:" + (recording ? playing ? " Recording / playing " : " Recording " : playing ? " Playing " : " Idle ")
                                 + " Record pos = " + recordpos + " Play pos = " + playpos + " Loop " + (looping ? "On" : "Off");
            }
            if (system != null)
            {
                system.update();
            }
        }
Example #4
0
        private MusicPlayer()
        {
            result = FMOD.Factory.System_Create(out FMODSystem);

            if (result != FMOD.RESULT.OK)
            {
                throw new Exception("This crap didn't work!!");
            }

            result = FMODSystem.setDSPBufferSize(1024, 10);
            result = FMODSystem.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)0);

            var info = new FMOD.CREATESOUNDEXINFO();
            var song = new FMOD.Sound();

            ChannelGroup = new FMOD.ChannelGroup();
            ChannelGroup.clearHandle();

            result = FMODSystem.createStream("rain.ogg", FMOD.MODE.DEFAULT, out song);

            result = FMODSystem.playSound(song, ChannelGroup, false, out Channel);



            bool isPlaying = false;

            Channel.isPlaying(out isPlaying);

            Channel.setVolume(1);
            Channel.setMode(FMOD.MODE.LOOP_NORMAL);
            Channel.setLoopCount(-1);

            int t = 1;
        }
        private void timer_Tick(object sender, System.EventArgs e)
        {
            FMOD.RESULT    result;
            FMOD.OPENSTATE openstate       = 0;
            uint           percentbuffered = 0;
            bool           starving        = false;
            bool           busy            = false;

            if (soundcreated)
            {
                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;

                for (;;)
                {
                    FMOD.TAG tag = new FMOD.TAG();
                    if (sound.getTag(null, -1, ref tag) != FMOD.RESULT.OK)
                    {
                        break;
                    }
                    if (tag.datatype == FMOD.TAGDATATYPE.STRING)
                    {
                        textBox.Text = tag.name + " = " + Marshal.PtrToStringAnsi(tag.data) + " (" + tag.datalen + " bytes)";
                    }
                    else
                    {
                        break;
                    }
                }

                result = channel.getPaused(ref paused);
                ERRCHECK(result);
                result = channel.isPlaying(ref playing);
                ERRCHECK(result);
                result = channel.getPosition(ref ms, FMOD.TIMEUNIT.MS);
                ERRCHECK(result);

                statusBar.Text = "Time " + (ms / 1000 / 60) + ":" + (ms / 1000 % 60) + ":" + (ms / 10 % 100) + (openstate == FMOD.OPENSTATE.BUFFERING ? " Buffering..." : (openstate == FMOD.OPENSTATE.CONNECTING ? " Connecting..." : (paused ? " Paused       " : (playing ? " Playing      " : " Stopped      ")))) + "(" + percentbuffered + "%)" + (starving ? " STARVING" : "        ");
            }

            if (system != null)
            {
                system.update();
            }
        }
        private bool IsPlaying()
        {
            bool isPlaying = false;

            if (_channel != null)
            {
                _channel.isPlaying(out isPlaying);
            }
            return(isPlaying);
        }
Example #7
0
        public static bool IsPlaying()
        {
            if (FMODChannel != null)
            {
                bool isPlaying = false;
                FMODChannel.isPlaying(ref isPlaying);
                return(isPlaying);
            }

            return(false);
        }
Example #8
0
        public bool IsPlaying()
        {
            bool isPlaying = false;

            if (MusicChannel != null)
            {
                MusicChannel.isPlaying(out isPlaying);
            }

            return(isPlaying);
        }
Example #9
0
        public bool isPlay()
        {
            if (channelMusic == null)
            {
                return(false);
            }

            bool rst = false;

            channelMusic.isPlaying(out rst);

            return(rst);
        }
Example #10
0
        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
                    {
                        //
                    }
                }
            }
        }
        private void timer_Tick(object sender, System.EventArgs e)
        {
            FMOD.RESULT result;
            uint        ms              = 0;
            uint        lenms           = 0;
            bool        paused          = false;
            bool        playing         = false;
            int         channelsplaying = 0;

            if (channel != null)
            {
                FMOD.Sound currentsound = null;

                result = channel.isPlaying(ref playing);
                if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE) && (result != FMOD.RESULT.ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = channel.getPaused(ref paused);
                if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE) && (result != FMOD.RESULT.ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = channel.getPosition(ref ms, FMOD.TIMEUNIT.MS);
                if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE) && (result != FMOD.RESULT.ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                channel.getCurrentSound(ref currentsound);
                if (currentsound != null)
                {
                    result = currentsound.getLength(ref lenms, FMOD.TIMEUNIT.MS);
                    if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE) && (result != FMOD.RESULT.ERR_CHANNEL_STOLEN))
                    {
                        ERRCHECK(result);
                    }
                }

                system.getChannelsPlaying(ref channelsplaying);
            }

            statusBar.Text = "Time " + (ms / 1000 / 60) + ":" + (ms / 1000 % 60) + ":" + (ms / 10 % 100) + "/" + (lenms / 1000 / 60) + ":" + (lenms / 1000 % 60) + ":" + (lenms / 10 % 100) + " " + (paused ? "Paused " : playing ? "Playing" : "Stopped") + " Channels Playing " + channelsplaying;

            if (system != null)
            {
                system.update();
            }
        }
Example #12
0
        private void loadSound(string name)
        {
            if (channel != null)
            {
                bool playing = false;
                channel.isPlaying(ref playing);
                if (playing)
                {
                    channel.stop();
                }
                subsound.release();
                fsb.release();
            }

            FMOD.RESULT res = system.createSound(name, (FMOD.MODE._2D | FMOD.MODE.HARDWARE | FMOD.MODE.CREATESTREAM), ref fsb);



            if (res != FMOD.RESULT.OK)
            {
                MessageBox.Show("Cannot load file.  Reason: " + res.ToString(), "FMOD Load Error", MessageBoxButtons.OK);
            }
        }
Example #13
0
        private void CheckChannel()
        {
            bool p = false;

            FMOD.RESULT result = mChannel.isPlaying(ref p);

            if (result == FMOD.RESULT.ERR_INVALID_HANDLE || p == false)
            {
                CreateChannel();
            }
            else
            {
                FMOD_Audio.CheckFMODResult(result);
            }
        }
Example #14
0
        protected override void Update(GameTime gameTime)
        {
            KeyboardState ks = Keyboard.GetState();

            if (ks.IsKeyUp(Keys.Tab) && ksLast.IsKeyDown(Keys.Tab))
            {
                tuneIndex++;

                if (tuneIndex > tunes.Length - 1)
                {
                    tuneIndex = 0;
                }

                StartMusic(tuneIndex);
            }
            if ((ks.IsKeyUp(Keys.F1) && ksLast.IsKeyDown(Keys.F1)) ||
                (ks.IsKeyUp(Keys.Back) && ksLast.IsKeyDown(Keys.Back)))
            {
                if (SoundChannel != null)
                {
                    bool isPlaying = false;
                    SoundChannel.isPlaying(ref isPlaying);

                    if (isPlaying)
                    {
                        SoundChannel.stop();
                    }
                    else
                    {
                        StartMusic(tuneIndex);
                    }
                }
            }

            timing.Elapsed = gameTime.ElapsedGameTime;

            for (int i = 0; i < modules.Count; i++)
            {
                if (modules[i].Enabled)
                {
                    modules[i].Update();
                }
            }

            ksLast = ks;

            base.Update(gameTime);
        }
Example #15
0
        //public void UpdateOpenState()
        //{
        //    if (Sound != null)
        //    {
        //        FMOD.OPENSTATE openState;
        //        uint percentBuffered;
        //        bool starving;
        //        bool diskBusy;

        //        //check to see if it is ready
        //        Sound.getOpenState(out openState, out percentBuffered, out starving, out diskBusy);

        //        //set the open state
        //        OpenState = openState;
        //    }
        //}

        /// <summary>
        /// Gets whether the channel is currently playing
        /// </summary>
        /// <param name="channel"></param>
        /// <returns></returns>
        private bool GetIsPlaying()
        {
            if (this._channel == null)
            {
                return(false);
            }

            FMOD.RESULT result;
            bool        isPlaying = true;

            //get is playing
            result = _channel.isPlaying(out isPlaying);
            //CheckError(result);

            return(isPlaying);
        }
Example #16
0
        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));
        }
Example #17
0
 //float fTicking = 0;
 public override void Tick(float fElapsedTime, Vector3?vListenerPos)
 {
     base.Tick(fElapsedTime, vListenerPos);
     if (this.文件已载入 && m_FMODChannel != null)
     {
         m_FMODChannel.getMute(ref m_bMuted);
         //m_FMODChannel.getVolume(ref m_fVolumeMult);
         m_FMODChannel.getPaused(ref m_bPaused);
         m_FMODChannel.isPlaying(ref m_bPlaying);
         //fTicking += fElapsedTime;
     }
     //if (fTicking > 1.0F)
     //{
     //    fTicking = 0;
     //    string msg = String.Format("GM:{0},M:{1},GV:{2},V:{3}/{4}/{5},U:{6},P:{7}",
     //        m_HostPlayer.静音, m_bMuted, m_HostPlayer.音量倍率, m_fVolumeMult, m_fVolumeAttuMult, m_fVolumeMutedMult, m_bPaused, m_bPlaying);
     //    Framework.Log.ApplicationLogSink.Write("Sound:" + msg);
     //}
 }
Example #18
0
        private void timer_Tick(object sender, System.EventArgs e)
        {
            float frequency = 0, volume = 0, pan = 0;
            bool  playing = false;

            if (channel != null)
            {
                channel.getFrequency(ref frequency);
                channel.getVolume(ref volume);
                channel.getPan(ref pan);
                channel.isPlaying(ref playing);
            }

            statusBar.Text = "Channel " + (playing ? "playing" : "stopped") + " : Frequency " + frequency + " Volume " + volume + " Pan " + pan;

            if (system != null)
            {
                system.update();
            }
        }
Example #19
0
        private void timer_Tick(object sender, System.EventArgs e)
        {
            FMOD.RESULT result;
            uint        ms      = 0;
            uint        lenms   = 0;
            uint        lenmscd = 0;
            bool        playing = false;
            bool        paused  = false;

            if (channel != null)
            {
                result = channel.getPaused(ref paused);
                ERRCHECK(result);
                result = channel.isPlaying(ref playing);
                ERRCHECK(result);
                result = channel.getPosition(ref ms, FMOD.TIMEUNIT.MS);
                ERRCHECK(result);
                result = sound.getLength(ref lenms, FMOD.TIMEUNIT.MS);
                ERRCHECK(result);
            }

            if (cdsound != null)
            {
                /*
                 *  Get length of entire CD.  Did you know you can also play 'cdsound' and it will play the whole CD without gaps?
                 */
                result = cdsound.getLength(ref lenmscd, FMOD.TIMEUNIT.MS);
                ERRCHECK(result);
            }

            statusBar.Text = "Total CD length: " + (lenmscd / 1000 / 60) + ":" + (lenmscd / 1000 % 60) + ":" + (lenmscd / 10 % 100) +
                             " Track " + (currenttrack + 1) + "/" + numtracks + " : " + (ms / 1000 / 60) + ":" + (ms / 1000 % 60) + ":" + (ms / 10 % 100) + "/" + (lenms / 1000 / 60) + ":" + (lenms / 1000 % 60) + ":" + (lenms / 10 % 100) + (paused ? " Paused " : playing ? " Playing" : " Stopped");

            if (system != null)
            {
                system.update();
            }
        }
        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();
            }
        }
Example #21
0
        /**
         * called when this sample/effect should render itself, possibly spawning a new
         * playing instance or modifying an already playing instance.
         */
        internal void Render(RenderParams rp, RenderCanvas canvas, List <FMOD.DSP> dspList, int audioRepeats)
        {
#if DEBUG
            Util.Log("Render HID=" + rp.HierarchyID + " T=" + Math.Round(rp.Time, 3) + " AbsT=" + Math.Round(rp.AbsTime, 3) + " A=" + Math.Round(rp.Ampl, 3) + "\n");
#endif
            // check if duration is not exceeded
            if (rp.Time > _soundDuration * ((double)audioRepeats))
            {
                return;
            }

            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);
                //Util.ERRCHECK(r); // TODO is this needed?
                if (isPlayingNow)
                {   // if so, adapt sample properties only.
                    AdaptChannelSettings(channel, rp, canvas);

                    // check playing time
                    uint playPosMs      = 0;
                    int  idealPlayPosMs = (int)Math.Round(rp.Time * 1000.0);
                    channel.getPosition(ref playPosMs, FMOD.TIMEUNIT.MS);

                    if (Math.Abs(((int)playPosMs) - idealPlayPosMs) > 5000 && idealPlayPosMs >= 0)  // FIXME specify error margin better, somewhere? configurable per sample?
                    {
                        //FIXME HACK enable tracking when needed !!! below.
                        channel.setPosition((uint)idealPlayPosMs, FMOD.TIMEUNIT.MS);
                        playPosMs = (uint)idealPlayPosMs;
                    }
                    // store current pos on canvas
                    if (canvas.TimeMarker == 0)
                    {
                        canvas.TimeMarker = ((double)playPosMs) / 1000.0;
                    }
                }
                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 < _soundDuration - 0.050) // extra safety margin - do not start if close to end. TODO configurable time?
                {
                    channel = PlaySample(rp, canvas, dspList);
                    channel.setLoopCount(audioRepeats - 1);
                    if (channel != null)
                    {
#if DEBUG
                        Util.Log("Play   HID=" + rp.HierarchyID + " T=" + Math.Round(rp.Time, 3) + " AbsT=" + Math.Round(rp.AbsTime, 3) + " A=" + Math.Round(rp.Ampl, 3) + "\n");
#endif
                        // store playing sound in the table
                        _nowPlayingList[rp.HierarchyID] = channel;
                    }
                    else
                    {
                        Util.Log("Play FAILED rp.H-ID=" + rp.HierarchyID + " rp.Time=" + rp.Time + " rp.AbsTime=" + rp.AbsTime + "\n");
                    }
                }
            }
        }