mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-03-12 17:22:59 +00:00
Merge pull request #85 from tim-gromeyer/linux-adaptive-noise-level
[Linux] Implement adaptive audio noise
This commit is contained in:
@@ -36,5 +36,41 @@ ApplicationWindow {
|
|||||||
checked: airPodsTrayApp.conversationalAwareness
|
checked: airPodsTrayApp.conversationalAwareness
|
||||||
onCheckedChanged: airPodsTrayApp.conversationalAwareness = checked
|
onCheckedChanged: airPodsTrayApp.conversationalAwareness = checked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Slider {
|
||||||
|
visible: airPodsTrayApp.adaptiveModeActive
|
||||||
|
from: 0
|
||||||
|
to: 100
|
||||||
|
stepSize: 1
|
||||||
|
value: airPodsTrayApp.adaptiveNoiseLevel
|
||||||
|
|
||||||
|
property Timer debounceTimer: Timer {
|
||||||
|
interval: 500 // 500ms delay after last change
|
||||||
|
onTriggered: {
|
||||||
|
if (!parent.pressed) {
|
||||||
|
airPodsTrayApp.setAdaptiveNoiseLevel(parent.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onPressedChanged: {
|
||||||
|
if (!pressed) {
|
||||||
|
debounceTimer.stop()
|
||||||
|
airPodsTrayApp.setAdaptiveNoiseLevel(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onValueChanged: {
|
||||||
|
if (pressed) {
|
||||||
|
debounceTimer.restart()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: "Adaptive Noise Level: " + parent.value
|
||||||
|
color: "#ffffff"
|
||||||
|
anchors.top: parent.bottom
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,6 +63,17 @@ namespace AirPodsPackets
|
|||||||
static const QByteArray DISCONNECT_REQUEST = QByteArray::fromHex("00020000");
|
static const QByteArray DISCONNECT_REQUEST = QByteArray::fromHex("00020000");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adaptive Noise Packets
|
||||||
|
namespace AdaptiveNoise
|
||||||
|
{
|
||||||
|
const QByteArray HEADER = QByteArray::fromHex("0400040009002E");
|
||||||
|
|
||||||
|
inline QByteArray getPacket(int level)
|
||||||
|
{
|
||||||
|
return HEADER + static_cast<char>(level) + QByteArray::fromHex("000000");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parsing Headers
|
// Parsing Headers
|
||||||
namespace Parse
|
namespace Parse
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ class AirPodsTrayApp : public QObject {
|
|||||||
Q_PROPERTY(QString earDetectionStatus READ earDetectionStatus NOTIFY earDetectionStatusChanged)
|
Q_PROPERTY(QString earDetectionStatus READ earDetectionStatus NOTIFY earDetectionStatusChanged)
|
||||||
Q_PROPERTY(int noiseControlMode READ noiseControlMode WRITE setNoiseControlMode NOTIFY noiseControlModeChanged)
|
Q_PROPERTY(int noiseControlMode READ noiseControlMode WRITE setNoiseControlMode NOTIFY noiseControlModeChanged)
|
||||||
Q_PROPERTY(bool conversationalAwareness READ conversationalAwareness WRITE setConversationalAwareness NOTIFY conversationalAwarenessChanged)
|
Q_PROPERTY(bool conversationalAwareness READ conversationalAwareness WRITE setConversationalAwareness NOTIFY conversationalAwarenessChanged)
|
||||||
|
Q_PROPERTY(int adaptiveNoiseLevel READ adaptiveNoiseLevel WRITE setAdaptiveNoiseLevel NOTIFY adaptiveNoiseLevelChanged)
|
||||||
|
Q_PROPERTY(bool adaptiveModeActive READ adaptiveModeActive NOTIFY noiseControlModeChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AirPodsTrayApp(bool debugMode) : debugMode(debugMode) {
|
AirPodsTrayApp(bool debugMode) : debugMode(debugMode) {
|
||||||
@@ -96,6 +98,8 @@ public:
|
|||||||
QString earDetectionStatus() const { return m_earDetectionStatus; }
|
QString earDetectionStatus() const { return m_earDetectionStatus; }
|
||||||
int noiseControlMode() const { return static_cast<int>(m_noiseControlMode); }
|
int noiseControlMode() const { return static_cast<int>(m_noiseControlMode); }
|
||||||
bool conversationalAwareness() const { return m_conversationalAwareness; }
|
bool conversationalAwareness() const { return m_conversationalAwareness; }
|
||||||
|
bool adaptiveModeActive() const { return m_noiseControlMode == NoiseControlMode::Adaptive; }
|
||||||
|
int adaptiveNoiseLevel() const { return m_adaptiveNoiseLevel; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool debugMode;
|
bool debugMode;
|
||||||
@@ -256,6 +260,18 @@ public slots:
|
|||||||
saveConversationalAwarenessState();
|
saveConversationalAwarenessState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setAdaptiveNoiseLevel(int level)
|
||||||
|
{
|
||||||
|
level = qBound(0, level, 100);
|
||||||
|
if (m_adaptiveNoiseLevel != level && adaptiveModeActive())
|
||||||
|
{
|
||||||
|
m_adaptiveNoiseLevel = level;
|
||||||
|
QByteArray packet = AirPodsPackets::AdaptiveNoise::getPacket(level);
|
||||||
|
writePacketToSocket(packet, "Adaptive noise level packet written: ");
|
||||||
|
emit adaptiveNoiseLevelChanged(level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool writePacketToSocket(const QByteArray &packet, const QString &logMessage)
|
bool writePacketToSocket(const QByteArray &packet, const QString &logMessage)
|
||||||
{
|
{
|
||||||
if (socket && socket->isOpen())
|
if (socket && socket->isOpen())
|
||||||
@@ -697,6 +713,7 @@ signals:
|
|||||||
void earDetectionStatusChanged(const QString &status);
|
void earDetectionStatusChanged(const QString &status);
|
||||||
void batteryStatusChanged(const QString &status);
|
void batteryStatusChanged(const QString &status);
|
||||||
void conversationalAwarenessChanged(bool enabled);
|
void conversationalAwarenessChanged(bool enabled);
|
||||||
|
void adaptiveNoiseLevelChanged(int level);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSystemTrayIcon *trayIcon;
|
QSystemTrayIcon *trayIcon;
|
||||||
@@ -715,6 +732,7 @@ private:
|
|||||||
QString m_earDetectionStatus;
|
QString m_earDetectionStatus;
|
||||||
NoiseControlMode m_noiseControlMode = NoiseControlMode::Off;
|
NoiseControlMode m_noiseControlMode = NoiseControlMode::Off;
|
||||||
bool m_conversationalAwareness = false;
|
bool m_conversationalAwareness = false;
|
||||||
|
int m_adaptiveNoiseLevel = 50;
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user