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


C# AudioClip.GetData方法代码示例

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


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

示例1: GetClipData

	//Returns data from an AudioClip as a byte array.
	public static byte[] GetClipData(AudioClip _clip)
	{
		//Get data
		float[] floatData = new float[_clip.samples * _clip.channels];
		_clip.GetData(floatData,0);			
		
		//convert to byte array
		byte[] byteData = new byte[floatData.Length * 4];
		Buffer.BlockCopy(floatData, 0, byteData, 0, byteData.Length);
		
		return(byteData);
	}	
开发者ID:nulhax,项目名称:VOID,代码行数:13,代码来源:CAudioSystem.cs

示例2: _StartMicrophone

    private IEnumerator _StartMicrophone()
    {
        deviceName = PlayerPrefs.GetString("VJMicrophone.deviceName", "");

        while(micSemaphor > 0) {

            string currentDeviceName = deviceName;
            CheckSampleRate(currentDeviceName);

            Debug.Log("Microphone starting: " + currentDeviceName + " sampling rate:" + sampleRate);

            micClip = Microphone.Start(currentDeviceName, true, clipLength, sampleRate);
            float[] samples = new float[(int)(analysisWindow * sampleRate)];
            audio.clip = micClip;
            audio.Play();

            while (currentDeviceName == deviceName && micSemaphor > 0) {
                yield return 0;

                int position = Microphone.GetPosition(deviceName);
                if (position < samples.Length) position += clipLength * sampleRate;
                micClip.GetData(samples, position - samples.Length);
                audio.timeSamples = position;

                float rms = 0.0f;
                foreach (float lvl in samples) {
                    rms += lvl * lvl;
                }
                rms = Mathf.Sqrt(rms / samples.Length);

                level = Mathf.Clamp01( 0.5f * (2.0f + Mathf.Log10(rms)) );
            }

            audio.Stop();
            audio.clip = null;
            Debug.Log("Microphone stopping: " + currentDeviceName );
            Microphone.End(currentDeviceName);
        }
    }
开发者ID:8monolith8,项目名称:fuze-vj-kit,代码行数:39,代码来源:VJMicrophone.cs

示例3: Concat

        public static AudioClip Concat(this AudioClip audioClip, AudioClip otherClip)
        {
            int length = audioClip.samples >= otherClip.samples ? audioClip.samples : otherClip.samples;
            AudioClip clipSum = AudioClip.Create(audioClip.name + " + " + otherClip.name, length, audioClip.channels, audioClip.frequency, false);

            float[] dataSum;
            float[] otherData;

            if (audioClip.samples >= otherClip.samples)
            {
                dataSum = new float[audioClip.samples];
                audioClip.GetData(dataSum, 0);
                otherData = new float[otherClip.samples];
                otherClip.GetData(otherData, 0);
            }
            else
            {
                dataSum = new float[otherClip.samples];
                otherClip.GetData(dataSum, 0);
                otherData = new float[audioClip.samples];
                audioClip.GetData(otherData, 0);
            }

            for (int i = 0; i < otherData.Length; i++)
                dataSum[i] += otherData[i];

            clipSum.SetData(dataSum, 0);

            return clipSum;
        }
开发者ID:Magicolo,项目名称:PseudoFramework,代码行数:30,代码来源:AudioClipExtensions.cs

示例4: OVRHapticsClip

    /// <summary>
    /// Creates a haptics clip from the specified audio clip.
    /// </summary>
    public OVRHapticsClip(AudioClip audioClip, int channel = 0)
    {
        float[] audioData = new float[audioClip.samples * audioClip.channels];
        audioClip.GetData(audioData, 0);

        InitializeFromAudioFloatTrack(audioData, audioClip.frequency, audioClip.channels, channel);
    }
开发者ID:ranguera,项目名称:tron-trails,代码行数:10,代码来源:OVRHapticsClip.cs

示例5: TrimSilence

	public static AudioClip TrimSilence(AudioClip clip, float min) {
		var samples = new float[clip.samples];

		clip.GetData(samples, 0);

		return TrimSilence(new List<float>(samples), min, clip.channels, clip.frequency);
	}
开发者ID:Omicron3141,项目名称:Coalition-Command,代码行数:7,代码来源:SavWav.cs

示例6: GetAudioClipSamples

    private float[] GetAudioClipSamples(AudioClip clip)
    {
        float[] buffer = new float[clip.samples * clip.channels];

        clip.GetData(buffer, 0);

        return buffer;
    }
开发者ID:ian-campbell-brown,项目名称:SENG-ELEC-499,代码行数:8,代码来源:InlineAudioLoop.cs

示例7: Sampler

        //▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
        public Sampler(AudioClip sample)
        {
            output = new AudioSignal();
            pos = 0;

            // get samples data
            len = sample.samples;
            data = new float[len];
            sample.GetData (data, 0);
        }
开发者ID:cstoquer,项目名称:oodio-unity,代码行数:11,代码来源:Sampler.cs

示例8: TrimSilence

	public static AudioClip TrimSilence(AudioClip clip, float min) 
	{
		// do nothing if clip size is 0
		if ( clip.samples == 0 )
			return clip;
		
		var samples = new float[clip.samples];
 
		clip.GetData(samples, 0);

		return TrimSilence(new List<float>(samples), min, clip.channels, clip.frequency);
	}
开发者ID:MedStarSiTEL,项目名称:UnityTrauma,代码行数:12,代码来源:SaveWav.cs

示例9: ConvertSoundToString

    public string ConvertSoundToString(AudioClip clip)
    {
        string base64 = "";
        if (clip != null)
        {
            float[] fBytes = new float[clip.samples * clip.channels];
            byte[] bytes = new byte[fBytes.Length * 4];
            clip.GetData(fBytes, 0);
            Buffer.BlockCopy(fBytes, 0, bytes, 0, bytes.Length);

            base64 = Convert.ToBase64String(bytes);
        }
         return base64;
    }
开发者ID:theslimreaper,项目名称:DnD,代码行数:14,代码来源:Sound_Converter.cs

示例10: ConvertClipToByte

    public static Byte[] ConvertClipToByte(AudioClip clip)
    {
        if (clip == null)
        {
            Debug.Log("GetClipData audio.clip is null");
            return null;
        }

        float[] samples = new float[clip.samples];

        clip.GetData(samples, 0);


        Byte[] outData = new byte[samples.Length * 2];
        //Int16[] intData = new Int16[samples.Length];
        //converting in 2 float[] steps to Int16[], //then Int16[] to Byte[]

        int rescaleFactor = 32767; //to convert float to Int16

        for (int i = 0; i < samples.Length; i++)
        {
            short temshort = (short)(samples[i] * rescaleFactor);

            Byte[] temdata = System.BitConverter.GetBytes(temshort);

            outData[i * 2] = temdata[0];
            outData[i * 2 + 1] = temdata[1];


        }
        if (outData == null || outData.Length <= 0)
        {
            Debug.Log("GetClipData intData is null");
            return null;
        }
        //return intData;
        return outData;
    }
开发者ID:Blizzardx,项目名称:ClientFrameWork,代码行数:38,代码来源:MicroPhoneInput.cs

示例11: ConvertAndWrite

	static void ConvertAndWrite(FileStream fileStream, AudioClip clip) {

		var samples = new float[clip.samples];

		clip.GetData(samples, 0);

		Int16[] intData = new Int16[samples.Length];
		//converting in 2 float[] steps to Int16[], //then Int16[] to Byte[]

		Byte[] bytesData = new Byte[samples.Length * 2];
		//bytesData array is twice the size of
		//dataSource array because a float converted in Int16 is 2 bytes.

		int rescaleFactor = 32767; //to convert float to Int16

		for (int i = 0; i<samples.Length; i++) {
			intData[i] = (short) (samples[i] * rescaleFactor);
			Byte[] byteArr = new Byte[2];
			byteArr = BitConverter.GetBytes(intData[i]);
			byteArr.CopyTo(bytesData, i * 2);
		}

		fileStream.Write(bytesData, 0, bytesData.Length);
	}
开发者ID:Omicron3141,项目名称:Coalition-Command,代码行数:24,代码来源:SavWav.cs

示例12: printOutAudioClip

    public static void printOutAudioClip( AudioClip audioClip, ref AnimationCurve curve, float scaleX = 1f )
    {
        // Debug.Log("Audio channels:"+audioClip.channels+" frequency:"+audioClip.frequency+" length:"+audioClip.length+" samples:"+audioClip.samples);
        float[] samples = new float[audioClip.samples * audioClip.channels];
        audioClip.GetData(samples, 0);
        int i = 0;

        Keyframe[] frames = new Keyframe[samples.Length];
        while (i < samples.Length) {
           frames[i] = new Keyframe( (float)i * scaleX, samples[i] );
           ++i;
        }
        curve = new AnimationCurve( frames );
    }
开发者ID:4026,项目名称:worldgen,代码行数:14,代码来源:LeanAudio.cs

示例13: lipSync

    private void lipSync(AudioClip clip, int frame)
    {
        frame = ((int)(frame / NUMFRAMESLIPSYNC)) * NUMFRAMESLIPSYNC;
        int init = Mathf.CeilToInt(Globals.MILISPERFRAME * clip.frequency);
        float[] samples = new float[init * clip.channels * 3];
        init *= frame % (int)(clip.length * Globals.FRAMESPERSECOND);

        clip.GetData(samples, init);
        float midSamples = 0;
        for(int i = 0; i < samples.Length; ++i) {
            midSamples += Mathf.Abs(samples[i]);
        }
        midSamples /= samples.Length;

        Component[] children = GetComponentsInChildren<Component>(true);
        foreach(Component child in children) {
            if((child.name.StartsWith("exp_") && child.name.EndsWith("_m")) || child.name.StartsWith("lipsync_"))
                child.gameObject.SetActive(false);
            if(midSamples < 0.05f && mMouthClose && child.name == mExpression + "_m")
                child.gameObject.SetActive(true);
            else if(midSamples < 0.05f && !mMouthClose && child.name == "lipsync_00")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.05f && midSamples < 0.1f && child.name == "lipsync_06")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.1f && midSamples < 0.15f && child.name == "lipsync_07")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.15f && midSamples < 0.2f && child.name == "lipsync_01")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.2f && midSamples < 0.25f && child.name == "lipsync_04")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.25f && midSamples < 0.3f && child.name == "lipsync_05")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.3f && midSamples < 0.35f && child.name == "lipsync_06")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.35f && midSamples < 0.4f && child.name == "lipsync_07")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.4f && midSamples < 0.45f && child.name == "lipsync_08")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.45f && child.name == "lipsync_09")
                child.gameObject.SetActive(true);

            /*if(midSamples < 0.05f && mMouthClose && child.name == mExpression + "_m")
                child.gameObject.SetActive(true);
            else if(midSamples < 0.05f && !mMouthClose && child.name == "lipsync_00")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.05f && midSamples < 0.1f && child.name == "lipsync_01")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.1f && midSamples < 0.15f && child.name == "lipsync_02")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.15f && midSamples < 0.2f && child.name == "lipsync_03")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.2f && midSamples < 0.25f && child.name == "lipsync_04")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.25f && midSamples < 0.3f && child.name == "lipsync_05")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.3f && midSamples < 0.35f && child.name == "lipsync_06")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.35f && midSamples < 0.4f && child.name == "lipsync_07")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.4f && midSamples < 0.45f && child.name == "lipsync_08")
                child.gameObject.SetActive(true);
            else if(midSamples >= 0.45f && child.name == "lipsync_09")
                child.gameObject.SetActive(true);*/

            /*if(midSamples<0.01f && child.name==mExpression+"_m")
            child.gameObject.SetActive(true);
            else if(midSamples>=0.01f && midSamples<0.05f && child.name=="lipsync_01")
                child.gameObject.SetActive(true);
            else if(midSamples>=0.05f && midSamples<0.1f && child.name=="lipsync_02")
                child.gameObject.SetActive(true);
            else if(midSamples>=0.1f && midSamples<0.15f && child.name=="lipsync_03")
                child.gameObject.SetActive(true);
            else if(midSamples>=0.15f && midSamples<0.2f && child.name=="lipsync_04")
                child.gameObject.SetActive(true);
            else if(midSamples>=0.2f && midSamples<0.25f && child.name=="lipsync_05")
                child.gameObject.SetActive(true);
            else if(midSamples>=0.25f && midSamples<0.3f && child.name=="lipsync_06")
                child.gameObject.SetActive(true);
            else if(midSamples>=0.3f && midSamples<0.35f && child.name=="lipsync_07")
                child.gameObject.SetActive(true);
            else if(midSamples>=0.35f && midSamples<0.4f && child.name=="lipsync_08")
                child.gameObject.SetActive(true);
            else if(midSamples>=0.4f && child.name=="lipsync_09")
                child.gameObject.SetActive(true);*/
        }
    }
开发者ID:tonylavenders,项目名称:test-video-record,代码行数:86,代码来源:DataManager.cs

示例14: Volume

        public static AudioClip Volume(AudioClip clip, float volume)
        {
            var data = new float[clip.samples];
            clip.GetData(data, 0);

            data = Volume(data, volume);

            var filtered = AudioClip.Create(clip.name, clip.samples, 1, clip.frequency, false, false);
            filtered.SetData(data, 0);
            return filtered;
        }
开发者ID:BasmanovDaniil,项目名称:Whoosh,代码行数:11,代码来源:Audio.cs

示例15: CreatePreview

    public static Texture2D CreatePreview(AudioClip aud, int width, int height, Color color, PreviewType previewType)
    {
        int step = Mathf.CeilToInt((aud.samples * aud.channels) / width);
        float[] samples = new float[aud.samples * aud.channels];

        //workaround to prevent the error in the function getData when Audio Importer loadType is "compressed in memory"
        string path = AssetDatabase.GetAssetPath(aud);
        AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
        AudioImporterLoadType audioLoadTypeBackup = audioImporter.loadType;
        audioImporter.loadType = AudioImporterLoadType.StreamFromDisc;
        AssetDatabase.ImportAsset(path);

        //getData after the loadType changed
        aud.GetData(samples, 0);

        //restore the loadType
        audioImporter.loadType = audioLoadTypeBackup;
        AssetDatabase.ImportAsset(path);

        Texture2D img = new Texture2D(width, height, TextureFormat.RGBA32, false);

        if (previewType == PreviewType.wave)
        {

            Color[] xy = new Color[width * height];
            for (int x = 0; x < width * height; x++)
            {
                xy[x] = new Color(0, 0, 0, 0);
                //xy[x] = new Color(0, 1, 0, 0.2f);
            }

            img.SetPixels(xy);

            int i = 0;
            while (i < width)
            {
                int barHeight = Mathf.CeilToInt(Mathf.Clamp(Mathf.Abs(samples[i * step]) * height, 0, height));
                int add = samples[i * step] > 0 ? 1 : -1;
                for (int j = 0; j < barHeight; j++)
                {
                    img.SetPixel(i, Mathf.FloorToInt(height / 2) - (Mathf.FloorToInt(barHeight / 2) * add) + (j * add), color);
                }
                ++i;

            }

            img.Apply();
        }
        else if (previewType == PreviewType.bar)
        {
            img = new Texture2D(width, 1, TextureFormat.RGBA32, false);
            int i = 0;
            while (i < width)
            {
                //int barHeight = Mathf.CeilToInt(Mathf.Clamp(Mathf.Abs(samples[i * step]) * height, 0, height));
                //int add = samples[i * step] > 0 ? 1 : -1;
                float colorIntensity = Mathf.Clamp(Mathf.Abs(samples[i * step]) * 10f, 0, 1);
                Color colorReturn = new Color(color.r / colorIntensity, color.g / colorIntensity, color.b / colorIntensity, colorIntensity / 4f);
                img.SetPixel(i, 0, colorReturn);
                ++i;
            }
            img.Apply();

        }
        else if (previewType == PreviewType.both)
        {
            /*
            Color[] xy = new Color[width * height];
            for (int x = 0; x < width * height; x++)
            {
                xy[x] = new Color(1, 0, 0, 1);
                //xy[x] = new Color(0, 1, 0, 0.2f);
            }
            img.SetPixels(xy);
            */
            int i = 0;
            while (i < width)
            {
                int barHeight = Mathf.CeilToInt(Mathf.Clamp(Mathf.Abs(samples[i * step]) * height, 0, height));
                int add = samples[i * step] > 0 ? 1 : -1;

                float colorIntensity = Mathf.Clamp(Mathf.Abs(samples[i * step]) * 10f, 0, 1);

                Color colorReturn = new Color(color.r / colorIntensity, color.g / colorIntensity, color.b / colorIntensity, colorIntensity / 6f);

                for (int j = 0; j < height; j++)
                {
                    img.SetPixel(i, j, colorReturn);
                }

                for (int j = 0; j < barHeight; j++)
                {
                    img.SetPixel(i, Mathf.FloorToInt(height / 2) - (Mathf.FloorToInt(barHeight / 2) * add) + (j * add), color);
                }
                ++i;

            }

            img.Apply();

//.........这里部分代码省略.........
开发者ID:Lumennes,项目名称:tagarela,代码行数:101,代码来源:TagarelaAudioSpectrum.cs


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