2 * Sonitus - StereoSeparationFilter.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 java.util.Arrays;
21 import java.util.List;
23 import net.pterodactylus.sonitus.data.Controller;
24 import net.pterodactylus.sonitus.data.Filter;
25 import net.pterodactylus.sonitus.data.controller.Knob;
28 * {@link Filter} implementation that can reduce the stereo width of a signal,
29 * or even reverse the channels.
31 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33 public class StereoSeparationFilter extends AudioProcessingFilter {
35 /** The separation knob. */
36 private final Knob separationKnob;
38 /** Creates a new stereo separation filter. */
39 public StereoSeparationFilter() {
40 super("Stereo Separation");
41 separationKnob = new Knob("Separation", 1.0);
49 public List<Controller<?>> controllers() {
50 return Arrays.<Controller<?>>asList(separationKnob);
54 protected int[] processSamples(int[] samples) {
55 if (samples.length == 1) {
58 int[] processedSamples = new int[samples.length];
59 double a = (separationKnob.value() + 1) / 2.0;
60 processedSamples[0] = (int) (samples[0] * a + samples[1] * (1 - a));
61 processedSamples[1] = (int) (samples[1] * a + samples[0] * (1 - a));
62 return processedSamples;