Question about Gigabit-Ethernet-AVB-endpoint-example

Sub forums for various specialist XMOS applications. e.g. USB audio, motor control and robotics.
User avatar
gerrykurz
XCore Addict
Posts: 204
Joined: Sun Jun 01, 2014 10:25 pm

Question about Gigabit-Ethernet-AVB-endpoint-example

Post by gerrykurz »

I am modifying the Gigabit-Ethernet-AVB-endpoint-example code for my application and I have a question about the buffer_manager_to_i2s application.

In the i2s.init case there is the following code:

Code: Select all

case i2s.init(i2s_config_t &?i2s_config, tdm_config_t &?tdm_config):
      // Receive the first free buffer and initial sample rate
      unsafe 
      {
        c_audio :> double_buffer;
        p_in_frame = &double_buffer->buffer[double_buffer->active_buffer];
        c_audio :> cur_sample_rate;
      }
      i2s_config.mode = I2S_MODE_I2S;
      // I2S has 32 bits per sample. *2 as 2 channels
      const unsigned num_bits = 64;
      case i2s.init(i2s_config_t &?i2s_config, tdm_config_t &?tdm_config):
      // Receive the first free buffer and initial sample rate
      unsafe 
      {
        c_audio :> double_buffer;
        p_in_frame = &double_buffer->buffer[double_buffer->active_buffer];
        c_audio :> cur_sample_rate;
      }
      i2s_config.mode = I2S_MODE_I2S;
      // I2S has 32 bits per sample. *2 as 2 channels
      const unsigned num_bits = 64;
      const unsigned mclk = MASTER_TO_WORDCLOCK_RATIO * 48000;
      // Calculate the MCLK to BCLK ratio using the current sample rate and bits per sample
      i2s_config.mclk_bclk_ratio = mclk / ( cur_sample_rate * num_bits);

      // Calculate the MCLK to BCLK ratio using the current sample rate and bits per sample
      i2s_config.mclk_bclk_ratio = mclk / ( cur_sample_rate * num_bits);
I have already modified the following line from

const unsigned mclk = 512 * 48000;

to

const unsigned mclk = MASTER_TO_WORDCLOCK_RATIO * 48000;

so that I am using a define for the mclk to lrclk ratio which in my application needs to be 256

So that is all fine and good but I am wondering about the sample rate.

I was going to use a define for that as well but it seems the sample rate is determined by the audio buffering code in the line:

c_audio :> cur_sample_rate;

So I have two questions:

How is the current sample rate actually determined and/or set in the audio buffering routine?

And shouldn't the constant 48000 be replaced by the cur_sample_rate variable?

Cheers, Gerry


User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Post by Andy »

The I2S operation has changed slightly from the previous release. The master clock frequency is now fixed and the MCLK-BCLK ratio modified to achieve different sample rates.

The current sample rate is set by the set_device_media_clock_rate() command on the AVB API interface. It is called during the application initialisation and may also be called on receipt of a 1722.1 SET_SAMPLING_RATE command from a Controller.
User avatar
gerrykurz
XCore Addict
Posts: 204
Joined: Sun Jun 01, 2014 10:25 pm

Post by gerrykurz »

What do you mean when you say the master clock frequency is fixed?

Are you talking about MCLK?

The I2S user guide clearly states that MCLK frequencies of 24.756 and 12.288 MHz are known working configurations.

Are you saying that this is not the case?
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Post by Andy »

Yes MCLK stands for master clock.

AVB v6 multiplied the master clock frequency by 2 (24.576 *2) to achieve a 48 to 96 kHz sample rate change. A 49.152 MHz master clock isn't supported by lib_i2s so the master clock is now fixed at a constant frequency and the master clock to bit clock ratio is modified to achieve the correct sample rate.

Although lib_i2s supports a 12.288 MHz master clock, lib_tsn's media clock server will only generate 24.576 or 22.579 MHz by default.
User avatar
gerrykurz
XCore Addict
Posts: 204
Joined: Sun Jun 01, 2014 10:25 pm

Post by gerrykurz »

Ok and in my application, I am using the CS2300 to generate the master clock and I have already changed the initialization routine to generate a 12.288 MHz clock which is what I need for my DSP, ADC's and DAC.

So as long as the I2S will work fine with this clock, then do you see any other complications?