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.
Sox Resample library sources are here: http://sourceforge.net/p/soxr/code/ci/master/tree/
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.
Please refer to example3.c in the example programs in the sox source files. You have use the sox effect "rate" for down-sampling. I tried it & was able to successfully down-sample the wav file but i'm facing a problem on the wave getting clipped. You can refer to my post her Downsampling a wav file using libsox