Skip to content

Commit

Permalink
Add uint8 support for number of times to loop (xid6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ullenius committed Jul 20, 2023
1 parent 05141c9 commit a52f562
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/main/java/se/anosh/spctag/dao/Xid6Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ private static boolean isAscii(int ch) {

final BiConsumer<Id, byte[]> oneByteData = (id, data) -> setData(id.tag, data[0]);

private void setData(final Xid6Tag tag, final byte b) {
final Map<Xid6Tag, Consumer<Byte>> mappings = Map.of(
private void setData(final Xid6Tag tag, final short val) {
final Map<Xid6Tag, Consumer<Short>> mappings = Map.of(
Xid6Tag.EMULATOR, xid6::setEmulator,
Xid6Tag.OST_DISC, xid6::setOstDisc,
Xid6Tag.LOOP_TIMES, xid6::setLoop
);
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<Type, BiConsumer<Id, byte[]>> mappedBehaviourDataStoredInHeader = Map.of(
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/se/anosh/spctag/domain/Xid6.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
}

Expand All @@ -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() {
Expand Down Expand Up @@ -177,23 +176,23 @@ 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() {
return mixingLevel;
}

public void setMixingLevel(long mixingLevel) {
this.mixingLevel = mixingLevel & 0xFFFF_FFFFL; //uint32
this.mixingLevel = mixingLevel & 0xFFFF_FFFFL; // uint32
}

public void setYear(int year) {
Expand Down
14 changes: 10 additions & 4 deletions src/test/java/se/anosh/spctag/Xid6Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
}

Expand Down Expand Up @@ -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());
}

}

0 comments on commit a52f562

Please sign in to comment.