All of lore.kernel.org
 help / color / mirror / Atom feed
* capturing data from the microphone
@ 2010-01-04 17:39 Riccardo Magliocchetti
  2010-01-05 15:24 ` Marc Garnier
  2010-01-05 16:48 ` pl bossart
  0 siblings, 2 replies; 15+ messages in thread
From: Riccardo Magliocchetti @ 2010-01-04 17:39 UTC (permalink / raw)
  To: alsa-devel

[the same message is waiting in moderator queue, sorry if you receive it two times]

Hello,

i'm trying to capture audio data from the microphone, but i'm not able to
read any frames.
The frames are always 0 and delay is fixed to 2730. I've tried calling
snd_pcm_avail_delay,  snd_pcm_avail_update but does not make a difference.
The soundcard is driven by  snd_hda_intel. The code is more or less the
same as Paul Davis' tutorial on using the alsa api.

This is the code for init and the loop that tries to read the data:

#define MIC_BUFSIZE 4096

static gpointer snd_pcm_read(gpointer data)
{
   int error;
   snd_pcm_sframes_t frames = MIC_BUFSIZE;

   while (TRUE) {

     if ((error = snd_pcm_wait (pcm_handle, 1000)) < 0) {
         g_printerr("Failed to poll: %s\n", snd_strerror(error));
         continue;
     }

     if ((error = snd_pcm_avail(pcm_handle)) < 0) {
       if (error == -EPIPE) {
         g_printerr("xrun! %s\n", snd_strerror(error));
         continue;
         //return GINT_TO_POINTER(FALSE);
       } else {
         g_printerr("alsa_pcm_avail_update error %s\n", snd_strerror(error));
         continue;
         //return GINT_TO_POINTER(FALSE);
       }
     }

     frames = error;
     if (frames == 0)
       continue;

     frames = frames > MIC_BUFSIZE ? MIC_BUFSIZE : frames;
     g_printerr ("frames: %ld\n", frames);
     g_static_mutex_lock(&mutex);
     error = snd_pcm_readi(pcm_handle, Mic_Buffer[Mic_WriteBuf], frames);
     g_static_mutex_unlock(&mutex);
     if (error < 0)
         error = snd_pcm_recover(pcm_handle, error, 0);
     if (error < 0) {
        LOG("snd_pcm_readi FAIL!: %s\n", snd_strerror(error));
     }
   }

   return GINT_TO_POINTER(TRUE);
}

BOOL Mic_Init()
{
     snd_pcm_hw_params_t *hwparams;
     snd_pcm_sw_params_t *swparams;
     int err;

     if (Mic_Inited)
         return TRUE;

     // Open the default sound card in capture
     if ((err = snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_CAPTURE,
/*SND_PCM_NONBLOCK*/ 0)) < 0) {
         g_printerr("Failed to open device: %s\n", snd_strerror(err));
         return FALSE;
     }

     // Allocate the snd_pcm_hw_params_t structure and fill it.
     snd_pcm_hw_params_alloca(&hwparams);
     if ((err = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0) {
         g_printerr("Failed to setup hw parameters: %s\n", snd_strerror(err));
         return FALSE;
     }

     //Set the access
     if ((err = snd_pcm_hw_params_set_access(pcm_handle, hwparams,
SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
         g_printerr("Failed to set access: %s\n", snd_strerror(err));
         return FALSE;
     }

     //dir 0 == exacte (Rate = 16K exacte)
     if ((err = snd_pcm_hw_params_set_rate(pcm_handle, hwparams, 16000, 0)) < 0) {
         g_printerr("Failed to set rate: %s\n", snd_strerror(err));
         return FALSE;
     }

     /* Set sample format */
     if ((err = snd_pcm_hw_params_set_format(pcm_handle, hwparams, SND_PCM_FORMAT_S8)) < 0) {
         g_printerr("Failed to set format: %s\n", snd_strerror(err));
         return FALSE;
     }

     // Set one channel (mono)
     if ((err = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, 1)) < 0) {
         g_printerr("Failed to set channels: %s\n", snd_strerror(err));
         return FALSE;
     }

     //Set the params
     if ((err = snd_pcm_hw_params(pcm_handle, hwparams)) < 0) {
         g_printerr("Failed to set hw parameters: %s\n", snd_strerror(err));
         return FALSE;
     }

     snd_pcm_sw_params_alloca(&swparams);
     if ((err = snd_pcm_sw_params_current (pcm_handle, swparams)) < 0) {
         g_printerr("Failed to set current sw parameters: %s\n", snd_strerror(err));
         return FALSE;
     }

     if ((err = snd_pcm_sw_params_set_avail_min (pcm_handle, swparams, MIC_BUFSIZE)) < 0) {
         g_printerr("Failed to set minimum available count: %s\n", snd_strerror(err));
         return FALSE;
     }

     if ((err = snd_pcm_sw_params_set_start_threshold (pcm_handle, swparams, 0U)) < 0) {
         g_printerr("Failed to set start mode: %s\n", snd_strerror(err));
         return FALSE;
     }

     if ((err = snd_pcm_sw_params (pcm_handle, swparams)) < 0) {
         g_printerr("Failed to set sw parameters: %s\n", snd_strerror(err));
         return FALSE;
     }

     if ((err = snd_pcm_prepare (pcm_handle)) < 0) {
         g_printerr("Failed to prepare audio interface to use: %s\n", snd_strerror(err));
         return FALSE;
     }

     Mic_Inited = TRUE;
     Mic_Reset();

     mic_reader = g_thread_create(snd_pcm_read, NULL, TRUE, NULL);

     return TRUE;
}


thanks,
Riccardo

^ permalink raw reply	[flat|nested] 15+ messages in thread
* How to use soc API without codec driver
@ 2009-12-08 14:46 Marc Garnier
  2009-12-08 14:51 ` Mark Brown
  0 siblings, 1 reply; 15+ messages in thread
From: Marc Garnier @ 2009-12-08 14:46 UTC (permalink / raw)
  To: alsa-devel

Hi,

I need to receive and transmit PCM data through SSC port of a sam9261 to 
a device which doesn't have any kind of I/O controls (neither i2c nor 
spi). So, I wonder how to deal with the codec driver side.
Someone could explain me what are the minimum requirements to write a 
Asoc driver of this kind?

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2010-01-14  7:49 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-04 17:39 capturing data from the microphone Riccardo Magliocchetti
2010-01-05 15:24 ` Marc Garnier
2010-01-06  1:07   ` Raymond Yau
2010-01-06  7:58     ` Marc Garnier
2010-01-06  8:46       ` Raymond Yau
2010-01-06  9:09         ` Marc Garnier
2010-01-05 16:48 ` pl bossart
2010-01-05 22:12   ` Riccardo Magliocchetti
2010-01-06 23:59     ` Raymond Yau
2010-01-07 18:34       ` Riccardo Magliocchetti
2010-01-11 13:59         ` Riccardo Magliocchetti
2010-01-11 14:03           ` Jaroslav Kysela
2010-01-14  7:49             ` Raymond Yau
  -- strict thread matches above, loose matches on Subject: below --
2009-12-08 14:46 How to use soc API without codec driver Marc Garnier
2009-12-08 14:51 ` Mark Brown
2009-12-09  6:39   ` Marc Garnier
2009-12-09 10:45     ` Mark Brown
     [not found]       ` <4B44617B.2030002@heig-vd.ch>
     [not found]         ` <20100106103937.GA25344@rakim.wolfsonmicro.main>
     [not found]           ` <4B446974.1090205@heig-vd.ch>
2010-01-06 11:39             ` capturing data from the microphone Mark Brown
2010-01-06 13:34               ` Riccardo Magliocchetti

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.