ref: 2c4651293b18eceac8cbb39ed4d3e48667941d52
parent: 18298ac2ea381cbee1b7e45cf0c824cca29b097e
author: cbagwell <cbagwell>
date: Fri Mar 5 15:54:19 EST 1999
Updating resample effect and fixing SEEK_* stuff
--- a/Changelog
+++ b/Changelog
@@ -37,6 +37,9 @@
o Made AIFF handler work with invalid headers that some programs generate.
Also fix an Endian bug thats been there for quick a long time (when
ran on Intel machines).
+ o Resample function was updated by Andreas Wilde
+ (andreas@eakaw2.et.tu-dresden.de) to fix problem were freqs. were
+ off by a factor of 2.
sox-12.15
---------
--- a/TODO
+++ b/TODO
@@ -15,15 +15,6 @@
o Grab latest stand alone version of resample and replace Sox's
outdated version.
- o Find a mantainer for each supported platform. Try hard to shrink
- the number of makefiles by having all systems compile using one
- makefile.
-
- o Fix for how include files are found when fseek() is used. In most
- configs it has to hardcode the values for things like SEEK_SET. *BAD*
- Include files are a mess, i.e. fseek problem. Need to resort to
- something like autoconf to really support all these platforms.
-
o Create a version of OSS and Sun driver that can play and record from the
same device in duplex.
--- a/sox.1
+++ b/sox.1
@@ -9,7 +9,7 @@
.if t .sp .5v
.if n .sp
..
-.TH SoX 1 "September 6, 1998"
+.TH SoX 1 "March 5, 1999"
.SH NAME
sox \- Sound eXchange : universal sound sample translator
.SH SYNOPSIS
@@ -622,11 +622,19 @@
resample [ \fIrolloff\fR [ \fIbeta\fR ] ]
Translate input sampling rate to output sampling rate
via simulated analog filtration.
-This method is slow and uses lots of RAM,
-but gives much better results then
-.B rate
-(This has empirically been shown to be false. The
-resample algorthym needs to be updated from its original source).
+This method is slower than
+.B rate,
+but gives much
+better results. rolloff refers to the cut-off frequency of the
+low pass filter and is given in terms of the
+Nyquist frequency for the lower sample rate. rolloff therefor should
+be something between 0. and 1., in practice 0.8-0.95. beta trades stop band
+rejection against transition width from passband to stop band. Larger
+beta means a slower transition and greater stopband rejection. beta
+should be at least greater than 2. The default is rollof 0.8, beta 17.5,
+which is rather conservative with respect to aliasing. Lower beta
+and higher rolloff values preserve more high frequency signal energy,
+but introduce measurable artifacts.
.TP 10
reverb \fIgain-out delay \fR[ \fIdelay ... \fR]
Add reverbation to a sound sample. Each delay is given
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -6,9 +6,16 @@
#include <errno.h>
#include <string.h>
#include <stdlib.h>
+#include <stdio.h>
+
#ifdef VMS
#include <perror.h>
#endif
+
+#ifdef unix
+#include <unistd.h> /* For SEEK_* defines if not found in stdio */
+#endif
+
#include "st.h"
/* Private data used by writer */
@@ -16,13 +23,6 @@
ULONG nsamples;
FILE *ch[4];
};
-
-#ifndef SEEK_CUR
-#define SEEK_CUR 1
-#endif
-#ifndef SEEK_SET
-#define SEEK_SET 0
-#endif
void svxwriteheader(P2(ft_t, LONG));
--- a/src/cvsd.c
+++ b/src/cvsd.c
@@ -39,10 +39,11 @@
#include <math.h>
#include <string.h>
#include <time.h>
+#include <stdio.h>
-#ifndef SEEK_SET
-#define SEEK_SET 0 /* nasty nasty */
-#endif /* SEEK_SET */
+#ifdef unix
+#include <unistd.h> /* For SEEK_* defines if not found in stdio */
+#endif
#include "cvsdfilt.h"
#include "st.h"
--- a/src/maud.c
+++ b/src/maud.c
@@ -21,8 +21,11 @@
#include "libst.h"
#include <string.h>
#include <stdlib.h>
+#include <stdio.h>
-#define SEEK_CUR 1 /* nasty nasty */
+#ifdef unix
+#include <unistd.h> /* For SEEK_* defines if not found in stdio */
+#endif
/* Private data for MAUD file */
struct maudstuff { /* max. 100 bytes!!!! */
--- a/src/resample.c
+++ b/src/resample.c
@@ -24,7 +24,10 @@
* version of the above software! Someone please perform this and
* send patches to cbagwell@sprynet.com.
*/
-
+/* Fixed bug: roll off frequency was wrong, too high by 2 when upsampling,
+ * too low by 2 when downsampling.
+ * Andreas Wilde, 12. Feb. 1999, andreas@eakaw2.et.tu-dresden.de
+*/
#include <math.h>
#include <stdlib.h>
#include "st.h"
@@ -33,7 +36,7 @@
#include "resdefs.h"
#include "resampl.h"
-#define IBUFFSIZE 1024 /* Input buffer size */
+#define IBUFFSIZE 4096 /* Input buffer size */
#define OBUFFSIZE (IBUFFSIZE*MAXFACTOR+2) /* Calc'd out buffer size */
/* Private data for Lerp via LCM file */
@@ -104,10 +107,11 @@
{
resample_t resample = (resample_t) effp->priv;
- resample->rolloff = 0.85;
- resample->beta = 2.120;
+ /* These defaults are conservative with respect to aliasing. */
+ resample->rolloff = 0.8;
+ resample->beta = 17.5;
- /* I don't know why this fails! */
+ /* This used to fail, but with sox-12.15 it works. AW */
if ((n >= 1) && !sscanf(argv[0], "%lf", &resample->rolloff))
fail("Usage: resample [ rolloff [ beta ] ]");
else if ((resample->rolloff < 0.01) || (resample->rolloff > 1.0))
@@ -118,10 +122,8 @@
else if (resample->beta < 1.0)
fail("resample: beta factor (%f) no good, should be >= 1.0",
resample->beta);
- /*
fprintf(stderr, "resample opts: %f, %f\n",
resample->rolloff, resample->beta);
- */
}
/*
@@ -133,12 +135,6 @@
resample_t resample = (resample_t) effp->priv;
int i;
- if ((LONG)effp->ininfo.rate > (LONG)effp->outinfo.rate)
- resample->rolloff = ((double)effp->outinfo.rate /
- (double)effp->ininfo.rate) * 0.97; /* empirical */
- else
- resample->rolloff = 0.85;
-
resample->InterpFilt = 1; /* interpolate filter: slower */
resample->Factor =
(double)effp->outinfo.rate / (double)effp->ininfo.rate;
@@ -571,11 +567,11 @@
int i;
/* Calculate filter coeffs: */
- c[0] = 2.0*frq;
+ c[0] = frq;
for (i=1; i<N; i++)
{
temp = PI*(double)i/(double)Num;
- c[i] = sin(2.0*temp*frq)/temp;
+ c[i] = sin(temp*frq)/temp;
}
/* Calculate and Apply Kaiser window to filter coeffs: */
--- a/src/reverse.c
+++ b/src/reverse.c
@@ -13,19 +13,15 @@
*/
#include <math.h>
+#include <stdio.h>
+
+#ifdef unix
+#include <unistd.h> /* For SEEK_* defines if not found in stdio */
+#endif
+
#include "st.h"
IMPORT FILE *tmpfile();
-
-#ifndef SEEK_SET
-#define SEEK_SET 0
-#endif
-#ifndef SEEK_CUR
-#define SEEK_CUR 1
-#endif
-#ifndef SEEK_END
-#define SEEK_END 2
-#endif
/* Private data */
typedef struct reversestuff {
--- a/src/sndrtool.c
+++ b/src/sndrtool.c
@@ -9,6 +9,12 @@
#include <math.h>
#include <string.h>
+#include <stdio.h>
+
+#ifdef unix
+#include <unistd.h> /* For SEEK_* defines if not found in stdio */
+#endif
+
#include "st.h"
/* Private data used by writer */