Example #1
0
        /// <summary>
        /// Check and fix any problem with hardware.
        /// </summary>
        private void CheckDriver()
        {
            //Get number of driver available
            int DriverNumber = 0;

            CheckError(m_System.getNumDrivers(ref DriverNumber));

            //Driver checking
            #region Solve hardware problems
            //If there's 0 driver, no sound
            if (DriverNumber <= 0)
            {
                CheckError(m_System.setOutput(OUTPUTTYPE.NOSOUND));
            }
            else
            {
                //Get driver capability
                int         MinFreq = 0, MaxFreq = 0;
                CAPS        Capability  = CAPS.NONE;
                SPEAKERMODE Speakermode = SPEAKERMODE.STEREO;
                CheckError(m_System.getDriverCaps(0, ref Capability, ref MinFreq, ref MaxFreq, ref Speakermode));

                //Set spearker mode according to the driver
                CheckError(m_System.setSpeakerMode(Speakermode));

                //Set buffer if not using hardware accceleration
                if ((Capability & CAPS.HARDWARE_EMULATED) == CAPS.HARDWARE_EMULATED)
                {
                    CheckError(m_System.setDSPBufferSize(Global.EMULATED_BUFFERSIZE, Global.EMULATED_BUFFERCOUNT));
                }

                //Get user driver data
                GUID          Guid       = new GUID();
                StringBuilder DriverName = new StringBuilder(Global.MAX_DRIVERNAME);
                CheckError(m_System.getDriverInfo(0, DriverName, Global.MAX_DRIVERNAME, ref Guid));

                //If driver is sigmatel
                if (DriverName.Equals(new StringBuilder((Global.SIGMATEL_DRIVERNAME))))
                {
                    //Fix crackling
                    CheckError(m_System.setSoftwareFormat(
                                   Global.SIGMATEL_SAMPLERATE,
                                   SOUND_FORMAT.PCMFLOAT,
                                   0,
                                   0,
                                   DSP_RESAMPLER.LINEAR));
                }
            }
            #endregion
        }
Example #2
0
        public List <string> GetSoundDevices()
        {
            List <string> soundDevices     = new List <string>();
            int           iNumberOfDrivers = 0;

            this.system.getNumDrivers(ref iNumberOfDrivers);

            for (int i = 0; i < iNumberOfDrivers; i++)
            {
                StringBuilder name = new StringBuilder(200);
                FMOD.GUID     guid = new FMOD.GUID();
                system.getDriverInfo(i, name, 200, ref guid);
                soundDevices.Add(name.ToString());
            }

            return(soundDevices);
        }
Example #3
0
        ///<summary>
        ///    Return an array of strings which are the driver names for the playback devices.
        ///</summary>
        public string[] GetAllPlaybackDevices(FMOD.System fmod)
        {
            FMOD.RESULT   result;
            int           numPlaybackDevices = 0;
            StringBuilder drivername         = new StringBuilder(256);

            // Get playback drivers
            result = fmod.getNumDrivers(ref numPlaybackDevices);
            CheckRetCode(result);

            string[] playbackDeviceNames = new string[numPlaybackDevices];

            for (int count = 0; count < numPlaybackDevices; count++)
            {
                FMOD.GUID guid = new FMOD.GUID();
                result = fmod.getDriverInfo(count, drivername, drivername.Capacity, ref guid);
                // result = fmod.getDriverName(count, drivername, drivername.Capacity);
                CheckRetCode(result);
                playbackDeviceNames[count] = drivername.ToString();
            }
            return(playbackDeviceNames);
        }
Example #4
0
        private void comboBoxOutput_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            FMOD.RESULT   result     = FMOD.RESULT.OK;
            StringBuilder drivername = new StringBuilder(256);
            int           numdrivers = 0;

            switch (comboBoxOutput.SelectedIndex)
            {
            case 0:
                result = system.setOutput(FMOD.OUTPUTTYPE.DSOUND);
                break;

            case 1:
                result = system.setOutput(FMOD.OUTPUTTYPE.WINMM);
                break;

            case 2:
                result = system.setOutput(FMOD.OUTPUTTYPE.ASIO);
                break;
            }
            ERRCHECK(result);

            /*
             *  Get Playback drivers
             */
            result = system.getNumDrivers(ref numdrivers);
            ERRCHECK(result);

            for (int count = 0; count < numdrivers; count++)
            {
                result = system.getDriverInfo(count, drivername, drivername.Capacity, ref guid);
                ERRCHECK(result);

                comboBoxPlayback.Items.Add(drivername.ToString());
            }

            comboBoxPlayback.Enabled = true;
        }
Example #5
0
        // ========================================================================================================================================
        #region User support
        /// <summary>
        /// Enumerates available audio outputs in the system and returns their names.
        /// </summary>
        /// <returns></returns>
        public List <string> AvailableOutputs()
        {
            List <string> availableDriversNames = new List <string>();

            int numDrivers;

            result = system.getNumDrivers(out numDrivers);
            ERRCHECK(result, "system.getNumDrivers");

            for (int i = 0; i < numDrivers; ++i)
            {
                int namelen = 255;
                System.Text.StringBuilder name = new System.Text.StringBuilder(namelen);
                System.Guid      guid;
                int              systemrate;
                FMOD.SPEAKERMODE speakermode;
                int              speakermodechannels;

                result = system.getDriverInfo(i, name, namelen, out guid, out systemrate, out speakermode, out speakermodechannels);
                ERRCHECK(result, "system.getDriverInfo");

                availableDriversNames.Add(name.ToString());

                LOG(LogLevel.DEBUG, "{0}{1}guid: {2}{3}systemrate: {4}{5}speaker mode: {6}{7}channels: {8}"
                    , name
                    , System.Environment.NewLine
                    , guid
                    , System.Environment.NewLine
                    , systemrate
                    , System.Environment.NewLine
                    , speakermode
                    , System.Environment.NewLine
                    , speakermodechannels
                    );
            }

            return(availableDriversNames);
        }
        private void threeD_Load(object sender, System.EventArgs e)
        {
            uint version = 0;

            FMOD.RESULT result;

            trackBarPosition.Enabled = false;

            /*
             *  Create a System object and initialize.
             */
            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();
            }

            FMOD.CAPS        caps        = FMOD.CAPS.NONE;
            FMOD.SPEAKERMODE speakermode = FMOD.SPEAKERMODE.STEREO;

            int           outputrate = 0;
            StringBuilder name       = new StringBuilder(128);

            result = system.getDriverCaps(0, ref caps, ref outputrate, ref speakermode);
            ERRCHECK(result);

            result = system.setSpeakerMode(speakermode);                                         /* Set the user selected speaker mode. */
            ERRCHECK(result);

            if ((caps & FMOD.CAPS.HARDWARE_EMULATED) == FMOD.CAPS.HARDWARE_EMULATED)             /* The user has the 'Acceleration' slider set to off!  This is really bad for latency!. */
            {                                                                                    /* You might want to warn the user about this. */
                result = system.setDSPBufferSize(1024, 10);                                      /* At 48khz, the latency between issuing an fmod command and hearing it will now be about 213ms. */
                ERRCHECK(result);
            }

            FMOD.GUID guid = new FMOD.GUID();

            result = system.getDriverInfo(0, name, 256, ref guid);
            ERRCHECK(result);

            if (name.ToString().IndexOf("SigmaTel") != -1)               /* Sigmatel sound devices crackle for some reason if the format is pcm 16bit.  pcm floating point output seems to solve it. */
            {
                result = system.setSoftwareFormat(48000, FMOD.SOUND_FORMAT.PCMFLOAT, 0, 0, FMOD.DSP_RESAMPLER.LINEAR);
                ERRCHECK(result);
            }

            result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
            if (result == FMOD.RESULT.ERR_OUTPUT_CREATEBUFFER)
            {
                result = system.setSpeakerMode(FMOD.SPEAKERMODE.STEREO);                             /* Ok, the speaker mode selected isn't supported by this soundcard.  Switch it back to stereo... */
                ERRCHECK(result);

                result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null);                        /* Replace with whatever channel count and flags you use! */
                ERRCHECK(result);
            }

            /*
             *  Set the distance units. (meters/feet etc).
             */
            result = system.set3DSettings(1.0f, DISTANCEFACTOR, 1.0f);
            ERRCHECK(result);

            /*
             *  Load some sounds
             */
            result = system.createSound("../../../../../examples/media/drumloop.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._3D), ref sound1);
            ERRCHECK(result);
            result = sound1.set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR);
            ERRCHECK(result);
            result = sound1.setMode(FMOD.MODE.LOOP_NORMAL);
            ERRCHECK(result);

            result = system.createSound("../../../../../examples/media/jaguar.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._3D), ref sound2);
            ERRCHECK(result);
            result = sound2.set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR);
            ERRCHECK(result);
            result = sound2.setMode(FMOD.MODE.LOOP_NORMAL);
            ERRCHECK(result);

            result = system.createSound("../../../../../examples/media/swish.wav", (FMOD.MODE.HARDWARE | FMOD.MODE._2D), ref sound3);
            ERRCHECK(result);

            /*
             *  Play sounds at certain positions
             */
            {
                FMOD.VECTOR pos1 = new FMOD.VECTOR();
                pos1.x = -10.0f * DISTANCEFACTOR; pos1.y = -0.0f; pos1.z = 0.0f;

                FMOD.VECTOR vel1 = new FMOD.VECTOR();
                vel1.x = 0.0f; vel1.y = 0.0f; vel1.z = 0.0f;

                result = system.playSound(FMOD.CHANNELINDEX.FREE, sound1, true, ref channel1);
                ERRCHECK(result);
                result = channel1.set3DAttributes(ref pos1, ref vel1);
                ERRCHECK(result);
                result = channel1.setPaused(false);
                ERRCHECK(result);
            }

            {
                FMOD.VECTOR pos2 = new FMOD.VECTOR();
                pos2.x = 15.0f * DISTANCEFACTOR; pos2.y = -0.0f; pos2.z = -0.0f;

                FMOD.VECTOR vel2 = new FMOD.VECTOR();
                vel2.x = 0.0f; vel2.y = 0.0f; vel2.z = 0.0f;

                result = system.playSound(FMOD.CHANNELINDEX.FREE, sound2, true, ref channel2);
                ERRCHECK(result);
                result = channel2.set3DAttributes(ref pos2, ref vel2);
                ERRCHECK(result);
                result = channel2.setPaused(false);
                ERRCHECK(result);
            }

            lastpos.x = 0.0f;
            lastpos.y = 0.0f;
            lastpos.z = 0.0f;

            listenerpos.x = 0.0f;
            listenerpos.y = 0.0f;
            listenerpos.z = -1.0f * DISTANCEFACTOR;
        }
Example #7
0
        public static bool Init()
        {
            FMOD.RESULT result;

            CONTROLS[(int)CONTROLTYPE.DIRECT]   = new ControlInfo(new PointF(0.0f, 1.0f), new PointF(0.5f, 0.0f), new PointF(1.0f, 0.6f), new PointF(-0.5f, 0.0f));
            CONTROLS[(int)CONTROLTYPE.REVERB]   = new ControlInfo(new PointF(0.0f, 0.3f), new PointF(0.5f, 0.0f), new PointF(1.0f, 0.0f), new PointF(-0.5f, 0.0f));
            CONTROLS[(int)CONTROLTYPE.LOWPASS]  = new ControlInfo(new PointF(0.0f, 1.0f), new PointF(0.5f, 0.0f), new PointF(1.0f, 0.0f), new PointF(-0.5f, 0.0f));
            CONTROLS[(int)CONTROLTYPE.ROLLOFF]  = new ControlInfo(new PointF(0.0f, 1.0f), new PointF(0.5f, 0.0f), new PointF(1.0f, 0.7f), new PointF(-0.5f, 0.0f));
            CONTROLS[(int)CONTROLTYPE.PANLEVEL] = new ControlInfo(new PointF(0.0f, 0.0f), new PointF(0.5f, 0.0f), new PointF(0.7f, 1.0f), new PointF(-0.5f, 0.0f));

            result = FMOD.Factory.System_Create(ref system);
            ERRCHECK(result);

            uint version = 0;

            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();
            }

            FMOD.CAPS        caps        = FMOD.CAPS.NONE;
            FMOD.SPEAKERMODE speakermode = FMOD.SPEAKERMODE.STEREO;

            int           minfrequency = 0, maxfrequency = 0;
            StringBuilder name = new StringBuilder(128);

            result = system.getDriverCaps(0, ref caps, ref minfrequency, ref maxfrequency, ref speakermode);
            ERRCHECK(result);

            result = system.setSpeakerMode(speakermode);
            ERRCHECK(result);

            if ((caps & FMOD.CAPS.HARDWARE_EMULATED) == FMOD.CAPS.HARDWARE_EMULATED)
            {
                result = system.setDSPBufferSize(1024, 10);
                ERRCHECK(result);
            }

            FMOD.GUID guid = new FMOD.GUID();

            result = system.getDriverInfo(0, name, 256, ref guid);
            ERRCHECK(result);

            if (name.ToString().IndexOf("SigmaTel") != -1)
            {
                result = system.setSoftwareFormat(48000, FMOD.SOUND_FORMAT.PCMFLOAT, 0, 0, FMOD.DSP_RESAMPLER.LINEAR);
                ERRCHECK(result);
            }

            result = system.init(32, FMOD.INITFLAGS.NORMAL | FMOD.INITFLAGS._3D_RIGHTHANDED, (IntPtr)null);
            if (result == FMOD.RESULT.ERR_OUTPUT_CREATEBUFFER)
            {
                result = system.setSpeakerMode(FMOD.SPEAKERMODE.STEREO);
                ERRCHECK(result);

                result = system.init(32, FMOD.INITFLAGS.NORMAL | FMOD.INITFLAGS._3D_RIGHTHANDED, (IntPtr)null);
                ERRCHECK(result);
            }

            result = system.set3DSettings(2.0f, 100.0f, 1.0f);
            ERRCHECK(result);

            result = system.set3DRolloffCallback(ROLLOFFCALLBACK);
            ERRCHECK(result);

            FMOD.VECTOR pos; pos.x = 0.0f; pos.y = 0.0f; pos.z = 0.0f;
            FMOD.VECTOR vel; vel.x = 0.0f; vel.y = 0.0f; vel.z = 0.0f;
            FMOD.VECTOR dir; dir.x = 0.0f; dir.y = 1.0f; dir.z = 0.0f;
            FMOD.VECTOR up; up.x   = 0.0f; up.y = 0.0f; up.z = 1.0f;
            result = system.get3DListenerAttributes(0, ref pos, ref vel, ref dir, ref up);
            ERRCHECK(result);

            FMOD.PRESET preset = new FMOD.PRESET();
            REVERB[(int)REVERBTYPE.OFF]              = preset.OFF();
            REVERB[(int)REVERBTYPE.GENERIC]          = preset.GENERIC();
            REVERB[(int)REVERBTYPE.PADDEDCELL]       = preset.PADDEDCELL();
            REVERB[(int)REVERBTYPE.ROOM]             = preset.ROOM();
            REVERB[(int)REVERBTYPE.BATHROOM]         = preset.BATHROOM();
            REVERB[(int)REVERBTYPE.LIVINGROOM]       = preset.LIVINGROOM();
            REVERB[(int)REVERBTYPE.STONEROOM]        = preset.STONEROOM();
            REVERB[(int)REVERBTYPE.AUDITORIUM]       = preset.AUDITORIUM();
            REVERB[(int)REVERBTYPE.CONCERTHALL]      = preset.CONCERTHALL();
            REVERB[(int)REVERBTYPE.CAVE]             = preset.CAVE();
            REVERB[(int)REVERBTYPE.ARENA]            = preset.ARENA();
            REVERB[(int)REVERBTYPE.HANGAR]           = preset.HANGAR();
            REVERB[(int)REVERBTYPE.CARPETTEDHALLWAY] = preset.CARPETTEDHALLWAY();
            REVERB[(int)REVERBTYPE.HALLWAY]          = preset.HALLWAY();
            REVERB[(int)REVERBTYPE.STONECORRIDOR]    = preset.STONECORRIDOR();
            REVERB[(int)REVERBTYPE.ALLEY]            = preset.ALLEY();
            REVERB[(int)REVERBTYPE.FOREST]           = preset.FOREST();
            REVERB[(int)REVERBTYPE.CITY]             = preset.CITY();
            REVERB[(int)REVERBTYPE.MOUNTAINS]        = preset.MOUNTAINS();
            REVERB[(int)REVERBTYPE.QUARRY]           = preset.QUARRY();
            REVERB[(int)REVERBTYPE.PLAIN]            = preset.PLAIN();
            REVERB[(int)REVERBTYPE.PARKINGLOT]       = preset.PARKINGLOT();
            REVERB[(int)REVERBTYPE.SEWERPIPE]        = preset.SEWERPIPE();
            REVERB[(int)REVERBTYPE.UNDERWATER]       = preset.UNDERWATER();
            SetReverb(REVERBTYPE.OFF);

            return(true);
        }
Example #8
0
        private void MultipleSoundCard_Load(object sender, System.EventArgs e)
        {
            FMOD.RESULT   result;
            uint          version    = 0;
            int           numdrivers = 0;
            StringBuilder drivername = new StringBuilder(256);

            FMOD.GUID guid = new FMOD.GUID();

            playA.Enabled = false;
            playB.Enabled = false;

            /*
             *  Create Sound Card A
             */
            result = FMOD.Factory.System_Create(ref systemA);
            ERRCHECK(result);

            result = systemA.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 = systemA.getNumDrivers(ref numdrivers);
            ERRCHECK(result);

            for (int count = 0; count < numdrivers; count++)
            {
                result = systemA.getDriverInfo(count, drivername, drivername.Capacity, ref guid);
                ERRCHECK(result);

                comboBox1.Items.Add(drivername.ToString());
            }

            /*
             *  Create Sound Card B
             */
            result = FMOD.Factory.System_Create(ref systemB);
            ERRCHECK(result);

            result = systemB.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 = systemB.getNumDrivers(ref numdrivers);
            ERRCHECK(result);

            for (int count = 0; count < numdrivers; count++)
            {
                result = systemB.getDriverInfo(count, drivername, drivername.Capacity, ref guid);
                ERRCHECK(result);

                comboBox2.Items.Add(drivername.ToString());
            }
        }
Example #9
0
        private void PitchDetection_Load(object sender, System.EventArgs e)
        {
            int  numdrivers = 0;
            uint version    = 0;

            FMOD.RESULT   result;
            StringBuilder drivername = new StringBuilder(256);

            FMOD.GUID guid = new FMOD.GUID();

            comboBoxOutput.Enabled   = true;
            comboBoxPlayback.Enabled = false;
            comboBoxRecord.Enabled   = false;

            /*
             *  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();
            }

            /*
             *  Get output modes
             */
            comboBoxOutput.Items.Add("DirectSound");
            comboBoxOutput.Items.Add("Windows Multimedia WaveOut");
            comboBoxOutput.Items.Add("ASIO");

            /*
             *  Get Playback drivers
             */
            result = system.getNumDrivers(ref numdrivers);
            ERRCHECK(result);

            for (int count = 0; count < numdrivers; count++)
            {
                result = system.getDriverInfo(count, drivername, drivername.Capacity, ref guid);
                ERRCHECK(result);

                comboBoxPlayback.Items.Add(drivername.ToString());
            }

            /*
             *  Get Record drivers
             */
            result = system.getRecordNumDrivers(ref numdrivers);
            ERRCHECK(result);

            for (int count = 0; count < numdrivers; count++)
            {
                result = system.getRecordDriverInfo(count, drivername, drivername.Capacity, ref guid);
                ERRCHECK(result);

                comboBoxRecord.Items.Add(drivername.ToString());
            }
        }