From a52f56296a56caa27bb0b9ca878f1702de6be130 Mon Sep 17 00:00:00 2001 From: "Anosh D. Ullenius" Date: Thu, 20 Jul 2023 19:39:03 +0200 Subject: [PATCH] Add uint8 support for number of times to loop (xid6) --- .../java/se/anosh/spctag/dao/Xid6Reader.java | 6 +++--- .../java/se/anosh/spctag/domain/Xid6.java | 19 +++++++++---------- src/test/java/se/anosh/spctag/Xid6Test.java | 14 ++++++++++---- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/se/anosh/spctag/dao/Xid6Reader.java b/src/main/java/se/anosh/spctag/dao/Xid6Reader.java index ed5861d..7316944 100644 --- a/src/main/java/se/anosh/spctag/dao/Xid6Reader.java +++ b/src/main/java/se/anosh/spctag/dao/Xid6Reader.java @@ -76,8 +76,8 @@ private static boolean isAscii(int ch) { final BiConsumer oneByteData = (id, data) -> setData(id.tag, data[0]); - private void setData(final Xid6Tag tag, final byte b) { - final Map> mappings = Map.of( + private void setData(final Xid6Tag tag, final short val) { + final Map> mappings = Map.of( Xid6Tag.EMULATOR, xid6::setEmulator, Xid6Tag.OST_DISC, xid6::setOstDisc, Xid6Tag.LOOP_TIMES, xid6::setLoop @@ -85,7 +85,7 @@ private void setData(final Xid6Tag tag, final byte b) { if (!mappings.containsKey(tag)) { throw new IllegalArgumentException("no mapping found for: " + tag); } - mappings.get(tag).accept(b); + mappings.get(tag).accept((short) (val & 0xFF) ); // uint8 } private final Map> mappedBehaviourDataStoredInHeader = Map.of( diff --git a/src/main/java/se/anosh/spctag/domain/Xid6.java b/src/main/java/se/anosh/spctag/domain/Xid6.java index 0899f8f..cf98956 100644 --- a/src/main/java/se/anosh/spctag/domain/Xid6.java +++ b/src/main/java/se/anosh/spctag/domain/Xid6.java @@ -31,12 +31,11 @@ public final class Xid6 { private Byte ostDisc; private OstTrack ostTrack; private String publisher; - private Long loopLength; // uint32 private Long endLength; // uint32 private Long fadeLength; // uint32 private short mutedChannels; // uint8 - private Byte loops; // TODO support uint8 + private Short loops; // uint8, number of times to loop private Long mixingLevel; // uint32 private Long introLength; // uint32 @@ -105,7 +104,7 @@ public Emulator getEmulator() { return emulator; } - public void setEmulator(byte emulator) { + public void setEmulator(short emulator) { this.emulator = EmulatorFactory.createEmulator(emulator, EmulatorFactory.Type.JAPANESE); } @@ -121,8 +120,8 @@ public Byte getOstDisc() { return ostDisc; } - public void setOstDisc(byte ostDisc) { - this.ostDisc = ostDisc; + public void setOstDisc(short ostDisc) { + this.ostDisc = (byte) (ostDisc & 0xFF); } public OstTrack getOstTrack() { @@ -177,15 +176,15 @@ public String getMutedChannels() { } public void setMutedChannels(short mutedVoices) { - this.mutedChannels = (short) (mutedVoices & 0xFFFF); + this.mutedChannels = (short) (mutedVoices & 0xFF); // uint8 } - public Byte getLoops() { + public Short getLoops() { return loops; } - public void setLoop(byte loops) { - this.loops = loops; + public void setLoop(short loops) { + this.loops = (short) (loops & 0xFF); } public Long getMixingLevel() { @@ -193,7 +192,7 @@ public Long getMixingLevel() { } public void setMixingLevel(long mixingLevel) { - this.mixingLevel = mixingLevel & 0xFFFF_FFFFL; //uint32 + this.mixingLevel = mixingLevel & 0xFFFF_FFFFL; // uint32 } public void setYear(int year) { diff --git a/src/test/java/se/anosh/spctag/Xid6Test.java b/src/test/java/se/anosh/spctag/Xid6Test.java index d3a86a7..56cc097 100644 --- a/src/test/java/se/anosh/spctag/Xid6Test.java +++ b/src/test/java/se/anosh/spctag/Xid6Test.java @@ -19,8 +19,6 @@ public class Xid6Test { - private Path spc; - private SpcDao dao; private Xid6 uut; private static final String SPC_XID6 = "src/test/resources/spc/xid6.spc"; @@ -31,8 +29,8 @@ public class Xid6Test { @BeforeEach void setup() throws IOException { - spc = Paths.get(SPC_XID6); - dao = new SpcFile(spc.toString()); + Path spc = Paths.get(SPC_XID6); + SpcDao dao = new SpcFile(spc.toString()); uut = dao.readXid6(); } @@ -217,4 +215,12 @@ void toStringDoesNotCrash() { assertNotNull(empty.toString()); } + @Test + void numberOfTimesToLoopUint8() { + Xid6 xid6 = new Xid6(); + xid6.setLoop(Short.MAX_VALUE); + final short expected = 255; + assertEquals(expected, xid6.getLoops()); + } + }