CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
[CriAtom] Real-time parameter control

Description of the sample

Overview

cri4u_samples_criatom_scene04_game_mini.png

This sample demonstrates how to control playback parameters, such as volume and pitch, in real-time during sound playback.

Operations

Click on the cube on the screen. The narration is started.

You can move the sliders to control the playback parameters.
The table below shows the correspondence between the sliders and the playback parameters.

Sliders and playback parameters
Slider Playback parameter
Volume Control Volume
Pitch Control Pitch
Bus Send 00 Bus send 0: Master bus
Bus Send 01 Bus send 1: Reverb
Bus Send 02 Bus send 2: Pitch shifter
Bus Send 03 Bus send 3: Echo/surrounder
Bus Send 04 Bus send 4: Compressor
Bus Send 05 Bus send 5: Chorus
Bus Send 06 Bus send 6: Biquad lowpass filter
Bus Send 07 Bus send 7: Distortion

To initialize the parameters, click on the Reset Parameters button.

Scene information


Middleware CRI ADX (CRI Atom)
Sample Basic sample
Location /CRIWARE/SDK/unity/samples/UnityProject/Assets/Scenes/criatom/basic/
Scene file Scene_04_ControlParameter.unity


Description of the program

When you create sound data in CRI Atom Craft, you can set playback parameters for cues, tracks, and waveforms.
When a script plays a cue, the playback parameters that are set for the cue are used for playback.
However, you can change the playback parameters in real time after the playback has started.
  • Playback parameters
    • Volume
    • Pitch (changes the playback speed)
    • Bandpass
    • Equalizing filter
    • Panning
    • Pitch shift (maintaining the playback speed)
    • Compressor
    • Distortion
    • Reverb
    • Bus send level

Volume control and pitch control

/* Volume */
private float volumeValue = 1.0f;
/* Pitch */
private float pitchValue = 0.0f;
/* Pitch control GUI */
GUI.Label (new Rect(20, 18 * (gui_i++), 200, 24), "Pitch Control Value " + this.pitchValue.ToString("0.00"));
this.pitchValue = GUI.HorizontalSlider(new Rect(20, 18 * (gui_i++), 200, 12), pitchValue, -1200.0f, 1200.0f);
if (GUI.changed || on_reset == true) {
CriAtomSource atom_source = gameObject.GetComponent<CriAtomSource>();
/* If the parameter are in the Inspector, control them there */
atom_source.volume = volumeValue;
atom_source.pitch = pitchValue;
}

Attaching DSP bus settings

The settings related to the DSP bus are configured in CRI Atom Craft.
They mostly concern the DSP effects (such as reverb, delay, distortion, and pitch shift) for each bus.

You must call the AttachDspBusSetting() function before you can use these settings.
This sample automatically attaches the DSP bus settings when the CRI component of the [CRIWARE] object is initialized (the ACF file is loaded).

Bus send level

Bus send is mainly used to enable the DSP effects.
The bus send level is combined with the level set for the data. Therefore, the data level must be at 1.0 (open) beforehand.
The DSP bus to which the data is sent must be connected with the DSP effects and with the final output.

/* Bus send 0-7 */
private float[] busSendlevelValue = new float[maxBus];
...
GUILayout.BeginVertical();
for (int i = 0; i < maxBus / 2; i++) {
GUILayout.Label ("[" + i.ToString() + "] " + this.busSendlevelValue[i].ToString("0.00") + busEffectType[i]);
this.busSendlevelValue[i] = Scene_00_GUI.HorizontalSlider(busSendlevelValue[i], 0.0f, 1.0f);
}
GUILayout.EndVertical();
GUILayout.BeginVertical();
GUILayout.Space(12);
GUILayout.EndVertical();
GUILayout.BeginVertical();
for (int i = maxBus / 2; i < maxBus; i++) {
GUILayout.Label ("[" + i.ToString() + "] " + this.busSendlevelValue[i].ToString("0.00") + busEffectType[i]);
this.busSendlevelValue[i] = Scene_00_GUI.HorizontalSlider(busSendlevelValue[i], 0.0f, 1.0f);
}
GUILayout.EndVertical();
...
/* Update the bus send level. */
/* A parameter that does not exist on the Inspector side, control it by functions. */
/* Bus 0 is 1.0f by default, and multiplication is applied. */
atom_source.SetBusSendLevel(0, this.busSendlevelValue[0]);
for (int i = 1; i < maxBus; i++) {
/* Bus 1-7 is 0.0f by default, and addition is applied.(specifying offset) */
atom_source.SetBusSendLevelOffset(i, this.busSendlevelValue[i]);
}