Here you can find the source of subtractSignals(double[] s1, double[] s2)
public static double[] subtractSignals(double[] s1, double[] s2)
//package com.java2s; /**//from w ww. j a v a 2s .c o m * Copyright 2000-2009 DFKI GmbH. * All Rights Reserved. Use is subject to license terms. * * This file is part of MARY TTS. * * MARY TTS is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ public class Main { public static double[] subtractSignals(double[] s1, double[] s2) { return addSignals(s1, 1.0, s2, -1.0); } public static double[] addSignals(double[] s1, double[] s2) { int len = 0; if (s1 != null) len = s1.length; if (s2 != null && s2.length > len) len = s2.length; double[] y = null; if (len > 0) y = new double[len]; if (s1 != null) System.arraycopy(s1, 0, y, 0, s1.length); if (s2 != null) { for (int i = 0; i < s2.length; i++) y[i] += s2[i]; } return y; } public static double[] addSignals(double[] s1, double gain1, double[] s2, double gain2) { int len = 0; if (s1 != null) len = s1.length; if (s2 != null && s2.length > len) len = s2.length; double[] y = null; if (len > 0) y = new double[len]; if (s1 != null) System.arraycopy(s1, 0, y, 0, s1.length); if (s2 != null) { for (int i = 0; i < s2.length; i++) y[i] = gain1 * y[i] + gain2 * s2[i]; } else if (s1 != null) { for (int i = 0; i < s1.length; i++) y[i] = gain1 * y[i]; } return y; } }