Re: [Alsa-user] Redirecting Mic Input in software (no arecord / aplay involved)

2008-03-19 Thread Clemens Ladisch
I wrote:
 However, an even better solution for your problem would be to enable the
 input monitoring function of your sound card.

Okay, monitoring is now supported, with this patch:
http://hg.alsa-project.org/alsa-kernel/rev/0fff88f7f05b

To enable monitoring from a script, run

amixer cset name=Analog Input Monitor Switch on

or name=Analog Input Monitor Switch,index=1 for the second analog
input.


HTH
Clemens

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


Re: [Alsa-user] Redirecting Mic Input in software (no arecord / aplay involved)

2008-03-13 Thread Clemens Ladisch
Thierry Bouchard wrote:
 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?

Input monitoring means that the recorded data is played back
immediately.  You are implementing this in software, but doing it in
hardware would be much easier (for you) and have less latency.


Regards,
Clemens

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


Re: [Alsa-user] Redirecting Mic Input in software (no arecord / aplay involved)

2008-03-12 Thread Clemens Ladisch
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

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user