public bool GetData (float[] data, int offsetSamples);

Descripción

Llena un arreglo con una muestra de datos desde el 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 the offsetSamples parameter to start the read from a specific 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.

Nótese que con archivos de audio comprimidos, los datos de muestra solo pueden ser obtenidos cuando el Load Type (Tipo de carga) está puesto en Decompress on Load (Descomprimir durante la carga) en el importador de audio. Si este no es el caso, entonces el arreglo se retornará con ceros para todos los datos de muestra.

using UnityEngine;

public class Example : MonoBehaviour { // Read all the samples from the clip, reducing their gain by half // as we go along.

void Start() { AudioSource audioSource = GetComponent<AudioSource>(); float[] samples = new float[audioSource.clip.samples * audioSource.clip.channels]; audioSource.clip.GetData(samples, 0);

for (int i = 0; i < samples.Length; ++i) { samples[i] = samples[i] * 0.5f; }

audioSource.clip.SetData(samples, 0); } }