2 * Sonitus - FlacDecoder.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sonitus.data.filter;
20 import net.pterodactylus.sonitus.data.Metadata;
22 import com.google.common.collect.ImmutableList;
25 * Decoder {@link net.pterodactylus.sonitus.data.Filter} for FLAC files.
27 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29 public class FlacDecoder extends ExternalFilter {
31 /** The location of the binary. */
32 private final String binary;
34 /** Whether to swap the bytes. */
35 private boolean swapBytes;
38 * Creates a new FLAC decoder.
41 * The location of the binary
43 public FlacDecoder(String binary) {
44 super("FLAC Decoder");
49 // EXTERNALFILTER METHODS
53 protected String binary(Metadata metadata) {
58 protected Iterable<String> parameters(Metadata metadata) {
59 ImmutableList.Builder<String> parameters = ImmutableList.builder();
61 parameters.add("--decode");
62 parameters.add("--stdout");
63 parameters.add("--silent");
64 parameters.add("--output-name=-");
65 parameters.add("--force-raw-format");
67 parameters.add("--endian=little");
69 parameters.add("--endian=big");
71 parameters.add(String.format("--channels=%d", metadata.channels()));
72 parameters.add("--bps=16");
73 parameters.add(String.format("--sample-rate=%d", metadata.frequency()));
74 parameters.add("--sign=signed");
76 return parameters.build();