Skip to content

Commit

Permalink
Fixed DMXSound having wrong padding values. (Issue #19)
Browse files Browse the repository at this point in the history
  • Loading branch information
MTrop committed Nov 22, 2023
1 parent 8755db5 commit f64694c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Doom Struct (C) 2015-2023
by Matt Tropiano et al. (see AUTHORS.txt)


Changed in 2.15.2
-----------------

- `Fixed` Proper padding values on DMX sound export. (Issue #19)


Changed in 2.15.1
-----------------

Expand Down
20 changes: 11 additions & 9 deletions src/main/java/net/mtrop/doom/sound/DMXSound.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,21 +331,23 @@ public void readBytes(InputStream in) throws IOException
@Override
public void writeBytes(OutputStream out) throws IOException
{
final byte[] PADDING = new byte[]{
0x7F, 0x7F, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x7F
};
SerialWriter sw = new SerialWriter(SerialWriter.LITTLE_ENDIAN);
sw.writeUnsignedShort(out, 3); // format type
sw.writeUnsignedShort(out, sampleRate);
sw.writeUnsignedInteger(out, sampleCount + (PADDING.length * 2));
sw.writeUnsignedInteger(out, sampleCount + (16 * 2)); // padding is 2 sets of 16 bytes

byte[] PAD = new byte[16];

Arrays.fill(PAD, (byte)(getSampleUnsignedByte(0) & 0x0ff));

sw.writeBytes(out, PAD);

sw.writeBytes(out, PADDING);
for (int i = 0; i < sampleCount; i++)
sw.writeUnsignedByte(out, getSampleUnsignedByte(i));
sw.writeBytes(out, PADDING);

Arrays.fill(PAD, (byte)(getSampleUnsignedByte(sampleCount - 1) & 0x0ff));

sw.writeBytes(out, PAD);
}

@Override
Expand Down

0 comments on commit f64694c

Please sign in to comment.