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);
 }
Example #2
0
 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);
     }
 }
Example #3
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 #4
0
        private bool PlaySoundCallback(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);
                    channel.setCallback(FMOD.CHANNEL_CALLBACKTYPE.END, endPlayCallback, 0);
                }

                return(FMOD.ERROR.ERRCHECK(result));
            }
            catch
            { return(false); }
        }
Example #5
0
 public SoundInstance(FMOD.Channel channel, Sound sound)
 {
     Sound   = sound;
     Channel = channel;
     //We have to hold a reference or the GC will collect and crash everything
     _callback = (channelPtr, controlType, callbackType, data1, data2) =>
     {
         if (callbackType == FMOD.CHANNELCONTROL_CALLBACK_TYPE.END)
         {
             _ended = true;
             Sound.Player.ActiveSoundInstanceQueue.Remove(this);
             if (_endedCallback != null)
             {
                 _endedCallback(this);
             }
         }
         return(FMOD.RESULT.OK);
     };
     FMOD.Error.Check(Channel.setCallback(_callback));
 }
Example #6
0
        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);
        }