Ejemplo n.º 1
0
        ///<summary>
        ///    Return an array of strings which are the driver names for the "microphone" devices.
        ///</summary>
        public string[] GetAllMicrophoneDevices(FMOD.System fmod)
        {
            FMOD.RESULT   result;
            int           numSoundSources = 0;
            StringBuilder drivername      = new StringBuilder(256);

//             result = system.setDriver(selected);
//             ERRCHECK(result);

            // Get Record drivers
            result = fmod.getRecordNumDrivers(ref numSoundSources);
            CheckRetCode(result);

            string[] soundSourceNames = new string[numSoundSources];

            for (int count = 0; count < numSoundSources; count++)
            {
                FMOD.GUID guid = new FMOD.GUID();
                result = fmod.getRecordDriverInfo(count, drivername, drivername.Capacity, ref guid);
                // result = fmod.getRecordDriverName(count, drivername, drivername.Capacity);
                CheckRetCode(result);
                soundSourceNames[count] = drivername.ToString();
            }
            return(soundSourceNames);
        }
Ejemplo n.º 2
0
        private void comboBoxOutput_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            FMOD.RESULT   result     = FMOD.RESULT.OK;
            StringBuilder drivername = new StringBuilder(256);
            int           numdrivers = 0;

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

            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;

            default:
                return;
            }
            ERRCHECK(result);

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

            comboBoxOutput.Enabled = false;
            comboBoxRecord.Enabled = true;
        }
Ejemplo n.º 3
0
        private void comboBoxPlayback_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            FMOD.RESULT   result;
            StringBuilder drivername = new StringBuilder(256);
            int           numdrivers = 0;

            selected = comboBoxPlayback.SelectedIndex;

            comboBoxRecord.Enabled = true;

            /*
             *  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());
            }
        }
Ejemplo n.º 4
0
        IEnumerator RecordCR()
        {
            int recRate = 0;
            int namelen = 255;

            System.Text.StringBuilder name = new System.Text.StringBuilder(namelen);
            System.Guid       guid;
            FMOD.SPEAKERMODE  speakermode;
            FMOD.DRIVER_STATE driverstate;
            result = system.getRecordDriverInfo(this.recordDeviceId, name, namelen, out guid, out recRate, out speakermode, out recChannels, out driverstate);
            ERRCHECK(result, "system.getRecordDriverInfo");

            // compensate the input rate for the current output rate
            this.GetComponent <AudioSource>().pitch = ((float)(recRate * recChannels) / (float)(AudioSettings.outputSampleRate * (int)AudioSettings.speakerMode));

            exinfo                  = new FMOD.CREATESOUNDEXINFO();
            exinfo.numchannels      = recChannels;
            exinfo.format           = FMOD.SOUND_FORMAT.PCM16;
            exinfo.defaultfrequency = recRate;
            exinfo.length           = (uint)(recRate * sizeof(short) * recChannels);

            result = system.createSound(string.Empty, FMOD.MODE.LOOP_NORMAL | FMOD.MODE.OPENUSER, ref exinfo, out sound);
            ERRCHECK(result, "system.createSound");

            this.GetComponent <AudioSource>().Play();

            result = system.recordStart(this.recordDeviceId, sound, true);
            ERRCHECK(result, "system.recordStart");

            result = sound.getLength(out soundlength, FMOD.TIMEUNIT.PCM);
            ERRCHECK(result, "sound.getLength");

            this.isRecording = true;

            if (this.OnRecordingStarted != null)
            {
                this.OnRecordingStarted.Invoke(this.gameObjectName);
            }

            for (;;)
            {
                result = system.update();
                ERRCHECK(result, "system.update", false);

                if (this.isPaused)
                {
                    yield return(null);
                }

                uint recordpos = 0;

                system.getRecordPosition(this.recordDeviceId, out recordpos);
                ERRCHECK(result, "system.getRecordPosition");

                if (recordpos != lastrecordpos)
                {
                    int blocklength;

                    blocklength = (int)recordpos - (int)lastrecordpos;
                    if (blocklength < 0)
                    {
                        blocklength += (int)soundlength;
                    }

                    /*
                     * Lock the sound to get access to the raw data.
                     */
                    result = sound.@lock((uint)(lastrecordpos * exinfo.numchannels * 2), (uint)(blocklength * exinfo.numchannels * 2), out ptr1, out ptr2, out len1, out len2);   /* * exinfo.numchannels * 2 = stereo 16bit.  1 sample = 4 bytes. */

                    /*
                     * Write it to output.
                     */
                    if (ptr1.ToInt64() != 0 && len1 > 0)
                    {
                        datalength += len1;
                        byte[] barr = new byte[len1];
                        Marshal.Copy(ptr1, barr, 0, (int)len1);

                        this.AddBytesToOutputBuffer(barr);
                    }
                    if (ptr2.ToInt64() != 0 && len2 > 0)
                    {
                        datalength += len2;
                        byte[] barr = new byte[len2];
                        Marshal.Copy(ptr2, barr, 0, (int)len2);
                        this.AddBytesToOutputBuffer(barr);
                    }

                    /*
                     * Unlock the sound to allow FMOD to use it again.
                     */
                    result = sound.unlock(ptr1, ptr2, len1, len2);
                }

                lastrecordpos = recordpos;

                // print(string.Format("Record buffer pos = {0} : Record time = {1}:{2}", recordpos, datalength / exinfo.defaultfrequency / exinfo.numchannels / 2 / 60, (datalength / exinfo.defaultfrequency / exinfo.numchannels / 2) % 60));

                // System.Threading.Thread.Sleep(10);

                yield return(null);
            }
        }
Ejemplo n.º 5
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());
            }
        }