CRI ADX  Last Updated: 2024-07-17 10:47 p
About CriAtomDbas
CriAtomDbas is a module for the management of streaming buffers.
When streaming playback is performed on CRI Atom, all required streaming buffers are managed by a D-BAS.

Basic Instructions for D-BAS Creation

The following sample code creates a D-BAS with the default settings.
CriAtomDbasConfig dbas_config;
CriSint32 dbas_wrok_size;
void* dbas_work;
CriAtomDbasId dbas_id;
dbas_wrok_size = criAtomDbas_CalculateWorkSize(&dbas_config);
dbas_work = malloc((size_t)dbas_wrok_size);
dbas_id = criAtomDbas_Create(&dbas_config, dbas_work, dbas_wrok_size);
CriSint32 CriAtomDbasId
Atom D-BAS ID.
Definition: cri_le_atom.h:2513
CriAtomDbasId criAtomDbas_Create(const CriAtomDbasConfig *config, void *work, CriSint32 work_size)
Create D-BAS.
#define criAtomDbas_SetDefaultConfig(p_config)
Set default parameters for CriAtomDbasConfig.
Definition: cri_le_atom.h:427
CriSint32 criAtomDbas_CalculateWorkSize(const CriAtomDbasConfig *config)
Calculate work area size for creating D-BAS.
D-BAS creation parameter structure.
Definition: cri_le_atom.h:2527
If the D-BAS creation is successful, the criAtomDbas_Create function returns a valid D-BAS ID. If the D-BAS creation fails, the criAtomDbas_Create function returns CRIATOMDBAS_ILLEGAL_ID.

D-BAS Creation Parameters

The size of the streaming buffers managed by the D-BAS depends on the D-BAS creation parameters. The main creation parameters are the maximum number of streams CriAtomDbasConfig::max_streams and the maximum bitrate CriAtomDbasConfig::max_bps. Which parameter affects the streaming buffer by how much depends on the combination of parameters used.
As a guideline, the streaming buffer size is directly proportional to ::CriAtomDbasConfigmax_streams, and increases exponentially the larger the ::CriAtomDbasConfigmax_bps parameter is.
If a value greater than the reading capabilities of the target device is specified for max_bps, the creation of the D-BAS will fail. This is because when data with a bitrate greater than the reading capabilities of the target device is played, the streaming playback will always stutter.
The following is an example of settings to perform the streaming playback of four items: two sets of 48 kHz stereo ADX data and two sets of high-quality 48 kHz stereo HCA data.
CriSint32 adx_bps;
CriSint32 hca_bps;
CriAtomDbasConfig dbas_config;
CriSint32 dbas_wrok_size;
void* dbas_work;
CriAtomDbasId dbas_id;
/* Calculate the bitrate of the 48 kHz stereo ADX data. */
adx_bps = criAtom_CalculateAdxBitrate(2, 48000);
/* Calculate the bitrate of the high-quality 48 kHz stereo HCA data. */
/* Total of four streams */
dbas_config.max_streams = 4;
/* Set the total bitrate for two 48 kHz stereo ADX data and two high-quality 48 kHz stereo HCA data */
dbas_config.max_bps = adx_bps * 2 + hca_bps * 2;
dbas_wrok_size = criAtomDbas_CalculateWorkSize(&dbas_config);
dbas_work = malloc((size_t)dbas_wrok_size);
dbas_id = criAtomDbas_Create(&dbas_config, dbas_work, dbas_wrok_size);
CriSint32 criAtom_CalculateAdxBitrate(CriSint32 num_channels, CriSint32 sampling_rate)
Calculate bit rate of ADX data.
CriSint32 criAtom_CalculateHcaBitrate(CriSint32 num_channels, CriSint32 sampling_rate, CriAtomEncodeQuality quality)
Calculate bit rate of HCA data.
@ CRIATOM_ENCODE_QUALITY_HIGH
Definition: cri_le_atom.h:894
CriSint32 max_bps
Maximum bit rate.
Definition: cri_le_atom.h:2558
CriSint32 max_streams
Maximum number of streaming.
Definition: cri_le_atom.h:2545

Adjusting the D-BAS Creation Parameters

In many cases, the playback bitrate and the number of streams will vary depending on the scene, such as a single high quality 5.1-channel 48 kHz HCA data stream in one scene and eight monaural 24 kHz high-compression HCA data streams in another scene.
However, regardless of any status changes, D-BAS always manages the streaming buffer it is given when the D-BAS was created. In some scenes, a smaller streaming buffer may be sufficient, but in other scenes, the streaming buffer may be too small.
To allocate a sufficient streaming buffer for the D-BAS for any scene, the application must either recreate the D-BAS for each scene or create the D-BAS with a streaming buffer that can handle any scene.

Recreating the D-BAS for Each Scene

Recreating the D-BAS for each scene is simple. All you need to do is call the criAtomDbas_Destroy function when changing scenes, destroy the existing D-BAS, and then use the criAtomDbas_Create function to create a new D-BAS.
CriSint32 adx_bps;
CriSint32 hca_bps;
CriAtomDbasConfig dbas_config;
CriSint32 dbas_wrok_size;
void* dbas_work;
CriAtomDbasId dbas_id;
/* Calculate the bitrate of the 48 kHz stereo ADX data. */
adx_bps = criAtom_CalculateAdxBitrate(2, 48000);
/* Calculate the bitrate of the high-quality 48 kHz stereo HCA data. */
/* Total of four streams */
dbas_config.max_streams = 4;
/* Set the total bitrate for two 48 kHz stereo ADX data and two high-quality 48 kHz stereo HCA data */
dbas_config.max_bps = adx_bps * 2 + hca_bps * 2;
dbas_wrok_size = criAtomDbas_CalculateWorkSize(&dbas_config);
dbas_work = malloc((size_t)dbas_wrok_size);
dbas_id = criAtomDbas_Create(&dbas_config, dbas_work, dbas_wrok_size);
:
:
:
/* Change scenes */
:
:
:
/* Destroy existing D-BAS */
/* Caution: If there are any sounds currently in streaming playback, this will be blocked while waiting for them to stop. */
/* Change the parameters and recreate. */
/* Change the total number of streams to two */
dbas_config.max_streams = 2;
/* All streams will be high-quality 48 kHz stereo HCA data */
dbas_config.max_bps = hca_bps * 2;
dbas_wrok_size = criAtomDbas_CalculateWorkSize(&dbas_config);
dbas_work = malloc((size_t)dbas_wrok_size);
dbas_id = criAtomDbas_Create(&dbas_config, dbas_work, dbas_wrok_size);
void criAtomDbas_Destroy(CriAtomDbasId atom_dbas_id)
Destroy D-BAS.
This method minimizes the amount of memory used in each scene, but because the D-BAS must be destroyed before recreating it, it is impossible to have any streaming music during a scene change for example.

Creating a D-BAS for All Scenes

The simplest method to create a D-BAS that works for all scenes is to set the worst-case values for the number of streams and for the playback bitrate in your application.
For example, if in scene A there are 16 streams with a playback bitrate of 1 mbps, and in scene B there are 4 streams at 2 mbps, set the largest of these values when creating the D-BAS.
CriAtomDbasConfig dbas_config;
CriSint32 dbas_wrok_size;
void* dbas_work;
CriAtomDbasId dbas_id;
/* Set the number of streams used in scene A */
dbas_config.max_streams = 16;
/* Set the playback bitrate used in scene B */
dbas_config.max_bps = 2 * 1000 * 1000; /* 2 mbps */
dbas_wrok_size = criAtomDbas_CalculateWorkSize(&dbas_config);
dbas_work = malloc((size_t)dbas_wrok_size);
dbas_id = criAtomDbas_Create(&dbas_config, dbas_work, dbas_wrok_size);
::CrsiAtomDbasConfig::max_streams is also the upper limit for the number of streams using the D-BAS. Therefore, if you want to use the same D-BAS for all scenes, set the maximum number of streams across all scenes to CriAtomDbasConfig::max_streams.

Determining the Parameters to Set for the D-BAS Afterwards

You cannot set the appropriate D-BAS creation parameters until you know what type of streaming playback will be performed throughout your entire application. However, if you need to set the playback bitrate in addition to the number of streams, this becomes difficult to determine in advance.
To solve this problem, you can create the D-BAS with larger than needed parameters, then use the criAtom_GetStreamingInfo function to obtain the actual number of streams and playback bitrate and then determine the correct D-BAS creation parameters to use.
The criAtom_GetStreamingInfo function acquires the number of streams and the playback bitrate at the time when the function is called. You can keep a log of the number of streams and the playback bitrate at regular intervals while your application is running and then apply those logged values to the D-BAS to allocate the exact streaming buffers needed without wasting any memory.
CriAtomStreamingInfo streaming_info;
CriBool is_succeeded;
is_succeeded = criAtom_GetStreamingInfo(streaming_info);
if (is_succeeded == CRI_TRUE) {
/* Remember the largest value */
if (actual_max_streams < streaming_info.num_streaming) {
actual_max_streams = streaming_info.num_streaming;
}
/* Remember the largest value */
if (actual_max_bps < streaming_info.total_bps) {
actual_max_bps = streaming_info.total_bps;
}
}
:
:
:
/* Output to console when the application is terminated */
printf("Actual Max Streams:%d\n", actual_max_streams);
printf("Actual Max Bitrate:%d\n", actual_max_bps);
CriBool criAtom_GetStreamingInfo(CriAtomStreamingInfo *streaming_info)
Acquire streaming info.
Streaming information.
Definition: cri_le_atom.h:976
CriFloat32 total_bps
Current total streaming bit rate.
Definition: cri_le_atom.h:992
CriSint32 num_streaming
Current number of streaming sounds.
Definition: cri_le_atom.h:983

Relationship With Sofdec2 (CRI Mana)

With multi-streaming playback, movie data may be played in addition to audio data.
In CRIWARE, audio data is played by ADX, while movie data playback is handled by Sofdec2.
When performing multi-streaming of both audio data and movie data, the overall streaming rate management does not distinguish between audio and movie data. Therefore, when used together with Sofdec2, you must also add the number of movie streams and the movie playback bitrate when specifying values for CriAtomDbasConfig::max_streams and CriAtomDbasConfig::max_bps.
However, D-BAS only manages the streaming buffer used by ADX. Sofdec2 has its own streaming buffer, so the D-BAS streaming buffer is not used when playing movies.
In order to allocate a D-BAS streaming buffer for movie playback without waste, set the number of movie streams and the movie playback bitrate to ::max_mana_streams and ::max_mana_bps.
The following is an example of the D-BAS settings for a scene that plays four audio clips and one movie simultaneously.
CriAtomDbasConfig dbas_config;
CriSint32 dbas_wrok_size;
void* dbas_work;
CriAtomDbasId dbas_id;
const CriSint32 atom_streams = 4; /* Four audio streams */
const CriSint32 atom_bps = 320 * 1000; /* 320 kbps */
const CriSint32 mana_streams = 1; /* One movie stream */
const CriSint32 mana_bps = 15 * 1000 * 1000; /* 15 mbps */
/* Add the amount for movie playback */
dbas_config.max_streams = atom_streams + mana_streams;
dbas_config.max_bps = atom_bps + mana_bps;
/* Tell D-BAS the number of streams and bitrate for movie playback */
dbas_config.max_mana_streams = mana_streams;
dbas_config.max_mana_bps = mana_bps;
dbas_wrok_size = criAtomDbas_CalculateWorkSize(&dbas_config);
dbas_work = malloc((size_t)dbas_wrok_size);
dbas_id = criAtomDbas_Create(&dbas_config, dbas_work, dbas_wrok_size);
CriSint32 max_mana_streams
Maximum number of streams played back by CRI Mana.
Definition: cri_le_atom.h:2567
CriSint32 max_mana_bps
Maximum bit rate for CRI Mana playback.
Definition: cri_le_atom.h:2576