Exemplo n.º 1
0
            public SoundLib()
            {
                if (system != null)
                {
                    return;
                }

                FMOD.RESULT result = FMOD.Factory.System_Create(out system);
                if (ERRCHECK(result, "System_Create"))
                {
                    return;
                }

                uint version;

                result = system.getVersion(out version);
                ERRCHECK(result, "system.getVersion");
                if (version < FMOD.VERSION.number)
                {
                    Report.ReportLog("Error! Old version of FMOD " + version.ToString("X") + " detected.  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
                    system.close();
                    system.release();
                    system = null;
                    return;
                }

                result = system.init(1, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
                if (ERRCHECK(result, "system.init"))
                {
                    system.close();
                    system.release();
                    system = null;
                    return;
                }
            }
Exemplo n.º 2
0
 public void Teardown()
 {
     m_masterChannelGroup.release();
     m_fmodSystem.update();
     m_fmodSystem.close();
     m_fmodSystem.release();
 }
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);
        }
        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.º 5
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.º 6
0
        void OnDisable()
        {
            this.StopFMODSound();

            if (this.pcmReadCallbackBuffer != null)
            {
                this.pcmReadCallbackBuffer[0].Clear();
                this.pcmReadCallbackBuffer[1].Clear();

                this.pcmReadCallbackBuffer[0] = null;
                this.pcmReadCallbackBuffer[1] = null;

                this.pcmReadCallbackBuffer.Clear();
                this.pcmReadCallbackBuffer = null;
            }

            this.pcmreadcallback   = null;
            this.pcmsetposcallback = null;

            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
        public bool Destroy()
        {
            m_system.close();
            m_system.release();

            Console.WriteLine("[FMOD] SoundSystem destroyed");
            return(true);
        }
Exemplo n.º 8
0
        public void Dispose()
        {
            if (_system != null)
            {
                _system.close();
                _system.release();

                _system = null;
            }
        }
Exemplo n.º 9
0
        protected virtual void OnDisable()
        {
            this.Stop();

            if (system != null && !this.unstableShutdown)
            {
                result = system.close();
                // ERRCHECK(result, "system.close", false);

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

            system = null;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            //destroy FMOD
            if (_system != null)
            {
                FMOD.RESULT result;

                //close system
                result = _system.close();
                CheckError(result);

                //release system
                result = _system.release();
                CheckError(result);
            }
        }
Exemplo n.º 11
0
        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent)
            {
                Content.Unload();
            }

            FMOD.RESULT result;

            if (SoundSystem != null)
            {
                result = SoundSystem.close();
                ERRCHECK(result);
                result = SoundSystem.release();
                ERRCHECK(result);
            }
        }
Exemplo n.º 12
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.º 13
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                FMOD.RESULT result;

                /*
                 *  Shut down
                 */
                for (int count = 0; count < 6; count++)
                {
                    if (sound[count] != null)
                    {
                        result = sound[count].release();
                        ERRCHECK(result);
                    }
                }

                if (groupA != null)
                {
                    result = groupA.release();
                    ERRCHECK(result);
                }
                if (groupB != null)
                {
                    result = groupB.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.º 14
0
        //gameover sequence and destructor
        public void GameOver()
        {
            //stop timer
            gravity.Stop();
            gravity.Enabled = false;

            //reinitialize score
            score = 0;

            //remove all buttons
            for (int ix = Controls.Count - 1; ix >= 0; ix--)
            {
                if (Controls[ix] is Button && Controls[ix] != start && Controls[ix] != loadSongs)
                {
                    Controls[ix].Dispose();
                }
            }

            //get system and then release it to be able to load a new song
            FMOD.System sys = new FMOD.System();
            sys = detector.getSystem();
            sys.release();
            sys.close();

            //messagebox showing high score
            MessageBox.Show("Game Over" + "\nHigh Score: " + Convert.ToString(high), "Euphoria", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //show hidden UI
            start.Visible      = true;
            songs.Visible      = true;
            loadSongs.Visible  = true;
            difficulty.Visible = true;

            //hide in-game UI
            highScore.Visible    = false;
            scoreDisplay.Visible = false;
            np.Visible           = false;

            //remove hitfield
            Controls.Remove(pic);
            Controls.Remove(hitBar);
        }
Exemplo n.º 15
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.º 16
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.º 17
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.º 18
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.º 19
0
        private float BPMDetection(string filename)
        {
            float bpm = 0.0f;

            const int CHUNKSIZE = 4096;

            FMOD.RESULT result;
            FMOD.System systemBpm = null;
            FMOD.Sound  soundBpm  = null;

            // Create a System object and initialize.
            result = FMOD.Factory.System_Create(ref systemBpm);
            ERRCHECK(result);

            // Zuerst in eine WAVE-Umwandeln
            result = systemBpm.init(1, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
            ERRCHECK(result);

            result = systemBpm.createSound(filename, FMOD.MODE.OPENONLY | FMOD.MODE.ACCURATETIME, ref soundBpm);
            ERRCHECK(result);

            /*
             *  Decode the sound and write it to a .raw file.
             */
            {
                IntPtr data = Marshal.AllocHGlobal(CHUNKSIZE);
                byte[] buffer = new byte[CHUNKSIZE];
                uint   length = 0, read = 0;
                uint   bytesread = 0;

                MemoryStream memStream = new MemoryStream();

                result = soundBpm.getLength(ref length, FMOD.TIMEUNIT.PCMBYTES);
                ERRCHECK(result);

                bytesread = 0;
                do
                {
                    result = soundBpm.readData(data, CHUNKSIZE, ref read);

                    Marshal.Copy(data, buffer, 0, CHUNKSIZE);

                    memStream.Write(buffer, 0, (int)read);

                    bytesread += read;
                }while (result == FMOD.RESULT.OK && read == CHUNKSIZE);

                /*
                 *  Loop terminates when either
                 *  1. the read function returns an error.  (ie FMOD_ERR_FILE_EOF etc).
                 *  2. the amount requested was different to the amount returned. (somehow got an EOF without the file error, maybe a non stream file format like mod/s3m/xm/it/midi).
                 *
                 *  If 'bytesread' is bigger than 'length' then it just means that FMOD miscalculated the size,
                 *  but this will not usually happen if FMOD_ACCURATETIME is used.  (this will give the correct length for VBR formats)
                 */

                memStream.Close();

                // In float umwandeln
                byte[]  samples      = memStream.ToArray();
                float[] floatSamples = new float[samples.Length / 2];
                //for (int i = 0; i < samples.Length; i += 4)
                for (int i = samples.Length / 4; i < samples.Length * 3 / 4; i += 4)
                {
                    short sampleLeft  = BitConverter.ToInt16(samples, i);
                    short sampleRight = BitConverter.ToInt16(samples, i + 2);

                    floatSamples[i / 2]     = (float)sampleLeft / 32768.0f;
                    floatSamples[i / 2 + 1] = (float)sampleRight / 32768.0f;
                }

                BigMansStuff.PracticeSharp.Core.SoundTouchSharp soundTouch = new BigMansStuff.PracticeSharp.Core.SoundTouchSharp();

                bpm = soundTouch.DetectBPM(2, 44100, floatSamples, floatSamples.Length);

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

            return(bpm);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Konvertieren von von Sound Dateien zu WAVE mit PCM Header
        /// </summary>
        /// <param name="src">Kompletter Pfad zur Quell Datei</param>
        /// <param name="dest">Kompletter Pfad zur Ziel Datei</param>
        /// <returns></returns>
        public bool ConvertToWAVE(string src_file, string dest_file, ConvertToWaveProgressDelegate convertToWaveProgressDelegate)
        {
            uint version = 0;

            FMOD.RESULT result;
            const int   CHUNKSIZE = 262144;

            FMOD.System system = null;
            FMOD.Sound  sound  = null;

            /*
             *  Global Settings
             */
            result = FMOD.Factory.System_Create(ref system);
            if (result != FMOD.RESULT.OK)
            {
                return(false);
            }

            result = system.getVersion(ref version);
            ERRCHECK(result);
            if (version < FMOD.VERSION.number)
            {
                //MessageBox.Show("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
                return(false);
            }

            result = system.init(1, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
            ERRCHECK(result);

            result = system.createSound(src_file, FMOD.MODE.OPENONLY | FMOD.MODE.ACCURATETIME, ref sound);

            if (result != FMOD.RESULT.OK)
            {
                return(false);
            }


            /*
             *  Decode the sound and write it to a .raw file.
             */
            IntPtr data = Marshal.AllocHGlobal(CHUNKSIZE);

            byte[] buffer = new byte[CHUNKSIZE];
            uint   length = 0, read = 0;
            uint   bytesread = 0;

            FileStream fs = new FileStream(dest_file, FileMode.Create, FileAccess.Write);

            result = sound.getLength(ref length, FMOD.TIMEUNIT.PCMBYTES);
            ERRCHECK(result);

            bytesread = 0;
            do
            {
                result = sound.readData(data, CHUNKSIZE, ref read);

                Marshal.Copy(data, buffer, 0, CHUNKSIZE);

                fs.Write(buffer, 0, (int)read);

                bytesread += read;

                double percent = 100.0 / (double)length * (double)bytesread;

                convertToWaveProgressDelegate(src_file, dest_file, percent);
                System.Windows.Forms.Application.DoEvents();
                //statusBar.Text = "writing " + bytesread + " bytes of " + length + " to output.raw";
            }while (result == FMOD.RESULT.OK && read == CHUNKSIZE);

            //statusBar.Text = "done";

            /*
             *  Loop terminates when either
             *  1. the read function returns an error.  (ie FMOD_ERR_FILE_EOF etc).
             *  2. the amount requested was different to the amount returned. (somehow got an EOF without the file error, maybe a non stream file format like mod/s3m/xm/it/midi).
             *
             *  If 'bytesread' is bigger than 'length' then it just means that FMOD miscalculated the size,
             *  but this will not usually happen if FMOD_ACCURATETIME is used.  (this will give the correct length for VBR formats)
             */

            fs.Close();


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

            return(true);
        }
Exemplo n.º 21
0
        private void playButton_Click(object sender, System.EventArgs e)
        {
            uint version = 0;

            FMOD.RESULT result;

            /*
             *  Global Settings
             */
            result = FMOD.Factory.System_Create(ref system);
            ERRCHECK(result);

            result = system.getVersion(ref version);
            ERRCHECK(result);
            if (version < FMOD.VERSION.number)
            {
                MessageBox.Show("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
                Application.Exit();
            }

            result = system.init(1, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
            ERRCHECK(result);

            result = system.createSound("../../../../../examples/media/wave.mp3", FMOD.MODE.OPENONLY | FMOD.MODE.ACCURATETIME, ref sound);
            ERRCHECK(result);

            /*
             *  Decode the sound and write it to a .raw file.
             */
            {
                IntPtr data = Marshal.AllocHGlobal(CHUNKSIZE);
                byte[] buffer = new byte[CHUNKSIZE];
                uint   length = 0, read = 0;
                uint   bytesread = 0;

                FileStream fs = new FileStream("output.raw", FileMode.Create, FileAccess.Write);

                result = sound.getLength(ref length, FMOD.TIMEUNIT.PCMBYTES);
                ERRCHECK(result);

                bytesread = 0;
                do
                {
                    result = sound.readData(data, CHUNKSIZE, ref read);

                    Marshal.Copy(data, buffer, 0, CHUNKSIZE);

                    fs.Write(buffer, 0, (int)read);

                    bytesread += read;

                    statusBar.Text = "writing " + bytesread + " bytes of " + length + " to output.raw";
                }while(result == FMOD.RESULT.OK && read == CHUNKSIZE);

                statusBar.Text = "done";

                /*
                 *  Loop terminates when either
                 *  1. the read function returns an error.  (ie FMOD_ERR_FILE_EOF etc).
                 *  2. the amount requested was different to the amount returned. (somehow got an EOF without the file error, maybe a non stream file format like mod/s3m/xm/it/midi).
                 *
                 *  If 'bytesread' is bigger than 'length' then it just means that FMOD miscalculated the size,
                 *  but this will not usually happen if FMOD_ACCURATETIME is used.  (this will give the correct length for VBR formats)
                 */

                fs.Close();


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