delete bundled libgsm
[sox.git] / src / swap.c
blobd39310cfb0c58cad2085c01d88046da3cdb93170
1 /* libSoX effect: swap pairs of audio channels
3 * First version written 01/2012 by Ulrich Klauer.
4 * Replaces an older swap effect originally written by Chris Bagwell
5 * on March 16, 1999.
7 * Copyright 2012 Chris Bagwell and SoX Contributors
9 * This library is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or (at
12 * your option) any later version.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
17 * General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "sox_i.h"
26 static int start(sox_effect_t *effp)
28 return effp->in_signal.channels >= 2 ? SOX_SUCCESS : SOX_EFF_NULL;
31 static int flow(sox_effect_t *effp, const sox_sample_t *ibuf,
32 sox_sample_t *obuf, size_t *isamp, size_t *osamp)
34 size_t len = min(*isamp, *osamp);
35 size_t channels = effp->in_signal.channels;
36 len /= channels;
37 *isamp = *osamp = len * channels;
39 while (len--) {
40 size_t i;
41 for (i = 0; i + 1 < channels; i += 2) {
42 *obuf++ = ibuf[1];
43 *obuf++ = ibuf[0];
44 ibuf += 2;
46 if (channels % 2)
47 *obuf++ = *ibuf++;
50 return SOX_SUCCESS;
53 sox_effect_handler_t const *lsx_swap_effect_fn(void)
55 static sox_effect_handler_t handler = {
56 "swap", NULL,
57 SOX_EFF_MCHAN | SOX_EFF_MODIFY,
58 NULL, start, flow, NULL, NULL, NULL,
61 return &handler;