mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-01-29 06:10:52 +00:00
[Linux] Implement adaptive audio noice
This commit is contained in:
@@ -36,5 +36,41 @@ ApplicationWindow {
|
||||
checked: airPodsTrayApp.conversationalAwareness
|
||||
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");
|
||||
}
|
||||
|
||||
// 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
|
||||
namespace Parse
|
||||
{
|
||||
|
||||
@@ -18,6 +18,8 @@ class AirPodsTrayApp : public QObject {
|
||||
Q_PROPERTY(QString earDetectionStatus READ earDetectionStatus NOTIFY earDetectionStatusChanged)
|
||||
Q_PROPERTY(int noiseControlMode READ noiseControlMode WRITE setNoiseControlMode NOTIFY noiseControlModeChanged)
|
||||
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:
|
||||
AirPodsTrayApp(bool debugMode) : debugMode(debugMode) {
|
||||
@@ -96,6 +98,8 @@ public:
|
||||
QString earDetectionStatus() const { return m_earDetectionStatus; }
|
||||
int noiseControlMode() const { return static_cast<int>(m_noiseControlMode); }
|
||||
bool conversationalAwareness() const { return m_conversationalAwareness; }
|
||||
bool adaptiveModeActive() const { return m_noiseControlMode == NoiseControlMode::Adaptive; }
|
||||
int adaptiveNoiseLevel() const { return m_adaptiveNoiseLevel; }
|
||||
|
||||
private:
|
||||
bool debugMode;
|
||||
@@ -251,6 +255,18 @@ public slots:
|
||||
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)
|
||||
{
|
||||
if (socket && socket->isOpen())
|
||||
@@ -692,6 +708,7 @@ signals:
|
||||
void earDetectionStatusChanged(const QString &status);
|
||||
void batteryStatusChanged(const QString &status);
|
||||
void conversationalAwarenessChanged(bool enabled);
|
||||
void adaptiveNoiseLevelChanged(int level);
|
||||
|
||||
private:
|
||||
QSystemTrayIcon *trayIcon;
|
||||
@@ -710,6 +727,7 @@ private:
|
||||
QString m_earDetectionStatus;
|
||||
NoiseControlMode m_noiseControlMode = NoiseControlMode::Off;
|
||||
bool m_conversationalAwareness = false;
|
||||
int m_adaptiveNoiseLevel = 50;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
Reference in New Issue
Block a user