Re: AUDIORECDEVICE environment variable in sndio lib

2020-11-18 Thread Peter J. Philipp
Sorry I apologize, I had my kern.audio.record set to 0.  It works for me.

*red faced*

-peter

On Wed, Nov 18, 2020 at 04:12:25PM +0100, Peter J. Philipp wrote:
> On Wed, Nov 18, 2020 at 11:00:17AM +0100, Alexandre Ratchov wrote:
> > Thanks; semarie suggested a similar diff, so below is an attempt to
> > take into account all the suggestions:
> > 
> > - add AUDIOPLAYDEVICE, to handle play-only devices as well. We've the
> >   very same problem for them.
> > 
> > - use AUDIODEVICE if play-only (rec-only) mode is used but the
> >   corresponding AUDIOPLAYDEVICE (AUDIORECDEVICE) var is not defined
> > 
> > - minimal update for AUDIO{PLAY,REC}DEVICE in the man page
> > 
> > OK?
> 
> This stopped working for me today when I tested it.  My box saw a reboot
> though.
> 
> :-(
> 
> I used AUDIOPLAYDEVICE=snd/0 AUDIORECDEVICE=snd/1 audacity
> 
> also
>   AUDIODEVICE=snd/0 AUDIORECDEVICE=snd/1 audacity
> 
> I'm looking over the code a little, but I can't guarantee I'll find what's
> wrong.
> 
> Best Regards,
> 
> -peter
> 
> 
> 
> > Index: sio.c
> > ===
> > RCS file: /cvs/src/lib/libsndio/sio.c,v
> > retrieving revision 1.24
> > diff -u -p -r1.24 sio.c
> > --- sio.c   29 Jun 2019 06:05:26 -  1.24
> > +++ sio.c   18 Nov 2020 09:49:24 -
> > @@ -52,7 +52,12 @@ sio_open(const char *str, unsigned int m
> > if (str == NULL) /* backward compat */
> > str = devany;
> > if (strcmp(str, devany) == 0 && !issetugid()) {
> > -   str = getenv("AUDIODEVICE");
> > +   if ((mode & SIO_PLAY) == 0)
> > +   str = getenv("AUDIORECDEVICE");
> > +   if ((mode & SIO_REC) == 0)
> > +   str = getenv("AUDIOPLAYDEVICE");
> > +   if (mode == (SIO_PLAY | SIO_REC) || str == NULL)
> > +   str = getenv("AUDIODEVICE");
> > if (str == NULL)
> > str = devany;
> > }
> > Index: sndio.7
> > ===
> > RCS file: /cvs/src/lib/libsndio/sndio.7,v
> > retrieving revision 1.24
> > diff -u -p -r1.24 sndio.7
> > --- sndio.7 18 Jul 2020 05:01:14 -  1.24
> > +++ sndio.7 18 Nov 2020 09:49:24 -
> > @@ -151,9 +151,11 @@ If
> >  .Cm default
> >  is used as the audio device, the program will use the
> >  one specified in the
> > -.Ev AUDIODEVICE
> > -environment variable.
> > -If it is not set, the program first tries to connect to
> > +.Ev AUDIODEVICE , AUDIOPLAYDEVICE
> > +and/or
> > +.Ev AUDIORECDEVICE
> > +environment variables.
> > +If they are not set, the program first tries to connect to
> >  .Li snd/0 .
> >  If that fails, it then tries to use
> >  .Li rsnd/0 .
> > @@ -190,10 +192,20 @@ and contains 128 bits of raw random data
> >  If a session needs to be shared between multiple users, they
> >  can connect to the server using the same cookie.
> >  .Sh ENVIRONMENT
> > -.Bl -tag -width "AUDIODEVICEXXX" -compact
> > +.Bl -tag -width "AUDIOPLAYDEVICE" -compact
> >  .It Ev AUDIODEVICE
> >  Audio device descriptor to use
> >  when no descriptor is explicitly specified to a program.
> > +.It Ev AUDIOPLAYDEVICE
> > +Audio device descriptor to use for play-only mode
> > +when no descriptor is explicitly specified to a program.
> > +Overrides
> > +.Ev AUDIODEVICE .
> > +.It Ev AUDIORECDEVICE
> > +Audio device descriptor to use for record-only mode
> > +when no descriptor is explicitly specified to a program.
> > +Overrides
> > +.Ev AUDIODEVICE .
> >  .It Ev MIDIDEVICE
> >  MIDI port descriptor to use
> >  when no descriptor is explicitly specified to a program.
> 



Re: AUDIORECDEVICE environment variable in sndio lib

2020-11-18 Thread Peter J. Philipp
On Wed, Nov 18, 2020 at 11:00:17AM +0100, Alexandre Ratchov wrote:
> Thanks; semarie suggested a similar diff, so below is an attempt to
> take into account all the suggestions:
> 
> - add AUDIOPLAYDEVICE, to handle play-only devices as well. We've the
>   very same problem for them.
> 
> - use AUDIODEVICE if play-only (rec-only) mode is used but the
>   corresponding AUDIOPLAYDEVICE (AUDIORECDEVICE) var is not defined
> 
> - minimal update for AUDIO{PLAY,REC}DEVICE in the man page
> 
> OK?

This stopped working for me today when I tested it.  My box saw a reboot
though.

:-(

I used AUDIOPLAYDEVICE=snd/0 AUDIORECDEVICE=snd/1 audacity

also
AUDIODEVICE=snd/0 AUDIORECDEVICE=snd/1 audacity

I'm looking over the code a little, but I can't guarantee I'll find what's
wrong.

Best Regards,

-peter



> Index: sio.c
> ===
> RCS file: /cvs/src/lib/libsndio/sio.c,v
> retrieving revision 1.24
> diff -u -p -r1.24 sio.c
> --- sio.c 29 Jun 2019 06:05:26 -  1.24
> +++ sio.c 18 Nov 2020 09:49:24 -
> @@ -52,7 +52,12 @@ sio_open(const char *str, unsigned int m
>   if (str == NULL) /* backward compat */
>   str = devany;
>   if (strcmp(str, devany) == 0 && !issetugid()) {
> - str = getenv("AUDIODEVICE");
> + if ((mode & SIO_PLAY) == 0)
> + str = getenv("AUDIORECDEVICE");
> + if ((mode & SIO_REC) == 0)
> + str = getenv("AUDIOPLAYDEVICE");
> + if (mode == (SIO_PLAY | SIO_REC) || str == NULL)
> + str = getenv("AUDIODEVICE");
>   if (str == NULL)
>   str = devany;
>   }
> Index: sndio.7
> ===
> RCS file: /cvs/src/lib/libsndio/sndio.7,v
> retrieving revision 1.24
> diff -u -p -r1.24 sndio.7
> --- sndio.7   18 Jul 2020 05:01:14 -  1.24
> +++ sndio.7   18 Nov 2020 09:49:24 -
> @@ -151,9 +151,11 @@ If
>  .Cm default
>  is used as the audio device, the program will use the
>  one specified in the
> -.Ev AUDIODEVICE
> -environment variable.
> -If it is not set, the program first tries to connect to
> +.Ev AUDIODEVICE , AUDIOPLAYDEVICE
> +and/or
> +.Ev AUDIORECDEVICE
> +environment variables.
> +If they are not set, the program first tries to connect to
>  .Li snd/0 .
>  If that fails, it then tries to use
>  .Li rsnd/0 .
> @@ -190,10 +192,20 @@ and contains 128 bits of raw random data
>  If a session needs to be shared between multiple users, they
>  can connect to the server using the same cookie.
>  .Sh ENVIRONMENT
> -.Bl -tag -width "AUDIODEVICEXXX" -compact
> +.Bl -tag -width "AUDIOPLAYDEVICE" -compact
>  .It Ev AUDIODEVICE
>  Audio device descriptor to use
>  when no descriptor is explicitly specified to a program.
> +.It Ev AUDIOPLAYDEVICE
> +Audio device descriptor to use for play-only mode
> +when no descriptor is explicitly specified to a program.
> +Overrides
> +.Ev AUDIODEVICE .
> +.It Ev AUDIORECDEVICE
> +Audio device descriptor to use for record-only mode
> +when no descriptor is explicitly specified to a program.
> +Overrides
> +.Ev AUDIODEVICE .
>  .It Ev MIDIDEVICE
>  MIDI port descriptor to use
>  when no descriptor is explicitly specified to a program.



Re: AUDIORECDEVICE environment variable in sndio lib

2020-11-18 Thread Alexandre Ratchov
On Tue, Nov 17, 2020 at 05:09:28PM +, Stuart Henderson wrote:
> On 2020/11/17 17:13, Peter J. Philipp wrote:
> > Hi,
> > 
> > I have a mic on snd/1 and speakers on snd/0.  I had tried a lot of different
> > settings with audacity port but couldn't get this to work, so I chose the
> > method of last resort.  Below is a patch to allow an AUDIORECDEVICE 
> > environment
> > variable specifying the wanted microphone.
> 
> This seems a worthwhile addition.
> 
> > Index: sio.c
> > ===
> > RCS file: /cvs/src/lib/libsndio/sio.c,v
> > retrieving revision 1.24
> > diff -u -p -u -r1.24 sio.c
> > --- sio.c   29 Jun 2019 06:05:26 -  1.24
> > +++ sio.c   17 Nov 2020 16:13:04 -
> > @@ -43,6 +43,7 @@ sio_open(const char *str, unsigned int m
> >  {
> > static char devany[] = SIO_DEVANY;
> > struct sio_hdl *hdl;
> > +   char *rec = NULL;
> >  
> >  #ifdef DEBUG
> > _sndio_debug_init();
> > @@ -55,6 +56,12 @@ sio_open(const char *str, unsigned int m
> > str = getenv("AUDIODEVICE");
> > if (str == NULL)
> > str = devany;
> > +   rec = getenv("AUDIORECDEVICE");
> > +   if (rec == NULL)
> > +   rec = devany;
> > +
> > +   if (rec && mode == SIO_REC)
> > +   str = rec;
> 
> If AUDIORECDEVICE is unset, it would be better to fallback to
> AUDIODEVICE rather than directly to devany.
> 

Thanks; semarie suggested a similar diff, so below is an attempt to
take into account all the suggestions:

- add AUDIOPLAYDEVICE, to handle play-only devices as well. We've the
  very same problem for them.

- use AUDIODEVICE if play-only (rec-only) mode is used but the
  corresponding AUDIOPLAYDEVICE (AUDIORECDEVICE) var is not defined

- minimal update for AUDIO{PLAY,REC}DEVICE in the man page

OK?

Index: sio.c
===
RCS file: /cvs/src/lib/libsndio/sio.c,v
retrieving revision 1.24
diff -u -p -r1.24 sio.c
--- sio.c   29 Jun 2019 06:05:26 -  1.24
+++ sio.c   18 Nov 2020 09:49:24 -
@@ -52,7 +52,12 @@ sio_open(const char *str, unsigned int m
if (str == NULL) /* backward compat */
str = devany;
if (strcmp(str, devany) == 0 && !issetugid()) {
-   str = getenv("AUDIODEVICE");
+   if ((mode & SIO_PLAY) == 0)
+   str = getenv("AUDIORECDEVICE");
+   if ((mode & SIO_REC) == 0)
+   str = getenv("AUDIOPLAYDEVICE");
+   if (mode == (SIO_PLAY | SIO_REC) || str == NULL)
+   str = getenv("AUDIODEVICE");
if (str == NULL)
str = devany;
}
Index: sndio.7
===
RCS file: /cvs/src/lib/libsndio/sndio.7,v
retrieving revision 1.24
diff -u -p -r1.24 sndio.7
--- sndio.7 18 Jul 2020 05:01:14 -  1.24
+++ sndio.7 18 Nov 2020 09:49:24 -
@@ -151,9 +151,11 @@ If
 .Cm default
 is used as the audio device, the program will use the
 one specified in the
-.Ev AUDIODEVICE
-environment variable.
-If it is not set, the program first tries to connect to
+.Ev AUDIODEVICE , AUDIOPLAYDEVICE
+and/or
+.Ev AUDIORECDEVICE
+environment variables.
+If they are not set, the program first tries to connect to
 .Li snd/0 .
 If that fails, it then tries to use
 .Li rsnd/0 .
@@ -190,10 +192,20 @@ and contains 128 bits of raw random data
 If a session needs to be shared between multiple users, they
 can connect to the server using the same cookie.
 .Sh ENVIRONMENT
-.Bl -tag -width "AUDIODEVICEXXX" -compact
+.Bl -tag -width "AUDIOPLAYDEVICE" -compact
 .It Ev AUDIODEVICE
 Audio device descriptor to use
 when no descriptor is explicitly specified to a program.
+.It Ev AUDIOPLAYDEVICE
+Audio device descriptor to use for play-only mode
+when no descriptor is explicitly specified to a program.
+Overrides
+.Ev AUDIODEVICE .
+.It Ev AUDIORECDEVICE
+Audio device descriptor to use for record-only mode
+when no descriptor is explicitly specified to a program.
+Overrides
+.Ev AUDIODEVICE .
 .It Ev MIDIDEVICE
 MIDI port descriptor to use
 when no descriptor is explicitly specified to a program.



Re: AUDIORECDEVICE environment variable in sndio lib

2020-11-17 Thread Solene Rapenne
On Tue, 17 Nov 2020 18:23:55 +0100
"Peter J. Philipp" :

 
> This is a good suggestion!  Thanks!  I have updated the patch.  I also
> appreciate Solene's offer for manpage addition, thanks!
> 
> New diff follows... let me know if it can be done better, I won't be able
> to update it until tomorrow.
> 
> -peter

I suggest this change.

I added the new variable after MIDIDEVICE in the ENVIRONMENT section
to keep order of appearance in the document.

Index: sndio.7
===
RCS file: /home/reposync/src/lib/libsndio/sndio.7,v
retrieving revision 1.24
diff -u -p -r1.24 sndio.7
--- sndio.7 18 Jul 2020 05:01:14 -  1.24
+++ sndio.7 17 Nov 2020 18:32:34 -
@@ -157,6 +157,10 @@ If it is not set, the program first trie
 .Li snd/0 .
 If that fails, it then tries to use
 .Li rsnd/0 .
+The
+.Ev AUDIORECDEVICE
+environment variable
+defines a device to use prior to the audio device when recording.
 .Pp
 Similarly, if no MIDI descriptor is provided to a program
 or when the reserved word
@@ -196,6 +200,9 @@ Audio device descriptor to use
 when no descriptor is explicitly specified to a program.
 .It Ev MIDIDEVICE
 MIDI port descriptor to use
+when no descriptor is explicitly specified to a program.
+.It Ev AUDIORECDEVICE
+Audio recording device descriptor to use
 when no descriptor is explicitly specified to a program.
 .El
 .Pp



Re: AUDIORECDEVICE environment variable in sndio lib

2020-11-17 Thread Solene Rapenne
On Tue, 17 Nov 2020 17:13:49 +0100
"Peter J. Philipp" :

> Hi,
> 
> I have a mic on snd/1 and speakers on snd/0.  I had tried a lot of different
> settings with audacity port but couldn't get this to work, so I chose the
> method of last resort.  Below is a patch to allow an AUDIORECDEVICE 
> environment
> variable specifying the wanted microphone.
> 
> -peter

I have no opinion about the diff itself, but this would require
a man page update that I propose myself to write if the diff is OK.

It works fine for me, I've been able to use my DAC and my usb
microphone in audacity. It was something that I wanted to be able
to do since long time and I'm very happy to see it possible.



Re: AUDIORECDEVICE environment variable in sndio lib

2020-11-17 Thread Ingo Schwarze
Hi Solene,

sorry if i misunderstand because i did not fully follow the thread...

Solene Rapenne wrote on Tue, Nov 17, 2020 at 07:36:38PM +0100:

> I added the new variable after MIDIDEVICE in the ENVIRONMENT section
> to keep order of appearance in the document.

Usually, we order the ENVIRONMENT section alphabetically.

Also, on first sight, the text of AUDIODEVICE and AUDIORECDEVICE
seems to cause a contradiction.  The earlier text below "Default
Audio and MIDI devices" appears to resolve the apparent contradiction,
but wouldn't it be better to give a complete definition at one
place?  For example similar to ths:

.It Ev AUDIODEVICE
Audio device descriptor to use for playback when no descriptor is
explicitly specified to a program.  It is also used for recording if
.Ev AUDIORECDEVICE
is unset.
.It Ev AUDIORECDEVICE
Audio device descriptor to use for recording when no descriptor is
explicitly specified to a program.
.It Ev MIDIDEVICE
[... unchanged ...]

And below "Default Audio and MIDI devices" something like:

When no audio device descriptor is provided to a program
or when the reserved word
.Cm default
is passed as the device descriptor,
the program uses the one specified in the
.Ev AUDIODEVICE
environment variable for playback and the one specified in
.Ev AUDIORECDEVICE
for recording, falling back to
.Ev AUDIODEVICE
if the latter is unset.
If the applicable variables are unset, the program first tries
to connect to [...]

Feel free to ignore me if i misunderstood or if you disagree,
or to tweak the wording according to your taste.

Yours,
  Ingo


> Index: sndio.7
> ===
> RCS file: /home/reposync/src/lib/libsndio/sndio.7,v
> retrieving revision 1.24
> diff -u -p -r1.24 sndio.7
> --- sndio.7   18 Jul 2020 05:01:14 -  1.24
> +++ sndio.7   17 Nov 2020 18:32:34 -
> @@ -157,6 +157,10 @@ If it is not set, the program first trie
>  .Li snd/0 .
>  If that fails, it then tries to use
>  .Li rsnd/0 .
> +The
> +.Ev AUDIORECDEVICE
> +environment variable
> +defines a device to use prior to the audio device when recording.
>  .Pp
>  Similarly, if no MIDI descriptor is provided to a program
>  or when the reserved word
> @@ -196,6 +200,9 @@ Audio device descriptor to use
>  when no descriptor is explicitly specified to a program.
>  .It Ev MIDIDEVICE
>  MIDI port descriptor to use
> +when no descriptor is explicitly specified to a program.
> +.It Ev AUDIORECDEVICE
> +Audio recording device descriptor to use
>  when no descriptor is explicitly specified to a program.
>  .El
>  .Pp
> 



Re: AUDIORECDEVICE environment variable in sndio lib

2020-11-17 Thread Klemens Nanni
On Tue, Nov 17, 2020 at 06:23:55PM +0100, Peter J. Philipp wrote:
> On Tue, Nov 17, 2020 at 05:09:28PM +, Stuart Henderson wrote:
> > If AUDIORECDEVICE is unset, it would be better to fallback to
> > AUDIODEVICE rather than directly to devany.
> 
> This is a good suggestion!  Thanks!  I have updated the patch.  I also
> appreciate Solene's offer for manpage addition, thanks!
Afaict this will match existing behaviour after your patch with
AUDIORECDEVICE not being set, so that's good.



Re: AUDIORECDEVICE environment variable in sndio lib

2020-11-17 Thread Stuart Henderson
On 2020/11/17 18:23, Peter J. Philipp wrote:
> On Tue, Nov 17, 2020 at 05:09:28PM +, Stuart Henderson wrote:
> > On 2020/11/17 17:13, Peter J. Philipp wrote:
> > > Hi,
> > > 
> > > I have a mic on snd/1 and speakers on snd/0.  I had tried a lot of 
> > > different
> > > settings with audacity port but couldn't get this to work, so I chose the
> > > method of last resort.  Below is a patch to allow an AUDIORECDEVICE 
> > > environment
> > > variable specifying the wanted microphone.
> > 
> > This seems a worthwhile addition.
> > 
> > > Index: sio.c
> > > ===
> > > RCS file: /cvs/src/lib/libsndio/sio.c,v
> > > retrieving revision 1.24
> > > diff -u -p -u -r1.24 sio.c
> > > --- sio.c 29 Jun 2019 06:05:26 -  1.24
> > > +++ sio.c 17 Nov 2020 16:13:04 -
> > > @@ -43,6 +43,7 @@ sio_open(const char *str, unsigned int m
> > >  {
> > >   static char devany[] = SIO_DEVANY;
> > >   struct sio_hdl *hdl;
> > > + char *rec = NULL;
> > >  
> > >  #ifdef DEBUG
> > >   _sndio_debug_init();
> > > @@ -55,6 +56,12 @@ sio_open(const char *str, unsigned int m
> > >   str = getenv("AUDIODEVICE");
> > >   if (str == NULL)
> > >   str = devany;
> > > + rec = getenv("AUDIORECDEVICE");
> > > + if (rec == NULL)
> > > + rec = devany;
> > > +
> > > + if (rec && mode == SIO_REC)
> > > + str = rec;
> > 
> > If AUDIORECDEVICE is unset, it would be better to fallback to
> > AUDIODEVICE rather than directly to devany.
> 
> This is a good suggestion!  Thanks!  I have updated the patch.  I also
> appreciate Solene's offer for manpage addition, thanks!
> 
> New diff follows... let me know if it can be done better, I won't be able
> to update it until tomorrow.
> 
> -peter
> 
> Index: sio.c
> ===
> RCS file: /cvs/src/lib/libsndio/sio.c,v
> retrieving revision 1.24
> diff -u -p -u -r1.24 sio.c
> --- sio.c 29 Jun 2019 06:05:26 -  1.24
> +++ sio.c 17 Nov 2020 17:18:57 -
> @@ -43,6 +43,7 @@ sio_open(const char *str, unsigned int m
>  {
>   static char devany[] = SIO_DEVANY;
>   struct sio_hdl *hdl;
> + char *rec = NULL;
>  
>  #ifdef DEBUG
>   _sndio_debug_init();
> @@ -55,6 +56,12 @@ sio_open(const char *str, unsigned int m
>   str = getenv("AUDIODEVICE");
>   if (str == NULL)
>   str = devany;
> + rec = getenv("AUDIORECDEVICE");
> + if (rec == NULL)
> + rec = str;
> +
> + if (rec && mode == SIO_REC)
> + str = rec;

the "if rec == NULL" needs to go for that to work; simplifies the diff
nicely too :)

Index: sio.c
===
RCS file: /cvs/src/lib/libsndio/sio.c,v
retrieving revision 1.24
diff -u -p -r1.24 sio.c
--- sio.c   29 Jun 2019 06:05:26 -  1.24
+++ sio.c   17 Nov 2020 17:27:42 -
@@ -43,6 +43,7 @@ sio_open(const char *str, unsigned int m
 {
static char devany[] = SIO_DEVANY;
struct sio_hdl *hdl;
+   char *rec = NULL;
 
 #ifdef DEBUG
_sndio_debug_init();
@@ -55,6 +56,9 @@ sio_open(const char *str, unsigned int m
str = getenv("AUDIODEVICE");
if (str == NULL)
str = devany;
+   rec = getenv("AUDIORECDEVICE");
+   if (rec && mode == SIO_REC)
+   str = rec;
}
if (strcmp(str, devany) == 0) {
hdl = _sio_aucat_open("snd/0", mode, nbio);
Index: sioctl.c
===
RCS file: /cvs/src/lib/libsndio/sioctl.c,v
retrieving revision 1.1
diff -u -p -r1.1 sioctl.c
--- sioctl.c26 Feb 2020 13:53:58 -  1.1
+++ sioctl.c17 Nov 2020 17:27:42 -
@@ -28,6 +28,7 @@ sioctl_open(const char *str, unsigned in
 {
static char devany[] = SIO_DEVANY;
struct sioctl_hdl *hdl;
+   char *rec = NULL;
 
 #ifdef DEBUG
_sndio_debug_init();
@@ -38,6 +39,9 @@ sioctl_open(const char *str, unsigned in
str = getenv("AUDIODEVICE");
if (str == NULL)
str = devany;
+   rec = getenv("AUDIORECDEVICE");
+   if (rec && mode == SIO_REC)
+   str = rec;
}
if (strcmp(str, devany) == 0) {
hdl = _sioctl_aucat_open("snd/0", mode, nbio);



Re: AUDIORECDEVICE environment variable in sndio lib

2020-11-17 Thread Peter J. Philipp
On Tue, Nov 17, 2020 at 05:09:28PM +, Stuart Henderson wrote:
> On 2020/11/17 17:13, Peter J. Philipp wrote:
> > Hi,
> > 
> > I have a mic on snd/1 and speakers on snd/0.  I had tried a lot of different
> > settings with audacity port but couldn't get this to work, so I chose the
> > method of last resort.  Below is a patch to allow an AUDIORECDEVICE 
> > environment
> > variable specifying the wanted microphone.
> 
> This seems a worthwhile addition.
> 
> > Index: sio.c
> > ===
> > RCS file: /cvs/src/lib/libsndio/sio.c,v
> > retrieving revision 1.24
> > diff -u -p -u -r1.24 sio.c
> > --- sio.c   29 Jun 2019 06:05:26 -  1.24
> > +++ sio.c   17 Nov 2020 16:13:04 -
> > @@ -43,6 +43,7 @@ sio_open(const char *str, unsigned int m
> >  {
> > static char devany[] = SIO_DEVANY;
> > struct sio_hdl *hdl;
> > +   char *rec = NULL;
> >  
> >  #ifdef DEBUG
> > _sndio_debug_init();
> > @@ -55,6 +56,12 @@ sio_open(const char *str, unsigned int m
> > str = getenv("AUDIODEVICE");
> > if (str == NULL)
> > str = devany;
> > +   rec = getenv("AUDIORECDEVICE");
> > +   if (rec == NULL)
> > +   rec = devany;
> > +
> > +   if (rec && mode == SIO_REC)
> > +   str = rec;
> 
> If AUDIORECDEVICE is unset, it would be better to fallback to
> AUDIODEVICE rather than directly to devany.

This is a good suggestion!  Thanks!  I have updated the patch.  I also
appreciate Solene's offer for manpage addition, thanks!

New diff follows... let me know if it can be done better, I won't be able
to update it until tomorrow.

-peter

Index: sio.c
===
RCS file: /cvs/src/lib/libsndio/sio.c,v
retrieving revision 1.24
diff -u -p -u -r1.24 sio.c
--- sio.c   29 Jun 2019 06:05:26 -  1.24
+++ sio.c   17 Nov 2020 17:18:57 -
@@ -43,6 +43,7 @@ sio_open(const char *str, unsigned int m
 {
static char devany[] = SIO_DEVANY;
struct sio_hdl *hdl;
+   char *rec = NULL;
 
 #ifdef DEBUG
_sndio_debug_init();
@@ -55,6 +56,12 @@ sio_open(const char *str, unsigned int m
str = getenv("AUDIODEVICE");
if (str == NULL)
str = devany;
+   rec = getenv("AUDIORECDEVICE");
+   if (rec == NULL)
+   rec = str;
+
+   if (rec && mode == SIO_REC)
+   str = rec;
}
if (strcmp(str, devany) == 0) {
hdl = _sio_aucat_open("snd/0", mode, nbio);
Index: sioctl.c
===
RCS file: /cvs/src/lib/libsndio/sioctl.c,v
retrieving revision 1.1
diff -u -p -u -r1.1 sioctl.c
--- sioctl.c26 Feb 2020 13:53:58 -  1.1
+++ sioctl.c17 Nov 2020 17:18:57 -
@@ -28,6 +28,7 @@ sioctl_open(const char *str, unsigned in
 {
static char devany[] = SIO_DEVANY;
struct sioctl_hdl *hdl;
+   char *rec = NULL;
 
 #ifdef DEBUG
_sndio_debug_init();
@@ -38,6 +39,14 @@ sioctl_open(const char *str, unsigned in
str = getenv("AUDIODEVICE");
if (str == NULL)
str = devany;
+   
+   rec = getenv("AUDIORECDEVICE");
+   if (rec == NULL)
+   rec = str;
+   
+   if (rec && mode == SIO_REC)
+   str = rec;
+   
}
if (strcmp(str, devany) == 0) {
hdl = _sioctl_aucat_open("snd/0", mode, nbio);



Re: AUDIORECDEVICE environment variable in sndio lib

2020-11-17 Thread Stuart Henderson
On 2020/11/17 17:13, Peter J. Philipp wrote:
> Hi,
> 
> I have a mic on snd/1 and speakers on snd/0.  I had tried a lot of different
> settings with audacity port but couldn't get this to work, so I chose the
> method of last resort.  Below is a patch to allow an AUDIORECDEVICE 
> environment
> variable specifying the wanted microphone.

This seems a worthwhile addition.

> Index: sio.c
> ===
> RCS file: /cvs/src/lib/libsndio/sio.c,v
> retrieving revision 1.24
> diff -u -p -u -r1.24 sio.c
> --- sio.c 29 Jun 2019 06:05:26 -  1.24
> +++ sio.c 17 Nov 2020 16:13:04 -
> @@ -43,6 +43,7 @@ sio_open(const char *str, unsigned int m
>  {
>   static char devany[] = SIO_DEVANY;
>   struct sio_hdl *hdl;
> + char *rec = NULL;
>  
>  #ifdef DEBUG
>   _sndio_debug_init();
> @@ -55,6 +56,12 @@ sio_open(const char *str, unsigned int m
>   str = getenv("AUDIODEVICE");
>   if (str == NULL)
>   str = devany;
> + rec = getenv("AUDIORECDEVICE");
> + if (rec == NULL)
> + rec = devany;
> +
> + if (rec && mode == SIO_REC)
> + str = rec;

If AUDIORECDEVICE is unset, it would be better to fallback to
AUDIODEVICE rather than directly to devany.