X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fdata%2Ffilter%2FLameMp3Encoder.java;h=ffd4cc69b73ce3c25b0d50315048fe818f17a71a;hb=cbeadf6d9eea57ab98cacd60e2419dd3c18bef89;hp=c88d93955e2f9f30bab8e4e8200d2b2ad2027c1e;hpb=3edbf1f9c810e2e58aa3e78dab903cc7b01828c3;p=sonitus.git diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Encoder.java b/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Encoder.java index c88d939..ffd4cc6 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Encoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Encoder.java @@ -19,7 +19,7 @@ package net.pterodactylus.sonitus.data.filter; import java.util.Arrays; -import net.pterodactylus.sonitus.data.Format; +import net.pterodactylus.sonitus.data.Metadata; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; @@ -52,7 +52,7 @@ public class LameMp3Encoder extends ExternalMp3Encoder { private final String binary; /** Whether to swap bytes in the input. */ - private final boolean swapBytes; + private boolean swapBytes; /** The preset to use. */ private final Optional preset; @@ -60,19 +60,18 @@ public class LameMp3Encoder extends ExternalMp3Encoder { /** The bitrate to encode to. */ private final Optional bitrate; + /** Whether to use highest quality encoding. */ + private boolean hq = false; + /** * Creates a new LAME MP3 encoder. * * @param binary * The location of the binary - * @param swapBytes - * {@code true} to swap bytes in the input, {@code false} to use platform - * endianness * @param preset - * The preset to use */ - public LameMp3Encoder(String binary, boolean swapBytes, Preset preset) { - this(binary, swapBytes, preset, -1); + public LameMp3Encoder(String binary, Preset preset) { + this(binary, preset, -1); } /** @@ -80,14 +79,10 @@ public class LameMp3Encoder extends ExternalMp3Encoder { * * @param binary * The location of the binary - * @param swapBytes - * {@code true} to swap bytes in the input, {@code false} to use platform - * endianness * @param bitrate - * The bitrate to encode to (in kbps) */ - public LameMp3Encoder(String binary, boolean swapBytes, int bitrate) { - this(binary, swapBytes, null, bitrate); + public LameMp3Encoder(String binary, int bitrate) { + this(binary, null, bitrate); } /** @@ -95,35 +90,56 @@ public class LameMp3Encoder extends ExternalMp3Encoder { * * @param binary * The location of the binary - * @param swapBytes - * {@code true} to swap bytes in the input, {@code false} to use platform - * endianness * @param preset * The preset to use * @param bitrate - * The bitrate to encode to (in kbps) */ - private LameMp3Encoder(String binary, boolean swapBytes, Preset preset, int bitrate) { + private LameMp3Encoder(String binary, Preset preset, int bitrate) { + super("LAME Encoder"); this.binary = binary; - this.swapBytes = swapBytes; this.preset = Optional.fromNullable(preset); this.bitrate = (bitrate < 0) ? Optional.absent() : Optional.of(bitrate); } + /** + * Sets whether to swap bytes on the input to encode + * + * @param swapBytes + * {@code true} to swap the input bytes, {@code false} to use platform + * endianness + * @return This MP3 encoder + */ + public LameMp3Encoder swapBytes(boolean swapBytes) { + this.swapBytes = swapBytes; + return this; + } + + /** + * Sets whether to use highest quality encoding. + * + * @param hq + * {@code true} to use highest quality encoding, {@code false} otherwise + * @return This MP3 encoder + */ + public LameMp3Encoder hq(boolean hq) { + this.hq = hq; + return this; + } + // // EXTERNALFILTER METHODS // @Override - protected String binary(Format format) { + protected String binary(Metadata metadata) { return binary; } @Override - protected Iterable parameters(Format format) { - ImmutableList.Builder parameters = ImmutableList.builder(); + protected Iterable parameters(Metadata metadata) { + ImmutableList.Builder parameters = ImmutableList.builder(); parameters.add("-r"); - parameters.add("-s").add(String.valueOf(format.frequency() / 1000.0)); + parameters.add("-s").add(String.valueOf(metadata.frequency() / 1000.0)); if (swapBytes) { parameters.add("-x"); } @@ -138,7 +154,9 @@ public class LameMp3Encoder extends ExternalMp3Encoder { parameters.add(String.valueOf(bitrate.get())); } parameters.add("-p"); - parameters.add("-q").add("0"); + if (hq) { + parameters.add("-q").add("0"); + } parameters.add("-").add("-"); return parameters.build(); }