Advertisement
Guest User

Untitled

a guest
Mar 18th, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.64 KB | None | 0 0
  1. /* Simple example of using SoX libraries
  2.  *
  3.  * Copyright (c) 2007-8 robs@users.sourceforge.net
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify it
  6.  * under the terms of the GNU General Public License as published by the
  7.  * Free Software Foundation; either version 2 of the License, or (at your
  8.  * option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
  13.  * Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License along
  16.  * with this program; if not, write to the Free Software Foundation, Inc.,
  17.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18.  */
  19.  
  20. #ifdef NDEBUG /* N.B. assert used with active statements so enable always. */
  21. #undef NDEBUG /* Must undef above assert.h or other that might include it. */
  22. #endif
  23.  
  24. #include "sox.h"
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <assert.h>
  28.  
  29. /*
  30.  * Reads input file, applies vol & flanger effects, stores in output file.
  31.  * E.g. example1 monkey.au monkey.aiff
  32.  */
  33. int main(int argc, char * argv[])
  34. {
  35.   static sox_format_t * in, * out; /* input and output files */
  36.   sox_effects_chain_t * chain;
  37.   sox_effect_t * e;
  38.   char * args[10];
  39.  
  40.   assert(argc == 5);
  41.  
  42.   printf("\nGiven input:\n%s %s %s %s %s\n\n", argv[0], argv[1], argv[2], argv[3], argv[4]);
  43.  
  44.   /* All libSoX applications must start by initialising the SoX library */
  45.   assert(sox_init() == SOX_SUCCESS);
  46.  
  47.   /* Open the input file (with default parameters) */
  48.   assert(in = sox_open_read(argv[1], NULL, NULL, NULL));
  49.  
  50.   /* Open the output file; we must specify the output signal characteristics.
  51.    * Since we are using only simple effects, they are the same as the input
  52.    * file characteristics */
  53.   assert(out = sox_open_write(argv[2], &in->signal, NULL, NULL, NULL, NULL));
  54.  
  55.   /* Create an effects chain; some effects need to know about the input
  56.    * or output file encoding so we provide that information here */
  57.   chain = sox_create_effects_chain(&in->encoding, &out->encoding);
  58.  
  59.   /* The first effect in the effect chain must be something that can source
  60.    * samples; in this case, we use the built-in handler that inputs
  61.    * data from an audio file */
  62.   e = sox_create_effect(sox_find_effect("input"));
  63.   args[0] = (char *)in, assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
  64.   /* This becomes the first `effect' in the chain */
  65.   assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
  66.   free(e);
  67.  
  68.   /* Create the `trim' effect, and initialise it with the desired parameters: */
  69.   e = sox_create_effect(sox_find_effect("trim"));
  70.   args[0] = argv[3], args[1] = argv[4], assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
  71.   /* Add the effect to the end of the effects processing chain: */
  72.   assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
  73.   free(e);
  74.  
  75.   /* The last effect in the effect chain must be something that only consumes
  76.    * samples; in this case, we use the built-in handler that outputs
  77.    * data to an audio file */
  78.   e = sox_create_effect(sox_find_effect("output"));
  79.   args[0] = (char *)out, assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
  80.   assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
  81.   free(e);
  82.  
  83.   /* Flow samples through the effects processing chain until EOF is reached */
  84.   sox_flow_effects(chain, NULL, NULL);
  85.  
  86.   /* All done; tidy up: */
  87.   sox_delete_effects_chain(chain);
  88.   sox_close(out);
  89.   sox_close(in);
  90.   sox_quit();
  91.   return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement