Other Parts Discussed in Thread: AM625, SK-AM62B-P1
Tool/software:
I am running into an audio issue with our custom hardware, using the AM625 (specifically, the VAR-SOM-AM62 from Variscite). I believe the issue to be at the kernel/driver/chip level, nothing specific to their SOM.
I cannot get the problem to show up on the Variscite EVK. So I believe the issue only shows up due to some specific configuration/combination that exists in our custom image/hardware. Again, I don't think there is a problem with the hardware, only that the hardware reveals some lower level bug/issue.
I have spent several weeks observing this issue and attempting to narrow down the problem.
The Problem
The problem shows up as glitchy audio. It only shows up after playback has been ongoing for some time (after about ~45 minutes). The glitch shows up as 1 of 2 forms:
- Per ALSA period, a few samples are correct and the rest are zeros
- Per ALSA period, a few samples are zero and the rest are correct
So if the ALSA period is 256 samples, the glitch can be seen every 256 samples.
Testing Methodology
Either gstreamer or speaker-test is used to generate a sine wave:
gst-launch-1.0 audiotestsrc freq=440 ! alsasink device=playback1 --verbose
speaker-test -c 2 -r 46512 -t sine -f 440 -D playback1
The audio ultimately hits a DAC, so it is easy enough to observe the result on an o-scope. There are actually multiple DACs, using different formats (one is I2S, the other is TDM). The problem occurs with either. To verify the issue is not occurring somewhere further down the line, rather then coming out of the AM62x, it was easy enough to confirm the MCASP data line also is glitchy, matching what is ultimately seen on the DAC outputs.
A DSP is routing audio between all of these. If the waveform is generated within the DSP, there are no glitches. Just another confirmation that the glitchy audio only happens when originated from the AM62x.
No errors are printed to the console, either from gstreamer or linux (dmesg). There are no reported xruns. Stopping the pipeline and starting it again fixes it immediately.
Unique things about the hardware
The MCASPs (MCASP0 and MCASP2) are connected to an external DSP, rather than traditional codecs. As such, the audio devices are configured as `simple-audio-card` with a patch for allowing a codec of type `snd-soc-dummy`. The ALSA `asound.conf` then has each output/input defined correctly to use the correct samplerate, etc. which is all handled on the DSP side. So, the DSP is the master, providing the BCK and FS clocks. The sample rates are not typical (46512Hz and 186048Hz), but is correctly defined everywhere in the chain.
MCASP0 is TDM16, and MCASP2 is I2S. The problem is exhibited on either one.
As another test, the clocks have been changed to typical audio clocks (48kHz). The problem still appeared.
I have built up a minimal image which starts from a known image (`var-thin-image`), and only adds what is absolutely necessary to test:
- Patch for `snd-soc-dummy`
- device tree changes for the target hardware
- add some gstreamer packages not included by default (audiotstsrc, alsasink, etc.)
- a minimal `asound.conf` to test a single stereo output of the TDM16 on MCASP0
Then I manually initialize the DAC and DSP (none of my application code is ever actually run). From there, it is just a matter of running that simple gstreamer pipeline and waiting until the output has glitches.
Additionally, I added CONFIG_DYNAMIC_DEBUG, to see if anything useful would be printed out during playback. Nothing useful ended up being printed out after enabling print statements for basically anything related to audio (k3-udma*, sound/core/*, sound/soc/*, etc.)
An additional discovery is that it seems that the glitches do not occur if the sound card is accessed directly.
For the TDM outputs, using dshare or dmix, the glitches show up. They do not seem to occur if accessed directly (e.g. plug to hw:0,0).
Here is scope capture of the audio when it is glitching:
You can see the period between the glitches matches exactly the ALSA period of 256 samples (5.33ms @ 48kHz).
Here is the corresponding MCASP data line
This particular issue has been stalling progress for a while now, so appreciate any insights on this.