sox-devel@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
* Issue with using sox resample library apis, to downsample audio from input rate(44.1Khz, 2 channel, 16 bit), to output rate(16Khz, 1 channel, 16 bit).
@ 2014-07-24 17:56 sudha krishna
  0 siblings, 0 replies; only message in thread
From: sudha krishna @ 2014-07-24 17:56 UTC (permalink / raw)
  To: sox-devel@lists.sourceforge.net


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

Hi Sox-group,

Objective: I am trying to use sox-resample library, to downsample from input rate(44.1Khz, 2 channel, 16 bit),
to output rate(16Khz, 1 channel, 16 bit). Is it possible to use sox-resample library for this process.

I tried soxr_oneshot this api, and the output produced, does not have the original voice of the input buffer, 
it has a weird sounding voice output, far from the original voice input.

Also tried the soxr_create and soxr_process apis, and did not get correct output.

I am not sure, if these apis(soxr_oneshot, soxr_create, and soxr_process) have an option,
to downgrade number of channels, and whether we can specify 16 bit or 8 bit.

Also not sure, if I should be using LibSox apis, such as sox_create_effect/sox_add_effect, and whether that is a better option.

Here is sample code using, soxr_oneshot, please let me know, what could be wrong, or if you have any suggestions.

#define INPUT_RATE(44100)
#define OUTPUT_RATE(16000)
#define INPUT_NUM_CHANNELS (2)
#define OUTPUT_NUM_CHANNELS (1)

#define OUTPUT_BLOCK_ALIGN (2)

/*
ibuf - pointer to input buffer.
length - length of input buffer.
block_align - sample size of input rate.
*/
static int sox_test_function(void *ibuf, UINT32 length, UINT32 block_align)
{

size_t olen = (size_t)((length * OUTPUT_RATE * OUTPUT_NUM_CHANNELS)/ (INPUT_RATE * OUTPUT_NUM_CHANNELS));   
float * obuf = (float *)malloc(OUTPUT_BLOCK_ALIGN * olen);
memset(obuf, 0, (OUTPUT_BLOCK_ALIGN * olen));
size_t odone;
    FILE *ofile;
    UINT32 written = 0;

//SKR: Need to find out, if we can downgrade # of channels..can we do that..??
//also not sure..how to specify 16 bit/8 bit..etc..
soxr_error_t err = soxr_oneshot(
    INPUT_RATE,
    OUTPUT_RATE,
    1,
    ibuf , length/block_align, NULL,
    obuf, olen/OUTPUT_BLOCK_ALIGN, &odone,
    NULL,
    NULL,
    NULL);

    ofile = fopen("nwave_file_16k_pcm.raw", "wb");
    
if (ofile == NULL) {
        perror("Invalid file specified.");
        exit(-1);
    }

    written = fwrite(obuf, OUTPUT_BLOCK_ALIGN, odone, ofile); // Consume output.

   return 0;

}

Please let me know, what could be wrong, or if you have any suggestions.


Thanks,

Krishna

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

[-- Attachment #2: Type: text/plain, Size: 362 bytes --]

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds

[-- Attachment #3: 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] only message in thread

only message in thread, other threads:[~2014-07-24 17:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-24 17:56 Issue with using sox resample library apis, to downsample audio from input rate(44.1Khz, 2 channel, 16 bit), to output rate(16Khz, 1 channel, 16 bit) sudha krishna

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).