1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-24 07:38:45 +02:00

Sony WH-1000XM3: Fix Ambient Sound Control commands, potentially improving ANC quality

This commit is contained in:
José Rebelo 2021-12-24 14:20:33 +00:00 committed by Gitea
parent 931cde2dc7
commit 8eb0b310ba

View File

@ -78,34 +78,46 @@ public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
buf.put(PayloadType.AMBIENT_SOUND_CONTROL_SET.getCode());
buf.put((byte) 0x02);
if (AmbientSoundControl.Mode.OFF.equals(ambientSoundControl.getMode())) {
buf.put((byte) 0x00);
} else {
buf.put((byte) 0x11);
}
buf.put((byte) 0x01);
switch (ambientSoundControl.getMode()) {
case NOISE_CANCELLING:
buf.put((byte) 2);
break;
case WIND_NOISE_REDUCTION:
if (supportsWindNoiseCancelling()) {
buf.put((byte) 0x02);
switch (ambientSoundControl.getMode()) {
case NOISE_CANCELLING:
buf.put((byte) 2);
break;
case WIND_NOISE_REDUCTION:
buf.put((byte) 1);
break;
case OFF:
case AMBIENT_SOUND:
default:
buf.put((byte) 0);
break;
}
} else {
buf.put((byte) 0x00);
if (AmbientSoundControl.Mode.NOISE_CANCELLING.equals(ambientSoundControl.getMode())) {
buf.put((byte) 1);
break;
case OFF:
case AMBIENT_SOUND:
default:
} else {
buf.put((byte) 0);
break;
}
}
buf.put((byte) 0x01);
buf.put((byte) 0x01); // ?
buf.put((byte) (ambientSoundControl.isFocusOnVoice() ? 0x01 : 0x00));
switch (ambientSoundControl.getMode()) {
case OFF:
case AMBIENT_SOUND:
buf.put((byte) (ambientSoundControl.getAmbientSound() + 1));
buf.put((byte) (ambientSoundControl.getAmbientSound()));
break;
case WIND_NOISE_REDUCTION:
case NOISE_CANCELLING:
@ -442,13 +454,22 @@ public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
} else if (payload[2] == (byte) 0x01) {
// Enabled, determine mode
if (payload[4] == (byte) 0x00) {
mode = AmbientSoundControl.Mode.AMBIENT_SOUND;
} else if (payload[4] == (byte) 0x01) {
// FIXME: ANC gets incorrectly identified wind reduction for WF-SP800N
mode = AmbientSoundControl.Mode.WIND_NOISE_REDUCTION;
} else if (payload[4] == (byte) 0x02) {
mode = AmbientSoundControl.Mode.NOISE_CANCELLING;
if (payload[3] == 0x00) {
// Only ANC and Ambient Sound supported?
if (payload[4] == (byte) 0x00) {
mode = AmbientSoundControl.Mode.AMBIENT_SOUND;
} else if (payload[4] == (byte) 0x01) {
mode = AmbientSoundControl.Mode.NOISE_CANCELLING;
}
} else if (payload[3] == 0x02) {
// Supports wind noise reduction
if (payload[4] == (byte) 0x00) {
mode = AmbientSoundControl.Mode.AMBIENT_SOUND;
} else if (payload[4] == (byte) 0x01) {
mode = AmbientSoundControl.Mode.WIND_NOISE_REDUCTION;
} else if (payload[4] == (byte) 0x02) {
mode = AmbientSoundControl.Mode.NOISE_CANCELLING;
}
}
}
@ -826,4 +847,18 @@ public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
return Collections.singletonList(event);
}
private boolean supportsWindNoiseCancelling() {
// TODO: We should be able to determine this dynamically...
final DeviceType deviceType = getDevice().getType();
switch (deviceType) {
case SONY_WH_1000XM3:
return true;
default:
LOG.error("Unknown Sony device type '{}' with key '{}'", deviceType, deviceType.getKey());
return false;
}
}
}