diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2024-03-13 17:56:09 +0100 |
---|---|---|
committer | Andreas Eversberg <jolly@eversberg.eu> | 2024-03-30 23:28:10 +0100 |
commit | ce58b765f5403f95fe23c23894102b6c7bdfa67d (patch) | |
tree | e56b9ef730a26ed79bf754d442ae2c1c78c5ce9e /src | |
parent | fabc849642a97a2420972dc88812f5c38a019036 (diff) |
A different recording device may be specified for sound card access
Diffstat (limited to 'src')
-rw-r--r-- | src/libmobile/main_mobile.c | 6 | ||||
-rw-r--r-- | src/libsound/sound_alsa.c | 37 |
2 files changed, 22 insertions, 21 deletions
diff --git a/src/libmobile/main_mobile.c b/src/libmobile/main_mobile.c index 2494adc..e104f8c 100644 --- a/src/libmobile/main_mobile.c +++ b/src/libmobile/main_mobile.c @@ -247,8 +247,9 @@ void main_mobile_print_help(const char *arg0, const char *ext_usage) printf(" -k --kanal <channel>\n"); printf(" -k --channel <channel>\n"); printf(" Channel (German = Kanal) number of \"Sender\" (German = Transceiver)\n"); - printf(" -a --audio-device hw:<card>,<device>\n"); + printf(" -a --audio-device hw:<card>,<device>[/hw:<card>.<rec-device>]\n"); printf(" Sound card and device number (default = '%s')\n", dsp_device[0]); + printf(" You may specify a different recording device by using '/'.\n"); printf(" Don't set it for SDR!\n"); printf(" -s --samplerate <rate>\n"); printf(" Sample rate of sound device (default = '%d')\n", dsp_samplerate); @@ -276,8 +277,9 @@ void main_mobile_print_help(const char *arg0, const char *ext_usage) printf(" -e --echo-test\n"); printf(" Use echo test, to send back audio from mobile phone's microphone to\n"); printf(" the speaker. (German: 'Blasprobe').\n"); - printf(" -c --call-device hw:<card>,<device>\n"); + printf(" -c --call-device hw:<card>,<device>[/hw:<card>.<rec-device>]\n"); printf(" Sound card and device number for headset (default = '%s')\n", call_device); + printf(" You may specify a different recording device by using '/'.\n"); printf(" --call-samplerate <rate>\n"); printf(" Sample rate of sound device for headset (default = '%d')\n", call_samplerate); printf(" --call-buffer <ms>\n"); diff --git a/src/libsound/sound_alsa.c b/src/libsound/sound_alsa.c index ca743f1..fd3dd70 100644 --- a/src/libsound/sound_alsa.c +++ b/src/libsound/sound_alsa.c @@ -36,7 +36,7 @@ typedef struct sound { int pchannels, cchannels; int channels; /* required number of channels */ int samplerate; /* required sample rate */ - char *audiodev; /* required device */ + char *caudiodev, *paudiodev; /* required device */ double spl_deviation; /* how much deviation is one sample step */ #ifdef HAVE_MOBILE double paging_phaseshift; /* phase to shift every sample */ @@ -127,22 +127,14 @@ static int dev_open(sound_t *sound) { int rc, rc_rec, rc_play; - rc_play = snd_pcm_open(&sound->phandle, sound->audiodev, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); - rc_rec = snd_pcm_open(&sound->chandle, sound->audiodev, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK); - if (rc_play < 0 && rc_rec < 0) { - LOGP(DSOUND, LOGL_ERROR, "Failed to open '%s'! (%s)\n", sound->audiodev, snd_strerror(rc_play)); - LOGP(DSOUND, LOGL_ERROR, "Run 'aplay -l' to get a list of available cards and devices.\n"); - LOGP(DSOUND, LOGL_ERROR, "Then use 'hw:<card>:<device>' for audio device.\n"); - return rc_play; - } - if (rc_play < 0) { - LOGP(DSOUND, LOGL_ERROR, "Failed to open '%s' for playback! (%s) Please select a device that supports both direction audio.\n", sound->audiodev, snd_strerror(rc_play)); - return rc_play; - } - if (rc_rec < 0) { - LOGP(DSOUND, LOGL_ERROR, "Failed to open '%s' for capture! (%s) Please select a device that supports both direction audio.\n", sound->audiodev, snd_strerror(rc_rec)); - return rc_rec; - } + rc_play = snd_pcm_open(&sound->phandle, sound->paudiodev, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); + rc_rec = snd_pcm_open(&sound->chandle, sound->caudiodev, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK); + if (rc_play < 0) + LOGP(DSOUND, LOGL_ERROR, "Failed to open '%s' for playback! (%s) Please select a device that supports playing audio.\n", sound->paudiodev, snd_strerror(rc_play)); + if (rc_rec < 0) + LOGP(DSOUND, LOGL_ERROR, "Failed to open '%s' for capture! (%s) Please select a device that supports capturing audio.\n", sound->caudiodev, snd_strerror(rc_rec)); + if (rc_play < 0 || rc_rec < 0) + return (rc_play < 0) ? rc_play : rc_rec; rc = set_hw_params(sound->phandle, sound->samplerate, &sound->pchannels); if (rc < 0) { @@ -193,6 +185,7 @@ void *sound_open(const char *audiodev, double __attribute__((unused)) *tx_freque { sound_t *sound; const char *env; + char *p; int rc; if (channels < 1 || channels > 2) { @@ -206,7 +199,13 @@ void *sound_open(const char *audiodev, double __attribute__((unused)) *tx_freque return NULL; } - sound->audiodev = strdup(audiodev); // is feed when closed + sound->paudiodev = strdup(audiodev); // is feed when closed + if ((p = strchr(sound->paudiodev, '/'))) { + *p++ = '\0'; + sound->caudiodev = p; + } else { + sound->caudiodev = sound->paudiodev; + } sound->channels = channels; sound->samplerate = samplerate; sound->spl_deviation = max_deviation / 32767.0; @@ -261,7 +260,7 @@ void sound_close(void *inst) sound_t *sound = (sound_t *)inst; dev_close(sound); - free(sound->audiodev); + free(sound->paudiodev); free(sound); } |