CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
Output waveform capturing

Description of the sample

Overview

This is a sample showing how to capture the output waveform data and visualize it.

cri4u_samples_criatom_script06_main.png

Operations

No operations are available.

Scene information


Middleware CRI ADX (CRI Atom)
Sample Script sample: Output waveform capturing
Location /CRIWARE/SDK/unity/samples/UnityProject/Assets/Scenes/criatom/script/ScriptSample06_OutputCapture/Scenes
Scene file ScriptSample06_OutputCapture.unity
Original ADX data Data: Simple cross-fading of music


Description of the program

This is a sample showing how to capture the output waveform data and visualize it.
The values of the PCM data are converted to the Y-axis position of the cube, forming the shape of the waveform graph.
The music is specified in the sample script and will be played when the script starts executing.

About the output waveform capturing script

The waveform data of the audio output can be acquired by the audio output data analysis function of ADX.
The script file WaveMeter.cs demonstrated how to do this.
The specific procedure is as follows:

  1. Initialize the CriAtomExOutputAnalyzer with the appropriate configuration parameters.
    • Set the member enablePcmCapture of the structure CriAtomExOutputAnalyzer.Config to true, and specify numCapturedPcmSamples as the length (number of samples) of the data which you want to acquire.
    • Initialize CriAtomExOutputAnalyzer by passing the configured Config structure to the constructor.

  2. Attach the audio data analysis module to CriAtomExPlayer before the audio is played.
    • Use CriAtomExOutputAnalyzer.AttachExPlayer(CriAtomExPlayer)
    • It is also possible to attach to the DSP bus. In that case, use CriAtomExOutputAnalyzer.AttachDspBus(string busName) instead.
    • Attaching will fail if performed after the audio being played.

  3. Use the GetPcmData function during playback to get and visualize the waveform data.
    • Execute CriAtomExOutputAnalyzer.GetPcmData(ref float[] pcmData, int channelId) inside Update() to get the PCM data from the specified channel.
    • The PCM data is output as a float array to the reference argument.
    • If the length of the output pcmData array passed to the reference argument is less than numCapturedPcmSamples set in (1), the memory space will be reallocated in GetPcmData. To avoid unnecessary GC, secure an array with a length of numCapturedPcmSamples or more in advance.

Attention
When the output analysis function is no longer needed, such as at the end of the script execution, execute CriAtomExOutputAnalyzer.DetachExPlayer() (DetachDspBus if attached to the DSP bus) and then CriAtomExOutputAnalyzer.Dispose() to destroy the instances.