[alsa-devel] Need Help: Repeated Jackhammer noise after several hours of play and heavy cpu usage in snd_pcm_dmix_sync_area
Gabriel M. Beddingfield
gabrbedd at gmail.com
Wed Feb 19 16:16:51 CET 2014
On 02/19/2014 04:07 AM, Adarsh wrote:
> We are facing a issue where if gdb is attached to the our long running
> sound process and continued,
> jackhammer sound is played over and over again abusing the speakers.
> Process details:
> 1. We are using RW_INTERLEAVED access as described in write_loop method in
> /test/pcm.c and opening 'default' device.
> 2. However to disable the underruns, the
> snd_pcm_sw_params_set_stop_threshold is set to 0x7fffffff which is greater
> than boundary
This doesn't prevent underruns. Underruns happen when the software
doesn't keep up with the hardware.
What this disables is your ability to detect and recover from an
underrun. So, what you're experiencing is expected behavior. If you
never reach the stop threshold but userspace fails to write new audio to
the buffer. Since you instructed the driver/hardware to *not* stop in
the event of an underrun, it repeatedly cycles on the same, stale
buffer. This gives you the "jackhammer" sound.
> 3.Period size is 1024 and buffer size is 2048. We try to write period_size
> no of frames using snd_pcm_writei.
> (I am attaching a sample program which shows this behaviour.)
> Steps to Reproduce:
> 1. Left process running for over 12 hours.
> 2. gdb is attached to the process and continued inside gdb.
When gdb attached to the process, you certainly stopped writing new
audio to the buffer because your process got a SIGSTOP... causing all
threads to freeze.
> 3. At this point, the thread went into a tight loop taking >100% cpu and
> repeatedly playing same sound. It did not recover for a long time.
...I'm not sure what you're seeing here. Possibly dmix is trying to
make the best of a bad situation.
> Is it that setting of stop threshold to 0x7fffffff is triggering this and
> attaching gdb is making the buffer pointers misbehave?
> If so, what can be done if we do not want PCM to stop? I have tried by
> setting silence threshold and silence size to let alsa
> play silence by itself but still observed the issue.
It depends on what you're trying to solve by attaching with gdb.
GDB is good for a lot of things, but solving problems in real-time
systems (like audio) has never been one of them. So, chances are that
gdb is the wrong tool for what you're trying to do.
More information about the Alsa-devel