Convert CR/LF -> LF

Spotted by Alam Arias
This commit is contained in:
Chris Robinson 2010-03-18 14:23:31 -07:00
parent 781444d12c
commit e1965fe7d9
3 changed files with 1031 additions and 1031 deletions

View File

@ -1,201 +1,201 @@
/*- /*-
* Copyright (c) 2005 Boris Mikhaylov * Copyright (c) 2005 Boris Mikhaylov
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, * without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to * distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to * permit persons to whom the Software is furnished to do so, subject to
* the following conditions: * the following conditions:
* *
* The above copyright notice and this permission notice shall be * The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software. * included in all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include "config.h" #include "config.h"
#include <math.h> #include <math.h>
#include "bs2b.h" #include "bs2b.h"
#ifndef M_PI #ifndef M_PI
#define M_PI 3.14159265358979323846 #define M_PI 3.14159265358979323846
#endif #endif
/* Single pole IIR filter. /* Single pole IIR filter.
* O[n] = a0*I[n] + a1*I[n-1] + b1*O[n-1] * O[n] = a0*I[n] + a1*I[n-1] + b1*O[n-1]
*/ */
/* Lowpass filter */ /* Lowpass filter */
#define lo_filter(in, out_1) (bs2b->a0_lo*(in) + bs2b->b1_lo*(out_1)) #define lo_filter(in, out_1) (bs2b->a0_lo*(in) + bs2b->b1_lo*(out_1))
/* Highboost filter */ /* Highboost filter */
#define hi_filter(in, in_1, out_1) (bs2b->a0_hi*(in) + bs2b->a1_hi*(in_1) + bs2b->b1_hi*(out_1)) #define hi_filter(in, in_1, out_1) (bs2b->a0_hi*(in) + bs2b->a1_hi*(in_1) + bs2b->b1_hi*(out_1))
/* Set up all data. */ /* Set up all data. */
static void init(struct bs2b *bs2b) static void init(struct bs2b *bs2b)
{ {
double Fc_lo, Fc_hi; double Fc_lo, Fc_hi;
double G_lo, G_hi; double G_lo, G_hi;
double x; double x;
if ((bs2b->srate > 192000) || (bs2b->srate < 2000)) if ((bs2b->srate > 192000) || (bs2b->srate < 2000))
bs2b->srate = BS2B_DEFAULT_SRATE; bs2b->srate = BS2B_DEFAULT_SRATE;
switch(bs2b->level) switch(bs2b->level)
{ {
case BS2B_LOW_CLEVEL: /* Low crossfeed level */ case BS2B_LOW_CLEVEL: /* Low crossfeed level */
Fc_lo = 360.0; Fc_lo = 360.0;
Fc_hi = 501.0; Fc_hi = 501.0;
G_lo = 0.398107170553497; G_lo = 0.398107170553497;
G_hi = 0.205671765275719; G_hi = 0.205671765275719;
break; break;
case BS2B_MIDDLE_CLEVEL: /* Middle crossfeed level */ case BS2B_MIDDLE_CLEVEL: /* Middle crossfeed level */
Fc_lo = 500.0; Fc_lo = 500.0;
Fc_hi = 711.0; Fc_hi = 711.0;
G_lo = 0.459726988530872; G_lo = 0.459726988530872;
G_hi = 0.228208484414988; G_hi = 0.228208484414988;
break; break;
case BS2B_HIGH_CLEVEL: /* High crossfeed level (virtual speakers are closer to itself) */ case BS2B_HIGH_CLEVEL: /* High crossfeed level (virtual speakers are closer to itself) */
Fc_lo = 700.0; Fc_lo = 700.0;
Fc_hi = 1021.0; Fc_hi = 1021.0;
G_lo = 0.530884444230988; G_lo = 0.530884444230988;
G_hi = 0.250105790667544; G_hi = 0.250105790667544;
break; break;
case BS2B_LOW_ECLEVEL: /* Low easy crossfeed level */ case BS2B_LOW_ECLEVEL: /* Low easy crossfeed level */
Fc_lo = 360.0; Fc_lo = 360.0;
Fc_hi = 494.0; Fc_hi = 494.0;
G_lo = 0.316227766016838; G_lo = 0.316227766016838;
G_hi = 0.168236228897329; G_hi = 0.168236228897329;
break; break;
case BS2B_MIDDLE_ECLEVEL: /* Middle easy crossfeed level */ case BS2B_MIDDLE_ECLEVEL: /* Middle easy crossfeed level */
Fc_lo = 500.0; Fc_lo = 500.0;
Fc_hi = 689.0; Fc_hi = 689.0;
G_lo = 0.354813389233575; G_lo = 0.354813389233575;
G_hi = 0.187169483835901; G_hi = 0.187169483835901;
break; break;
default: /* High easy crossfeed level */ default: /* High easy crossfeed level */
bs2b->level = BS2B_HIGH_ECLEVEL; bs2b->level = BS2B_HIGH_ECLEVEL;
Fc_lo = 700.0; Fc_lo = 700.0;
Fc_hi = 975.0; Fc_hi = 975.0;
G_lo = 0.398107170553497; G_lo = 0.398107170553497;
G_hi = 0.205671765275719; G_hi = 0.205671765275719;
break; break;
} /* switch */ } /* switch */
/* $fc = $Fc / $s; /* $fc = $Fc / $s;
* $d = 1 / 2 / pi / $fc; * $d = 1 / 2 / pi / $fc;
* $x = exp(-1 / $d); * $x = exp(-1 / $d);
*/ */
x = exp(-2.0 * M_PI * Fc_lo / bs2b->srate); x = exp(-2.0 * M_PI * Fc_lo / bs2b->srate);
bs2b->b1_lo = x; bs2b->b1_lo = x;
bs2b->a0_lo = G_lo * (1.0 - x); bs2b->a0_lo = G_lo * (1.0 - x);
x = exp(-2.0 * M_PI * Fc_hi / bs2b->srate); x = exp(-2.0 * M_PI * Fc_hi / bs2b->srate);
bs2b->b1_hi = x; bs2b->b1_hi = x;
bs2b->a0_hi = 1.0 - G_hi * (1.0 - x); bs2b->a0_hi = 1.0 - G_hi * (1.0 - x);
bs2b->a1_hi = -x; bs2b->a1_hi = -x;
bs2b->gain = 1.0 / (1.0 - G_hi + G_lo); bs2b->gain = 1.0 / (1.0 - G_hi + G_lo);
} /* init */ } /* init */
/* Exported functions. /* Exported functions.
* See descriptions in "bs2b.h" * See descriptions in "bs2b.h"
*/ */
void bs2b_set_level(struct bs2b *bs2b, int level) void bs2b_set_level(struct bs2b *bs2b, int level)
{ {
if(level == bs2b->level) if(level == bs2b->level)
return; return;
bs2b->level = level; bs2b->level = level;
init(bs2b); init(bs2b);
} /* bs2b_set_level */ } /* bs2b_set_level */
int bs2b_get_level(struct bs2b *bs2b) int bs2b_get_level(struct bs2b *bs2b)
{ {
return bs2b->level; return bs2b->level;
} /* bs2b_get_level */ } /* bs2b_get_level */
void bs2b_set_srate(struct bs2b *bs2b, int srate) void bs2b_set_srate(struct bs2b *bs2b, int srate)
{ {
if (srate == bs2b->srate) if (srate == bs2b->srate)
return; return;
bs2b->srate = srate; bs2b->srate = srate;
init(bs2b); init(bs2b);
} /* bs2b_set_srate */ } /* bs2b_set_srate */
int bs2b_get_srate(struct bs2b *bs2b) int bs2b_get_srate(struct bs2b *bs2b)
{ {
return bs2b->srate; return bs2b->srate;
} /* bs2b_get_srate */ } /* bs2b_get_srate */
void bs2b_clear(struct bs2b *bs2b) void bs2b_clear(struct bs2b *bs2b)
{ {
int loopv = sizeof(bs2b->last_sample); int loopv = sizeof(bs2b->last_sample);
while (loopv) while (loopv)
{ {
((char *)&bs2b->last_sample)[--loopv] = 0; ((char *)&bs2b->last_sample)[--loopv] = 0;
} }
} /* bs2b_clear */ } /* bs2b_clear */
int bs2b_is_clear(struct bs2b *bs2b) int bs2b_is_clear(struct bs2b *bs2b)
{ {
int loopv = sizeof(bs2b->last_sample); int loopv = sizeof(bs2b->last_sample);
while (loopv) while (loopv)
{ {
if (((char *)&bs2b->last_sample)[--loopv] != 0) if (((char *)&bs2b->last_sample)[--loopv] != 0)
return 0; return 0;
} }
return 1; return 1;
} /* bs2b_is_clear */ } /* bs2b_is_clear */
void bs2b_cross_feed(struct bs2b *bs2b, float *sample) void bs2b_cross_feed(struct bs2b *bs2b, float *sample)
{ {
/* Lowpass filter */ /* Lowpass filter */
bs2b->last_sample.lo[0] = lo_filter(sample[0], bs2b->last_sample.lo[0]); bs2b->last_sample.lo[0] = lo_filter(sample[0], bs2b->last_sample.lo[0]);
bs2b->last_sample.lo[1] = lo_filter(sample[1], bs2b->last_sample.lo[1]); bs2b->last_sample.lo[1] = lo_filter(sample[1], bs2b->last_sample.lo[1]);
/* Highboost filter */ /* Highboost filter */
bs2b->last_sample.hi[0] = hi_filter(sample[0], bs2b->last_sample.asis[0], bs2b->last_sample.hi[0]); bs2b->last_sample.hi[0] = hi_filter(sample[0], bs2b->last_sample.asis[0], bs2b->last_sample.hi[0]);
bs2b->last_sample.hi[1] = hi_filter(sample[1], bs2b->last_sample.asis[1], bs2b->last_sample.hi[1]); bs2b->last_sample.hi[1] = hi_filter(sample[1], bs2b->last_sample.asis[1], bs2b->last_sample.hi[1]);
bs2b->last_sample.asis[0] = sample[0]; bs2b->last_sample.asis[0] = sample[0];
bs2b->last_sample.asis[1] = sample[1]; bs2b->last_sample.asis[1] = sample[1];
/* Crossfeed */ /* Crossfeed */
sample[0] = bs2b->last_sample.hi[0] + bs2b->last_sample.lo[1]; sample[0] = bs2b->last_sample.hi[0] + bs2b->last_sample.lo[1];
sample[1] = bs2b->last_sample.hi[1] + bs2b->last_sample.lo[0]; sample[1] = bs2b->last_sample.hi[1] + bs2b->last_sample.lo[0];
/* Bass boost cause allpass attenuation */ /* Bass boost cause allpass attenuation */
sample[0] *= bs2b->gain; sample[0] *= bs2b->gain;
sample[1] *= bs2b->gain; sample[1] *= bs2b->gain;
/* Clipping of overloaded samples */ /* Clipping of overloaded samples */
#if 0 #if 0
if (sample[0] > 1.0) if (sample[0] > 1.0)
sample[0] = 1.0; sample[0] = 1.0;
if (sample[0] < -1.0) if (sample[0] < -1.0)
sample[0] = -1.0; sample[0] = -1.0;
if (sample[1] > 1.0) if (sample[1] > 1.0)
sample[1] = 1.0; sample[1] = 1.0;
if (sample[1] < -1.0) if (sample[1] < -1.0)
sample[1] = -1.0; sample[1] = -1.0;
#endif #endif
} /* bs2b_cross_feed */ } /* bs2b_cross_feed */

View File

@ -1,109 +1,109 @@
/*- /*-
* Copyright (c) 2005 Boris Mikhaylov * Copyright (c) 2005 Boris Mikhaylov
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, * without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to * distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to * permit persons to whom the Software is furnished to do so, subject to
* the following conditions: * the following conditions:
* *
* The above copyright notice and this permission notice shall be * The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software. * included in all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#ifndef BS2B_H #ifndef BS2B_H
#define BS2B_H #define BS2B_H
/* Number of crossfeed levels */ /* Number of crossfeed levels */
#define BS2B_CLEVELS 3 #define BS2B_CLEVELS 3
/* Normal crossfeed levels */ /* Normal crossfeed levels */
#define BS2B_HIGH_CLEVEL 3 #define BS2B_HIGH_CLEVEL 3
#define BS2B_MIDDLE_CLEVEL 2 #define BS2B_MIDDLE_CLEVEL 2
#define BS2B_LOW_CLEVEL 1 #define BS2B_LOW_CLEVEL 1
/* Easy crossfeed levels */ /* Easy crossfeed levels */
#define BS2B_HIGH_ECLEVEL BS2B_HIGH_CLEVEL + BS2B_CLEVELS #define BS2B_HIGH_ECLEVEL BS2B_HIGH_CLEVEL + BS2B_CLEVELS
#define BS2B_MIDDLE_ECLEVEL BS2B_MIDDLE_CLEVEL + BS2B_CLEVELS #define BS2B_MIDDLE_ECLEVEL BS2B_MIDDLE_CLEVEL + BS2B_CLEVELS
#define BS2B_LOW_ECLEVEL BS2B_LOW_CLEVEL + BS2B_CLEVELS #define BS2B_LOW_ECLEVEL BS2B_LOW_CLEVEL + BS2B_CLEVELS
/* Default crossfeed levels */ /* Default crossfeed levels */
#define BS2B_DEFAULT_CLEVEL BS2B_HIGH_ECLEVEL #define BS2B_DEFAULT_CLEVEL BS2B_HIGH_ECLEVEL
/* Default sample rate (Hz) */ /* Default sample rate (Hz) */
#define BS2B_DEFAULT_SRATE 44100 #define BS2B_DEFAULT_SRATE 44100
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
struct bs2b { struct bs2b {
int level; /* Crossfeed level */ int level; /* Crossfeed level */
int srate; /* Sample rate (Hz) */ int srate; /* Sample rate (Hz) */
/* Lowpass IIR filter coefficients */ /* Lowpass IIR filter coefficients */
double a0_lo; double a0_lo;
double b1_lo; double b1_lo;
/* Highboost IIR filter coefficients */ /* Highboost IIR filter coefficients */
double a0_hi; double a0_hi;
double a1_hi; double a1_hi;
double b1_hi; double b1_hi;
/* Global gain against overloading */ /* Global gain against overloading */
double gain; double gain;
/* Buffer of last filtered sample. /* Buffer of last filtered sample.
* [0] - first channel, [1] - second channel * [0] - first channel, [1] - second channel
*/ */
struct t_last_sample { struct t_last_sample {
double asis[2]; double asis[2];
double lo[2]; double lo[2];
double hi[2]; double hi[2];
} last_sample; } last_sample;
}; };
/* Clear buffers and set new coefficients with new crossfeed level value. /* Clear buffers and set new coefficients with new crossfeed level value.
* level - crossfeed level of *LEVEL values. * level - crossfeed level of *LEVEL values.
*/ */
void bs2b_set_level(struct bs2b *bs2b, int level); void bs2b_set_level(struct bs2b *bs2b, int level);
/* Return current crossfeed level value */ /* Return current crossfeed level value */
int bs2b_get_level(struct bs2b *bs2b); int bs2b_get_level(struct bs2b *bs2b);
/* Clear buffers and set new coefficients with new sample rate value. /* Clear buffers and set new coefficients with new sample rate value.
* srate - sample rate by Hz. * srate - sample rate by Hz.
*/ */
void bs2b_set_srate(struct bs2b *bs2b, int srate); void bs2b_set_srate(struct bs2b *bs2b, int srate);
/* Return current sample rate value */ /* Return current sample rate value */
int bs2b_get_srate(struct bs2b *bs2b); int bs2b_get_srate(struct bs2b *bs2b);
/* Clear buffer */ /* Clear buffer */
void bs2b_clear(struct bs2b *bs2b); void bs2b_clear(struct bs2b *bs2b);
/* Return 1 if buffer is clear */ /* Return 1 if buffer is clear */
int bs2b_is_clear(struct bs2b *bs2b); int bs2b_is_clear(struct bs2b *bs2b);
/* Crossfeeds one stereo sample that are pointed by sample. /* Crossfeeds one stereo sample that are pointed by sample.
* [0] - first channel, [1] - second channel. * [0] - first channel, [1] - second channel.
* Returns crossfided samle by sample pointer. * Returns crossfided samle by sample pointer.
*/ */
/* sample poits to floats */ /* sample poits to floats */
void bs2b_cross_feed(struct bs2b *bs2b, float *sample); void bs2b_cross_feed(struct bs2b *bs2b, float *sample);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* BS2B_H */ #endif /* BS2B_H */

File diff suppressed because it is too large Load Diff