From e55b73056ded4218d687168b1989b6fe8ef5c917 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 6 Feb 2023 00:46:30 +0100 Subject: [PATCH 1/3] Plugins (portaudio): Report why the input stream could not be opened --- .../plugins/input/portaudio/input_portaudio.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libvisual-plugins/plugins/input/portaudio/input_portaudio.c b/libvisual-plugins/plugins/input/portaudio/input_portaudio.c index 486c76ac5..735741682 100644 --- a/libvisual-plugins/plugins/input/portaudio/input_portaudio.c +++ b/libvisual-plugins/plugins/input/portaudio/input_portaudio.c @@ -103,7 +103,12 @@ int inp_portaudio_init (VisPluginData *plugin) const PaError open_error = Pa_OpenStream (&priv->stream, &input_parameters, NULL, SAMPLE_RATE, FRAMES, paClipOff, NULL, NULL); - visual_log_return_val_if_fail (open_error == paNoError, -3); + if (open_error != paNoError) { + visual_log (VISUAL_LOG_CRITICAL, + "PortAudio: Could not open input stream, error %d \"%s\".", + open_error, Pa_GetErrorText (open_error)); + return -3; + } // Allocate buffer const visual_size_t buffer_size_bytes = FRAMES * CHANNELS * (SAMPLE_FORMAT_BITS / 8); From bbfca070df631c0b22476b457baa230f02c82f95 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 6 Feb 2023 21:50:49 +0100 Subject: [PATCH 2/3] Plugins (portaudio): Fall back to mono input when stereo fails .. with an "Invalid number of channels" error. --- .../plugins/input/portaudio/input_portaudio.c | 66 +++++++++++++++---- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/libvisual-plugins/plugins/input/portaudio/input_portaudio.c b/libvisual-plugins/plugins/input/portaudio/input_portaudio.c index 735741682..b65b42f67 100644 --- a/libvisual-plugins/plugins/input/portaudio/input_portaudio.c +++ b/libvisual-plugins/plugins/input/portaudio/input_portaudio.c @@ -29,8 +29,6 @@ VISUAL_PLUGIN_API_VERSION_VALIDATOR #define SAMPLE_RATE 44100 #define SAMPLE_RATE_TYPE_LV VISUAL_AUDIO_SAMPLE_RATE_44100 -#define CHANNELS 2 -#define CHANNELS_TYPE VISUAL_AUDIO_SAMPLE_CHANNEL_STEREO #define SAMPLE_FORMAT_BITS 16 #define SAMPLE_FORMAT_PA paInt16 #define SAMPLE_FORMAT_LV VISUAL_AUDIO_SAMPLE_FORMAT_S16 @@ -39,6 +37,7 @@ VISUAL_PLUGIN_API_VERSION_VALIDATOR typedef struct { PaStream *stream; + unsigned int channel_count; // 0 (unknown), 1 (mono) or 2 (stereo) void * buffer; } PortAudioPrivate; @@ -93,25 +92,46 @@ int inp_portaudio_init (VisPluginData *plugin) visual_log_return_val_if_fail (input_device != paNoDevice, -3); // Open stream + // Try stereo first, fall back to mono as needed + priv->channel_count = 2; // i.e. stereo const double latency_seconds = 1.0 / SAMPLE_RATE * FRAMES; - const PaStreamParameters input_parameters = { + PaStreamParameters input_parameters = { .device = input_device, - .channelCount = CHANNELS, + .channelCount = priv->channel_count, .sampleFormat = SAMPLE_FORMAT_PA, .suggestedLatency = latency_seconds, .hostApiSpecificStreamInfo = NULL}; - const PaError open_error = + const PaError stereo_open_error = Pa_OpenStream (&priv->stream, &input_parameters, NULL, SAMPLE_RATE, FRAMES, paClipOff, NULL, NULL); - if (open_error != paNoError) { - visual_log (VISUAL_LOG_CRITICAL, - "PortAudio: Could not open input stream, error %d \"%s\".", - open_error, Pa_GetErrorText (open_error)); - return -3; + if (stereo_open_error != paNoError) { + if (stereo_open_error != paInvalidChannelCount) { + visual_log (VISUAL_LOG_CRITICAL, + "PortAudio: Could not open stereo input stream, error %d \"%s\".", + stereo_open_error, Pa_GetErrorText (stereo_open_error)); + return -3; + } + + // Try again with mono + assert(stereo_open_error == paInvalidChannelCount); + visual_log (VISUAL_LOG_INFO, "PortAudio: Could not open stereo input stream, trying again with mono."); + priv->channel_count = 1; // i.e. mono + input_parameters.channelCount = priv->channel_count; + + const PaError mono_open_error = + Pa_OpenStream (&priv->stream, &input_parameters, NULL, + SAMPLE_RATE, FRAMES, paClipOff, NULL, NULL); + if (mono_open_error != paNoError) { + visual_log (VISUAL_LOG_CRITICAL, + "PortAudio: Could not open mono input stream, error %d \"%s\".", + mono_open_error, Pa_GetErrorText (mono_open_error)); + return -3; + } } + visual_log (VISUAL_LOG_INFO, "PortAudio: Input stream opened with %d channel(s).", priv->channel_count); // Allocate buffer - const visual_size_t buffer_size_bytes = FRAMES * CHANNELS * (SAMPLE_FORMAT_BITS / 8); + const visual_size_t buffer_size_bytes = FRAMES * priv->channel_count * (SAMPLE_FORMAT_BITS / 8); priv->buffer = malloc (buffer_size_bytes); visual_log_return_val_if_fail (priv->buffer != NULL, -4); @@ -166,13 +186,31 @@ int inp_portaudio_upload (VisPluginData *plugin, VisAudio *audio) return 0; } - const visual_size_t bytes_to_write = frames_to_read * CHANNELS * (SAMPLE_FORMAT_BITS / 8); + const visual_size_t bytes_to_write = frames_to_read * priv->channel_count * (SAMPLE_FORMAT_BITS / 8); VisBuffer buffer; visual_buffer_init(&buffer, priv->buffer, bytes_to_write, NULL); - visual_audio_samplepool_input(audio->samplepool, &buffer, SAMPLE_RATE_TYPE_LV, - SAMPLE_FORMAT_LV, CHANNELS_TYPE); + if (priv->channel_count == 2) { + visual_audio_samplepool_input(audio->samplepool, &buffer, SAMPLE_RATE_TYPE_LV, + SAMPLE_FORMAT_LV, VISUAL_AUDIO_SAMPLE_CHANNEL_STEREO); + } else { + assert(priv->channel_count == 1); + + // Let's feed the same mono input to both the left and right channel. + // This helps actors plugins that call + // "visual_audio_get_sample ([..], [..], VISUAL_AUDIO_CHANNEL_RIGHT)" + // explicitly without checking return values. + const char * const channels[] = { + VISUAL_AUDIO_CHANNEL_LEFT, + VISUAL_AUDIO_CHANNEL_RIGHT + }; + + for (size_t i = 0; i < sizeof(channels) / sizeof(channels[0]); i++) { + visual_audio_samplepool_input_channel(audio->samplepool, &buffer, SAMPLE_RATE_TYPE_LV, + SAMPLE_FORMAT_LV, channels[i]); + } + } } // we never get here From ba33b0c039ca17e463662ad95024980b47671618 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 14 Feb 2023 16:36:39 +0100 Subject: [PATCH 3/3] Plugins: Sync translations --- libvisual-plugins/po/de.po | 6 +++--- libvisual-plugins/po/es_AR.po | 6 +++--- libvisual-plugins/po/es_ES.po | 6 +++--- libvisual-plugins/po/libvisual-plugins-0.4.pot | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libvisual-plugins/po/de.po b/libvisual-plugins/po/de.po index b67161da1..f24e7436a 100644 --- a/libvisual-plugins/po/de.po +++ b/libvisual-plugins/po/de.po @@ -11,7 +11,7 @@ msgid "" msgstr "" "Project-Id-Version: libvisual-plugins 0.4.0\n" "Report-Msgid-Bugs-To: https://github.com/Libvisual/libvisual/issues/\n" -"POT-Creation-Date: 2023-02-14 16:26+0100\n" +"POT-Creation-Date: 2023-02-14 16:36+0100\n" "PO-Revision-Date: 2017-11-23 18:08:07+0200\n" "Last-Translator: Chris Leick \n" "Language-Team: German \n" @@ -520,11 +520,11 @@ msgstr "falscher Dateideskriptor %d" msgid "Could not munmap() area %p+%d. %s" msgstr "munmap() von Bereich %p+%d nicht möglich. %s" -#: plugins/input/portaudio/input_portaudio.c:62 +#: plugins/input/portaudio/input_portaudio.c:61 msgid "PortAudio capture plugin" msgstr "PortAudio-Erfassungserweiterung" -#: plugins/input/portaudio/input_portaudio.c:63 +#: plugins/input/portaudio/input_portaudio.c:62 msgid "Use this plugin to capture PCM data from the PortAudio record device" msgstr "" "Benutzen Sie diese Erweiterung, um PCM-Daten vom PortAudio-Aufzeichungsgerät " diff --git a/libvisual-plugins/po/es_AR.po b/libvisual-plugins/po/es_AR.po index e3a2a0cba..345b9496d 100644 --- a/libvisual-plugins/po/es_AR.po +++ b/libvisual-plugins/po/es_AR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Libvisual plugins 0.3.0\n" "Report-Msgid-Bugs-To: https://github.com/Libvisual/libvisual/issues/\n" -"POT-Creation-Date: 2023-02-14 16:26+0100\n" +"POT-Creation-Date: 2023-02-14 16:36+0100\n" "PO-Revision-Date: 2005-03-16 00:11-0300\n" "Last-Translator: Duilio Javier Protti \n" "Language-Team: Spanish \n" @@ -504,11 +504,11 @@ msgstr "%d es un descriptor de archivo erróneo" msgid "Could not munmap() area %p+%d. %s" msgstr "No se puede munmap()-ear área %p+%d: %s" -#: plugins/input/portaudio/input_portaudio.c:62 +#: plugins/input/portaudio/input_portaudio.c:61 msgid "PortAudio capture plugin" msgstr "Plugin de captura de audio PortAudio" -#: plugins/input/portaudio/input_portaudio.c:63 +#: plugins/input/portaudio/input_portaudio.c:62 msgid "Use this plugin to capture PCM data from the PortAudio record device" msgstr "" "Use este plugin para capturar datos PCM del dispositivo de grabación " diff --git a/libvisual-plugins/po/es_ES.po b/libvisual-plugins/po/es_ES.po index 77526d93a..95f435b4f 100644 --- a/libvisual-plugins/po/es_ES.po +++ b/libvisual-plugins/po/es_ES.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Libvisual plugins 0.3.0\n" "Report-Msgid-Bugs-To: https://github.com/Libvisual/libvisual/issues/\n" -"POT-Creation-Date: 2023-02-14 16:26+0100\n" +"POT-Creation-Date: 2023-02-14 16:36+0100\n" "PO-Revision-Date: 2005-03-16 00:11-0300\n" "Last-Translator: Duilio Javier Protti \n" "Language-Team: Spanish \n" @@ -504,11 +504,11 @@ msgstr "%d es un descriptor de archivo erróneo" msgid "Could not munmap() area %p+%d. %s" msgstr "No se puede munmap()-ear área %p+%d: %s" -#: plugins/input/portaudio/input_portaudio.c:62 +#: plugins/input/portaudio/input_portaudio.c:61 msgid "PortAudio capture plugin" msgstr "Plugin de captura de audio PortAudio" -#: plugins/input/portaudio/input_portaudio.c:63 +#: plugins/input/portaudio/input_portaudio.c:62 msgid "Use this plugin to capture PCM data from the PortAudio record device" msgstr "" "Use este plugin para capturar datos PCM del dispositivo de grabación " diff --git a/libvisual-plugins/po/libvisual-plugins-0.4.pot b/libvisual-plugins/po/libvisual-plugins-0.4.pot index cab911089..243022a8f 100644 --- a/libvisual-plugins/po/libvisual-plugins-0.4.pot +++ b/libvisual-plugins/po/libvisual-plugins-0.4.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: libvisual-plugins 0.4.1\n" "Report-Msgid-Bugs-To: https://github.com/Libvisual/libvisual/issues/\n" -"POT-Creation-Date: 2023-02-14 16:26+0100\n" +"POT-Creation-Date: 2023-02-14 16:36+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -478,10 +478,10 @@ msgstr "" msgid "Could not munmap() area %p+%d. %s" msgstr "" -#: plugins/input/portaudio/input_portaudio.c:62 +#: plugins/input/portaudio/input_portaudio.c:61 msgid "PortAudio capture plugin" msgstr "" -#: plugins/input/portaudio/input_portaudio.c:63 +#: plugins/input/portaudio/input_portaudio.c:62 msgid "Use this plugin to capture PCM data from the PortAudio record device" msgstr ""