CRI ADX  Last Updated: 2024-07-17 10:47 p
Spectrum Analyzer

Sample Directory

/CRIWARE/SDK/pc/samples/criatomex/spectrum_analyzer


Sample Description

This sample performs a frequency analysis of the sound passing through a bus.
Create a spectrum analyzer with the criAtomDspSpectra_Create function.
You can specify the number of bands for the analysis in the configuration structure (CriAtomDspSpectraConfig).
To acquire the bus sound, 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 demonstrates how to analyze sound on a bus with 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.