Add FLAC decoder filter.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 24 May 2013 21:12:22 +0000 (23:12 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 May 2013 20:54:37 +0000 (22:54 +0200)
src/main/java/net/pterodactylus/sonitus/data/filter/FlacDecoder.java [new file with mode: 0644]

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 (file)
index 0000000..cbb2698
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+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<String> parameters(Metadata metadata) {
+               ImmutableList.Builder<String> 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();
+       }
+
+}