Esempio n. 1
0
    public float[] rawSpectrum; // raw spectrum data from the audio source

    #endregion Fields

    #region Methods

    void Start()
    {
        bands = 64;
        fftWindowType = FFTWindow.BlackmanHarris;
        rawSpectrum = new float[bands];
        curedSpectrum = new float[bands];
    }
        protected override void Window(int windowId)
        {
            EditorGUILayout.BeginHorizontal();
            m_sampleCount = (SampleCount)SynthGraphEditorFactory.EnumFieldWithLabel( m_sampleCount, "Sample Count" );
            m_fftWindow   = (FFTWindow)SynthGraphEditorFactory.EnumFieldWithLabel( m_fftWindow, "Window Type" );
            EditorGUILayout.EndHorizontal();

            if ( ( m_windowRect.width >= MIN_GRAPH_WIDTH) && ( m_windowRect.height >= MIN_GRAPH_HEIGHT ) )
            {
                DrawGrid();

                if ( m_playbackObject == null )
                {
                    SetRequiresContiniousUpdates( false );
                }
                else
                {
                    DrawPlaybackSpectrum();
                }
            }
        }
Esempio n. 3
0
 private static extern void GetSpectrumDataHelper(float[] samples, int channel, FFTWindow window);
Esempio n. 4
0
 public static float[] GetSpectrumData(int numSamples, int channel, FFTWindow window)
 {
     float[] samples = new float[numSamples];
     GetSpectrumDataHelper(samples, channel, window);
     return samples;
 }
Esempio n. 5
0
    /// <summary>
    /// This is called when the vis manager is reset.
    /// </summary>
	public void Reset()
	{
		channel = Defaults.channel;
		windowSize = Defaults.windowSize;
		windowType = Defaults.windowType;
		
		m_bUseAudioListener = Defaults.useAudioListener;
		displaySpectrumDebug = Defaults.displaySpectrumDebug;
		displayDataGroupDebug = Defaults.displayDataGroupDebug;
		displayControllerDebug = Defaults.displayControllerDebug;
		debugSpectrumBarWidth = Defaults.debugSpectrumBarWidth;
		debugSpectrumBarHeight = Defaults.debugSpectrumBarHeight;
		debugRawAudioBarHeight = Defaults.debugRawAudioBarHeight;
		debugDataGroupBarWidth = Defaults.debugDataGroupBarWidth;
		debugDataGroupBarHeight = Defaults.debugDataGroupBarHeight;
		debugControllerBarWidth = Defaults.debugControllerBarWidth;
		debugControllerBarHeight = Defaults.debugControllerBarHeight;
		debugSeparation = Defaults.debugSeparation;
        debugTexture = null;
	}
		public Single[] GetSpectrumData(int numSamples, int channel, FFTWindow window){}
Esempio n. 7
0
 public float[] GetSpectrum(int numvalues, int channeloffset, FFTWindow windowtype)
 {
     var result = new float[numvalues];
     GetSpectrum(result, numvalues, channeloffset, windowtype);
     return result;
 }
Esempio n. 8
0
    public void GetSpectrumData(float[] samples, float[] spectrumReal, float[] spectrumImg, FFTWindow fftWindow)
    {
        if (null == samples)
        {
            return;
        }

        int size = samples.Length;
        if (null == m_complex ||
            m_complex.Length != size)
        {
            m_complex = new float[size];
        }

        m_fourierTransform.FFT(samples, m_complex, spectrumReal, spectrumImg);
    }
Esempio n. 9
0
 public void GetSpectrum(float[] spectrumarray, int numvalues, int channeloffset, FFTWindow windowtype)
 {
     GetSpectrum(DangerousGetHandle(), spectrumarray, numvalues, channeloffset, windowtype);
 }
Esempio n. 10
0
 private static extern void gst_fft_f32_window(IntPtr self, [MarshalAs(UnmanagedType.LPArray)] float [] timedata, FFTWindow window);
Esempio n. 11
0
    /// <summary>
    /// Returns a logarithmically scaled and proportionate array of spectrum data from the AudioSource.
    /// </summary>
    /// <param name="source">The AudioSource to take data from.</param>
    /// <param name="spectrumSize">The size of the returned array.</param>
    /// <param name="sampleSize">The size of sample to take from the AudioSource. Must be a power of two.</param>
    /// <param name="windowUsed">The FFTWindow to use when sampling.</param>
    /// <param name="channelUsed">The audio channel to use when sampling.</param>
    /// <returns>A logarithmically scaled and proportionate array of spectrum data from the AudioSource.</returns>
    public static float[] GetLogarithmicSpectrumData(AudioSource source, int spectrumSize, int sampleSize, FFTWindow windowUsed = FFTWindow.BlackmanHarris, int channelUsed = 0)
    {
        float[] spectrum = new float[spectrumSize];

        channelUsed = Mathf.Clamp(channelUsed, 0, 1);
        float[] samples = new float[Mathf.ClosestPowerOfTwo(sampleSize)];
        source.GetSpectrumData(samples, channelUsed, windowUsed);

        float highestLogSampleFreq = Mathf.Log(spectrum.Length + 1, 2); //gets the highest possible logged frequency, used to calculate which sample of the spectrum to use for a bar

        float logSampleFreqMultiplier = sampleSize / highestLogSampleFreq;

        for (int i = 0; i < spectrum.Length; i++)                                                                             //for each float in the output
        {
            float trueSampleIndex = (highestLogSampleFreq - Mathf.Log(spectrum.Length + 1 - i, 2)) * logSampleFreqMultiplier; //gets the index equiv of the logified frequency

            //the true sample is usually a decimal, so we need to lerp between the floor and ceiling of it.

            int sampleIndexFloor = Mathf.FloorToInt(trueSampleIndex);
            sampleIndexFloor = Mathf.Clamp(sampleIndexFloor, 0, samples.Length - 2);                                        //just keeping it within the spectrum array's range
            float sampleIndexDecimal = trueSampleIndex % 1;                                                                 //gets the decimal point of the true sample, for lerping

            float value = Mathf.SmoothStep(spectrum[sampleIndexFloor], spectrum[sampleIndexFloor + 1], sampleIndexDecimal); //smoothly interpolate between the two samples using the true index's decimal.

            value = value * trueSampleIndex;                                                                                //multiply value by its position to make it proportionate;

            value = Mathf.Sqrt(value);                                                                                      //compress the amplitude values by sqrt(x)

            spectrum[i] = value;
        }
        return(spectrum);
    }
Esempio n. 12
0
        //格式化音乐
        static public void SpectrumDataFormat(float[] samplesFormat, float[] samples, AudioSource audio = null, int channel = 0, FFTWindow window = FFTWindow.Rectangular)
        {
            if (audio != null)
            {
                audio.GetSpectrumData(samples, channel, window);
            }
            else
            {
                AudioListener.GetSpectrumData(samples, channel, window);
            }

            int disNum   = samples.Length / samplesFormat.Length;
            int audioNum = 0;

            for (int i = 1; i <= samplesFormat.Length; i++)
            {
                int   maxNum  = i * disNum;
                float tempNum = 0;
                for (; audioNum < maxNum; audioNum++)
                {
                    tempNum += samples[audioNum];
                }
                samplesFormat[i - 1] = tempNum / disNum;
            }
        }
Esempio n. 13
0
 /// <summary>
 /// Returns a block of the currently playing source's spectrum data.
 /// </summary>
 /// <param name='samples'>
 /// Samples.
 /// </param>
 /// <param name='channel'>
 /// Channel.
 /// </param>
 /// <param name='window'>
 /// Window.
 /// </param>
 public void GetSpectrumData(float[] samples, int channel, FFTWindow window)
 {
     audioSource.GetSpectrumData(samples, channel, window);
 }
Esempio n. 14
0
    public void GetSpectrumData(float[] samples, float[] spectrumReal, float[] spectrumImg, FFTWindow fftWindow)
    {
        if (null == samples)
        {
            return;
        }

        int size = samples.Length;

        if (null == m_complex ||
            m_complex.Length != size)
        {
            m_complex = new float[size];
        }

        m_fourierTransform.FFT(samples, m_complex, spectrumReal, spectrumImg);
    }
Esempio n. 15
0
 public void GetSpectrum(float[] spectrumarray, int numvalues, int channeloffset, FFTWindow windowtype)
 {
     GetSpectrum(DangerousGetHandle(), spectrumarray, numvalues, channeloffset, windowtype);
 }
Esempio n. 16
0
    /// <summary>
    /// Returns a logarithmically scaled and proportionate array of spectrum data from the AudioListener.
    /// </summary>
    /// <param name="spectrumSize">The size of the returned array.</param>
    /// <param name="sampleSize">The size of sample to take from the AudioListener. Must be a power of two. Will only be used in WebGL if no samples have been taken yet.</param>
    /// <param name="windowUsed">The FFTWindow to use when sampling. Unused in WebGL.</param>
    /// <param name="channelUsed">The audio channel to use when sampling. Unused in WebGL.</param>
    /// <returns>A logarithmically scaled and proportionate array of spectrum data from the AudioListener.</returns>
    public static float[] GetLogarithmicSpectrumData(int spectrumSize, int sampleSize, FFTWindow windowUsed = FFTWindow.BlackmanHarris, int channelUsed = 0)
    {
#if WEB_MODE
        sampleSize = SSWebInteract.SetFFTSize(sampleSize); //set the WebGL sampleSize if not already done, otherwise get the current sample size.
#endif
        float[] spectrum = new float[spectrumSize];

        channelUsed = Mathf.Clamp(channelUsed, 0, 1);

        float[] samples = new float[Mathf.ClosestPowerOfTwo(sampleSize)];

#if WEB_MODE
        SSWebInteract.GetSpectrumData(samples); //get the spectrum data from the JS lib
#else
        AudioListener.GetSpectrumData(samples, channelUsed, windowUsed);
#endif

        float highestLogSampleFreq = Mathf.Log(spectrum.Length + 1, 2); //gets the highest possible logged frequency, used to calculate which sample of the spectrum to use for a bar

        float logSampleFreqMultiplier = sampleSize / highestLogSampleFreq;

        for (int i = 0; i < spectrum.Length; i++)                                                                             //for each float in the output
        {
            float trueSampleIndex = (highestLogSampleFreq - Mathf.Log(spectrum.Length + 1 - i, 2)) * logSampleFreqMultiplier; //gets the index equiv of the logified frequency

            //the true sample is usually a decimal, so we need to lerp between the floor and ceiling of it.

            int sampleIndexFloor = Mathf.FloorToInt(trueSampleIndex);
            sampleIndexFloor = Mathf.Clamp(sampleIndexFloor, 0, samples.Length - 2);                                                        //just keeping it within the spectrum array's range

            float value = Mathf.SmoothStep(spectrum[sampleIndexFloor], spectrum[sampleIndexFloor + 1], trueSampleIndex - sampleIndexFloor); //smoothly interpolate between the two samples using the true index's decimal.

#if WEB_MODE
            value = value * (Mathf.Log(trueSampleIndex + 1) + 1); //different due to how the WebAudioAPI outputs spectrum data.
#else
            value = value * (trueSampleIndex + 1);                //multiply value by its position to make it proportionate
            value = Mathf.Sqrt(value);                            //compress the amplitude values by sqrt(x)
#endif
            spectrum[i] = value;
        }
        return(spectrum);
    }
Esempio n. 17
0
 private static extern Code GetSpectrum(IntPtr channel, [MarshalAs(UnmanagedType.LPArray)] float[] spectrumarray, int numvalues, int channeloffset, FFTWindow windowtype);
Esempio n. 18
0
    public void GetSpectrumData(FFTWindow fftWindow, out float[] spectrumReal, out float[] spectrumImag)
    {
        m_fourierTransform.FFT(m_fetchData, m_complex, m_spectrumReal, m_spectrumImag);

        // notify event that data changed
        if (null != SpectrumChanged)
        {
            SpectrumDataArgs args = new SpectrumDataArgs();
            args.Spectrum = m_spectrumReal;
            SpectrumChanged.Invoke(this, args);
        }

        spectrumReal = m_spectrumReal;
        spectrumImag = m_spectrumImag;
    }
Esempio n. 19
0
 public static void GetSpectrumData(float[] samples, int channel, FFTWindow window)
 {
     AudioListener.GetSpectrumDataHelper(samples, channel, window);
 }
 public virtual void GetSpectrumData(float[] samples, int channel, FFTWindow window)
 {
     mySource.GetSpectrumData(samples, channel, window);
 }
Esempio n. 21
0
 private extern void GetSpectrumDataHelper(float[] samples, int channel, FFTWindow window);
Esempio n. 22
0
		private void GetSpectrumDataHelper(Single[] samples, int channel, FFTWindow window){}
Esempio n. 23
0
 public float[] GetSpectrumData(int numSamples, int channel, FFTWindow window)
 {
     float[] array = new float[numSamples];
     this.GetSpectrumDataHelper(array, channel, window);
     return(array);
 }
Esempio n. 24
0
		public void GetSpectrumData(Single[] samples, int channel, FFTWindow window){}
Esempio n. 25
0
 public void GetSpectrumData(float[] samples, int channel, FFTWindow window)
 {
     this.GetSpectrumDataHelper(samples, channel, window);
 }
Esempio n. 26
0
 /// <summary>
 /// Returns a block of the currently playing source's spectrum data.
 /// </summary>
 /// <param name='samples'>
 /// Samples.
 /// </param>
 /// <param name='channel'>
 /// Channel.
 /// </param>
 /// <param name='window'>
 /// Window.
 /// </param>
 public void GetSpectrumData(float[] samples, int channel, FFTWindow window)
 {
     audioSource.GetSpectrumData(samples, channel, window);
 }
Esempio n. 27
0
 private static extern void gst_fft_f32_window (IntPtr self, [MarshalAs (UnmanagedType.LPArray)] float [] timedata, FFTWindow window);
Esempio n. 28
0
 /// <summary>
 /// <para>Provides a block of the listener (master)'s spectrum data.</para>
 /// </summary>
 /// <param name="samples">The array to populate with audio samples. Its length must be a power of 2.</param>
 /// <param name="channel">The channel to sample from.</param>
 /// <param name="window">The FFTWindow type to use when sampling.</param>
 public static void GetSpectrumData(float[] samples, int channel, FFTWindow window)
 {
     GetSpectrumDataHelper(samples, channel, window);
 }
Esempio n. 29
0
		public static float[] GetSpectrumData(int numSamples, int channel, FFTWindow window)
		{
			float[] array = new float[numSamples];
			AudioListener.GetSpectrumDataHelper(array, channel, window);
			return array;
		}
Esempio n. 30
0
 public float[] GetSpectrum(int numvalues, int channeloffset, FFTWindow windowtype)
 {
     float[] SpectrumArray = new float[numvalues];
     GetSpectrum(SpectrumArray, numvalues, channeloffset, windowtype);
     return SpectrumArray;
 }
 public void Reset()
 {
     FffWindowType = FFTWindow.BlackmanHarris;
     sampleRate = SampleRates.Hz2048;
 }
Esempio n. 32
0
 private static extern ErrorCode GetSpectrum(IntPtr system, [MarshalAs(UnmanagedType.LPArray)] float[] spectrumarray, int numvalues, int channeloffset, FFTWindow windowtype);
Esempio n. 33
0
 public static float[] GetSpectrumData(int numSamples, int channel, FFTWindow window)
 {
     float[] samples = new float[numSamples];
     GetSpectrumDataHelper(samples, channel, window);
     return(samples);
 }