All of lore.kernel.org
 help / color / mirror / Atom feed
* need some workarround or explanation.
@ 2011-11-04  8:50 Anders Gnistrup
  2011-11-04 11:46 ` Clemens Ladisch
  0 siblings, 1 reply; 4+ messages in thread
From: Anders Gnistrup @ 2011-11-04  8:50 UTC (permalink / raw)
  To: alsa-devel@alsa-project.org

Hello

I have a USB headset, where when plugged in, a volume setting is set on playback and capture channels using the ctl interface for the device.
After the volume is set I open the capture interface. but I have i have a 2-3 sec. delay that i just don't understand.

I might need to use another solution, but these are difficult to find.
The Headset is a plantronics.

The code is listed below.

#include <alsa/asoundlib.h>

#define qDebug printf
void set_default_volume(const char *a_hw_dev, int a_percent)
{
    int err;
    snd_mixer_t *handle;
    snd_mixer_selem_id_t *sid;
    snd_mixer_elem_t *elem;
    snd_mixer_selem_id_alloca(&sid);

    if ((err = snd_mixer_open(&handle, 0)) < 0)
    {
        qDebug("Mixer open error: %s\n", snd_strerror(err));
        return;
    }
    if ((err = snd_mixer_attach(handle, a_hw_dev)) < 0)
    {
        qDebug("Mixer attach %s error: %s\n", a_hw_dev, snd_strerror(err));
        snd_mixer_close(handle);
        return;
    }
    if ((err = snd_mixer_selem_register(handle, NULL, NULL)) < 0)
    {
        qDebug("Mixer register error: %s\n", snd_strerror(err));
        snd_mixer_close(handle);
        return;
    }
    err = snd_mixer_load(handle);
    if (err < 0)
    {
        qDebug("Mixer %s load error: %s\n", a_hw_dev, snd_strerror(err));
        snd_mixer_close(handle);
        return;
    }
    for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem))
    {
        snd_mixer_selem_get_id(elem, sid);
        qDebug("Simple mixer control '%s',%i\n", snd_mixer_selem_id_get_name(sid), snd_mixer_selem_id_get_index(sid));

        if (snd_mixer_selem_has_playback_switch(elem))
        {
            snd_mixer_selem_set_playback_switch_all(elem, 1); //unmute
        }

        if (snd_mixer_selem_has_playback_volume(elem))
        {
            long min, max;
            snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
            qDebug(" pvolume %ld/%ld\n", min , max);
            snd_mixer_selem_set_playback_volume_all(elem, (a_percent * (max-min))/100);
        }

        if (snd_mixer_selem_has_capture_switch(elem))
        {
            snd_mixer_selem_set_capture_switch_all(elem, 1); // unmute all
        }
        if (snd_mixer_selem_has_capture_volume(elem))
        {
            long min, max;
            snd_mixer_selem_get_capture_volume_range(elem, &min, &max);
            qDebug(" pvolume %ld/%ld\n", min , max);
            snd_mixer_selem_set_capture_volume_all(elem,  (a_percent * (max-min))/100); //set capture volume for all
        }
    }
    snd_mixer_close(handle);
    return;
}

int main(int argc, char *argv[])
{
    snd_pcm_t *m_pcm_handle;

    int err,count;
    // Open connection to the PCM devic
    if ((err = snd_pcm_open(&m_pcm_handle, "plughw:1,0", SND_PCM_STREAM_CAPTURE, 0)) < 0)
    {
        for (count=0; count < 5 && err == -EBUSY; count++)
        {
            sleep(1);
            qDebug("AlsaStream:%d open error: %s (%d)\n ", __LINE__, snd_strerror(err), err);
            err = snd_pcm_open(&m_pcm_handle, "plughw:1,0", SND_PCM_STREAM_CAPTURE, 0);
        }

        if (err < 0)
        {
            qDebug("AlsaStream:%d open error: %s (%d)\n ", __LINE__, snd_strerror(err), err);
            return;
        }
        if (err>= 0)
        {
            printf("Success\n");
        }
    }
    set_default_volume("hw:1", 20);
    snd_pcm_close(m_pcm_handle);
    return 0;
}

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

* Re: need some workarround or explanation.
  2011-11-04  8:50 need some workarround or explanation Anders Gnistrup
@ 2011-11-04 11:46 ` Clemens Ladisch
  2011-11-04 11:48   ` Anders Gnistrup
  0 siblings, 1 reply; 4+ messages in thread
From: Clemens Ladisch @ 2011-11-04 11:46 UTC (permalink / raw)
  To: Anders Gnistrup; +Cc: alsa-devel@alsa-project.org

Anders Gnistrup wrote:
> I have a USB headset, where when plugged in, a volume setting is set on
> playback and capture channels using the ctl interface for the device.
> After the volume is set I open the capture interface. but I have i have
> a 2-3 sec. delay that i just don't understand.

What is delayed?


Regards,
Clemens

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

* Re: need some workarround or explanation.
  2011-11-04 11:46 ` Clemens Ladisch
@ 2011-11-04 11:48   ` Anders Gnistrup
  2011-11-04 16:38     ` Clemens Ladisch
  0 siblings, 1 reply; 4+ messages in thread
From: Anders Gnistrup @ 2011-11-04 11:48 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel@alsa-project.org

Hi

The snd_pcm_open call.
If I call the program after 10sec after i have plugged in the headset, there is no problem.

Anders

________________________________________
From: Clemens Ladisch [clemens@ladisch.de]
Sent: Friday, November 04, 2011 12:46 PM
To: Anders Gnistrup
Cc: alsa-devel@alsa-project.org
Subject: Re: [alsa-devel] need some workarround or explanation.

Anders Gnistrup wrote:
> I have a USB headset, where when plugged in, a volume setting is set on
> playback and capture channels using the ctl interface for the device.
> After the volume is set I open the capture interface. but I have i have
> a 2-3 sec. delay that i just don't understand.

What is delayed?


Regards,
Clemens

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

* Re: need some workarround or explanation.
  2011-11-04 11:48   ` Anders Gnistrup
@ 2011-11-04 16:38     ` Clemens Ladisch
  0 siblings, 0 replies; 4+ messages in thread
From: Clemens Ladisch @ 2011-11-04 16:38 UTC (permalink / raw)
  To: Anders Gnistrup; +Cc: alsa-devel@alsa-project.org

Anders Gnistrup wrote:
> The snd_pcm_open call.

Strange, because that part of the driver doesn't access the device at
all, and shouldn't be able to wait.

Could you use strace to check which system call has the delay?


Regards,
Clemens

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

end of thread, other threads:[~2011-11-04 16:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-04  8:50 need some workarround or explanation Anders Gnistrup
2011-11-04 11:46 ` Clemens Ladisch
2011-11-04 11:48   ` Anders Gnistrup
2011-11-04 16:38     ` Clemens Ladisch

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.