Home | History | Annotate | Download | only in dsp
      1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
      2  * Use of this source code is governed by a BSD-style license that can be
      3  * found in the LICENSE file.
      4  */
      5 
      6 #ifndef EQ2_H_
      7 #define EQ2_H_
      8 
      9 #ifdef __cplusplus
     10 extern "C" {
     11 #endif
     12 
     13 /* "eq2" is a two channel version of the "eq" filter. It processes two channels
     14  * of data at once to increase performance. */
     15 
     16 #include "biquad.h"
     17 
     18 /* Maximum number of biquad filters an EQ2 can have per channel */
     19 #define MAX_BIQUADS_PER_EQ2 10
     20 
     21 struct eq2;
     22 
     23 /* Create an EQ2. */
     24 struct eq2 *eq2_new();
     25 
     26 /* Free an EQ2. */
     27 void eq2_free(struct eq2 *eq2);
     28 
     29 /* Append a biquad filter to an EQ2. An EQ2 can have at most MAX_BIQUADS_PER_EQ2
     30  * biquad filters per channel.
     31  * Args:
     32  *    eq2 - The EQ2 we want to use.
     33  *    channel - 0 or 1. The channel we want to append the filter to.
     34  *    type - The type of the biquad filter we want to append.
     35  *    frequency - The value should be in the range [0, 1]. It is relative to
     36  *        half of the sampling rate.
     37  *    Q, gain - The meaning depends on the type of the filter. See Web Audio
     38  *        API for details.
     39  * Returns:
     40  *    0 if success. -1 if the eq has no room for more biquads.
     41  */
     42 int eq2_append_biquad(struct eq2 *eq2, int channel,
     43 		      enum biquad_type type, float freq, float Q, float gain);
     44 
     45 /* Append a biquad filter to an EQ2. An EQ2 can have at most MAX_BIQUADS_PER_EQ2
     46  * biquad filters. This is similar to eq2_append_biquad(), but it specifies the
     47  * biquad coefficients directly.
     48  * Args:
     49  *    eq2 - The EQ2 we want to use.
     50  *    channel - 0 or 1. The channel we want to append the filter to.
     51  *    biquad - The parameters for the biquad filter.
     52  * Returns:
     53  *    0 if success. -1 if the eq has no room for more biquads.
     54  */
     55 int eq2_append_biquad_direct(struct eq2 *eq2, int channel,
     56 			     const struct biquad *biquad);
     57 
     58 /* Process a buffer of audio data through the EQ2.
     59  * Args:
     60  *    eq2 - The EQ2 we want to use.
     61  *    data0 - The array of channel 0 audio samples.
     62  *    data1 - The array of channel 1 audio samples.
     63  *    count - The number of elements in each of the data array to process.
     64  */
     65 void eq2_process(struct eq2 *eq2, float *data0, float *data1, int count);
     66 
     67 #ifdef __cplusplus
     68 } /* extern "C" */
     69 #endif
     70 
     71 #endif /* EQ2_H_ */
     72