mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-22 14:32:58 +02:00
Reverting r12850...hopefully
Never removed one before, but I'm pretty sure it is correct.
This commit is contained in:
@@ -1,48 +1,48 @@
|
||||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Example 1: `One-shot' resample a single block of data in memory.
|
||||
*
|
||||
* N.B. See example 2 for how to resample a stream (of blocks).
|
||||
*
|
||||
* 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 = argc > 1? atof(arg[1]) : 1; /* Default to upsampling */
|
||||
double orate = argc > 2? atof(arg[2]) : 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]);
|
||||
puts(soxr_strerror(error)); /* ...and the reported result. */
|
||||
|
||||
free(out); /* Tidy up. */
|
||||
return !!error;
|
||||
(void)argc, (void)arg; /* Not used in this example. */
|
||||
}
|
||||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Example 1: `One-shot' resample a single block of data in memory.
|
||||
*
|
||||
* N.B. See example 2 for how to resample a stream (of blocks).
|
||||
*
|
||||
* 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 = argc > 1? atof(arg[1]) : 1; /* Default to upsampling */
|
||||
double orate = argc > 2? atof(arg[2]) : 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]);
|
||||
puts(soxr_strerror(error)); /* ...and the reported result. */
|
||||
|
||||
free(out); /* Tidy up. */
|
||||
return !!error;
|
||||
(void)argc, (void)arg; /* Not used in this example. */
|
||||
}
|
||||
|
Reference in New Issue
Block a user