mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-28 02:27:32 +01:00
Sony WH-1000XM3: Fix Ambient Sound Control commands, potentially improving ANC quality
This commit is contained in:
parent
931cde2dc7
commit
8eb0b310ba
@ -78,12 +78,15 @@ public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
|
|||||||
|
|
||||||
buf.put(PayloadType.AMBIENT_SOUND_CONTROL_SET.getCode());
|
buf.put(PayloadType.AMBIENT_SOUND_CONTROL_SET.getCode());
|
||||||
buf.put((byte) 0x02);
|
buf.put((byte) 0x02);
|
||||||
|
|
||||||
if (AmbientSoundControl.Mode.OFF.equals(ambientSoundControl.getMode())) {
|
if (AmbientSoundControl.Mode.OFF.equals(ambientSoundControl.getMode())) {
|
||||||
buf.put((byte) 0x00);
|
buf.put((byte) 0x00);
|
||||||
} else {
|
} else {
|
||||||
buf.put((byte) 0x11);
|
buf.put((byte) 0x11);
|
||||||
}
|
}
|
||||||
buf.put((byte) 0x01);
|
|
||||||
|
if (supportsWindNoiseCancelling()) {
|
||||||
|
buf.put((byte) 0x02);
|
||||||
|
|
||||||
switch (ambientSoundControl.getMode()) {
|
switch (ambientSoundControl.getMode()) {
|
||||||
case NOISE_CANCELLING:
|
case NOISE_CANCELLING:
|
||||||
@ -98,14 +101,23 @@ public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
|
|||||||
buf.put((byte) 0);
|
buf.put((byte) 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
buf.put((byte) 0x00);
|
||||||
|
|
||||||
buf.put((byte) 0x01);
|
if (AmbientSoundControl.Mode.NOISE_CANCELLING.equals(ambientSoundControl.getMode())) {
|
||||||
|
buf.put((byte) 1);
|
||||||
|
} else {
|
||||||
|
buf.put((byte) 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.put((byte) 0x01); // ?
|
||||||
buf.put((byte) (ambientSoundControl.isFocusOnVoice() ? 0x01 : 0x00));
|
buf.put((byte) (ambientSoundControl.isFocusOnVoice() ? 0x01 : 0x00));
|
||||||
|
|
||||||
switch (ambientSoundControl.getMode()) {
|
switch (ambientSoundControl.getMode()) {
|
||||||
case OFF:
|
case OFF:
|
||||||
case AMBIENT_SOUND:
|
case AMBIENT_SOUND:
|
||||||
buf.put((byte) (ambientSoundControl.getAmbientSound() + 1));
|
buf.put((byte) (ambientSoundControl.getAmbientSound()));
|
||||||
break;
|
break;
|
||||||
case WIND_NOISE_REDUCTION:
|
case WIND_NOISE_REDUCTION:
|
||||||
case NOISE_CANCELLING:
|
case NOISE_CANCELLING:
|
||||||
@ -442,15 +454,24 @@ public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
|
|||||||
} else if (payload[2] == (byte) 0x01) {
|
} else if (payload[2] == (byte) 0x01) {
|
||||||
// Enabled, determine mode
|
// Enabled, determine mode
|
||||||
|
|
||||||
|
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) {
|
if (payload[4] == (byte) 0x00) {
|
||||||
mode = AmbientSoundControl.Mode.AMBIENT_SOUND;
|
mode = AmbientSoundControl.Mode.AMBIENT_SOUND;
|
||||||
} else if (payload[4] == (byte) 0x01) {
|
} else if (payload[4] == (byte) 0x01) {
|
||||||
// FIXME: ANC gets incorrectly identified wind reduction for WF-SP800N
|
|
||||||
mode = AmbientSoundControl.Mode.WIND_NOISE_REDUCTION;
|
mode = AmbientSoundControl.Mode.WIND_NOISE_REDUCTION;
|
||||||
} else if (payload[4] == (byte) 0x02) {
|
} else if (payload[4] == (byte) 0x02) {
|
||||||
mode = AmbientSoundControl.Mode.NOISE_CANCELLING;
|
mode = AmbientSoundControl.Mode.NOISE_CANCELLING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mode == null) {
|
if (mode == null) {
|
||||||
LOG.warn("Unable to determine ambient sound control mode from {}", GB.hexdump(payload));
|
LOG.warn("Unable to determine ambient sound control mode from {}", GB.hexdump(payload));
|
||||||
@ -826,4 +847,18 @@ public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
|
|||||||
|
|
||||||
return Collections.singletonList(event);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user