xmos / lib_src

Sample rate conversion library
Other
16 stars 20 forks source link

i2s val hasn't set to 0 after optical cable had removed #132

Closed jian-yuan-cmd closed 2 months ago

jian-yuan-cmd commented 2 months ago

Some projects need the input audio stream from ADAT or SPDIF ,and sent to I2S after SRC. I found that the I2S data wasn't set to 0 after removing the optical cable. So I modified the asynchronous_fifo_consumer_get() function in lib_src: After copying the ASRC output data to the sending BUF of I2S, I fill 0 to buffer of ASRC output that data has used recently. After the above modification and verification, it was found that the I2S output data was setted to 0 after removing the optical cable. This results meet expectations, so I provide feedback hereby. The code is as follows.  void asynchronous_fifo_consumer_get(asynchronous_fifo_t state, int32_t samples, int32_t timestamp) { ... ... ... ... ... ...

ifdef XS2A

memcpy(samples, state->buffer + read_ptr * channel_count, channel_count * sizeof(int));
(void)copy_mask; // Remove unused var warning

else

register int32_t *ptr asm("r11") = state->buffer + read_ptr * channel_count;
asm("vldr %0[0]" :: "r" (ptr));
asm("vstrpv %0[0], %1" :: "r" (samples), "r" (copy_mask));

endif

// clear the asrc_buffer for clr outpul_Val after optical-cable had removed _jian 20240819 memset( state->buffer + read_ptr channel_count, 0, channel_count sizeof(int32_t) ); // added _jian 20240819

... ...
... ...

... ... }

ed-xmos commented 2 months ago

Thanks for your feedback. I noticed the same issue recently when reviewing the code. With FIFOs it's good to have a defined output in the case of underflow/overflow or at least some way to notify the user that the data is valid and the FIFO is behaving normally so the application code can decide what to output. In audio systems, a random DC value is not desirable when idle.

I'll discuss this internally and keep you posted.

ed-xmos commented 2 months ago

The FIFO can potentially be used for data other than PCM (eg. DSD). So setting to zero is not always a good idea. We think the best thing to do will be to return a flag from asynchronous_fifo_consumer_get() which the application can then best decide what to do with. In PCM cases, zeroing the samples makes sense of course.

@jian-yuan-cmd is this acceptable?

If so we can update the FIFO code and ASRC task in lib_src. We are making changes at the moment anyway.

jian-yuan-cmd commented 2 months ago

Yes, I think your idea is very good. I agree with your idea completely, thanks.

ed-xmos commented 2 months ago

https://github.com/xmos/lib_src/pull/135