Skip to content

Commit

Permalink
Fix Xbox 360 RB drumkit velocity calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNathannator committed Jun 18, 2024
1 parent 4081ddb commit 340bdd3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions Packages/com.thenathannator.plasticband/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Dates are relative to UTC.
### Fixed

- PS3 Rock Band guitars now handle the whammy bar's null state value correctly. It will no longer snap to the middle after a few moments of no movement.
- The yellow and green pads on Xbox 360 Rock Band 1 kits are now read correctly, there was an issue in the velocity conversion code.

## [0.7.1] - 2024/05/09

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,56 +119,61 @@ public bool dpadRight
byte IFourLaneDrumkitState_Flags.redPadVelocity
{
get => GetVelocity_Positive(redVelocity);
set => SetVelocity_Positive(ref redVelocity, value);
set => redVelocity = SetVelocity_Positive(value);
}

byte IFourLaneDrumkitState_Flags.yellowPadVelocity
{
get => GetVelocity_Negative(yellowVelocity);
set => SetVelocity_Negative(ref yellowVelocity, value);
set => yellowVelocity = SetVelocity_Negative(value);
}

byte IFourLaneDrumkitState_Flags.bluePadVelocity
{
get => GetVelocity_Positive(blueVelocity);
set => SetVelocity_Positive(ref blueVelocity, value);
set => blueVelocity = SetVelocity_Positive(value);
}

byte IFourLaneDrumkitState_Flags.greenPadVelocity
{
get => GetVelocity_Negative(greenVelocity);
set => SetVelocity_Negative(ref greenVelocity, value);
set => greenVelocity = SetVelocity_Negative(value);
}

byte IFourLaneDrumkitState_Flags.yellowCymbalVelocity
{
get => GetVelocity_Negative(yellowVelocity);
set => SetVelocity_Negative(ref yellowVelocity, value);
set => yellowVelocity = SetVelocity_Negative(value);
}

byte IFourLaneDrumkitState_Flags.blueCymbalVelocity
{
get => GetVelocity_Positive(blueVelocity);
set => SetVelocity_Positive(ref blueVelocity, value);
set => blueVelocity = SetVelocity_Positive(value);
}

byte IFourLaneDrumkitState_Flags.greenCymbalVelocity
{
get => GetVelocity_Negative(greenVelocity);
set => SetVelocity_Negative(ref greenVelocity, value);
set => greenVelocity = SetVelocity_Negative(value);
}

private static byte GetVelocity_Positive(short velocity)
=> (byte)((~velocity & 0x7FFF) >> 7);
=> (byte)(255 - (byte)(velocity >> 7));

private static byte GetVelocity_Negative(short velocity)
=> (byte)((velocity & 0x7FFF) >> 7);
{
if (velocity == 0)
return 255;

return (byte)(255 - (byte)((~velocity) >> 7));
}

private static void SetVelocity_Positive(ref short velocity, byte value)
=> velocity = (short)(~value << 7);
private static short SetVelocity_Positive(byte value)
=> (short)(32767 - ((value << 7) | (value >> 1)));

private static void SetVelocity_Negative(ref short velocity, byte value)
=> velocity = (short)(value << 7);
private static short SetVelocity_Negative(byte value)
=> (short)(-32767 + ((value << 7) | (value >> 1)));
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
Expand Down

0 comments on commit 340bdd3

Please sign in to comment.