All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jörg Krause" <joerg.krause@embedded.rocks>
To: alsa-devel@alsa-project.org
Subject: Re: Toggle GPIO if ALSA playbacks begins or ends
Date: Fri, 26 Aug 2016 14:59:49 +0200	[thread overview]
Message-ID: <1472216389.32160.7.camel@embedded.rocks> (raw)
In-Reply-To: <1472149668.24475.10.camel@embedded.rocks>

On Do, 2016-08-25 at 20:27 +0200, Jörg Krause wrote:
> Hi,
> 
> I am looking for a way to toggle a GPIO if ALSA is about to play or
> has
> stopped to turn an external amplifier on/off.
> 
> Can it be done using libasound or can I use a plugin or write one?

After having a long night digging through ALSA's sourced I got it
working writing a PCM hook library. Basically, it does the following:

static int snd_pcm_hook_gpio_hook_close(snd_pcm_hook_t *hook)
{
	int fd;

	/*
	 * Set GPIO LOW
	 */

	return 0;
}

int _snd_pcm_hook_gpio_hook_install(snd_pcm_t *pcm, snd_config_t *conf)
{
	int fd;
	int err;

	snd_pcm_hook_t *h_close = NULL;

	err = snd_pcm_hook_add(&h_close, pcm, SND_PCM_HOOK_TYPE_CLOSE,
			       snd_pcm_hook_gpio_hook_close, NULL);
	if (err < 0)
		goto _err;

	/* Init and set GPIO HIGH
         */

	return 0;

_err:
	if (h_close)
		snd_pcm_hook_remove(h_close);

	return err;
}
SND_DLSYM_BUILD_VERSION(_snd_pcm_hook_gpio_hook_install,
SND_CONFIG_DLSYM_VERSION_HOOK);

For reference my asound.conf:

pcm.softvol {
    type softvol
    slave {
        pcm "gpio_hook"
    }
    control {
        name "Master"
        card 0
    }
}
pcm_hook_type.gpio_hook {
    lib "libasound_gpio_hook.so"
}
pcm.softvol_hook {
    type hooks
    slave {
        pcm "hw:0"
    }
    hooks.0 {
        type "gpio_hook"
    }
}

Jörg
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

      reply	other threads:[~2016-08-26 13:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-25 18:27 Toggle GPIO if ALSA playbacks begins or ends Jörg Krause
2016-08-26 12:59 ` Jörg Krause [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1472216389.32160.7.camel@embedded.rocks \
    --to=joerg.krause@embedded.rocks \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.