java获取音频驱动程序_AudioClip.GetData 获取数据 - Unity5 中文 API 手册

JavaScript => public function GetData(data: float[], offsetSamples: int): bool;

C# => public bool GetData(float[] data, int offsetSamples);

Description 描述

Fills an array with sample data from the clip.

该剪辑的采样数据数据。

The samples are floats ranging from -1.0f to 1.0f. The sample count is determined by the length of the float array. Use offsetSamples to start the read from a random position in the clip. If the read length from the offset is longer than the clip length, the read will wrap around and read the remaining samples from the start of the clip.

采样的浮点数范围是-1.0 ~ 1.0,采样数由浮点数数组的长度确定。使用offsetSamples从剪辑的随机位置开始读。如果从偏移值读取的长度比剪辑长,读取将环绕从剪辑开始读取剩余采样。

Note that with compressed audio files, the sample data can only be retrieved when the Load Type is set to Decompress on Load in the audio importer. If this is not the case then the array will be returned with zeroes for all the sample values.

注意,压缩的音频文件,当加载类型在音频导入器设置为加载时解压缩时,采样数据只能被读取。如果这不是这种情况,那么数组将返回所有采样值为零。

JavaScript:

// Read all the samples from the clip, reducing their gain by half

// as we go along.

function Start () {

var aud = GetComponent.();

var samples = new float[aud.clip.samples * aud.clip.channels];

aud.clip.GetData(samples, 0);

for (var i = 0; i < samples.Length; ++i)

samples[i] = samples[i] * 0.5f;

aud.clip.SetData(samples, 0);

}

C#:

using UnityEngine;

using System.Collections;

public class ExampleClass : MonoBehaviour {

void Start() {

AudioSource aud = GetComponent();

float[] samples = new float[aud.clip.samples * aud.clip.channels];

aud.clip.GetData(samples, 0);

int i = 0;

while (i < samples.Length) {

samples[i] = samples[i] * 0.5F;

++i;

}

aud.clip.SetData(samples, 0);

}

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值