예제 #1
0
        private void drawOscilliscope(Graphics g)
        {
            int numchannels = 0;
            int dummy       = 0;

            FMOD.SOUND_FORMAT  dummyformat    = FMOD.SOUND_FORMAT.NONE;
            FMOD.DSP_RESAMPLER dummyresampler = FMOD.DSP_RESAMPLER.LINEAR;
            int count  = 0;
            int count2 = 0;

            system.getSoftwareFormat(ref dummy, ref dummyformat, ref numchannels, ref dummy, ref dummyresampler, ref dummy);

            /*
             *      DRAW WAVEDATA
             */
            for (count = 0; count < numchannels; count++)
            {
                system.getWaveData(wavedata, WAVEDATASIZE, count);

                for (count2 = 0; count2 < WAVEDATASIZE - 1; count2++)
                {
                    float y;

                    y = (wavedata[count2] + 1) / 2.0f * GRAPHICWINDOW_HEIGHT;

                    g.FillRectangle(mBrushWhite, count2 + GRAPHICWINDOW_WIDTH - WAVEDATASIZE - 10.0f, y, 1.0f, 1.0f);
                }
            }
        }
예제 #2
0
        public float[][] GetWaveData()
        {
            int numchannels = 0;
            int dummy       = 0;

            FMOD.SOUND_FORMAT  dummyformat    = FMOD.SOUND_FORMAT.NONE;
            FMOD.DSP_RESAMPLER dummyresampler = FMOD.DSP_RESAMPLER.LINEAR;
            int       count        = 0;
            const int WAVEDATASIZE = 512;

            system.getSoftwareFormat(ref dummy, ref dummyformat, ref numchannels, ref dummy, ref dummyresampler, ref dummy);

            float[][] wavedata = new float[numchannels][];

            /*
             *      DRAW WAVEDATA
             */
            for (count = 0; count < numchannels; count++)
            {
                wavedata[count] = new float[WAVEDATASIZE];

                if (currentChannel != null)
                {
                    currentChannel.getWaveData(wavedata[count], WAVEDATASIZE, count);
                }
            }

            return(wavedata);
        }
예제 #3
0
        private void drawSpectrum(Graphics g)
        {
            int numchannels = 0;
            int dummy       = 0;

            FMOD.SOUND_FORMAT  dummyformat    = FMOD.SOUND_FORMAT.NONE;
            FMOD.DSP_RESAMPLER dummyresampler = FMOD.DSP_RESAMPLER.LINEAR;
            int count  = 0;
            int count2 = 0;


            system.getSoftwareFormat(ref dummy, ref dummyformat, ref numchannels, ref dummy, ref dummyresampler, ref dummy);

            /*
             *      DRAW SPECTRUM
             */
            for (count = 0; count < numchannels; count++)
            {
                float max = 0;

                system.getSpectrum(spectrum, SPECTRUMSIZE, count, FMOD.DSP_FFT_WINDOW.TRIANGLE);

                for (count2 = 0; count2 < 255; count2++)
                {
                    if (max < spectrum[count2])
                    {
                        max = spectrum[count2];
                    }
                }

                /*
                 *  The upper band of frequencies at 44khz is pretty boring (ie 11-22khz), so we are only
                 *  going to display the first 256 frequencies, or (0-11khz)
                 */
                for (count2 = 0; count2 < 255; count2++)
                {
                    float height;

                    height = spectrum[count2] / max * GRAPHICWINDOW_HEIGHT;

                    if (height >= GRAPHICWINDOW_HEIGHT)
                    {
                        height = GRAPHICWINDOW_HEIGHT - 1;
                    }

                    if (height < 0)
                    {
                        height = 0;
                    }

                    height = GRAPHICWINDOW_HEIGHT - height;

                    g.FillRectangle(mBrushGreen, count2, height, 1.0f, GRAPHICWINDOW_HEIGHT - height);
                }
            }
        }
예제 #4
0
        private void comboBoxRecord_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO();
            FMOD.RESULT            result;
            FMOD.DSP_RESAMPLER     resampler = FMOD.DSP_RESAMPLER.MAX;
            int selected = comboBoxRecord.SelectedIndex;
            int temp     = 0;

            FMOD.SOUND_FORMAT format = FMOD.SOUND_FORMAT.NONE;

            result = system.setSoftwareFormat(OUTPUTRATE, FMOD.SOUND_FORMAT.PCM16, 1, 0, 0);
            ERRCHECK(result);

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

            result = system.getSoftwareFormat(ref outputfreq, ref format, ref temp, ref temp, ref resampler, ref temp);
            ERRCHECK(result);

            /*
             *  Create a sound to record to.
             */
            exinfo.cbsize           = Marshal.SizeOf(exinfo);
            exinfo.numchannels      = 1;
            exinfo.format           = FMOD.SOUND_FORMAT.PCM16;
            exinfo.defaultfrequency = OUTPUTRATE;
            exinfo.length           = (uint)(exinfo.defaultfrequency * 2 * exinfo.numchannels * 5);

            result = system.createSound((string)null, (FMOD.MODE._2D | FMOD.MODE.SOFTWARE | FMOD.MODE.LOOP_NORMAL | FMOD.MODE.OPENUSER), ref exinfo, ref sound);
            ERRCHECK(result);

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

            /*
             *  Start recording
             */
            result = system.recordStart(selected, sound, true);
            ERRCHECK(result);

            Thread.Sleep(200);      /* Give it some time to record something */

            result = system.playSound(FMOD.CHANNELINDEX.REUSE, sound, false, ref channel);
            ERRCHECK(result);

            /* Dont hear what is being recorded otherwise it will feedback.  Spectrum analysis is done before volume scaling in the DSP chain */
            result = channel.setVolume(0);
            ERRCHECK(result);
        }
예제 #5
0
        /// <summary>
        /// Run through each of the frequency bands and record the data
        /// for the current pont in time in the audio track
        /// </summary>
        private void GetSpectrumData(uint period)
        {
//			int num = 0;
//			int num2 = 0;
            int sampleRate        = 0;
            int numOutputChannels = 0;
            int maxInputChannels  = 0;
            int numBits           = 0;

            FMOD.SOUND_FORMAT  sOUND_FORMAT  = FMOD.SOUND_FORMAT.NONE;
            FMOD.DSP_RESAMPLER dSP_RESAMPLER = FMOD.DSP_RESAMPLER.LINEAR;

            m_FMOD_system.getSoftwareFormat(ref sampleRate /* num2 */,
                                            ref sOUND_FORMAT,
                                            ref numOutputChannels /* num */,
                                            ref maxInputChannels /* num2 */,
                                            ref dSP_RESAMPLER,
                                            ref numBits /* num2 */);

            // for each of the output channels
            for (int currentChannel = 0; currentChannel < numOutputChannels; currentChannel++)
            {
                // get the spectrum data for this channel
                m_FMOD_system.getSpectrum(m_FMOD_spectrum, 512, currentChannel, FMOD.DSP_FFT_WINDOW.TRIANGLE);

                // update each frequency band for this period
                foreach (var currentFrequencyBand in m_mapOfFrequencyBands)
                {
                    // this is a magic number that I have not yet tracked down.
                    float currentLevel = 0f;
                    for (int j = currentFrequencyBand.Value.FmodLowFrequency; j < currentFrequencyBand.Value.FmodHighFrequency; j++)
                    {
                        // find the highest value available to this band
                        currentLevel = Math.Max(currentLevel, m_FMOD_spectrum[j]);
                    }
                    currentFrequencyBand.Value.add(period, currentLevel);
                } // end process each frequency band
            }     // end process each channel
        }         // GetSpectrumData
예제 #6
0
        public float[][] GetSpectrum()
        {
            system.update();

            int numchannels = 0;
            int dummy       = 0;

            FMOD.SOUND_FORMAT  dummyformat    = FMOD.SOUND_FORMAT.NONE;
            FMOD.DSP_RESAMPLER dummyresampler = FMOD.DSP_RESAMPLER.LINEAR;
            int count  = 0;
            int count2 = 0;

            system.getSoftwareFormat(ref dummy, ref dummyformat, ref numchannels, ref dummy, ref dummyresampler, ref dummy);
            float[][] spectrum = new float[numchannels][];

            /*
             *      DRAW SPECTRUM
             */
            for (count = 0; count < numchannels; count++)
            {
                float max = 0;

                spectrum[count] = new float[SPECTRUMSIZE];

                if (currentChannel != null)
                {
                    currentChannel.getSpectrum(spectrum[count], SPECTRUMSIZE, count, FMOD.DSP_FFT_WINDOW.HAMMING);

                    /*for (count2 = 0; count2 < SPECTRUMSIZE; count2++)
                     * {
                     *  if (max < spectrum[count][count2])
                     *  {
                     *      max = spectrum[count][count2];
                     *  }
                     * }*/

                    // Sonst sieht man nicht viel...
                    max = 0.2F;

                    for (count2 = 0; count2 < SPECTRUMSIZE; count2++)
                    {
                        float height;

                        height = spectrum[count][count2] / max;

                        if (height >= 1)
                        {
                            height = 1;
                        }

                        if (height < 0)
                        {
                            height = 0;
                        }

                        spectrum[count][count2] = height;
                    }
                }
            }

            return(spectrum);
        }