From: David ‘Bombe’ Roden Date: Fri, 24 May 2013 21:12:22 +0000 (+0200) Subject: Add FLAC decoder filter. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=344a255dd954f9d69aada430ad00bee5624a4281;p=sonitus.git Add FLAC decoder filter. --- diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/FlacDecoder.java b/src/main/java/net/pterodactylus/sonitus/data/filter/FlacDecoder.java new file mode 100644 index 0000000..cbb2698 --- /dev/null +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/FlacDecoder.java @@ -0,0 +1,78 @@ +/* + * Sonitus - FlacDecoder.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 net.pterodactylus.sonitus.data.Metadata; + +import com.google.common.collect.ImmutableList; + +/** + * Decoder {@link net.pterodactylus.sonitus.data.Filter} for FLAC files. + * + * @author David ‘Bombe’ Roden + */ +public class FlacDecoder extends ExternalFilter { + + /** The location of the binary. */ + private final String binary; + + /** Whether to swap the bytes. */ + private boolean swapBytes; + + /** + * Creates a new FLAC decoder. + * + * @param binary + * The location of the binary + */ + public FlacDecoder(String binary) { + this.binary = binary; + } + + // + // EXTERNALFILTER METHODS + // + + @Override + protected String binary(Metadata metadata) { + return binary; + } + + @Override + protected Iterable parameters(Metadata metadata) { + ImmutableList.Builder parameters = ImmutableList.builder(); + + parameters.add("--decode"); + parameters.add("--stdout"); + parameters.add("--silent"); + parameters.add("--output-name=-"); + parameters.add("--force-raw-format"); + if (swapBytes) { + parameters.add("--endian=little"); + } else { + parameters.add("--endian=big"); + } + parameters.add(String.format("--channels=%d", metadata.channels())); + parameters.add("--bps=16"); + parameters.add(String.format("--sample-rate=%d", metadata.frequency())); + parameters.add("--sign=signed"); + + return parameters.build(); + } + +}