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;
27 import com.google.common.eventbus.EventBus;
30 * {@link Filter} implementation that can reduce the stereo width of a signal,
31 * or even reverse the channels.
33 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
35 public class StereoSeparationFilter extends AudioProcessingFilter {
37 /** The separation knob. */
38 private final Knob separationKnob;
41 * Creates a new stereo separation filter.
46 public StereoSeparationFilter(EventBus eventBus) {
47 super(eventBus, "Stereo Separation");
48 separationKnob = new Knob("Separation", 1.0);
56 public List<Controller<?>> controllers() {
57 return Arrays.<Controller<?>>asList(separationKnob);
61 // AUDIOPROCESSINGFILTER METHODS
65 protected int[] processSamples(int[] samples) {
66 if (samples.length == 1) {
69 int[] processedSamples = new int[samples.length];
70 double a = (separationKnob.value() + 1) / 2.0;
71 processedSamples[0] = (int) (samples[0] * a + samples[1] * (1 - a));
72 processedSamples[1] = (int) (samples[1] * a + samples[0] * (1 - a));
73 return processedSamples;