Feature: add params of reverb

pull/221/head
xufuji456 2 years ago
parent 1c848cd2ab
commit 6cd54fb241
  1. 13
      app/src/main/cpp/sox/example0.c
  2. 113
      app/src/main/cpp/sox/example3.c

@ -70,10 +70,15 @@ int main(int argc, char * argv[])
assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS); assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
free(e); free(e);
/* Create the `flanger' effect, and initialise it with default parameters: */ args[0] = "--wet-only";
e = sox_create_effect(sox_find_effect("flanger")); args[1] = "50"; // reverberance [0, 100] 50%
assert(sox_effect_options(e, 0, NULL) == SOX_SUCCESS); args[2] = "50"; // hf_damping [0, 100] 50%
/* Add the effect to the end of the effects processing chain: */ args[3] = "100"; // room_scale [0, 100] 100%
args[4] = "100"; // stereo_depth [0, 100] 100%
args[5] = "0"; // pre_delay_ms [0, 500] 0ms
args[6] = "0"; // wet_gain_dB [-10, 10] 0dB
e = sox_create_effect(sox_find_effect("reverb"));
assert(sox_effect_options(e, 7, args) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS); assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
free(e); free(e);

@ -1,113 +0,0 @@
/* Simple example of using SoX libraries
*
* Copyright (c) 2007-9 robs@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* 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 General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef NDEBUG /* N.B. assert used with active statements so enable always. */
#undef NDEBUG /* Must undef above assert.h or other that might include it. */
#endif
#include "sox.h"
#include "util.h"
#include <stdio.h>
#include <assert.h>
/*
* Example of a custom output message handler.
*/
static void output_message(unsigned level, const char *filename, const char *fmt, va_list ap)
{
char const * const str[] = {"FAIL", "WARN", "INFO", "DBUG"};
if (sox_globals.verbosity >= level) {
char base_name[128];
sox_basename(base_name, sizeof(base_name), filename);
fprintf(stderr, "%s %s: ", str[min(level - 1, 3)], base_name);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
}
/*
* On an alsa capable system, plays an audio file starting 10 seconds in.
* Copes with sample-rate and channel change if necessary since its
* common for audio drivers to support a subset of rates and channel
* counts.
* E.g. example3 song2.ogg
*
* Can easily be changed to work with other audio device drivers supported
* by libSoX; e.g. "oss", "ao", "coreaudio", etc.
* See the soxformat(7) manual page.
*/
int main(int argc, char * argv[])
{
static sox_format_t * in, * out; /* input and output files */
sox_effects_chain_t * chain;
sox_effect_t * e;
sox_signalinfo_t interm_signal;
char * args[10];
assert(argc == 2);
sox_globals.output_message_handler = output_message;
sox_globals.verbosity = 1;
assert(sox_init() == SOX_SUCCESS);
assert((in = sox_open_read(argv[1], NULL, NULL, NULL)));
/* Change "alsa" in this line to use an alternative audio device driver: */
assert((out= sox_open_write("default", &in->signal, NULL, "alsa", NULL, NULL)));
chain = sox_create_effects_chain(&in->encoding, &out->encoding);
interm_signal = in->signal; /* NB: deep copy */
e = sox_create_effect(sox_find_effect("input"));
args[0] = (char *)in, assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &interm_signal, &in->signal) == SOX_SUCCESS);
free(e);
e = sox_create_effect(sox_find_effect("trim"));
args[0] = "10", assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &interm_signal, &in->signal) == SOX_SUCCESS);
free(e);
if (in->signal.rate != out->signal.rate) {
e = sox_create_effect(sox_find_effect("rate"));
assert(sox_effect_options(e, 0, NULL) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &interm_signal, &out->signal) == SOX_SUCCESS);
free(e);
}
if (in->signal.channels != out->signal.channels) {
e = sox_create_effect(sox_find_effect("channels"));
assert(sox_effect_options(e, 0, NULL) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &interm_signal, &out->signal) == SOX_SUCCESS);
free(e);
}
e = sox_create_effect(sox_find_effect("output"));
args[0] = (char *)out, assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &interm_signal, &out->signal) == SOX_SUCCESS);
free(e);
sox_flow_effects(chain, NULL, NULL);
sox_delete_effects_chain(chain);
sox_close(out);
sox_close(in);
sox_quit();
return 0;
}
Loading…
Cancel
Save