CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
[CriAtom] Estimating the latency of sound playback on Android device

Sample description

Overview

cri4u_samples_criatom_adv05_game_mini.png

This is a sample to estimate the latency of sound playback on an Android device running the sample application.
This sample scene follows the steps below.
  1. Start latency estimation
  2. Latency estimation is performed asynchronously
  3. Obtain the information about latency estimation and show it on the screen (execution status and estimate value)
  4. Finish latency estimation
Attention
This sample is not designed to provide low-latency sound playback. Also refer to Low-latency sound playback on Android .

How to use

  • [Estimator Status ] label
    Shows the execution status of latency estimation. There are four statuses. The initial status is "Stop."
    For details about the status, see the CriWare.CriAtomExLatencyEstimator.Status enumeration.

  • [Estimated Latency [msec]] label
    Shows the result (estimated value) of latency estimation. The unit is milliseconds.

  • [Initialize Estimator ] button
    Initializes and starts latency estimation.

  • [Finalize Estimator] button
    Finishes latency estimation.

Scene information


Middleware CRI ADX (CRI Atom)
Sample Advanced sample
Location /CRIWARE/SDK/unity/samples/UnityProject/Assets/Scenes/criatom/advanced/
Scene file Scene_05_EstimateSoundLatency.unity


Description of the program

Method to obtain the execution results

The CriWare.CriAtomExLatencyEstimator.GetCurrentInfo function is used to obtain the results.
This sample uses the code below to obtain these values.
void Update()
{
info = CriAtomExLatencyEstimator.GetCurrentInfo();
}
info is a CriWare.CriAtomExLatencyEstimator.EstimatorInfo structure variable. It is held as private members of this sample scene class, and is displayed in labels with the code below.
GUILayout.Label("Estimator Status : " + info.status); // Member that displays the execution status of latency estimation
GUILayout.Space(16);
GUILayout.Label("Estimated Latency[msec]: " + info.estimated_latency); // Member that displays the result of latency estimation (milliseconds)
GUILayout.Space(16);
When estimation is complete, the status becomes "Done." An estimated value (larger than zero) is obtained as the result.
When the status is other than "Done", the estimated value is zero.
Attention
The estimated value changes depending on the initial setting of the Atom library.
You can check the change by modifying the initial setting of the CriWare.CriWareInitializer component placed on this sample scene and reloading the scene.

Initialization

Use the CriWare.CriAtomExLatencyEstimator.InitializeModule function to initialize.
This sample uses the code below to initialize.
if (Scene_00_GUI.Button("Initialize Estimator", option)) {
if (!is_initialized) {
// Start latency estimation
CriAtomExLatencyEstimator.InitializeModule();
is_initialized = true;
}
}
This sample has an is_initialized flag to prevent multiple initializations.
When the InitializeModule function is called, latency estimation is initialized and started.
When latency estimation is started, the status becomes "Processing." Latency is estimated asynchronously.

Finalization

Use the CriWare.CriAtomExLatencyEstimator.FinalizeModule function to finalize.
This sample uses the code below to finalize.
if (Scene_00_GUI.Button("Finalize Estimator", option)) {
if (is_initialized) {
// Finish latency estimation
CriAtomExLatencyEstimator.FinalizeModule();
is_initialized = false;
}
}
The FinalizeModule function is a blocking function.
When this function is called, latency estimation always stops asynchronous processing and moves to the "Stop" status.