Very good explanation, I was aware of that parameter but since I wasn't sure about the problem that was happening, I didn't play too much with it. I tweaked that and the size of the buffer I read and write (which is the same) and everything is working fine now, thx! Your comment bring me another question though, why would enabling the input monitoring on my sound card have fixed my problem and would have been a better solution? What exactly is input monitoring? On Wednesday 12 March 2008 13:54:49 Clemens Ladisch wrote: > Thierry Bouchard wrote: > > Im trying to capture the Microphone input and redirect it right away into > > speakers. The problem is that whenever I use "snd_pcm_readi" > > and "snd_pcm_writei" one after each other in my capture loop, the pipe > > becomes broken on the output side, i.e. every call to "snd_pcm_writei" > > fails after it succeeded for like 2 passes. > > In the time that snd_pcm_readi needs to wait for a block of data to > become available, the data written by the last snd_pcm_writei call is > played by the sound card. Just when snd_pcm_readi returns, the playback > buffer has become completely empty, and even the slightest delay in > writing the next data to it will result in an underrun. > > To ensure that the playback buffer contains enough samples to adjust for > timing variations, do not start playing when the first block of data is > written to it but when the buffer is (almost) completely filled. > > The buffer fullness at which a playback device is started is called the > "start threshold". The default value is 1, i.e., after at least one > sample has been written to the buffer; you can change it with the > snd_pcm_sw_params_start_threshold function. > > The following is from the implementation of snd_pcm_set_params: > > snd_pcm_sw_params_t *swparams; > > snd_pcm_sw_params_alloca(&swparams); > ... > err = snd_pcm_sw_params_current(pcm, swparams); > if (err < 0) { > SNDERR("Unable to determine current swparams for %s: %s", s, > snd_strerror(err)); return err; > } > /* start the transfer when the buffer is almost full: */ > /* (buffer_size / avail_min) * avail_min */ > err = snd_pcm_sw_params_set_start_threshold(pcm, swparams, (buffer_size / > period_size) * period_size); if (err < 0) { > SNDERR("Unable to set start threshold mode for %s: %s", s, > snd_strerror(err)); return err; > } > /* allow the transfer when at least period_size samples can be processed > */ err = snd_pcm_sw_params_set_avail_min(pcm, swparams, period_size); if > (err < 0) { > SNDERR("Unable to set avail min for %s: %s", s, snd_strerror(err)); > return err; > } > /* write the parameters to the playback device */ > err = snd_pcm_sw_params(pcm, swparams); > if (err < 0) { > SNDERR("Unable to set sw params for %s: %s", s, snd_strerror(err)); > return err; > } > > > However, an even better solution for your problem would be to enable the > input monitoring function of your sound card. This should be supported > by the CMI8788 chip, but it isn't supported by the driver because so far > I have not been able to find out how it works. I'll look into it. > > > Regards, > Clemens CONFIDENTIALITY CAUTION This e-mail and any attachments may be confidential or legally privileged. If you received this message in error or are not the intended recipient, you should destroy the e-mail message and any attachments or copies, and you are prohibited from retaining, distributing, disclosing or using any information contained herein. Please inform us of the erroneous delivery by return e-mail. Thank you for your cooperation. DOCUMENT CONFIDENTIEL Le présent courriel et tout fichier joint à celui-ci peuvent contenir des renseignements confidentiels ou privilégiés. Si cet envoi ne s'adresse pas à vous ou si vous l'avez reçu par erreur, vous devez l'effacer. Vous ne pouvez conserver, distribuer, communiquer ou utiliser les renseignements qu'il contient. Nous vous prions de nous signaler l'erreur par courriel. Merci de votre collaboration. ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Alsa-user mailing list Alsa-user@xxxxxxxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/alsa-user