#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/platform/audio/biquad.h"
#include "build/build_config.h"
#include "third_party/blink/renderer/platform/audio/audio_utilities.h"
#include "third_party/blink/renderer/platform/audio/denormal_disabler.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/fdlibm/ieee754.h"
#include <stdio.h>
#include <algorithm>
#include <complex>
#if BUILDFLAG(IS_MAC)
#include <Accelerate/Accelerate.h>
#endif
namespace blink {
#if BUILDFLAG(IS_MAC)
const int kBiquadBufferSize = 1024;
#endif
static double pow10(double x) { … }
Biquad::Biquad(unsigned render_quantum_frames)
: … { … }
Biquad::~Biquad() = default;
void Biquad::Process(const float* source_p,
float* dest_p,
uint32_t frames_to_process) { … }
#if BUILDFLAG(IS_MAC)
void Biquad::ProcessFast(const float* source_p,
float* dest_p,
uint32_t frames_to_process) {
double filter_coefficients[5];
filter_coefficients[0] = b0_[0];
filter_coefficients[1] = b1_[0];
filter_coefficients[2] = b2_[0];
filter_coefficients[3] = a1_[0];
filter_coefficients[4] = a2_[0];
double* input_p = input_buffer_.Data();
double* output_p = output_buffer_.Data();
double* input2p = input_p + 2;
double* output2p = output_p + 2;
int n = frames_to_process;
while (n > 0) {
int frames_this_time = n < kBiquadBufferSize ? n : kBiquadBufferSize;
for (int i = 0; i < frames_this_time; ++i)
input2p[i] = *source_p++;
ProcessSliceFast(input_p, output_p, filter_coefficients, frames_this_time);
for (int i = 0; i < frames_this_time; ++i)
*dest_p++ = static_cast<float>(output2p[i]);
n -= frames_this_time;
}
}
void Biquad::ProcessSliceFast(double* source_p,
double* dest_p,
double* coefficients_p,
uint32_t frames_to_process) {
vDSP_deq22D(source_p, 1, coefficients_p, dest_p, 1, frames_to_process);
source_p[0] = source_p[frames_to_process - 2 + 2];
source_p[1] = source_p[frames_to_process - 1 + 2];
dest_p[0] = dest_p[frames_to_process - 2 + 2];
dest_p[1] = dest_p[frames_to_process - 1 + 2];
}
#endif
void Biquad::Reset() { … }
void Biquad::SetLowpassParams(int index, double cutoff, double resonance) { … }
void Biquad::SetHighpassParams(int index, double cutoff, double resonance) { … }
void Biquad::SetNormalizedCoefficients(int index,
double b0,
double b1,
double b2,
double a0,
double a1,
double a2) { … }
void Biquad::SetLowShelfParams(int index, double frequency, double db_gain) { … }
void Biquad::SetHighShelfParams(int index, double frequency, double db_gain) { … }
void Biquad::SetPeakingParams(int index,
double frequency,
double q,
double db_gain) { … }
void Biquad::SetAllpassParams(int index, double frequency, double q) { … }
void Biquad::SetNotchParams(int index, double frequency, double q) { … }
void Biquad::SetBandpassParams(int index, double frequency, double q) { … }
void Biquad::GetFrequencyResponse(int n_frequencies,
const float* frequency,
float* mag_response,
float* phase_response) { … }
static double RepeatedRootResponse(double n,
double c1,
double c2,
double r,
double log_eps) { … }
static double RootFinder(double low,
double high,
double log_eps,
double c1,
double c2,
double r) { … }
double Biquad::TailFrame(int coef_index, double max_frame) { … }
}