Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure DMA buffer is zeroed in 32 bits mode. (AUD-594) #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hallgrim
Copy link

@hallgrim hallgrim commented Feb 5, 2019

DMA buffers for I2S must be set to zero to prevent noise after playback stops. This works well in 16 bits mode. In 32 bits mode leaves some samples in the buffer and these samples repeat.

The existing code created a buffer of four times the number of samples in the DMA buffer. I think this is a hardcoded assumption of 16bits stereo (4 bytes per sample).
i2s->config.i2s_config.dma_buf_len * 4

The number of bytes in the DMA buffer cannot be reliably calculated. The logic is non-trivial (max 4096, etc.). It turns out that the I2S library already have a function to zero the buffer i2s_zero_dma_buffer. When I call i2s_zero_dma_buffer(i2s->config.i2s_port); instead of i2s_write(i2s->config.i2s_port, (char *)buf, i2s->config.i2s_config.dma_buf_len * 4, &bytes_written, portMAX_DELAY); I get no noise, neither in 16 or 32 bits mode.

There is a test on i2s->config.i2s_config.mode & I2S_MODE_DAC_BUILT_IN that sets the buffer to 0x80 instead of 0x00. I left this branch as it was with i2s_write instead of i2s_zero_dma_buffer, but I have not been able to test that there are no regression with the I2S_MODE_DAC_BUILT_IN.

@CLAassistant
Copy link

CLAassistant commented Feb 5, 2019

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@projectgus projectgus changed the title Make sure DMA buffer is zeroed in 32 bits mode. Make sure DMA buffer is zeroed in 32 bits mode. (AUD-594) Jul 23, 2019
@Alvin1Zhang
Copy link
Collaborator

@hallgrim Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants