mirror of
https://github.com/TomHarte/CLK.git
synced 2025-07-25 13:24:23 +00:00
Completed curly bracket movement.
This commit is contained in:
@@ -36,34 +36,28 @@ using namespace SignalProcessing;
|
||||
#define kCSKaiserBesselFilterFixedMultiplier 32767.0f
|
||||
#define kCSKaiserBesselFilterFixedShift 15
|
||||
|
||||
/* ino evaluates the 0th order Bessel function at a */
|
||||
float FIRFilter::ino(float a)
|
||||
{
|
||||
/*! Evaluates the 0th order Bessel function at @c a. */
|
||||
float FIRFilter::ino(float a) {
|
||||
float d = 0.0f;
|
||||
float ds = 1.0f;
|
||||
float s = 1.0f;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
d += 2.0f;
|
||||
ds *= (a * a) / (d * d);
|
||||
s += ds;
|
||||
}
|
||||
while(ds > s*1e-6f);
|
||||
} while(ds > s*1e-6f);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
//static void csfilter_setIdealisedFilterResponse(short *filterCoefficients, float *A, float attenuation, unsigned int numberOfTaps)
|
||||
void FIRFilter::coefficients_for_idealised_filter_response(short *filterCoefficients, float *A, float attenuation, unsigned int numberOfTaps)
|
||||
{
|
||||
void FIRFilter::coefficients_for_idealised_filter_response(short *filterCoefficients, float *A, float attenuation, unsigned int numberOfTaps) {
|
||||
/* calculate alpha, which is the Kaiser-Bessel window shape factor */
|
||||
float a; // to take the place of alpha in the normal derivation
|
||||
|
||||
if(attenuation < 21.0f)
|
||||
if(attenuation < 21.0f) {
|
||||
a = 0.0f;
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if(attenuation > 50.0f)
|
||||
a = 0.1102f * (attenuation - 8.7f);
|
||||
else
|
||||
@@ -76,8 +70,7 @@ void FIRFilter::coefficients_for_idealised_filter_response(short *filterCoeffici
|
||||
unsigned int Np = (numberOfTaps - 1) / 2;
|
||||
float I0 = ino(a);
|
||||
float NpSquared = (float)(Np * Np);
|
||||
for(unsigned int i = 0; i <= Np; i++)
|
||||
{
|
||||
for(unsigned int i = 0; i <= Np; i++) {
|
||||
filterCoefficientsFloat[Np + i] =
|
||||
A[i] *
|
||||
ino(a * sqrtf(1.0f - ((float)(i * i) / NpSquared) )) /
|
||||
@@ -85,38 +78,32 @@ void FIRFilter::coefficients_for_idealised_filter_response(short *filterCoeffici
|
||||
}
|
||||
|
||||
/* coefficients are symmetrical, so copy from right hand side to left side */
|
||||
for(unsigned int i = 0; i < Np; i++)
|
||||
{
|
||||
for(unsigned int i = 0; i < Np; i++) {
|
||||
filterCoefficientsFloat[i] = filterCoefficientsFloat[numberOfTaps - 1 - i];
|
||||
}
|
||||
|
||||
/* scale back up so that we retain 100% of input volume */
|
||||
float coefficientTotal = 0.0f;
|
||||
for(unsigned int i = 0; i < numberOfTaps; i++)
|
||||
{
|
||||
for(unsigned int i = 0; i < numberOfTaps; i++) {
|
||||
coefficientTotal += filterCoefficientsFloat[i];
|
||||
}
|
||||
|
||||
/* we'll also need integer versions, potentially */
|
||||
float coefficientMultiplier = 1.0f / coefficientTotal;
|
||||
for(unsigned int i = 0; i < numberOfTaps; i++)
|
||||
{
|
||||
for(unsigned int i = 0; i < numberOfTaps; i++) {
|
||||
filterCoefficients[i] = (short)(filterCoefficientsFloat[i] * kCSKaiserBesselFilterFixedMultiplier * coefficientMultiplier);
|
||||
}
|
||||
|
||||
delete[] filterCoefficientsFloat;
|
||||
}
|
||||
|
||||
void FIRFilter::get_coefficients(float *coefficients)
|
||||
{
|
||||
for(unsigned int i = 0; i < number_of_taps_; i++)
|
||||
{
|
||||
void FIRFilter::get_coefficients(float *coefficients) {
|
||||
for(unsigned int i = 0; i < number_of_taps_; i++) {
|
||||
coefficients[i] = (float)filter_coefficients_[i] / kCSKaiserBesselFilterFixedMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
FIRFilter::FIRFilter(unsigned int number_of_taps, float input_sample_rate, float low_frequency, float high_frequency, float attenuation)
|
||||
{
|
||||
FIRFilter::FIRFilter(unsigned int number_of_taps, float input_sample_rate, float low_frequency, float high_frequency, float attenuation) {
|
||||
// we must be asked to filter based on an odd number of
|
||||
// taps, and at least three
|
||||
if(number_of_taps < 3) number_of_taps = 3;
|
||||
@@ -135,8 +122,7 @@ FIRFilter::FIRFilter(unsigned int number_of_taps, float input_sample_rate, float
|
||||
|
||||
float *A = new float[Np+1];
|
||||
A[0] = 2.0f * (high_frequency - low_frequency) / input_sample_rate;
|
||||
for(unsigned int i = 1; i <= Np; i++)
|
||||
{
|
||||
for(unsigned int i = 1; i <= Np; i++) {
|
||||
float iPi = (float)i * (float)M_PI;
|
||||
A[i] =
|
||||
(
|
||||
@@ -151,7 +137,6 @@ FIRFilter::FIRFilter(unsigned int number_of_taps, float input_sample_rate, float
|
||||
delete[] A;
|
||||
}
|
||||
|
||||
FIRFilter::~FIRFilter()
|
||||
{
|
||||
FIRFilter::~FIRFilter() {
|
||||
delete[] filter_coefficients_;
|
||||
}
|
||||
|
@@ -57,24 +57,21 @@ class FIRFilter {
|
||||
@param src The source buffer to apply the filter to.
|
||||
@returns The result of applying the filter.
|
||||
*/
|
||||
inline short apply(const short *src)
|
||||
{
|
||||
inline short apply(const short *src) {
|
||||
#ifdef __APPLE__
|
||||
short result;
|
||||
vDSP_dotpr_s1_15(filter_coefficients_, 1, src, 1, &result, number_of_taps_);
|
||||
return result;
|
||||
#else
|
||||
int outputValue = 0;
|
||||
for(unsigned int c = 0; c < number_of_taps_; c++)
|
||||
{
|
||||
for(unsigned int c = 0; c < number_of_taps_; c++) {
|
||||
outputValue += filter_coefficients_[c] * src[c];
|
||||
}
|
||||
return (short)(outputValue >> kCSKaiserBesselFilterFixedShift);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline unsigned int get_number_of_taps()
|
||||
{
|
||||
inline unsigned int get_number_of_taps() {
|
||||
return number_of_taps_;
|
||||
}
|
||||
|
||||
|
@@ -23,8 +23,7 @@ namespace SignalProcessing {
|
||||
Pegs the beginning of both clocks to the time at which the stepper is created. So e.g. a stepper
|
||||
that converts from an input clock of 1200 to an output clock of 2 will first fire on cycle 600.
|
||||
*/
|
||||
class Stepper
|
||||
{
|
||||
class Stepper {
|
||||
public:
|
||||
/*!
|
||||
Establishes a stepper with a one-to-one conversion rate.
|
||||
@@ -48,12 +47,10 @@ class Stepper
|
||||
|
||||
@returns the number of output steps.
|
||||
*/
|
||||
inline uint64_t step()
|
||||
{
|
||||
inline uint64_t step() {
|
||||
uint64_t update = whole_step_;
|
||||
accumulated_error_ += adjustment_up_;
|
||||
if(accumulated_error_ > 0)
|
||||
{
|
||||
if(accumulated_error_ > 0) {
|
||||
update++;
|
||||
accumulated_error_ -= adjustment_down_;
|
||||
}
|
||||
@@ -65,12 +62,10 @@ class Stepper
|
||||
|
||||
@returns the number of output steps.
|
||||
*/
|
||||
inline uint64_t step(uint64_t number_of_steps)
|
||||
{
|
||||
inline uint64_t step(uint64_t number_of_steps) {
|
||||
uint64_t update = whole_step_ * number_of_steps;
|
||||
accumulated_error_ += adjustment_up_ * (int64_t)number_of_steps;
|
||||
if(accumulated_error_ > 0)
|
||||
{
|
||||
if(accumulated_error_ > 0) {
|
||||
update += 1 + (uint64_t)(accumulated_error_ / adjustment_down_);
|
||||
accumulated_error_ = (accumulated_error_ % adjustment_down_) - adjustment_down_;
|
||||
}
|
||||
@@ -80,16 +75,14 @@ class Stepper
|
||||
/*!
|
||||
@returns the output rate.
|
||||
*/
|
||||
inline uint64_t get_output_rate()
|
||||
{
|
||||
inline uint64_t get_output_rate() {
|
||||
return output_rate_;
|
||||
}
|
||||
|
||||
/*!
|
||||
@returns the input rate.
|
||||
*/
|
||||
inline uint64_t get_input_rate()
|
||||
{
|
||||
inline uint64_t get_input_rate() {
|
||||
return input_rate_;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user