CRI ADX  Last Updated: 2025-05-07 13:34 p
Spectrum Analyzer

Sample directory

/cri/pc/samples/criatomex/spectrum_analyzer

Data used in the sample

/cri/common/smpdata/criatomex/
  • SampleProject.acf
  • AtomCueSheet.acb
  • AtomCueSheet.awb

Sample description

This is a sample that performs frequency analysis of the audio flowing through the bus.
The spectrum analyzer is created with the criAtomDspSpectra_Create function.
The number of analysis bands can be specified using the configuration structure ( CriAtomDspSpectraConfig ).
To obtain the audio of the bus, register a callback function with criAtomExAsr_SetBusFilterCallback .
This callback function is called from the audio thread every time audio processing is performed.
The following code shows how to analyze the audio from the bus using a spectrum analyzer.
void main()
{
/* Create a spectrum analyzer */
app_obj->dsp_hn = criAtomDspSpectra_Create(NULL, NULL, 0);
/* Register a bus filter callback */
/* Note: In the following example, analysis is performed on signals passing through bus 7. */
criAtomExAsr_SetBusFilterCallback(7, app_filter_callback, NULL, app_obj);
for (;;) {
/* Get spectral information */
spectra_ptr = criAtomDspSpectra_GetLevels(app_obj->dsp_hn);
for (i = 0; i < NUM_BANDS; i++) {
/* Convert the value to decibels */
decibel = 20.0f * log10f(spectra_ptr[i]);
/* Select the display range */
/* In the following example, values greater than -96 dB are displayed */
graph[i] = (CriSint32)(decibel + 96.0f);
}
Sleep(10);
}
}
/* Filter callback */
static void app_filter_callback(void *obj, CriAtomPcmFormat format,
CriSint32 num_channels, CriSint32 num_samples, void *data[])
{
AppObj *app_obj = (AppObj*)obj;
/* Do nothing when not playing sound */
if ((num_channels <= 0) || (num_samples <= 0)) {
criAtomDspSpectra_Reset(app_obj->dsp_hn);
return;
}
/* Spectral analysis */
criAtomDspSpectra_Process(app_obj->dsp_hn, num_channels, num_samples, (CriFloat32 **)data);
}
void criAtomExAsr_SetBusFilterCallback(CriSint32 bus_no, CriAtomExAsrBusFilterCbFunc pre_func, CriAtomExAsrBusFilterCbFunc post_func, void *obj)
void criAtomDspSpectra_Reset(CriAtomDspSpectraHn spectra)
Reset spectrum analyzer.
void criAtomDspSpectra_Process(CriAtomDspSpectraHn spectra, CriUint32 num_channels, CriUint32 num_samples, CriFloat32 *pcm[])
Spectrum analysis.
CriAtomDspSpectraHn criAtomDspSpectra_Create(const CriAtomDspSpectraConfig *config, void *work, CriSint32 work_size)
Spectrum analyzer creation.
const CriFloat32 * criAtomDspSpectra_GetLevels(CriAtomDspSpectraHn spectra)
Acquire spectral analysis results.
enum CriAtomPcmFormatTag CriAtomPcmFormat
PCM format.