hyperion.ng/include/grabber/AudioGrabber.h
Michael Rochelle acdf733936
Audio Grabber Feature (#1570)
* Creating Audio Grabber

Creating Audio Grabber

Creating Audio Grabber.

Successfully began capturing audio in windows. Starting to implement a hard-coded UV Visualizer.

Got Windows DirectSound Implementation working.
Hardcoded basic VU Meter.

Begin working on linux audio grabber implementation.

Finished Linux Draft Implementation.
Minor Mods to windows implementation.

Windows:
 - Free memory used by device id.
 - Prevent starting audio if the grabber is disabled
 - More debug logging

Linux:
 - Prevent starting audio if the grabber is disabled

Added strings to english
Removed "custom" from device selection
Made hard-coded visualizer values configurable.
wrote values to imageData with BGR priority to enable configurable values to be set in RGB format.
created logic to support "Automatic" to enable the API to select the default device.

Add language key for audio in "Remote Control" section.
Removed audio configuration for number of channels. This was causing an error with some devices.

Fixed logic to update capture while its active.
Optimizing code .

UI Tweaks
Destructuring.

Fixed build error on linux.

Custom Effects - Clean-ups and Enhancements (#1163)

* Cleanup EffectFileHandler

* Support Custom Effect Schemas and align EffectFileHandler

* Change back to colon prefix for system effects

* WebSockets - Fix error in handling fragmented frames

* Correct missing colon updates

* Update json with image file location for custom gif effects

* Image effect deletion - considere full filename is stored in JSON

* Correct selection lists indentions

Creating Audio Grabber

Creating Audio Grabber

Creating Audio Grabber.

Successfully began capturing audio in windows. Starting to implement a hard-coded UV Visualizer.

Got Windows DirectSound Implementation working.
Hardcoded basic VU Meter.

Begin working on linux audio grabber implementation.

Finished Linux Draft Implementation.
Minor Mods to windows implementation.

Windows:
 - Free memory used by device id.
 - Prevent starting audio if the grabber is disabled
 - More debug logging

Linux:
 - Prevent starting audio if the grabber is disabled

Added strings to english
Removed "custom" from device selection
Made hard-coded visualizer values configurable.
wrote values to imageData with BGR priority to enable configurable values to be set in RGB format.
created logic to support "Automatic" to enable the API to select the default device.

Add language key for audio in "Remote Control" section.
Removed audio configuration for number of channels. This was causing an error with some devices.

Fixed logic to update capture while its active.
Optimizing code .

UI Tweaks
Destructuring.

Fixed build error on linux.

Commented setVideoMode from AudioGrabber.

Linux Threading changes.

Implementing new API

Continuing to implement audio into new APIs

Fixed Audio Grabber for DirectSound on Windows
Fixed UI for Audio Grabber Configuration
Default AUDIO to off unless specified.

fixed missing #ifdef for audio grabber.

Added logic to calculate a dynamic multiplier from the signal input.

Updating linux api for discovering devices.

Fixed HTML/JS issues with view.
Fixed NPE in Windows.
Disabled setting thread priority in linux.

updated the schema options check to pass through hidden states and commented the change.

Updated grabber start conditions
Updated Audio grabber to instantiate similar to video grabber

Updated windows grabber to set "started" flag to false when shutting down.
Removed "tryStart" to prevent enabling audio capture unnecessarily.

Fixing instance audio grabber device configuration

Added configurable resolution
Reduced tolerance to 5%
Fixed issue where grabber failed for additional instances when "start" was called multiple times.

Fixed resolution calculation

Change averaging algorithm to prevent overflowing the sum.

Updated logic to stop audio grabber when disabled.

Fix integer casting and rounding.

Restart grabber on configuration change.
Fix missing include/grabber/AudioGrabber.
Disable tolerance.

Added configurable tolerance.
Fixed tolerance algorithm.
reset multiplier on configuration change.

Line Endings

Proposed change and questions/request to fix

implementing more of LordGrey's suggestions.

Fix mode for snd_pcm_open. Latest ALSA uses SND_PCM_NONBLOCK instead of SND_PCM_OPEN_NONBLOCK
defaulted multiplier to 0 "auto"
defaulted tolerance to 20%

changed 100 to 100.0 for pixel value percentage calculation to fix value from being 0.

missed a 100 as a double so precision isn't lost during math operation.

Fix Windows grabber and further cleanups

Enable Audio grabbing in standard build

Remove empty methods

Fix audio capture priority setting

Remove unused code

Clean-up default config

Allow additional json-editor attributes

Allow multiple effects and resetting to defaults

Correct default values

Allow to build for Qt < 5.14

Update CodeQL build dependency

Update build dependencies

Remove effect1 placeholder

* Renamed uvMeter to VU Meter (Volume Unit)
- Fixed issues flagged by code scanning bot.

* Moved stop call into destructor of implementing class.

* Removed commented linux audio channel configuration logic.

---------

Co-authored-by: Michael Rochelle <michael@j2inn.com>
2023-02-19 09:36:39 +01:00

197 lines
4.3 KiB
C++

#ifndef AUDIOGRABBER_H
#define AUDIOGRABBER_H
#include <QObject>
#include <QColor>
#include <cmath>
// Hyperion-utils includes
#include <utils/ColorRgb.h>
#include <hyperion/Grabber.h>
#include <utils/Logger.h>
///
/// Base Audio Grabber Class
///
/// This class is extended by the windows audio grabber to provied DirectX9 access to the audio devices
/// This class is extended by the linux audio grabber to provide ALSA access to the audio devices
///
/// @brief The DirectX9 capture implementation
///
class AudioGrabber : public Grabber
{
Q_OBJECT
public:
///
/// Device properties
///
/// this structure holds the name, id, and inputs of the enumerated audio devices.
///
struct DeviceProperties
{
QString name = QString();
QString id = QString();
QMultiMap<QString, int> inputs = QMultiMap<QString, int>();
};
AudioGrabber();
~AudioGrabber() override;
///
/// Start audio capturing session
///
/// @returns true if successful
virtual bool start();
///
/// Stop audio capturing session
///
virtual void stop();
///
/// Restart the audio capturing session
///
void restart();
Logger* getLog();
///
/// Set Device
///
/// configures the audio device used by the grabber
///
/// @param[in] device identifier of audio device
void setDevice(const QString& device);
///
/// Set Configuration
///
/// sets the audio grabber's configuration parameters
///
/// @param[in] config object of configuration parameters
void setConfiguration(const QJsonObject& config);
///
/// Reset Multiplier
///
/// resets the calcualted audio multiplier so that it is recalculated
/// currently the multiplier is only reduced based on loudness.
///
/// TODO: also calculate a low signal and reset the multiplier
///
void resetMultiplier();
///
/// Discover
///
/// discovers audio devices in the system
///
/// @param[in] params discover parameters
/// @return array of audio devices
virtual QJsonArray discover(const QJsonObject& params);
signals:
void newFrame(const Image<ColorRgb>& image);
protected:
///
/// Process Audio Frame
///
/// this functions takes in an audio buffer and emits a visual representation of the audio data
///
/// @param[in] buffer The audio buffer to process
/// @param[in] length The length of audio data in the buffer
void processAudioFrame(int16_t* buffer, int length);
///
/// Audio device id / properties map
///
/// properties include information such as name, inputs, and etc...
///
QMap<QString, AudioGrabber::DeviceProperties> _deviceProperties;
///
/// Current device
///
QString _device;
///
/// Hot Color
///
/// the color of the leds when the signal is high or hot
///
QColor _hotColor;
///
/// Warn value
///
/// The maximum value of the warning color. above this threshold the signal is considered hot
///
int _warnValue;
///
/// Warn color
///
/// the color of the leds when the signal is in between the safe and warn value threshold
///
QColor _warnColor;
///
/// Save value
///
/// The maximum value of the safe color. above this threshold the signal enteres the warn zone.
/// below the signal is in the safe zone.
///
int _safeValue;
///
/// Safe color
///
/// the color of the leds when the signal is below the safe threshold
///
QColor _safeColor;
///
/// Multiplier
///
/// this value is used to multiply the input signal value. Some inputs may have a very low signal
/// and the multiplier is used to get the desired visualization.
///
/// When the multiplier is configured to 0, the multiplier is automatically configured based off of the average
/// signal amplitude and tolernace.
///
double _multiplier;
///
/// Tolerance
///
/// The tolerance is used to calculate what percentage of the top end part of the signal to ignore when
/// calculating the multiplier. This enables the effect to reach the hot zone with an auto configured multiplier
///
int _tolerance;
///
/// Dynamic Multiplier
///
/// This is the current value of the automatically configured multiplier.
///
double _dynamicMultiplier;
///
/// Started
///
/// true if the capturing session has started.
///
bool _started;
private:
///
/// @brief free the _screen pointer
///
void freeResources();
};
#endif // AUDIOGRABBER_H