vendredi 19 décembre 2014

How I can use the SOXR for resample in C#?

I read that SORX is a very good, fast and tiny resapler. I want use it in my c# program, but I can´t traslate C code to C#


I found the compiled LIBSOXR.DLL


I found one easy example in C



/* Example 1: `One-shot' resample a single block of data in memory.
*
* Optional arguments are: INPUT-RATE OUTPUT-RATE
*
* With the default arguments, the output should produce lines similar to the
* following:
*
* 0.00 0.71 1.00 0.71 -0.00 -0.71 -1.00 -0.71
*
* Gibbs effect may be seen at the ends of the resampled signal; this is because
* unlike a `real-world' signal, the synthetic input signal is not band-limited.
*/
#include <soxr.h>
#include "examples-common.h"
const float in[] = { /* Input: 12 cycles of a sine wave with freq. = irate/4 */
0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1,
0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1};

int main(int argc, char const * arg[])
{
double irate = 1; /*Upsampling */
double orate = 2; /*by a factor of 2. */
size_t olen = (size_t)(AL(in) * orate / irate + .5); /*Assay output len. */
float * out = malloc(sizeof(*out) * olen); /*Allocate output buffer.*/
size_t odone;

soxr_error_t error = soxr_oneshot(irate, orate, 1, /* Rates and # of chans. */
in, AL(in), NULL, /* Input. */
out, olen, &odone, /* Output. */
NULL, NULL, NULL); /* Default configuration.*/

unsigned i = 0; /* Print out the resampled data, */
while (i++ < odone)
printf("%5.2f%c", out[i-1], " \n"[!(i&7) || i == odone]);

printf("%-26s %s\n", arg[0], soxr_strerror(error)); /* and reported result. */
free(out); /* Tidy up. */
return !!error;
}


Can you help me for translate it to C#?


Thanks in advance


Aucun commentaire:

Enregistrer un commentaire