Version: Unity 7.0 Alpha (7000.0)
LanguageEnglish
  • C#

AudioRenderer.Render

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static bool Render(NativeArray<float> buffer);

Parameters

Parameter Description
buffer The buffer to write the sample data to. Its length must be the value that AudioRenderer.GetSampleCountForCaptureFrame returns, multiplied by the channel count of the current speaker mode.

Returns

bool Returns true if the recording succeeded and false if the engine isn't in recording mode.

Description

Writes the audio rendered since the previous call into the supplied buffer.

Call this method once per frame while the engine is in recording mode. Unity writes interleaved samples for every output channel into the buffer, so the buffer length must match the sample frame count that AudioRenderer.GetSampleCountForCaptureFrame reports, multiplied by the channel count of the current speaker mode.

An oversized buffer takes audio from ahead of the current frame, so the recording drifts out of sync with the visuals.

Call this method on every frame, including the frames where AudioRenderer.GetSampleCountForCaptureFrame returns 0, otherwise the capture stops producing samples. Pass a zero-length buffer on those frames. Calling this method outside recording mode logs an error and returns false.

using Unity.Collections;
using UnityEngine;

public class RenderExample : MonoBehaviour { void Update() { // Assumes AudioRenderer.Start has already been called. int sampleFrames = AudioRenderer.GetSampleCountForCaptureFrame(); AudioConfiguration config = AudioSettings.GetConfiguration(); AudioSpeakerMode speakerMode = config.speakerMode; int channels = speakerMode.ChannelCount();

int length = sampleFrames * channels; NativeArray<float> buffer = new NativeArray<float>( length, Allocator.Temp);

// A zero-length buffer is expected on frames that produce // fewer samples than one DSP buffer. if (AudioRenderer.Render(buffer) && sampleFrames > 0) Debug.Log("Rendered " + sampleFrames + " sample frames.");

buffer.Dispose(); } }