2008-08-20 14:36:24     ALSA problems in 2008R1-RC8

Document created by Aaronwu Employee on Aug 7, 2013
Version 1Show Document
  • View in full screen mode

2008-08-20 14:36:24     ALSA problems in 2008R1-RC8

Jason Hennigar (CANADA)

Message: 60775   


I am Designing a custom application to receive and transmit local and streaming audio using Speex, ALSA and the 1836 codec. During testing I encountered some problems with ALSA.


I am using the uClinux-dist-2008R1-RC8 configured for 5.1 surround sound with OSS disabled. Testing so far has been on a Blackfin 537 stamp board with the AD1836 daughter board on Sport 0.


Both the ALSA capture and playback are configured as follows:



Sample Rate: 8000


The only configuration difference between the capture and playback is the number of channels that are opened:

# capture channels: 4   (the driver, see attached, has been modified slightly to give access to 4 channels)

# playback channels: 6


The first problem that I encountered was when I tried setting the ALSA capture and playback period size to 160 samples in order to match what Speex requires. This (snd_pcm_hw_params_set_period_size) caused an Unaligned Data Access error. Because of this problem I'm having to use the default period sizes. The default capture period is 42 samples and the playback is 28 samples.


This leads to the second problem that I have encountered. The period sizes are not equivalent and are smaller then what Speex requires so I have added a accumulate/deaccumulate buffers. To receive and transmit the audio I am using the snd_pcm_readn and snd_pcm_writen functions. This gets past the configuration problems but now I am encountering a Tx under run that goes on forever. If the capture/playback are running at the same sample rate (8000/sec) I would expect a few under runs at the start which would clear up after a short while. When I comment out the readn and send garbage audio through the threads the Tx underrun does not occur. Using Top and commenting/uncommentting the readn/writen calls I saw that each one consumes about 22% CPU processing at their peak usage. The threads that I have written uses at most 3% CPU processing each at their peak.


As part of the testing I switched the configuration to Stereo and tried setting the period size to 160. In this case alsa allowed me to switch the period but crashed with an Unaligned Data access after the 5th snd_pcm_readn call. The default period size with this configuation was 85 frames for both the capture and playback.


Similar but not exact problems may have already been posted in the following threads:

mediastream, alsa, ad1981 and mmap



Re: Latency in Linphone and ALSA/SPORT/AD1981







2008-08-20 21:57:45     Re: ALSA problems in 2008R1-RC8


Message: 60780   




It would be easier to fix the issues if you had a reproducable test case that you could share. - since we have fixed the other issues that you pointed to...








2008-08-21 19:31:10     Re: ALSA problems in 2008R1-RC8

Jason Hennigar (CANADA)

Message: 60861   


Hi Robin,


As you suggested I moved to the newer 2008R1.5-RC3 build and have found that it allows the ALSA period size (snd_pcm_hw_params_set_period_size) to be changed for both Rx and Tx when configured for Stereo. However it only allows the Rx period size to be changed when configured for 5.1 surround. These two tests used the unmodified 1836 driver code and involved opening 2 Rx and 6 Tx channels.


Transmit underruns do not occur with the newer build either however the snd_pcm_writen appears to run a bit slow as samples build up and overflow in my applications queue and the audio is unintelligible. This occurs when using 2 Rx and either 2 or 6 Tx channels in stereo mode with their period size set to 160. It also occurs with 2Rx and 6 Tx channels in 5.1 surround with the Rx period size set to 160 and the Tx using the default.


I will give the most recent nightly build a try this evening to see if any of these problems have been resolved.








2008-08-25 14:27:12     Re: ALSA problems in 2008R1-RC8

Jason Hennigar (CANADA)

Message: 61039   


The playback period size is adjustable when using  5.1 surround, the same ALSA settings and uClinux SVN revision 7028. However the playback audio code still appears to be running slow when using snd_pcm_writen. The audio quality isn't good and the playback thread's queue overflows.


I'm going to try direct DMA acceeson the playback side to see if that helps.








2008-08-26 00:01:05     Re: ALSA problems in 2008R1-RC8

Sonic Zhang (CHINA)

Message: 61050   


Could you attach your test source code and 5.1 sound file here? Or submit a bug in our bug tracker with the attachments? Then, we can replicate your problem.






2008-08-26 20:55:07     Re: ALSA problems in 2008R1-RC8

Jason Hennigar (CANADA)

Message: 61138   


A test application is attached  that you will be able to use to reproduce the problems that I have been encountering. No audio file is required, you just need to play music or something into the ADC2 (Mic input) and it will be set out DAC1. Silence is sent to the other outputs when configured for 5.1 surround. If you want to test in stereo mode just set NUM_TX_CHNLS to 2 and I beleive it will work the same.


The problems have been highlighted with a FIXME in the code.


snd_pcm_writen seems to run a bit slow as audio buffers overflow on the queue between the Rx and Tx threads.


snd_pcm_mmap_begin returns with a bad file descriptor and areas is NULL.


Of less importance are snd_pcm_bytes_to_frames and snd_pcm_frames_to_bytes returning incorrect values.


Note that Posix queues have to be enabled. I would have included the configuration files but I wasn't 100% certain that I had the correct ones.






2008-08-27 15:22:17     Re: ALSA problems in 2008R1-RC8

Jason Hennigar (CANADA)

Message: 61186   


I submitted a bug report on these problems to track it in a more appropriate manor.







2008-08-28 22:25:48     Re: ALSA problems in 2008R1-RC8


Message: 61295   


If anyone wants a multi-channel audio file - try unzipping :  http://download.microsoft.com/download/6/b/1/6b17045c-6ce8-4dc4-a3b5-2717b8711fc8/8Channel.exe


It plays on my desktop with mplayer.






2008-09-03 19:04:05     Re: ALSA problems in 2008R1-RC8

Jason Hennigar (CANADA)

Message: 61594   


Hi Guys,


Setting the ALSA playback period size (snd_pcm_hw_params_set_period_size) when 5.1 is configured is broken again. I beleive that an update submitted between Aug. 29 and this afternoon caused the problem. When configured for stereo setting the playback period size works.


I've also noticed that when using amixer it is not possible to unmute the Mic (amixer sset Mic unmute) with the latest svn version (7044) of uclinux. However it is possible too mute and unmute the Master (amixer sset Master unmute).








2008-09-04 04:25:29     Re: ALSA problems in 2008R1-RC8

Cliff Cai (CHINA)

Message: 61618   


Hi Jason,


I think we'd better discuss this problem in bug tracker since you've reported it.


Best Regards