Re: [Alsa-user] Get triggered when the device opens
Hello, just to finish this thread, a colleague of mine put me on the right track: timers. If you look at the alsa-lib timer example http://www.alsa-project.org/alsa-doc/alsa-lib/_2test_2timer_8c-example.html , you see the timer interface being used to register on master timer ticks. The read loop simply waits on poll. Actually, timer work on a variety of events, see http://www.alsa-project.org/alsa-doc/alsa-lib/group___timer.html , enum snd_timer_event_t . To register on specific events, you create a filter mask of your events ( 1 << event1 || 1 << event2 || ... ) and set it to your timer parameters with snd_timer_params_set_filter . In read loop of the timer example, you just need to use snd_timer_tread_t instead of snd_timer_read_t . In my case, I registered on the timer events SND_TIMER_EVENT_MSTART and SND_TIMER_EVENT_MSTOP and it works as expected. Regards, Thomas From: Frank Thomas Sent: 04 June 2018 08:53:57 To: alsa-user@lists.sourceforge.net Subject: Get triggered when the device opens Hello, I'd like to apologise beforehand if I have not read enough documentation and/or source code to be posting here. Please do not hesitate to tell me to RTFM ☺ My application needs to get triggered when a mechanism any application is opening or closing a certain list of ALSA devices. It seems that ALSA hooks would be a way to do it. AFAIK I can only use a hook to trigger a function a in a pcm control plugins with certain arguments. I would need implement a control plugin that notifies my application for me and use a hook to trigger the trigger ☺ Is there another way, e.g. with the ALSA API, to get triggered on such events? Thanks in advance. Regards, Thomas Frank -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Alsa-user mailing list Alsa-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/alsa-user
Re: [Alsa-user] Get triggered when the device opens
> And how does that manufacturer tell you to use it? Get the clock started and configure. The loss of the WS signal is not intended and is a failure. A xrun results in configuration loss. > Anyway, it might be possible to write an external filter plugin: > https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_external_plugins.html I am doing that right now. Right now. It compiles but does not start: $ cat ~/.asoundrc pcm_hw_internal { type hw card 0 device 0 } pcm.myplugin { type myplugin slave { pcm pcm_hw_internal } } $ arecord -D myplugin /dev/zero ALSA lib dlmisc.c:142:(snd_dlsym_verify) unable to verify version for symbol _snd_pcm_myplugin_open ALSA lib dlmisc.c:263:(snd1_dlobj_cache_get) symbol _snd_pcm_myplugin_open is not defined inside /usr/lib/x86_64-linux-gnu/alsa-lib/libasound_module_pcm_myplugin.so arecord: main:722: audio open error: No such device or address This looks like a compile problem, but I don't what exactly. It is compiled like this: $ gcc -I/usr/include/alsa -Wall -g -lasound -fPIC -DPIC -shared -o build/libasound_module_pcm_myplugin.so alsa-plugin.c FYI: I am just testing this on my local machine (ubuntu 16.04) with pulseaudio killed (and autospawn=no). > Does the kernel driver start the I²S clocks in hw_params() or in trigger()? I cannot tell because I am not versed enough in device/ALSA/SOC drivers but I made a step by step device initialization via alsa-lib and the clock really starts only the device is written or read. The SOC manufacturer supplies the ALSA device drivers that utilizes the I2S/PCM interface to talk to the audio controller which I need to configure. Regards, Thomas Frank -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Alsa-user mailing list Alsa-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/alsa-user
Re: [Alsa-user] Get triggered when the device opens
This may, or may not be helpful. I'm not sure if they still do this or not, but S.U.S.E. Linux used to trigger various sounds on various events, like opening, and closing windows, mouse clicks, and so forth. You could mix, and match the sounds/events to the way you liked them. Having a look at their code might be a help. Bill On Mon, 4 Jun 2018, Frank Thomas via Alsa-user wrote: I would like to further clarify some things. I actually need get triggered when the ALSA device started to run, meaning the device is producing or outputting samples. FYI: The actual sound controller is connected via an I²S interface and synchronizes on its the word select signal. After the synchronisation, additional configuration must to occur before you can get valid samples from the ALSA interface. The configuration is lost upon synchronisation loss (ALSA device is not running anymore). -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Alsa-user mailing list Alsa-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/alsa-user-- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ Alsa-user mailing list Alsa-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/alsa-user
Re: [Alsa-user] Get triggered when the device opens
Frank Thomas via Alsa-user wrote: > On Mon, 2018-06-04 at 15:23 +0200, Clemens Ladisch via Alsa-user wrote: >> Frank Thomas via Alsa-user wrote: >>> The actual sound controller is connected via an I²S interface and >>> synchronizes on its the word select signal. After the synchronisation, >>> additional configuration must to occur before you can get valid samples >> >> Then why don't you do the configuration in the driver? > > The configuration is done with an userspace stack/framework which is > provided by the manufacturer of the controller. And how does that manufacturer tell you to use it? Anyway, it might be possible to write an external filter plugin: https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_external_plugins.html Does the kernel driver start the I²S clocks in hw_params() or in trigger()? Regards, Clemens -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Alsa-user mailing list Alsa-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/alsa-user
Re: [Alsa-user] Get triggered when the device opens
On Mon, 2018-06-04 at 15:23 +0200, Clemens Ladisch via Alsa-user wrote: > Frank Thomas via Alsa-user wrote: > > The actual sound controller is connected via an I²S interface and > > synchronizes on its the word select signal. After the > > synchronisation, > > additional configuration must to occur before you can get valid > > samples > > Then why don't you do the configuration in the driver? The configuration is done with an userspace stack/framework which is provided by the manufacturer of the controller. This stack is important for diagnostics purposes during configuration and runtime. Regards, Thomas -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Alsa-user mailing list Alsa-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/alsa-user
Re: [Alsa-user] Get triggered when the device opens
Frank Thomas via Alsa-user wrote: > The actual sound controller is connected via an I²S interface and > synchronizes on its the word select signal. After the synchronisation, > additional configuration must to occur before you can get valid samples Then why don't you do the configuration in the driver? Regards, Clemens -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Alsa-user mailing list Alsa-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/alsa-user
Re: [Alsa-user] Get triggered when the device opens
I would like to further clarify some things. I actually need get triggered when the ALSA device started to run, meaning the device is producing or outputting samples. FYI: The actual sound controller is connected via an I²S interface and synchronizes on its the word select signal. After the synchronisation, additional configuration must to occur before you can get valid samples from the ALSA interface. The configuration is lost upon synchronisation loss (ALSA device is not running anymore). -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Alsa-user mailing list Alsa-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/alsa-user
[Alsa-user] Get triggered when the device opens
Hello, I'd like to apologise beforehand if I have not read enough documentation and/or source code to be posting here. Please do not hesitate to tell me to RTFM ☺ My application needs to get triggered when a mechanism any application is opening or closing a certain list of ALSA devices. It seems that ALSA hooks would be a way to do it. AFAIK I can only use a hook to trigger a function a in a pcm control plugins with certain arguments. I would need implement a control plugin that notifies my application for me and use a hook to trigger the trigger ☺ Is there another way, e.g. with the ALSA API, to get triggered on such events? Thanks in advance. Regards, Thomas Frank -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Alsa-user mailing list Alsa-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/alsa-user