sox-devel@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
From: Stephen.Paterson <stephen.paterson@synety.com>
To: "sox-devel@lists.sourceforge.net" <sox-devel@lists.sourceforge.net>
Subject: Half length output with libsox for stereo -> mono
Date: Wed, 10 Apr 2013 12:04:28 +0000	[thread overview]
Message-ID: <BDC1841AE4B16746AB058F709D669BB0458AB650@AMSPRD0311MB400.eurprd03.prod.outlook.com> (raw)


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

Hi all,

I've found a couple of threads relating to this problem but I can't for the life of me get it to work.

The following command line works fine:

sox original.wav -c 1 -r 8000 converted.wav

I can't get it to work with libsox. I've made a tiny modification to example3.c that should do the same but no matter what I try I always end up with a file that is exactly half the length of the one I get from sox (or some crazy audio).
If I leave the output as stereo I get the full length audio but sadly stereo is no use to me.
The 2 threads I've found are [Sox-devel] 'Effects going crazy' - 2012-05-07 and [SoX] 'Channels/remix does not function as documented' - 2011-11-12
Nothing suggested in either seems to work for me. Could someone take a look at the attached code (it's very simple) to see if they can see what I'm doing wrong please? It's driving me crazy! I'm at the point of giving up and just spawning the sox executable from my code but that would make me cry.

The following is the format of my test input file but it needs to work for any wav file:
RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 24000 Hz

Desired output will always be in the following format regardless of the input format:
RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz

Apologies if this is more appropriate for sox-users. If so, just let me know and I'll post there.

Cheers


Stephen Paterson
Developer   |  SYNETY
www.synety.com<http://www.synety.com/>

ddi:    01134 166029
main: 0330 335 0000

SMARTER COMMUNICATIONS
Confidentiality: This e-mail transmission, including any attachments, is intended only for the named recipient(s) and may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you have received this transmission in error, or are not the named recipient(s), please notify the sender immediately by return e-mail and permanently delete this transmission, including any attachments.

Security: This e-mail and any attachments are believed to be free from any virus but it is the responsibility of the recipient to ensure this is so. E-mail is not a 100% secure communications medium. We recommend you observe this when e-mailing us.


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

[-- Attachment #2: main.cpp --]
[-- Type: application/octet-stream, Size: 1988 bytes --]

#include <sox.h>
#include <assert.h>

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) {
		fprintf(stderr, "%s %s: ", str[level - 1], filename);
		vfprintf(stderr, fmt, ap);
		fprintf(stderr, "\n");
	}
}

int main(int argc, char * argv[])
{
	static sox_format_t * in, * out;
	sox_effects_chain_t * chain;
	sox_effect_t * e;
	char * args[10];

	assert(argc == 2);
	sox_globals.output_message_handler = output_message;
	sox_globals.verbosity = 10;

	assert(sox_init() == SOX_SUCCESS);
	assert(in = sox_open_read(argv[1], NULL, NULL, NULL));
	assert(out= sox_open_write("converted.wav", &in->signal, NULL, "wav", NULL, NULL));

	chain = sox_create_effects_chain(&in->encoding, &out->encoding);

	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, &in->signal, &in->signal) == SOX_SUCCESS);
	free(e);

	out->signal.precision = 16;
	out->signal.rate = 8000;
	out->signal.channels = 1;

	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, &in->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, &in->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, &in->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;
}


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

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter

[-- 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

             reply	other threads:[~2013-04-10 12:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-10 12:04 Stephen.Paterson [this message]
2013-04-10 13:36 ` Half length output with libsox for stereo -> mono Stephen.Paterson
2013-04-10 15:47 ` Ulrich Klauer
2013-04-11 10:15   ` Stephen.Paterson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.sourceforge.net/lists/listinfo/sox-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BDC1841AE4B16746AB058F709D669BB0458AB650@AMSPRD0311MB400.eurprd03.prod.outlook.com \
    --to=sox-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).