At Fri, 20 Oct 2006 16:12:48 -0400, Lee Revell wrote: > > On Fri, 2006-10-20 at 14:55 +0200, Takashi Iwai wrote: > > > Anyway, I still can't make it work with the PCM indirect API. The best > > > I've managed to produce is choppy sound that seems to underrun every > > > period. Do you see what could be wrong with my code? > > > > You should give a fixed period size (0x2000), i.e. set both > > period_bytes_min and period_bytes_max = 0x4000 (and periods_min = 2) in > > snd_pcm_hardware. In this way, the ack is called at least at each > > time 0x2000 words are processed. > > > > I am doing this already. > > > BTW, what does dream_get_mpu_data_poll_status_byte() do? > > Does it check whether you can another push 0x2000 words? > > > > Yes, exactly. > > > If so, you should check this before claling > > snd_pcm_indirect_playback_transfer() in dream_work_transfer(). > > > > OK, I've made this change. > > > > > Possibly, the block transfer patch might be not needed if you add this > > check. > > > > OK, I feel I am getting closer. But it seems that only the first period > is played. Upon further inspection it looks like > snd_pcm_indirect_playback_transfer only causes dream_playback_copy to be > invoked the first time: > > ~ # aplay /usr/share/sounds/test/phone.wav > Playing WAVE '/usr/share/sounds/test/phone.wav': Signed 16 bit Little > Endian, Rate 44100 Hz, Stereo > hw_params: stereo yes, format 16bit, rate 44100 > dream_pcm_open: channel 0x0 eight_bit 0x0 stereo 0x1 rate 0xac44 > dream_playback_ack > dream_playback_copy: not running! > dream_pcm_start: channel is 0 > dream_work_transfer: polling status byte returned 0 > calling snd_pcm_indirect_playback_transfer > in dream_playback_copy: 0x4000 bytes DMA area 0xcdfb0000 sw_data 0x0 > dream_playback_ack > dream_playback_ack > dream_work_transfer: polling status byte returned 0 > calling snd_pcm_indirect_playback_transfer > dream_playback_ack > playback size is 0x1005 > dream_playback_ack > playback size is 0x100a > dream_playback_ack > playback size is 0x100f > dream_playback_ack > playback size is 0x1015 > dream_playback_ack > dream_playback_ack The problem looks like the calculation of dream->playback_hw_ptr passed to snd_pcm_indirect_playback_pointer(). This must be a _byte_ offset in the "hardware" ring buffer. That is, it's between 0 and (rec->hw_buffer_size - 1). You set hw_buffer_size = 0x4000, but calculate playback_hw_ptr as [0, runtime->buffer_size] and in frames. In such a case, you can set up in the following way: hw_buffer_size = sw_buffer_size = snd_pcm_lib_buffer_bytes(); hw_queue_size = 0x4000; and in pointer callback, snd_pcm_indirect_playback_pointer(substream, &dream->playback_rec, frames_to_bytes(runtime, dream->playback_hw_ptr); Well, but... This may still result in clicking noises because this handles as if periods=1. If we know that more than 0x4000 bytes can be pushed to the hardware, we can increase hw_queue_size accordingly, too. Alternatively, a better way is to let copy callback return the actually written size. Then the block transfer behavior can be implemented in the copy callback side (so you don't need block-transfer patch any more, too). The first patch is the change to API and its user in the current tree to check the return value of copy callback. The second patch is the change/fix to dream.c you attached. I suppose that dream_get_mpu_data_poll_status_bytes() can be called in the interrupt context, too. Takashi
Attachment:
pcm-indirect-copy-check.diff
Description: Binary data
Attachment:
dream.patch
Description: Binary data
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ Alsa-devel mailing list Alsa-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/alsa-devel