diff --git a/lib_xua/api/xua_conf_default.h b/lib_xua/api/xua_conf_default.h index ee3bc85f..964c6eb0 100644 --- a/lib_xua/api/xua_conf_default.h +++ b/lib_xua/api/xua_conf_default.h @@ -197,6 +197,10 @@ #define I2S_DOWNSAMPLE_CHANS_IN I2S_CHANS_ADC #endif +#ifndef XUA_I2S_DUMMY_SAMPS +#define XUA_I2S_DUMMY_SAMPS (1) +#endif + /** * @brief Number of bits per channel for I2S/TDM. Supported values: 16/32-bit. * diff --git a/lib_xua/src/core/audiohub/xua_audiohub.xc b/lib_xua/src/core/audiohub/xua_audiohub.xc index e50cee24..0dcaa83f 100755 --- a/lib_xua/src/core/audiohub/xua_audiohub.xc +++ b/lib_xua/src/core/audiohub/xua_audiohub.xc @@ -80,6 +80,14 @@ unsigned dsdMode = DSD_MODE_OFF; #endif #include "xua_audiohub_st.h" +static inline void PortOutput(buffered out port:32 p, int bits, int value) +{ + if(bits == 32) + p <: value; + else + partout(p, bits, value); +} + static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:32 p_lrclk) { #if CODEC_MASTER @@ -286,6 +294,19 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out else #endif { + +#if XUA_I2S_DUMMY_SAMPS + if(frameCount == 0) + { + for(int j = 0; j < XUA_I2S_DUMMY_SAMPS; j++) + for(int i = 0; i < I2S_WIRES_DAC; i++) + { + PortOutput(p_i2s_dac[i], XUA_I2S_N_BITS, 0); + } + } +#endif + + #if (I2S_CHANS_ADC != 0) #if (AUD_TO_USB_RATIO > 1) if (0 == audioToUsbRatioCounter) @@ -478,6 +499,25 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out } #endif +#if XUA_I2S_DUMMY_SAMPS + if(frameCount == 1) + { + int dummyBits; + for(int j = 0; j < XUA_I2S_DUMMY_SAMPS; j++) + { + for(int i = 0; i < I2S_WIRES_ADC; i++) + { + asm volatile("in %0, res[%1]" : "=r"(dummyBits) : "r"(p_i2s_adc[i])); + if(XUA_I2S_N_BITS) + set_port_shift_count(p_i2s_adc[i], XUA_I2S_N_BITS); + } + asm volatile("in %0, res[%1]" : "=r"(dummyBits) : "r"(p_lrclk)); + if(XUA_I2S_N_BITS) + set_port_shift_count(p_lrclk, XUA_I2S_N_BITS); + } + } +#endif + #if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0) syncError += HandleSampleClock(frameCount, p_lrclk); #endif diff --git a/tests/test_i2s_loopback/simulation.xc b/tests/test_i2s_loopback/simulation.xc index 9aafcf00..a974fb6a 100644 --- a/tests/test_i2s_loopback/simulation.xc +++ b/tests/test_i2s_loopback/simulation.xc @@ -1,6 +1,7 @@ // Copyright 2016-2023 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifdef SIMULATION +#include "xua.h" #include #include @@ -45,7 +46,7 @@ void slave_mode_clk_setup(const unsigned samFreq, const unsigned chans_per_frame const unsigned mclk_freq = 24576000; const unsigned mclk_bclk_ratio = mclk_freq / (chans_per_frame * samFreq * data_bits); - const unsigned bclk_lrclk_ratio = (chans_per_frame * data_bits); // 48.828Hz LRCLK + const unsigned bclk_lrclk_ratio = (chans_per_frame * data_bits + (data_bits * XUA_I2S_DUMMY_SAMPS)); // 48.828Hz LRCLK //bclk configure_clock_src_divide(clk_audio_bclk_gen, p_mclk_gen, mclk_bclk_ratio/2);