当前位置: 首页>>代码示例>>C#>>正文


C# AudioSource.GetOutputData方法代码示例

本文整理汇总了C#中UnityEngine.AudioSource.GetOutputData方法的典型用法代码示例。如果您正苦于以下问题:C# AudioSource.GetOutputData方法的具体用法?C# AudioSource.GetOutputData怎么用?C# AudioSource.GetOutputData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.AudioSource的用法示例。


在下文中一共展示了AudioSource.GetOutputData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetAveragedVolume

		public static float GetAveragedVolume(AudioSource audio, int samples) {
			float[] data = new float[samples];
			float a = 0;
			audio.GetOutputData(data,0);
			foreach(float s in data)
			{
				a += Mathf.Abs(s);
			}
			return a/samples;
		}
开发者ID:fromtons,项目名称:meme-pas-peur_app,代码行数:10,代码来源:AudioUtils.cs

示例2: getVolume

	public void getVolume(){
		audio = GetComponent<AudioSource> ();
		audio.GetOutputData(samples, 0);
		float sum = 0;
		for(int i=0; i< qsamples; i++){
			sum += samples[i]*samples[i];
		}
		rmsvalue = Mathf.Sqrt(sum/qsamples);
		//rmsvalue += 1;
		dbvalue = 20 * Mathf.Log10(rmsvalue/refvalue);
		if(dbvalue<-160){
			dbvalue = -160;
		}
	}
开发者ID:fawwaz,项目名称:baloon,代码行数:14,代码来源:baloon.cs

示例3: GetSamplesVolume

		float GetSamplesVolume(AudioSource audio)
		{
			audio.GetOutputData(waveData, chanel);
			float sum = 0;
			foreach (float s in waveData)
			{
				sum += Mathf.Abs(s);
			}
			return (sum / smaples);
		}
开发者ID:OsamaRazaAnsari,项目名称:2DDressUpGame,代码行数:10,代码来源:SoundStream.cs

示例4: Analyze

        /// <summary>
        /// Analyze upcoming audio signal and find the ticks.
        /// 
        /// The algorithm is simple : we analyze the upcoming signal in many parts with a size of a half tick (~44 samples at 44100 Hz);
        /// We take each time two parts of samples and if the first part has less gain than the second's,
        /// we consider that there is a tick in the second.
        /// 
        /// When the tick has been found, we approximatively skip to a place where the next tick could be
        /// in order to optimise the research.
        /// Otherwise we continue from the second part.
        /// </summary>
        /// <param name="audio">Audio source (Unity).</param>
        public static void Analyze(AudioSource audio)
        {
            int currentSample = audio.timeSamples;
            int samples = currentSample - lastAnalyzedSample;

            // We must analyze a range which can contain at least one tick.
            if (samples < tickMinDelta || samples == 0)
                return;

            // Copy the audio data in our buffer.
            float[] data = new float[samples];
            audio.GetOutputData (data, 0);
            data.CopyTo (_buffer, lastAnalyzedSample);

            // Ignore filters processes if audio source is a file.
            // The file is already processed.
            if (!sourceIsFile)
                Process (data);

            float[] means = new float[2]; // Two parts of samples.

            int d = tickSamples / 2; // Half tick.
            int parts = samples / d; // Number of parts to process.

            // Process the parts.
            for (int i = 0; i < parts - 1;) {
                means [0] = FlapiUtils.AbsMean (data, i * d, (i + 1) * d - 1); // Mean gain of first part.
                means [1] = FlapiUtils.AbsMean (data, (i + 1) * d, (i + 2) * d - 1); // Mean gain of second part.

                // Second part has more gain than first's ?
                if (means [1] > _threshold * means [0]) {
                    _ticks [lastAnalyzedSample + (i + 2) * d] = true; // Here's a tick !
                    i += 2 * d; //(tickMinDelta / d - 1); // Process to the approximative next tick.
                } else {
                    i++;
                }
            }

            _frequency = GetTicksFrequency (currentSample);
            lastAnalyzedSample = currentSample - (samples % tickMinDelta); // Next call skip after the last analyzed buffer.
        }
开发者ID:breathinggames,项目名称:bg_bloid,代码行数:53,代码来源:Flapi.cs


注:本文中的UnityEngine.AudioSource.GetOutputData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。