I am a new player on XMOS and recently I am so confused about some of the source code of AN00201,which is a demo running on the startkit ,looping an audio input back to an audio output with a biquad filter and a modulating gain applied to the signal. They belong to the i2s_handler funtion:

1.what does the "channel exchange"mean?
2.why "2" inside the "for" loop? Is it due to the "biquad" filter or there are 2 channels in total? I prefer the former reason but I want to ensure it.
3.and last , I have to admit that I don't really understand what is the "for" loop inside the "if" condition is doing exactly.
Thank you a lot! and the following is entire code of the i2s_handler function:
Code: Select all
[[distributable]]
void i2s_handler(server i2s_callback_if i2s,
client i2c_master_if i2c,
client output_gpio_if clock_select,
client output_gpio_if codec_reset,
streaming chanend c_dsp)
{
int32_t in_samps[2] = {0};
int32_t out_samps[2] = {0};
while (1) {
select {
case i2s.init(i2s_config_t &?i2s_config, tdm_config_t &?tdm_config):
/* Set CODEC in reset */
codec_reset.output(0);
/* Set master clock select appropriately */
if ((SAMPLE_FREQUENCY % 22050) == 0) {
clock_select.output(0);
}else {
clock_select.output(1);
}
/* Hold in reset for 2ms while waiting for MCLK to stabilise */
delay_milliseconds(2);
/* CODEC out of reset */
codec_reset.output(1);
cs4270_configure(i2c, CODEC_I2C_DEVICE_ADDR,
SAMPLE_FREQUENCY, MASTER_CLOCK_FREQUENCY,
CODEC_IS_I2S_SLAVE);
/* Configure the I2S bus */
i2s_config.mode = I2S_MODE_I2S;
i2s_config.mclk_bclk_ratio = (MASTER_CLOCK_FREQUENCY/SAMPLE_FREQUENCY)/64;
break;
case i2s.restart_check() -> i2s_restart_t restart:
// This application never restarts the I2S bus
restart = I2S_NO_RESTART;
break;
case i2s.receive(size_t index, int32_t sample):
if (index == 0) {
for (size_t i = 0; i < 2; i++) {
c_dsp <: in_samps[i];
c_dsp :> out_samps[i];
}
}
in_samps[index] = sample;
break;
case i2s.send(size_t index) -> int32_t sample:
sample = out_samps[index];
break; // end of select
}
}
};