From 85754e2a030dbff1245499f408c67ef154197fc4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 15 Mar 2013 23:51:39 +0100 Subject: [PATCH] Add LAME MP3 decoder. --- .../sonitus/data/filter/LameMp3Decoder.java | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java b/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java new file mode 100644 index 0000000..d824041 --- /dev/null +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java @@ -0,0 +1,64 @@ +/* + * Sonitus - LameMp3Decoder.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sonitus.data.filter; + +import com.google.common.collect.ImmutableList; + +/** + * {@link ExternalMp3Decoder} implementation that uses LAME to decode an MP3. + * + * @author David ‘Bombe’ Roden + */ +public class LameMp3Decoder extends ExternalMp3Decoder { + + /** + * Creates a new LAME MP3 decoder. + * + * @param binary + * The location of the binary + * @param swapBytes + * {@code true} to swap the decoded bytes, {@code false} to use platform + * endianness + */ + public LameMp3Decoder(String binary, boolean swapBytes) { + super(binary, generateParameters(swapBytes)); + } + + // + // STATIC METHODS + // + + /** + * Generates the parameters for LAME. + * + * @param swapBytes + * {@code true} to swap the decoded bytes, {@code false} to use platform + * endianness + * @return The parameters for LAME + */ + private static Iterable generateParameters(boolean swapBytes) { + ImmutableList.Builder parameters = ImmutableList.builder(); + parameters.add("--mp3input").add("--decode").add("-t"); + if (swapBytes) { + parameters.add("-x"); + } + parameters.add("-").add("-"); + return parameters.build(); + } + +} -- 2.7.4