sox-devel@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
* Bug in program or in libsox?
@ 2013-08-04 17:36 Christian Hoene
  2013-08-05 16:25 ` Ulrich Klauer
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Hoene @ 2013-08-04 17:36 UTC (permalink / raw)
  To: sox-devel


[-- Attachment #1.1: Type: text/plain, Size: 324 bytes --]

Hello,

 

the attached program converts a file to one channel and a sampling rate of
8000. If the input is a stereo file, then the duration of the output file is
half of the duration of the input file. The last half is missing.

 

What is wrong?

 

Thanks

Christian 

 

PS:
I am using sox-14.4.1 on a 64bit Ubuntu.

 


[-- Attachment #1.2: Type: text/html, Size: 2500 bytes --]

[-- Attachment #2: example6.c --]
[-- Type: application/octet-stream, Size: 4006 bytes --]

/* Simple example of using SoX libraries
 *
 * Copyright (c) 2007-8 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 <stdlib.h>
#include <stdio.h>
#include <assert.h>

/*
 * Reads input file, applies vol & flanger effects, stores in output file.
 * E.g. example1 monkey.au monkey.aiff
 */
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 outsig = { 8000, 1, 16, 0, NULL };
  char * args[10];

  assert(argc == 3);

  /* All libSoX applications must start by initialising the SoX library */
  assert(sox_init() == SOX_SUCCESS);

  /* Open the input file (with default parameters) */
  assert(in = sox_open_read(argv[1], NULL, NULL, NULL));


  /* Open the output file; we must specify the output signal characteristics.
   * Since we are using only simple effects, they are the same as the input
   * file characteristics */
  assert(out = sox_open_write(argv[2], &outsig, NULL, NULL, NULL, NULL));

  /* Create an effects chain; some effects need to know about the input
   * or output file encoding so we provide that information here */
  chain = sox_create_effects_chain(&in->encoding, &out->encoding);

  /* The first effect in the effect chain must be something that can source
   * samples; in this case, we use the built-in handler that inputs
   * data from an audio file */
  e = sox_create_effect(sox_find_effect("input"));
  args[0] = (char *)in, assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
  /* This becomes the first `effect' in the chain */
  assert(sox_add_effect(chain, e, &in->signal, &out->signal) == SOX_SUCCESS);
  free(e);

  /* Create the `rate' effect, and initialise it with the desired parameters: */
  e = sox_create_effect(sox_find_effect("rate"));
  assert(sox_effect_options(e, 0, NULL) == SOX_SUCCESS);
  /* Add the effect to the end of the effects processing chain: */
  assert(sox_add_effect(chain, e, &in->signal, &out->signal) == SOX_SUCCESS);
  free(e);

  /* Create the `channels' effect, and initialise it with default parameters: */
  e = sox_create_effect(sox_find_effect("channels"));
  assert(sox_effect_options(e, 0, NULL) == SOX_SUCCESS);
  /* Add the effect to the end of the effects processing chain: */
  assert(sox_add_effect(chain, e, &in->signal, &out->signal) == SOX_SUCCESS);
  free(e);

  /* The last effect in the effect chain must be something that only consumes
   * samples; in this case, we use the built-in handler that outputs
   * data to an audio file */
  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, &in->signal, &out->signal) == SOX_SUCCESS);
  free(e);

  /* Flow samples through the effects processing chain until EOF is reached */
  sox_flow_effects(chain, NULL, NULL);

  /* All done; tidy up: */
  sox_delete_effects_chain(chain);
  sox_close(out);
  sox_close(in);
  sox_quit();
  return 0;
}

[-- Attachment #3: Type: text/plain, Size: 417 bytes --]

------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk

[-- Attachment #4: Type: text/plain, Size: 158 bytes --]

_______________________________________________
SoX-devel mailing list
SoX-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Bug in program or in libsox?
  2013-08-04 17:36 Bug in program or in libsox? Christian Hoene
@ 2013-08-05 16:25 ` Ulrich Klauer
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Klauer @ 2013-08-05 16:25 UTC (permalink / raw)
  To: sox-devel

Christian Hoene wrote:

> the attached program converts a file to one channel and a sampling  
> rate of 8000. If the input is a stereo file, then the duration of  
> the output file is half of the duration of the input file. The last  
> half is missing.

sox_add_effect() modifies its "in" parameter, which therefore must not  
be the same as that used by the input format handler. See this commit  
on how to fix it:
https://github.com/uklauer/sox/commit/5fb5573e26bdac46be6953e0e0399d1a2aaeb350

Ulrich


------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-08-05 16:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-04 17:36 Bug in program or in libsox? Christian Hoene
2013-08-05 16:25 ` Ulrich Klauer

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/sox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).