Renamed uvMeter to VU Meter (Volume Unit)

- Fixed issues flagged by code scanning bot.
This commit is contained in:
Michael Rochelle 2023-02-18 12:40:13 -08:00
parent bd0a0df900
commit 7edfe54ed7
8 changed files with 225 additions and 178 deletions

View File

@ -534,7 +534,7 @@
"edt_conf_audio_device_title": "Audio Device", "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_expl": "Select an effect on how the audio signal is transformed to",
"edt_conf_audio_effects_title": "Audio Effects", "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_expl": "Hot Color",
"edt_conf_audio_effect_hotcolor_title": "Hot Color", "edt_conf_audio_effect_hotcolor_title": "Hot Color",
"edt_conf_audio_effect_multiplier_expl": "Audio Signal Value multiplier", "edt_conf_audio_effect_multiplier_expl": "Audio Signal Value multiplier",

View File

@ -93,8 +93,8 @@
"grabberAudio": { "grabberAudio": {
"enable": false, "enable": false,
"device": "auto", "device": "auto",
"audioEffect": "uvMeter", "audioEffect": "vuMeter",
"uvMeter": { "vuMeter": {
"flip": "NO_CHANGE", "flip": "NO_CHANGE",
"hotColor": [ 255, 0, 0 ], "hotColor": [ 255, 0, 0 ],
"multiplier": 1, "multiplier": 1,

View File

@ -8,38 +8,83 @@
// Hyperion-utils includes // Hyperion-utils includes
#include <grabber/AudioGrabber.h> #include <grabber/AudioGrabber.h>
///
/// @brief The Linux Audio capture implementation
///
class AudioGrabberLinux : public AudioGrabber class AudioGrabberLinux : public AudioGrabber
{ {
// FIXME: Update and add descriptions for functions and class
public: public:
AudioGrabberLinux(); AudioGrabberLinux();
///
/// Process audio buffer
///
void processAudioBuffer(snd_pcm_sframes_t frames); void processAudioBuffer(snd_pcm_sframes_t frames);
///
/// Is Running Flag
///
std::atomic<bool> _isRunning; std::atomic<bool> _isRunning;
///
/// Current capture device
///
snd_pcm_t * _captureDevice; snd_pcm_t * _captureDevice;
public slots: public slots:
///
/// Start audio capturing session
///
/// @returns true if successful
bool start() override; bool start() override;
///
/// Stop audio capturing session
///
void stop() override; void stop() override;
///
/// Discovery audio devices
///
QJsonArray discover(const QJsonObject& params) override; QJsonArray discover(const QJsonObject& params) override;
private: private:
///
/// Refresh audio devices
///
void refreshDevices(); void refreshDevices();
///
/// Configure current audio capture interface
///
bool configureCaptureInterface(); bool configureCaptureInterface();
///
/// Get device name from path
///
QString getDeviceName(const QString& devicePath) const; QString getDeviceName(const QString& devicePath) const;
///
/// Current sample rate
///
unsigned int _sampleRate; unsigned int _sampleRate;
///
/// Audio capture thread
///
pthread_t _audioThread; pthread_t _audioThread;
///
/// ALSA device configuration parameters
///
snd_pcm_hw_params_t * _captureDeviceConfig; snd_pcm_hw_params_t * _captureDeviceConfig;
}; };
///
/// Audio processing thread function
///
static void* AudioThreadRunner(void* params); static void* AudioThreadRunner(void* params);
#endif // AUDIOGRABBERLINUX_H #endif // AUDIOGRABBERLINUX_H

View File

@ -10,11 +10,13 @@
#include <grabber/AudioGrabberLinux.h> #include <grabber/AudioGrabberLinux.h>
#endif #endif
///
/// Audio Grabber wrapper
///
class AudioWrapper : public GrabberWrapper class AudioWrapper : public GrabberWrapper
{ {
public: public:
// FIXME: Update and add descriptions for functions and class
// The AudioWrapper has no params... // The AudioWrapper has no params...
/// ///
@ -30,6 +32,9 @@ class AudioWrapper : public GrabberWrapper
/// ///
~AudioWrapper() override; ~AudioWrapper() override;
///
/// Settings update handler
///
void handleSettingsUpdate(settings::type type, const QJsonDocument& config) override; void handleSettingsUpdate(settings::type type, const QJsonDocument& config) override;
public slots: public slots:
@ -37,7 +42,16 @@ class AudioWrapper : public GrabberWrapper
/// Performs a single frame grab and computes the led-colors /// Performs a single frame grab and computes the led-colors
/// ///
void action() override; void action() override;
///
/// Start audio capturing session
///
/// @returns true if successful
bool start() override; bool start() override;
///
/// Stop audio capturing session
///
void stop() override; void stop() override;
private: private:

View File

@ -89,9 +89,7 @@ void AudioGrabber::processAudioFrame(int16_t* buffer, int length)
// TODO: Support Stereo capture with different meters per side // TODO: Support Stereo capture with different meters per side
// Default UVMeter - Later Make this pluggable for different audio effects // Default VUMeter - 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...
double averageAmplitude = 0; double averageAmplitude = 0;
// Calculate the the average amplitude value in the buffer // Calculate the the average amplitude value in the buffer

View File

@ -205,14 +205,7 @@ bool AudioGrabberLinux::start()
stop(); stop();
return false; 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<THREADFUNCPTR>(&AudioThreadRunner), static_cast<void*>(this)) != 0) if (pthread_create(&_audioThread, &threadAttributes, static_cast<THREADFUNCPTR>(&AudioThreadRunner), static_cast<void*>(this)) != 0)
{ {
Debug(_log, "Failed to create audio capture thread"); 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); ssize_t bytes = snd_pcm_frames_to_bytes(_captureDevice, frames);
int16_t * buffer = static_cast<int16_t*>(calloc(static_cast<size_t>(bytes / 2), sizeof(int16_t))); // * snd_pcm_format_width(SND_PCM_FORMAT_S16_LE) / 8 * 2); int16_t * buffer = static_cast<int16_t*>(calloc(static_cast<size_t>(bytes / 2), sizeof(int16_t)));
if (frames == 0) if (frames == 0)
{ {

View File

@ -35,21 +35,21 @@
"type": "string", "type": "string",
"title": "edt_conf_audio_effects_title", "title": "edt_conf_audio_effects_title",
"required": true, "required": true,
"enum": [ "uvMeter" ], "enum": [ "vuMeter" ],
"default": "uvMeter", "default": "vuMeter",
"options": { "options": {
"enum_titles": [ "edt_conf_audio_effect_enum_uvmeter"] "enum_titles": [ "edt_conf_audio_effect_enum_vumeter" ]
}, },
"propertyOrder": 4 "propertyOrder": 4
}, },
"uvMeter": { "vuMeter": {
"type": "object", "type": "object",
"title": "", "title": "",
"required": true, "required": true,
"propertyOrder": 5, "propertyOrder": 5,
"options": { "options": {
"dependencies": { "dependencies": {
"audioEffect": "uvMeter" "audioEffect": "vuMeter"
} }
}, },
"properties": { "properties": {

View File

@ -734,13 +734,10 @@ void HyperionDaemon::handleSettingsUpdate(settings::type settingsType, const QJs
_audioGrabber = new AudioWrapper(); _audioGrabber = new AudioWrapper();
_audioGrabber->handleSettingsUpdate(settings::AUDIO, getSetting(settings::AUDIO)); _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); connect(this, &HyperionDaemon::settingsChanged, _audioGrabber, &AudioWrapper::handleSettingsUpdate);
Debug(_log, "Audio grabber created"); Debug(_log, "Audio grabber created");
} }
//_audioGrabber->tryStart();
#else #else
Debug(_log, "Audio capture not supported on this platform"); Debug(_log, "Audio capture not supported on this platform");
#endif #endif