protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                FMOD.RESULT result;

                /*
                 *  Shutdown
                 */
                if (sound != null)
                {
                    result = sound.release();
                    ERRCHECK(result);
                }
                if (system != null)
                {
                    result = system.close();
                    ERRCHECK(result);
                    result = system.release();
                    ERRCHECK(result);
                }

                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to stop playback on this channel, and release it
        /// </summary>
        public void StopAndRelease()
        {
            lock (this.p_Lock)
            {
                if (!this.isDisposed)
                {
                    this.isDisposed = true;
                    FMOD.Sound currentSound = null;

                    FMOD.RESULT result = this.Channel.getCurrentSound(ref currentSound);
                    if (result != FMOD.RESULT.OK)
                    {
                        throw new FMODException("Unable to retrieve current sound from channel", result);
                    }

                    result = currentSound.release();
                    if (result != FMOD.RESULT.OK)
                    {
                        throw new FMODException("Unable to release sound", result);
                    }
                    result = this.Channel.stop();
                    if (result != FMOD.RESULT.OK && result != FMOD.RESULT.ERR_INVALID_HANDLE) // FMOD.RESULT.ERR_INVALID_HANDLE usually means that the channel hasn't even started playing yet
                    {
                        throw new FMODException("Unable to release channel", result);
                    }
                    this.system.RemoveContainer(this);
                }
            }
        }
Exemplo n.º 3
0
        public void Destroy()
        {
            FMOD.RESULT result;

            result = s_level1.release();
            ERRCHECK(result);
            result = s_level2.release();
            ERRCHECK(result);
            result = s_jump.release();
            ERRCHECK(result);
            result = s_coin.release();
            ERRCHECK(result);
            result = s_brick.release();
            ERRCHECK(result);
            result = s_block.release();
            ERRCHECK(result);
            result = s_stomp.release();
            ERRCHECK(result);
            result = s_mush.release();
            ERRCHECK(result);
            result = s_fireball.release();
            ERRCHECK(result);

            result = soundsystem.close();
            ERRCHECK(result);
            result = soundsystem.release();
            ERRCHECK(result);
        }
Exemplo n.º 4
0
 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;
     }
 }
Exemplo n.º 5
0
 internal void OnChannelCleared(SoundChannel_FMOD chnl)
 {
     FMOD.Sound snd = chnl.RefFMODSound;
     if (snd != null)
     {
         Sounds.Remove(snd);
         snd.release();
         //bool invalid = true;
         //if (dcSounds.ContainsValue(snd))
         //{
         //    foreach (SoundChannel_FMOD ch in m_aChannels)
         //    {
         //        if (ch != chnl && ch.RefFMODSound == snd)
         //        {
         //            invalid = false;
         //            break;
         //        }
         //    }
         //}
         //if (invalid)
         //{
         //    if (dcSounds.ContainsValue(snd))
         //    {
         //        string[] files = (from kv in dcSounds where kv.Value == snd select kv.Key).ToArray();
         //        if (files != null)
         //        {
         //            foreach (var file in files)
         //                dcSounds.Remove(file);
         //        }
         //    }
         //    snd.release();
         //}
         chnl.RefFMODSound = null;
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Stop and try to release FMOD sound resources
        /// </summary>
        void Stop_Internal()
        {
            this.GetComponent <AudioSource>().Stop();

            this.isRecording = false;
            this.isPaused    = false;

            /*
             *  Shut down sound
             */
            if (sound != null)
            {
                result = sound.release();
                ERRCHECK(result, "sound.release", false);
            }

            sound = null;

            /*
             * Shut down
             */
            if (system != null)
            {
                result = system.close();
                ERRCHECK(result, "system.close", false);

                result = system.release();
                ERRCHECK(result, "system.release", false);
            }

            system = null;
        }
Exemplo n.º 7
0
        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();
            }
        }
Exemplo n.º 8
0
        /// <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();
        }
Exemplo n.º 9
0
 public void Dispose()
 {
     if (sounds != null)
     {
         sounds.release();
         sounds = null;
     }
 }
Exemplo n.º 10
0
        internal void Release()
        {
            if (!SoundSystem.AudioFound)
            {
                return;
            }

            RESULT result = _sound.release();
        }
Exemplo n.º 11
0
        private void JingleInit(string filename)
        {
            FMOD.Sound tempSound = null;
            thisLock = new Object();
            // Retrieve information about sound
            FMOD.RESULT result = system.createSound(filename, (FMOD.MODE._2D | FMOD.MODE.SOFTWARE), ref tempSound);
            ErrorCheck(result);

            FMOD.SOUND_TYPE   soundType   = (FMOD.SOUND_TYPE) 0;
            FMOD.SOUND_FORMAT soundFormat = (FMOD.SOUND_FORMAT) 0;

            int tempBits     = 0,
                tempChannels = 0,
                tempPriority = 0;

            uint tempPcm = 0;

            float tempFrequency = 0.0f,
                  tempPan       = 0.0f,
                  tempVolume    = 0.0f;

            result = tempSound.getFormat(ref soundType, ref soundFormat, ref tempChannels, ref tempBits);
            ErrorCheck(result);

            result = tempSound.getDefaults(ref tempFrequency, ref tempVolume, ref tempPan, ref tempPriority);
            ErrorCheck(result);

            result = tempSound.getLength(ref tempPcm, FMOD.TIMEUNIT.PCM);
            ErrorCheck(result);

            // Fill sound parameters
            ChannelCount = tempChannels;
            Frequency    = (int)tempFrequency;
            pcm          = tempPcm;
            bits         = tempBits;

            // Obtain Raw PCM data from sound
            GetRawData(tempSound, tempChannels, tempBits, tempPcm);


            // Release temp sound instance
            tempSound.release();
            tempSound = null;


            FMOD.CREATESOUNDEXINFO exInfo = new FMOD.CREATESOUNDEXINFO();
            exInfo.cbsize           = Marshal.SizeOf(exInfo);
            exInfo.length           = (uint)(pcm * sizeof(short));
            exInfo.numchannels      = ChannelCount;
            exInfo.format           = FMOD.SOUND_FORMAT.PCM16;
            exInfo.defaultfrequency = (int)Frequency;
            // Create a stream from obtained data

            result = system.createStream(SoundDataBuffer.Buffer, (FMOD.MODE.OPENMEMORY | FMOD.MODE.OPENRAW), ref exInfo, ref sounds);
            ErrorCheck(result);
        } // loading jingle
Exemplo n.º 12
0
        // every level transition we dump all fmod data in an attempt to eliminate the silly bugs
        public void releaseSound()
        {
            if (mSound != null)
            {
                FMOD.RESULT result = mSound.release();
                ERRCHECK(result);
            }

            mSound = null;
        }
Exemplo n.º 13
0
 public static void Stop()
 {
     if (SoundEngine.IsPlaying())
     {
         FMODChannel.stop();
         FMODSound.release();
         FMODChannel = null;
         FMODSound   = null;
     }
 }
Exemplo n.º 14
0
 public static void LoadSong(int id, bool loop)
 {
     PlayingSongID = id;
     if (CurrentSong != null)
     {
         CurrentSong.release();
     }
     FMOD.MODE mode = (loop) ? FMOD.MODE.LOOP_NORMAL : FMOD.MODE.DEFAULT;
     system.createStream(PlayList[id], mode, out CurrentSong);
     system.playSound(CurrentSong, ChannelGroup, false, out Channel);
 }
Exemplo n.º 15
0
 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);
 }
Exemplo n.º 16
0
 private void StopButton_Click(object sender, EventArgs e)
 {
     if (channel != null)
     {
         bool playing = false;
         channel.isPlaying(ref playing);
         if (playing)
         {
             channel.stop();
         }
         subsound.release();
     }
 }
Exemplo n.º 17
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 createSoundResult = fmodSystem.createSound(name, (FMOD.MODE._2D | FMOD.MODE.HARDWARE | FMOD.MODE.CREATESTREAM), ref fsb);

            if (createSoundResult != FMOD.RESULT.OK)
            {
                MessageBox.Show("Cannot load file.  Reason: " + createSoundResult.ToString(), "FMOD Load Error", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 18
0
        public static int GetLengthOfSoundfile(string filename)
        {
            FMOD.Sound  sound  = null;
            FMOD.RESULT res    = SoundEngine.Instance.system.createStream(filename, FMOD.MODE.OPENONLY, ref sound);
            uint        length = 0;

            if (sound != null)
            {
                sound.getLength(ref length, FMOD.TIMEUNIT.MS);
                sound.release();

                return((int)length);
            }

            return(0);
        }
Exemplo n.º 19
0
        private void About_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (soundChannel != null)
            {
                soundChannel.stop();
            }

            if (sound != null)
            {
                sound.release();
            }

            if (soundSystem != null)
            {
                soundSystem.close();
            }
        }
Exemplo n.º 20
0
        public override void Dispose()
        {
            PendingKill = true;
            foreach (var item in components)
            {
                item.Dispose();
            }
            foreach (var child in Children)
            {
                child.Dispose();
            }
            spawnFailSound.release();
            spawnPowerSource.release();
            spawnSuccess.release();

            System.GC.SuppressFinalize(this);
        }
        private void timer1_Tick(object sender, System.EventArgs e)
        {
            FMOD.RESULT result;

            if (!initialised)
            {
                ERRCHECK(result = FMOD.Event_Factory.EventSystem_Create(ref eventsystem));
                ERRCHECK(result = eventsystem.init(64, FMOD.INITFLAGS.NORMAL, (IntPtr)null, FMOD.EVENT_INITFLAGS.NORMAL));
                ERRCHECK(result = eventsystem.setMediaPath("../../../../examples/media/"));
                ERRCHECK(result = eventsystem.load("examples.fev"));
                ERRCHECK(result = eventsystem.getGroup("examples/FeatureDemonstration/SequencingAndStitching", false, ref eventgroup));

                ERRCHECK(result = eventsystem.getSystemObject(ref sys));
                ERRCHECK(result = sys.createStream("../../../../examples/media/tutorial_bank.fsb", (FMOD.MODE._2D | FMOD.MODE.SOFTWARE), ref fsb));

                initialised = true;
            }

            /*
             *  "Main Loop"
             */
            ERRCHECK(result = eventsystem.update());

            if (eventstart)
            {
                ERRCHECK(result = eventgroup.getEvent("ProgrammerSounds", FMOD.EVENT_MODE.DEFAULT, ref _event));
                ERRCHECK(result = _event.setCallback(eventcallback, (IntPtr)null));
                ERRCHECK(result = _event.start());

                eventstart = false;
            }

            /*
             *  Cleanup and exit
             */
            if (exit)
            {
                ERRCHECK(result = eventsystem.unload());
                ERRCHECK(result = fsb.release());
                ERRCHECK(result = eventsystem.release());

                Application.Exit();
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Reads the tag of a file
        /// </summary>
        /// <param name="filename"></param>
        public TagInfo ReadTags(string filename)
        {
            FMOD.Sound snd     = null;
            TagInfo    tagInfo = null;

            try
            {
                //if ok, create a sound with tag support
                FMOD.RESULT result;

                //open the sound for tag reading
                result = _system.createStream(filename, FMOD.MODE.OPENONLY, out snd);
                CheckError(result);

                //if ok, get the number of tags in the fie
                int numTags;
                int numTagsUpdated;

                //get num tags
                result = snd.getNumTags(out numTags, out numTagsUpdated);
                CheckError(result);

                //read the tags
                tagInfo = ReadTags(snd, numTags);
            }
            catch (Exception)
            {
                //ignore errors for now
            }
            finally
            {
                if (snd != null)
                {
                    //release the sound
                    snd.release();
                    snd = null;
                }
            }

            //return the tag info
            return(tagInfo);
        }
Exemplo n.º 23
0
        public static void Dispose()
        {
            FMOD.RESULT result;

            /*
             *  Shut down
             */
            if (sound != null)
            {
                result = sound.release();
                ERRCHECK(result);
            }

            if (system != null)
            {
                result = system.close();
                ERRCHECK(result);
                result = system.release();
                ERRCHECK(result);
            }
        }
Exemplo n.º 24
0
        protected override void Dispose(bool disposing)
        {
            /*
             *  Write back the wav header now that we know its length.
             */
            if (recording)
            {
                recording = false;

                WriteWavHeader(datalength);
            }

            if (disposing)
            {
                FMOD.RESULT result;

                /*
                 *  Shut down
                 */
                if (sound != null)
                {
                    result = sound.release();
                    ERRCHECK(result);
                }

                if (system != null)
                {
                    result = system.close();
                    ERRCHECK(result);
                    result = system.release();
                    ERRCHECK(result);
                }

                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
Exemplo n.º 25
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                FMOD.RESULT result;

                if (sound != null)
                {
                    result = sound.release();
                    ERRCHECK(result);
                }

                if (dsplowpass != null)
                {
                    result = dsplowpass.release();
                    ERRCHECK(result);
                }

                if (dspchorus != null)
                {
                    result = dspchorus.release();
                    ERRCHECK(result);
                }

                if (system != null)
                {
                    result = system.close();
                    ERRCHECK(result);

                    result = system.release();
                    ERRCHECK(result);
                }

                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
Exemplo n.º 26
0
        /// <summary>
        /// 停止
        /// </summary>
        public void stop()
        {
            if (channelMusic == null)
            {
                return;
            }

            try {
                //fmodSystem.close();
                //fmodSystem.release();
                //fmodSystem = null;

                channelMusic.stop();
                channelMusic = null;

                backgroundMusic.release();
                backgroundMusic = null;
            } catch (Exception ex) {
                Debug.WriteLine(ex.ToString());
            }
            //mciSendString("close media", "", 0, 0);
        }
Exemplo n.º 27
0
        public static void Dispose()
        {
            FMOD.RESULT result;

            if (sound1 != null)
            {
                result = sound1.release();
                ERRCHECK(result);
            }
            if (sound2 != null)
            {
                result = sound2.release();
                ERRCHECK(result);
            }
            if (system != null)
            {
                result = system.close();
                ERRCHECK(result);
                result = system.release();
                ERRCHECK(result);
            }
            //base.Dispose(disposing);
        }
Exemplo n.º 28
0
        void Dispose(bool disposing)
        {
            if (mIsDisposed)
            {
                return;
            }

            if (disposing)
            {
                GC.SuppressFinalize(this);

                mSystem = null;
            }

            if (mAudio.IsDisposed == false)
            {
                mSound.release();
            }

            mAudio = null;
            mSound = null;

            mIsDisposed = true;
        }
Exemplo n.º 29
0
        // 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
        }
        static FMOD.RESULT DialogueEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
        {
            FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);

            // Retrieve the user data
            IntPtr stringPtr;

            instance.getUserData(out stringPtr);

            // Get the string object
            GCHandle stringHandle = GCHandle.FromIntPtr(stringPtr);
            String   key          = stringHandle.Target as String;

            switch (type)
            {
            case FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND: {
                FMOD.MODE soundMode = FMOD.MODE.DEFAULT | FMOD.MODE.CREATESTREAM;
                var       parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));

                if (key.Contains("."))
                {
                    FMOD.Sound dialogueSound;
                    var        soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(Application.streamingAssetsPath + "/" + key, soundMode, out dialogueSound);
                    if (soundResult == FMOD.RESULT.OK)
                    {
                        parameter.sound         = dialogueSound.handle;
                        parameter.subsoundIndex = -1;
                        Marshal.StructureToPtr(parameter, parameterPtr, false);
                    }
                }
                else
                {
                    FMOD.Studio.SOUND_INFO dialogueSoundInfo;
                    var keyResult = FMODUnity.RuntimeManager.StudioSystem.getSoundInfo(key, out dialogueSoundInfo);
                    if (keyResult != FMOD.RESULT.OK)
                    {
                        break;
                    }
                    FMOD.Sound dialogueSound;
                    var        soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(dialogueSoundInfo.name_or_data, soundMode | dialogueSoundInfo.mode, ref dialogueSoundInfo.exinfo, out dialogueSound);
                    if (soundResult == FMOD.RESULT.OK)
                    {
                        parameter.sound         = dialogueSound.handle;
                        parameter.subsoundIndex = dialogueSoundInfo.subsoundindex;
                        Marshal.StructureToPtr(parameter, parameterPtr, false);
                    }
                }
            }
            break;

            case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROY_PROGRAMMER_SOUND: {
                var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
                var sound     = new FMOD.Sound();
                sound.handle = parameter.sound;
                sound.release();
            }
            break;

            case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROYED:
                // Now the event has been destroyed, unpin the string
                // memory so it can be garbage collected
                stringHandle.Free();
                break;
            }
            return(FMOD.RESULT.OK);
        }