How do I get information about current sample rate and bit d Topic is solved

If you have a simple question and just want an answer.
User avatar
sethu_jangala
XCore Expert
Posts: 589
Joined: Wed Feb 29, 2012 10:03 am

How do I get information about current sample rate and bit d

Post by sethu_jangala »



View Solution
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

Sample rate information can be obtained inside the function:

void AudioHwConfig(unsigned samFreq, unsigned mClk, chanend ?c_codec, unsigned dsdMode)

which can be found in audiohw.xc in the app_... directory. This function is called each time a new sample rate or stream type (DSD vs PCM) is selected. It's main function is to setup the hardware ready for the new stream, so does ADC/DAC initialisation etc.  Of course it can also set ports to, for example, display the sample rate status on LEDs. It's the main file for customisation of the SW reference design to your own hardware.
 
To get bit depth information depends on the version of the reference design. Versions 6.5.0 and before do not specifcally expose this information, however for tasks on the same tile, it is possible to use the:
GET_SHARED_GLOBAL(x, g)
macro found in xc_ptr.h to grab the following two globals:

g_curSubSlot_Out

g_curSubSlot_In

These globals contain the current slot size, which indicates either 2 bytes (16b audio UAC1/2), 3 bytes (24b audio UAC1) or 4 bytes (24b or 32b audio UAC2). Please note that, depending on configuration, not all sample depths will be available (default is 24b only for both UAC1 and UAC2).

If you are using ref design version 6.5.1 or later, getting bit depth is easier and can be done from a different tile (for example if I2S is on tile 1). It is passed as an unsigned int = [16, 24 or 32] down to audiohw.xc to the updated function:

void AudioHwConfig(unsigned samFreq, unsigned mClk, chanend ?c_codec, unsigned dsdMode, unsigned samRes_DAC, unsigned samRes_ADC)