From 7edfe54ed7c43c293f99e1ebb2edb90cc210ccf2 Mon Sep 17 00:00:00 2001 From: Michael Rochelle Date: Sat, 18 Feb 2023 12:40:13 -0800 Subject: [PATCH] Renamed uvMeter to VU Meter (Volume Unit) - Fixed issues flagged by code scanning bot. --- assets/webconfig/i18n/en.json | 2 +- config/hyperion.config.json.default | 4 +- include/grabber/AudioGrabberLinux.h | 51 ++- include/grabber/AudioWrapper.h | 16 +- libsrc/grabber/audio/AudioGrabber.cpp | 4 +- libsrc/grabber/audio/AudioGrabberLinux.cpp | 11 +- .../hyperion/schema/schema-grabberAudio.json | 312 +++++++++--------- src/hyperiond/hyperiond.cpp | 3 - 8 files changed, 225 insertions(+), 178 deletions(-) diff --git a/assets/webconfig/i18n/en.json b/assets/webconfig/i18n/en.json index 46e3fbc0..00af79eb 100644 --- a/assets/webconfig/i18n/en.json +++ b/assets/webconfig/i18n/en.json @@ -534,7 +534,7 @@ "edt_conf_audio_device_title": "Audio Device", "edt_conf_audio_effects_expl": "Select an effect on how the audio signal is transformed to", "edt_conf_audio_effects_title": "Audio Effects", - "edt_conf_audio_effect_enum_uvmeter": "UV-Meter", + "edt_conf_audio_effect_enum_vumeter": "VU-Meter", "edt_conf_audio_effect_hotcolor_expl": "Hot Color", "edt_conf_audio_effect_hotcolor_title": "Hot Color", "edt_conf_audio_effect_multiplier_expl": "Audio Signal Value multiplier", diff --git a/config/hyperion.config.json.default b/config/hyperion.config.json.default index 59ebeb79..84218810 100644 --- a/config/hyperion.config.json.default +++ b/config/hyperion.config.json.default @@ -93,8 +93,8 @@ "grabberAudio": { "enable": false, "device": "auto", - "audioEffect": "uvMeter", - "uvMeter": { + "audioEffect": "vuMeter", + "vuMeter": { "flip": "NO_CHANGE", "hotColor": [ 255, 0, 0 ], "multiplier": 1, diff --git a/include/grabber/AudioGrabberLinux.h b/include/grabber/AudioGrabberLinux.h index 95db8664..41f9a20a 100644 --- a/include/grabber/AudioGrabberLinux.h +++ b/include/grabber/AudioGrabberLinux.h @@ -8,38 +8,83 @@ // Hyperion-utils includes #include +/// +/// @brief The Linux Audio capture implementation +/// class AudioGrabberLinux : public AudioGrabber { - - // FIXME: Update and add descriptions for functions and class public: AudioGrabberLinux(); + /// + /// Process audio buffer + /// void processAudioBuffer(snd_pcm_sframes_t frames); + /// + /// Is Running Flag + /// std::atomic _isRunning; + + /// + /// Current capture device + /// snd_pcm_t * _captureDevice; public slots: + /// + /// Start audio capturing session + /// + /// @returns true if successful bool start() override; + + /// + /// Stop audio capturing session + /// void stop() override; + + /// + /// Discovery audio devices + /// QJsonArray discover(const QJsonObject& params) override; private: - + /// + /// Refresh audio devices + /// void refreshDevices(); + + /// + /// Configure current audio capture interface + /// bool configureCaptureInterface(); + /// + /// Get device name from path + /// QString getDeviceName(const QString& devicePath) const; + /// + /// Current sample rate + /// unsigned int _sampleRate; + + /// + /// Audio capture thread + /// pthread_t _audioThread; + /// + /// ALSA device configuration parameters + /// snd_pcm_hw_params_t * _captureDeviceConfig; }; +/// +/// Audio processing thread function +/// static void* AudioThreadRunner(void* params); #endif // AUDIOGRABBERLINUX_H diff --git a/include/grabber/AudioWrapper.h b/include/grabber/AudioWrapper.h index 519b4be7..9e13c933 100644 --- a/include/grabber/AudioWrapper.h +++ b/include/grabber/AudioWrapper.h @@ -10,11 +10,13 @@ #include #endif +/// +/// Audio Grabber wrapper +/// class AudioWrapper : public GrabberWrapper { public: - // FIXME: Update and add descriptions for functions and class // The AudioWrapper has no params... /// @@ -30,6 +32,9 @@ class AudioWrapper : public GrabberWrapper /// ~AudioWrapper() override; + /// + /// Settings update handler + /// void handleSettingsUpdate(settings::type type, const QJsonDocument& config) override; public slots: @@ -37,7 +42,16 @@ class AudioWrapper : public GrabberWrapper /// Performs a single frame grab and computes the led-colors /// void action() override; + + /// + /// Start audio capturing session + /// + /// @returns true if successful bool start() override; + + /// + /// Stop audio capturing session + /// void stop() override; private: diff --git a/libsrc/grabber/audio/AudioGrabber.cpp b/libsrc/grabber/audio/AudioGrabber.cpp index 92aa9fdf..c715660d 100644 --- a/libsrc/grabber/audio/AudioGrabber.cpp +++ b/libsrc/grabber/audio/AudioGrabber.cpp @@ -89,9 +89,7 @@ void AudioGrabber::processAudioFrame(int16_t* buffer, int length) // TODO: Support Stereo capture with different meters per side - // Default UVMeter - Later Make this pluggable for different audio effects - // FIXME: We might already reflect different ways of audio image representation in the grabber JSON. I will provide a sample how it might look like... - + // Default VUMeter - Later Make this pluggable for different audio effects double averageAmplitude = 0; // Calculate the the average amplitude value in the buffer diff --git a/libsrc/grabber/audio/AudioGrabberLinux.cpp b/libsrc/grabber/audio/AudioGrabberLinux.cpp index 82ca1465..ea79793d 100644 --- a/libsrc/grabber/audio/AudioGrabberLinux.cpp +++ b/libsrc/grabber/audio/AudioGrabberLinux.cpp @@ -205,14 +205,7 @@ bool AudioGrabberLinux::start() stop(); return false; } - /* - if (pthread_attr_setschedparam(&threadAttributes, &schedulerParameter) != 0) - { - Debug(_log, "Failed to set scheduler parameters"); - stopAudio(); - return false; - } - */ + if (pthread_create(&_audioThread, &threadAttributes, static_cast(&AudioThreadRunner), static_cast(this)) != 0) { Debug(_log, "Failed to create audio capture thread"); @@ -250,7 +243,7 @@ void AudioGrabberLinux::processAudioBuffer(snd_pcm_sframes_t frames) ssize_t bytes = snd_pcm_frames_to_bytes(_captureDevice, frames); - int16_t * buffer = static_cast(calloc(static_cast(bytes / 2), sizeof(int16_t))); // * snd_pcm_format_width(SND_PCM_FORMAT_S16_LE) / 8 * 2); + int16_t * buffer = static_cast(calloc(static_cast(bytes / 2), sizeof(int16_t))); if (frames == 0) { diff --git a/libsrc/hyperion/schema/schema-grabberAudio.json b/libsrc/hyperion/schema/schema-grabberAudio.json index f7824b91..b4225872 100644 --- a/libsrc/hyperion/schema/schema-grabberAudio.json +++ b/libsrc/hyperion/schema/schema-grabberAudio.json @@ -2,162 +2,162 @@ "type": "object", "required": true, "title": "edt_conf_audio_heading_title", - "properties": { - "enable": { - "type": "boolean", - "title": "edt_conf_general_enable_title", - "required": true, - "default": false, - "propertyOrder": 1 - }, - "available_devices": { - "type": "string", - "title": "edt_conf_grabber_discovered_title", - "default": "edt_conf_grabber_discovery_inprogress", - "options": { - "infoText": "edt_conf_grabber_discovered_title_info" - }, - "propertyOrder": 2, - "required": false - }, - "device": { - "type": "string", - "title": "edt_conf_enum_custom", - "default": "auto", - "options": { - "hidden": true - }, - "required": true, - "propertyOrder": 3, - "comment": "The 'available_audio_devices' settings are dynamically inserted into the WebUI under PropertyOrder '1'." - }, - "audioEffect": { - "type": "string", - "title": "edt_conf_audio_effects_title", - "required": true, - "enum": [ "uvMeter" ], - "default": "uvMeter", - "options": { - "enum_titles": [ "edt_conf_audio_effect_enum_uvmeter"] - }, - "propertyOrder": 4 - }, - "uvMeter": { - "type": "object", - "title": "", - "required": true, - "propertyOrder": 5, - "options": { - "dependencies": { - "audioEffect": "uvMeter" + "properties": { + "enable": { + "type": "boolean", + "title": "edt_conf_general_enable_title", + "required": true, + "default": false, + "propertyOrder": 1 + }, + "available_devices": { + "type": "string", + "title": "edt_conf_grabber_discovered_title", + "default": "edt_conf_grabber_discovery_inprogress", + "options": { + "infoText": "edt_conf_grabber_discovered_title_info" + }, + "propertyOrder": 2, + "required": false + }, + "device": { + "type": "string", + "title": "edt_conf_enum_custom", + "default": "auto", + "options": { + "hidden": true + }, + "required": true, + "propertyOrder": 3, + "comment": "The 'available_audio_devices' settings are dynamically inserted into the WebUI under PropertyOrder '1'." + }, + "audioEffect": { + "type": "string", + "title": "edt_conf_audio_effects_title", + "required": true, + "enum": [ "vuMeter" ], + "default": "vuMeter", + "options": { + "enum_titles": [ "edt_conf_audio_effect_enum_vumeter" ] + }, + "propertyOrder": 4 + }, + "vuMeter": { + "type": "object", + "title": "", + "required": true, + "propertyOrder": 5, + "options": { + "dependencies": { + "audioEffect": "vuMeter" + } + }, + "properties": { + "multiplier": { + "type": "number", + "title": "edt_conf_audio_effect_multiplier_title", + "default": 1, + "minimum": 0, + "step": 0.01, + "required": true, + "propertyOrder": 1, + "comment": "The multiplier is used to scale the audio input signal. Increase or decrease to achieve the desired effect. Set to 0 for auto" + }, + "tolerance": { + "type": "number", + "title": "edt_conf_audio_effect_tolerance_title", + "default": 5, + "minimum": 0, + "step": 1, + "append": "edt_append_percent", + "required": true, + "propertyOrder": 2, + "comment": "The tolerance is a percentage value from 0 - 100 used during auto multiplier calculation." + }, + "hotColor": { + "type": "array", + "title": "edt_conf_audio_effect_hotcolor_title", + "default": [ 255, 0, 0 ], + "format": "colorpicker", + "items": { + "type": "integer", + "minimum": 0, + "maximum": 255 + }, + "minItems": 3, + "maxItems": 3, + "required": true, + "propertyOrder": 3, + "comment": "Hot Color is the color the led's will reach when audio level exceeds the warn percentage" + }, + "warnColor": { + "type": "array", + "title": "edt_conf_audio_effect_warncolor_title", + "default": [ 255, 255, 0 ], + "format": "colorpicker", + "items": { + "type": "integer", + "minimum": 0, + "maximum": 255 + }, + "minItems": 3, + "maxItems": 3, + "required": true, + "propertyOrder": 4, + "comment": "Warn Color is the color the led's will reach when audio level exceeds the safe percentage" + }, + "warnValue": { + "type": "number", + "title": "edt_conf_audio_effect_warnvalue_title", + "default": 80, + "minimum": 0, + "step": 1, + "append": "edt_append_percent", + "required": true, + "propertyOrder": 5, + "comment": "Warn percentage is the percentage used to determine the maximum percentage of the audio warning level" + }, + "safeColor": { + "type": "array", + "title": "edt_conf_audio_effect_safecolor_title", + "default": [ 0, 255, 0 ], + "format": "colorpicker", + "items": { + "type": "integer", + "minimum": 0, + "maximum": 255 + }, + "minItems": 3, + "maxItems": 3, + "required": true, + "propertyOrder": 6, + "comment": "Safe Color is the color the led's will reach when audio level is below the warning percentage" + }, + "safeValue": { + "type": "number", + "title": "edt_conf_audio_effect_safevalue_title", + "default": 45, + "minimum": 0, + "step": 1, + "append": "edt_append_percent", + "required": true, + "propertyOrder": 7, + "comment": "Safe percentage is the percentage used to determine the maximum percentage of the audio safe level" + }, + "flip": { + "type": "string", + "title": "edt_conf_v4l2_flip_title", + "enum": [ "NO_CHANGE", "HORIZONTAL", "VERTICAL", "BOTH" ], + "default": "NO_CHANGE", + "options": { + "enum_titles": [ "edt_conf_enum_NO_CHANGE", "edt_conf_enum_HORIZONTAL", "edt_conf_enum_VERTICAL", "edt_conf_enum_BOTH" ] + }, + "required": true, + "access": "advanced", + "propertyOrder": 8 + } + } } - }, - "properties": { - "multiplier": { - "type": "number", - "title": "edt_conf_audio_effect_multiplier_title", - "default": 1, - "minimum": 0, - "step": 0.01, - "required": true, - "propertyOrder": 1, - "comment": "The multiplier is used to scale the audio input signal. Increase or decrease to achieve the desired effect. Set to 0 for auto" - }, - "tolerance": { - "type": "number", - "title": "edt_conf_audio_effect_tolerance_title", - "default": 5, - "minimum": 0, - "step": 1, - "append": "edt_append_percent", - "required": true, - "propertyOrder": 2, - "comment": "The tolerance is a percentage value from 0 - 100 used during auto multiplier calculation." - }, - "hotColor": { - "type": "array", - "title": "edt_conf_audio_effect_hotcolor_title", - "default": [ 255, 0, 0 ], - "format": "colorpicker", - "items": { - "type": "integer", - "minimum": 0, - "maximum": 255 - }, - "minItems": 3, - "maxItems": 3, - "required": true, - "propertyOrder": 3, - "comment": "Hot Color is the color the led's will reach when audio level exceeds the warn percentage" - }, - "warnColor": { - "type": "array", - "title": "edt_conf_audio_effect_warncolor_title", - "default": [ 255, 255, 0 ], - "format": "colorpicker", - "items": { - "type": "integer", - "minimum": 0, - "maximum": 255 - }, - "minItems": 3, - "maxItems": 3, - "required": true, - "propertyOrder": 4, - "comment": "Warn Color is the color the led's will reach when audio level exceeds the safe percentage" - }, - "warnValue": { - "type": "number", - "title": "edt_conf_audio_effect_warnvalue_title", - "default": 80, - "minimum": 0, - "step": 1, - "append": "edt_append_percent", - "required": true, - "propertyOrder": 5, - "comment": "Warn percentage is the percentage used to determine the maximum percentage of the audio warning level" - }, - "safeColor": { - "type": "array", - "title": "edt_conf_audio_effect_safecolor_title", - "default": [ 0, 255, 0 ], - "format": "colorpicker", - "items": { - "type": "integer", - "minimum": 0, - "maximum": 255 - }, - "minItems": 3, - "maxItems": 3, - "required": true, - "propertyOrder": 6, - "comment": "Safe Color is the color the led's will reach when audio level is below the warning percentage" - }, - "safeValue": { - "type": "number", - "title": "edt_conf_audio_effect_safevalue_title", - "default": 45, - "minimum": 0, - "step": 1, - "append": "edt_append_percent", - "required": true, - "propertyOrder": 7, - "comment": "Safe percentage is the percentage used to determine the maximum percentage of the audio safe level" - }, - "flip": { - "type": "string", - "title": "edt_conf_v4l2_flip_title", - "enum": [ "NO_CHANGE", "HORIZONTAL", "VERTICAL", "BOTH" ], - "default": "NO_CHANGE", - "options": { - "enum_titles": [ "edt_conf_enum_NO_CHANGE", "edt_conf_enum_HORIZONTAL", "edt_conf_enum_VERTICAL", "edt_conf_enum_BOTH" ] - }, - "required": true, - "access": "advanced", - "propertyOrder": 8 - } - } - } - }, + }, "additionalProperties": true } diff --git a/src/hyperiond/hyperiond.cpp b/src/hyperiond/hyperiond.cpp index 44eadf0a..b1ba12d4 100644 --- a/src/hyperiond/hyperiond.cpp +++ b/src/hyperiond/hyperiond.cpp @@ -734,13 +734,10 @@ void HyperionDaemon::handleSettingsUpdate(settings::type settingsType, const QJs _audioGrabber = new AudioWrapper(); _audioGrabber->handleSettingsUpdate(settings::AUDIO, getSetting(settings::AUDIO)); - //connect(this, &HyperionDaemon::setVideoMode, _audioGrabber, &AudioWrapper::setVideoMode); // Do we need this? connect(this, &HyperionDaemon::settingsChanged, _audioGrabber, &AudioWrapper::handleSettingsUpdate); Debug(_log, "Audio grabber created"); } - - //_audioGrabber->tryStart(); #else Debug(_log, "Audio capture not supported on this platform"); #endif