sudha krishna
2014-07-24 17:56:45 UTC
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
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