Exemple #1
0
        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";
        }
Exemple #2
0
        public static void StartMusic(int n)
        {
            if (SoundChannel != null)
            {
                SoundChannel.stop();
            }

            SoundSystem.playSound(FMOD.CHANNELINDEX.FREE, tunes[n], false, ref SoundChannel);
            SoundChannel.setVolume(0.5f);

            tuneIndex = n;
        }
Exemple #3
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();
        }
Exemple #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;
     }
 }
Exemple #5
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();
            }
        }
 public void Stop()
 {
     if (IsPlaying())
     {
         _channel.stop();
     }
 }
Exemple #7
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));
        }
Exemple #8
0
        public override void Stop()
        {
            if (mChannel == null)
            {
                return;
            }

            mChannel.stop();
        }
        public void Stop()
        {
            if (IsPlaying())
            {
                MusicChannel.stop();
            }

            m_iCurrentSongID = -1;
        }
Exemple #10
0
 public static void Stop()
 {
     if (SoundEngine.IsPlaying())
     {
         FMODChannel.stop();
         FMODSound.release();
         FMODChannel = null;
         FMODSound   = null;
     }
 }
Exemple #11
0
        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;
            }
        }
Exemple #12
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
                    {
                        //
                    }
                }
            }
        }
Exemple #13
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);
            }
        }
Exemple #14
0
 public static void StopSound()
 {
     if (!inited)
     {
         return;
     }
     // if (player == null) return;
     //  player.StopAllSounds();
     //if (sound == null) return;
     if (channel == null)
     {
         return;
     }
     channel.stop();
 }
Exemple #15
0
        private void About_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (soundChannel != null)
            {
                soundChannel.stop();
            }

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

            if (soundSystem != null)
            {
                soundSystem.close();
            }
        }
Exemple #16
0
        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 = "";
            }
        }
Exemple #17
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);
        }
Exemple #18
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
        }
Exemple #19
0
        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);
        }
 public void StopDialog()
 {
     Result = ChannelDialog.stop();
 }
Exemple #21
0
        }         // GetSpectrumData

        private void analyzeSoundTrack()
        {
            uint endPosition     = 0u;
            uint currentPosition = 0u;

            // reset all of the counters and such in the frequency band
            foreach (var current in m_mapOfFrequencyBands)
            {
                // clear and allocate new data arrays
                current.Value.reset((uint)(m_sequence.TotalEventPeriods + 1));
            }             // end reset the data arrays

//			m_FMOD_sound.release();
//			m_FMOD_system.close();
//			m_FMOD_system.release();
            FMOD_ERRCHECK(FMOD.Factory.System_Create(ref m_FMOD_system));
            m_FMOD_system.setOutput(FMOD.OUTPUTTYPE.NOSOUND_NRT);

            FMOD_ERRCHECK(m_FMOD_system.init(32, FMOD.INITFLAG.STREAM_FROM_UPDATE, IntPtr.Zero));
            m_FMOD_system.createStream(Path.Combine(Paths.AudioPath, m_sequence.Audio.FileName), (FMOD.MODE) 72u, ref m_FMOD_sound);

            // How much music is there (in ms)
            m_FMOD_sound.getLength(ref endPosition, FMOD.TIMEUNIT.MS);

            // set up a progress bar
            TranscribeDialog transcribeDialog = new TranscribeDialog((int)endPosition);

            transcribeDialog.Show();

            // set up the playback
            FMOD_ERRCHECK(m_FMOD_system.playSound(FMOD.CHANNELINDEX.FREE, m_FMOD_sound, false, ref m_FMOD_channel));

            // while there is more sound to process
            while (currentPosition < endPosition)
            {
                // GET the playback index
                m_FMOD_channel.getPosition(ref currentPosition, FMOD.TIMEUNIT.MS);
                uint currentPeriod = ((uint)currentPosition / (uint)m_sequence.EventPeriod);

                // tell the user where we are in the process
                transcribeDialog.Progress = (int)currentPosition;
                transcribeDialog.Refresh();

                // calculate the frequency bands for the current position
                GetSpectrumData(currentPeriod);

                // which period are we in?
                if (currentPeriod >= m_sequence.TotalEventPeriods)
                {
                    // time to stop
                    break;
                }                 // last period check

                m_FMOD_system.update();
            }             // end while

            // turn it all off
            m_FMOD_channel.stop();
            transcribeDialog.Hide();
            transcribeDialog.Dispose();
            m_FMOD_sound.release();
            m_FMOD_sound = null;
            m_FMOD_system.close();
            m_FMOD_system.release();
            m_FMOD_system = null;
        }         // analyzeSoundTrack
Exemple #22
0
        public void Stop()
        {
            if (mciCDEngine != null)
            {
                mciCDEngine.Stop();
                mciCDEngine.Close();
                mciCDEngine = null;
            }

            if (currentChannel != null)
            {
                currentChannel.stop();

                if (currentSoundIndex == 0)
                {
                    channel1 = null;
                }
                else
                {
                    channel2 = null;
                }
            }

            // Bei einer CD den cdSound offen lassen, damit das wechseln zwischen subTracks schneller geht.
            if (cdSound == null)
            {
                if (currentSound != null)
                {
                    currentSound.release();
                    if (currentSoundIndex == 0)
                    {
                        sound1 = null;
                    }
                    else
                    {
                        sound2 = null;
                    }
                }
            }

            /* Aktuell keinen PlayCounter schreiben, das die ID3-Routinen Buggy sind!!
             * for (int i = PlayCountFileList.Count - 1; i >= 0;i-- )
             * {
             *   try
             *   {
             *       FileStream fs = File.OpenWrite(PlayCountFileList[i]);
             *       fs.Close();
             *
             *       SoundFileInformation sfi = SoundFileInformation.GetSoundFileInformation(PlayCountFileList[i]);
             *
             *       sfi.PlayCount++;
             *
             *       SoundFileInformation.WriteMP3Tags(sfi, Field.TrackPlayCount);
             *
             *       PlayCountFileList.RemoveAt(i);
             *   }
             *   catch
             *   {
             *
             *   }
             * }*/
        }
Exemple #23
0
        /// <summary>
        /// Stop and try to release FMOD sound resources
        /// </summary>
        void Stop_Internal()
        {
            this.bufferFillPercentage = 0;
            this.isPlaying            = false;
            this.isPaused             = false;
            this.finished             = false;
            this.starving             = false;
            this.deviceBusy           = false;
            this.tags = new string[tagcount];

            /*
             *  Stop the channel, then wait for it to finish opening before we release it.
             */
            if (channel != null)
            {
                result = channel.stop();
                // ERRCHECK(result, "channel.stop", false);
            }

            channel = null;

            /*
             * on wrong requested audio type getOpenState is still returning BUFFERING/LOADING here
             * it is not possible to release sound and system due to FMOD deadlocking
             */
            this.unstableShutdown = false;

            LOG(LogLevel.DEBUG, "Waiting for sound to finish opening before trying to release it....");

            System.Threading.Thread.Sleep(50);

            int c = 0;

            do
            {
                if (++c > 5)
                {
                    break;
                }

                System.Threading.Thread.Sleep(10);

                result    = FMOD.RESULT.OK;
                openstate = FMOD.OPENSTATE.READY;

                if (system != null)
                {
                    result = system.update();
                    // ERRCHECK(result, "system.update", false);
                }

                if (sound != null)
                {
                    result = sound.getOpenState(out openstate, out bufferFillPercentage, out starving, out deviceBusy);
                    // ERRCHECK(result, "sound.getOpenState", false);

                    LOG(LogLevel.DEBUG, "Stream open state: {0}, buffer fill {1} starving {2} networkBusy {3}", openstate, bufferFillPercentage, starving, deviceBusy);
                }
            }while (openstate != FMOD.OPENSTATE.READY || result != FMOD.RESULT.OK);

            if (openstate == FMOD.OPENSTATE.BUFFERING)
            {
                if (result != FMOD.RESULT.ERR_NET_URL)
                {
                    this.unstableShutdown = true;
                    LOG(LogLevel.ERROR, "AudioStreamer is in unstable state - please restart editor/application. [{0} {1}]", openstate, result);
                }
            }


            /*
             *  Shut down
             */

            if (sound != null && !this.unstableShutdown)
            {
                result = sound.release();
                // ERRCHECK(result, "sound.release", false);
            }

            sound = null;
        }
 public void StopBGM()
 {
     IsBGMPlaying = false;
     Result       = ChannelBGM.stop();
 }
Exemple #25
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);
        }