All of lore.kernel.org
 help / color / mirror / Atom feed
* Toggle GPIO if ALSA playbacks begins or ends
@ 2016-08-25 18:27 Jörg Krause
  2016-08-26 12:59 ` Jörg Krause
  0 siblings, 1 reply; 2+ messages in thread
From: Jörg Krause @ 2016-08-25 18:27 UTC (permalink / raw)
  To: alsa-devel

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?

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

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

* Re: Toggle GPIO if ALSA playbacks begins or ends
  2016-08-25 18:27 Toggle GPIO if ALSA playbacks begins or ends Jörg Krause
@ 2016-08-26 12:59 ` Jörg Krause
  0 siblings, 0 replies; 2+ messages in thread
From: Jörg Krause @ 2016-08-26 12:59 UTC (permalink / raw)
  To: alsa-devel

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

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

end of thread, other threads:[~2016-08-26 13:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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.