Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-1.1
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-1.1
Commits
1ea3602b
Commit
1ea3602b
authored
Feb 14, 2006
by
Christophe Mutricy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
param_eq.c: eol style
parent
8cf1cce6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
344 additions
and
344 deletions
+344
-344
modules/audio_filter/param_eq.c
modules/audio_filter/param_eq.c
+344
-344
No files found.
modules/audio_filter/param_eq.c
View file @
1ea3602b
/*****************************************************************************
/*****************************************************************************
* param_eq.c:
* param_eq.c:
*****************************************************************************
*****************************************************************************
* Copyright (C) 2006 the VideoLAN team
* Copyright (C) 2006 the VideoLAN team
* $Id
: equalizer.c 13905 2006-01-12 23:10:04Z dionoea $
* $Id
$
*
*
* Authors: Antti Huovilainen
* Authors: Antti Huovilainen
* Sigmund A. Helberg <dnumgis@videolan.org>
* Sigmund A. Helberg <dnumgis@videolan.org>
*
*
* This program is free software; you can redistribute it and/or modify
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
*****************************************************************************/
/*****************************************************************************
/*****************************************************************************
* Preamble
* Preamble
*****************************************************************************/
*****************************************************************************/
#include <stdlib.h>
/* malloc(), free() */
#include <stdlib.h>
/* malloc(), free() */
#include <string.h>
#include <string.h>
#include <math.h>
#include <math.h>
#include <vlc/vlc.h>
#include <vlc/vlc.h>
#include <vlc/aout.h>
#include <vlc/aout.h>
#include "aout_internal.h"
#include "aout_internal.h"
/*****************************************************************************
/*****************************************************************************
* Module descriptor
* Module descriptor
*****************************************************************************/
*****************************************************************************/
static
int
Open
(
vlc_object_t
*
);
static
int
Open
(
vlc_object_t
*
);
static
void
Close
(
vlc_object_t
*
);
static
void
Close
(
vlc_object_t
*
);
static
void
CalcPeakEQCoeffs
(
float
,
float
,
float
,
float
,
float
*
);
static
void
CalcPeakEQCoeffs
(
float
,
float
,
float
,
float
,
float
*
);
static
void
CalcShelfEQCoeffs
(
float
,
float
,
float
,
int
,
float
,
float
*
);
static
void
CalcShelfEQCoeffs
(
float
,
float
,
float
,
int
,
float
,
float
*
);
static
void
ProcessEQ
(
float
*
,
float
*
,
float
*
,
int
,
int
,
float
*
,
int
);
static
void
ProcessEQ
(
float
*
,
float
*
,
float
*
,
int
,
int
,
float
*
,
int
);
static
void
DoWork
(
aout_instance_t
*
,
aout_filter_t
*
,
static
void
DoWork
(
aout_instance_t
*
,
aout_filter_t
*
,
aout_buffer_t
*
,
aout_buffer_t
*
);
aout_buffer_t
*
,
aout_buffer_t
*
);
vlc_module_begin
();
vlc_module_begin
();
set_description
(
_
(
"Parametric Equalizer"
)
);
set_description
(
_
(
"Parametric Equalizer"
)
);
set_shortname
(
N_
(
"Parametric Equalizer"
)
);
set_shortname
(
N_
(
"Parametric Equalizer"
)
);
set_capability
(
"audio filter"
,
0
);
set_capability
(
"audio filter"
,
0
);
set_category
(
CAT_AUDIO
);
set_category
(
CAT_AUDIO
);
set_subcategory
(
SUBCAT_AUDIO_AFILTER
);
set_subcategory
(
SUBCAT_AUDIO_AFILTER
);
add_float
(
"param-eq-lowf"
,
100
,
NULL
,
N_
(
"Low freq (Hz)"
),
NULL
,
VLC_FALSE
);
add_float
(
"param-eq-lowf"
,
100
,
NULL
,
N_
(
"Low freq (Hz)"
),
NULL
,
VLC_FALSE
);
add_float_with_range
(
"param-eq-lowgain"
,
0
,
-
20
.
0
,
20
.
0
,
NULL
,
add_float_with_range
(
"param-eq-lowgain"
,
0
,
-
20
.
0
,
20
.
0
,
NULL
,
N_
(
"Low freq gain (Db)"
),
NULL
,
VLC_FALSE
);
N_
(
"Low freq gain (Db)"
),
NULL
,
VLC_FALSE
);
add_float
(
"param-eq-highf"
,
10000
,
NULL
,
N_
(
"High freq (Hz)"
),
NULL
,
VLC_FALSE
);
add_float
(
"param-eq-highf"
,
10000
,
NULL
,
N_
(
"High freq (Hz)"
),
NULL
,
VLC_FALSE
);
add_float_with_range
(
"param-eq-highgain"
,
0
,
-
20
.
0
,
20
.
0
,
NULL
,
add_float_with_range
(
"param-eq-highgain"
,
0
,
-
20
.
0
,
20
.
0
,
NULL
,
N_
(
"High freq gain (Db)"
),
NULL
,
VLC_FALSE
);
N_
(
"High freq gain (Db)"
),
NULL
,
VLC_FALSE
);
add_float
(
"param-eq-f1"
,
300
,
NULL
,
N_
(
"Freq 1 (Hz)"
),
NULL
,
VLC_FALSE
);
add_float
(
"param-eq-f1"
,
300
,
NULL
,
N_
(
"Freq 1 (Hz)"
),
NULL
,
VLC_FALSE
);
add_float_with_range
(
"param-eq-gain1"
,
0
,
-
20
.
0
,
20
.
0
,
NULL
,
add_float_with_range
(
"param-eq-gain1"
,
0
,
-
20
.
0
,
20
.
0
,
NULL
,
N_
(
"Freq 1 gain (Db)"
),
NULL
,
VLC_FALSE
);
N_
(
"Freq 1 gain (Db)"
),
NULL
,
VLC_FALSE
);
add_float_with_range
(
"param-eq-q1"
,
3
,
0
.
1
,
100
.
0
,
NULL
,
add_float_with_range
(
"param-eq-q1"
,
3
,
0
.
1
,
100
.
0
,
NULL
,
N_
(
"Freq 1 Q"
),
NULL
,
VLC_FALSE
);
N_
(
"Freq 1 Q"
),
NULL
,
VLC_FALSE
);
add_float
(
"param-eq-f2"
,
1000
,
NULL
,
N_
(
"Freq 2 (Hz)"
),
NULL
,
VLC_FALSE
);
add_float
(
"param-eq-f2"
,
1000
,
NULL
,
N_
(
"Freq 2 (Hz)"
),
NULL
,
VLC_FALSE
);
add_float_with_range
(
"param-eq-gain2"
,
0
,
-
20
.
0
,
20
.
0
,
NULL
,
add_float_with_range
(
"param-eq-gain2"
,
0
,
-
20
.
0
,
20
.
0
,
NULL
,
N_
(
"Freq 2 gain (Db)"
),
NULL
,
VLC_FALSE
);
N_
(
"Freq 2 gain (Db)"
),
NULL
,
VLC_FALSE
);
add_float_with_range
(
"param-eq-q2"
,
3
,
0
.
1
,
100
.
0
,
NULL
,
add_float_with_range
(
"param-eq-q2"
,
3
,
0
.
1
,
100
.
0
,
NULL
,
N_
(
"Freq 2 Q"
),
NULL
,
VLC_FALSE
);
N_
(
"Freq 2 Q"
),
NULL
,
VLC_FALSE
);
add_float
(
"param-eq-f3"
,
3000
,
NULL
,
N_
(
"Freq 3 (Hz)"
),
NULL
,
VLC_FALSE
);
add_float
(
"param-eq-f3"
,
3000
,
NULL
,
N_
(
"Freq 3 (Hz)"
),
NULL
,
VLC_FALSE
);
add_float_with_range
(
"param-eq-gain3"
,
0
,
-
20
.
0
,
20
.
0
,
NULL
,
add_float_with_range
(
"param-eq-gain3"
,
0
,
-
20
.
0
,
20
.
0
,
NULL
,
N_
(
"Freq 3 gain (Db)"
),
NULL
,
VLC_FALSE
);
N_
(
"Freq 3 gain (Db)"
),
NULL
,
VLC_FALSE
);
add_float_with_range
(
"param-eq-q3"
,
3
,
0
.
1
,
100
.
0
,
NULL
,
add_float_with_range
(
"param-eq-q3"
,
3
,
0
.
1
,
100
.
0
,
NULL
,
N_
(
"Freq 3 Q"
),
NULL
,
VLC_FALSE
);
N_
(
"Freq 3 Q"
),
NULL
,
VLC_FALSE
);
set_callbacks
(
Open
,
Close
);
set_callbacks
(
Open
,
Close
);
vlc_module_end
();
vlc_module_end
();
/*****************************************************************************
/*****************************************************************************
* Local prototypes
* Local prototypes
*****************************************************************************/
*****************************************************************************/
typedef
struct
aout_filter_sys_t
typedef
struct
aout_filter_sys_t
{
{
/* Filter static config */
/* Filter static config */
float
f_lowf
,
f_lowgain
;
float
f_lowf
,
f_lowgain
;
float
f_f1
,
f_Q1
,
f_gain1
;
float
f_f1
,
f_Q1
,
f_gain1
;
float
f_f2
,
f_Q2
,
f_gain2
;
float
f_f2
,
f_Q2
,
f_gain2
;
float
f_f3
,
f_Q3
,
f_gain3
;
float
f_f3
,
f_Q3
,
f_gain3
;
float
f_highf
,
f_highgain
;
float
f_highf
,
f_highgain
;
/* Filter computed coeffs */
/* Filter computed coeffs */
float
coeffs
[
5
*
5
];
float
coeffs
[
5
*
5
];
/* State */
/* State */
float
*
p_state
;
float
*
p_state
;
}
aout_filter_sys_t
;
}
aout_filter_sys_t
;
/*****************************************************************************
/*****************************************************************************
* Open:
* Open:
*****************************************************************************/
*****************************************************************************/
static
int
Open
(
vlc_object_t
*
p_this
)
static
int
Open
(
vlc_object_t
*
p_this
)
{
{
aout_filter_t
*
p_filter
=
(
aout_filter_t
*
)
p_this
;
aout_filter_t
*
p_filter
=
(
aout_filter_t
*
)
p_this
;
aout_filter_sys_t
*
p_sys
;
aout_filter_sys_t
*
p_sys
;
vlc_bool_t
b_fit
=
VLC_TRUE
;
vlc_bool_t
b_fit
=
VLC_TRUE
;
int
i_samplerate
;
int
i_samplerate
;
if
(
p_filter
->
input
.
i_format
!=
VLC_FOURCC
(
'f'
,
'l'
,
'3'
,
'2'
)
||
if
(
p_filter
->
input
.
i_format
!=
VLC_FOURCC
(
'f'
,
'l'
,
'3'
,
'2'
)
||
p_filter
->
output
.
i_format
!=
VLC_FOURCC
(
'f'
,
'l'
,
'3'
,
'2'
)
)
p_filter
->
output
.
i_format
!=
VLC_FOURCC
(
'f'
,
'l'
,
'3'
,
'2'
)
)
{
{
b_fit
=
VLC_FALSE
;
b_fit
=
VLC_FALSE
;
p_filter
->
input
.
i_format
=
VLC_FOURCC
(
'f'
,
'l'
,
'3'
,
'2'
);
p_filter
->
input
.
i_format
=
VLC_FOURCC
(
'f'
,
'l'
,
'3'
,
'2'
);
p_filter
->
output
.
i_format
=
VLC_FOURCC
(
'f'
,
'l'
,
'3'
,
'2'
);
p_filter
->
output
.
i_format
=
VLC_FOURCC
(
'f'
,
'l'
,
'3'
,
'2'
);
msg_Warn
(
p_filter
,
"Bad input or output format"
);
msg_Warn
(
p_filter
,
"Bad input or output format"
);
}
}
if
(
!
AOUT_FMTS_SIMILAR
(
&
p_filter
->
input
,
&
p_filter
->
output
)
)
if
(
!
AOUT_FMTS_SIMILAR
(
&
p_filter
->
input
,
&
p_filter
->
output
)
)
{
{
b_fit
=
VLC_FALSE
;
b_fit
=
VLC_FALSE
;
memcpy
(
&
p_filter
->
output
,
&
p_filter
->
input
,
memcpy
(
&
p_filter
->
output
,
&
p_filter
->
input
,
sizeof
(
audio_sample_format_t
)
);
sizeof
(
audio_sample_format_t
)
);
msg_Warn
(
p_filter
,
"input and output formats are not similar"
);
msg_Warn
(
p_filter
,
"input and output formats are not similar"
);
}
}
if
(
!
b_fit
)
if
(
!
b_fit
)
{
{
return
VLC_EGENERIC
;
return
VLC_EGENERIC
;
}
}
p_filter
->
pf_do_work
=
DoWork
;
p_filter
->
pf_do_work
=
DoWork
;
p_filter
->
b_in_place
=
VLC_TRUE
;
p_filter
->
b_in_place
=
VLC_TRUE
;
/* Allocate structure */
/* Allocate structure */
p_sys
=
p_filter
->
p_sys
=
malloc
(
sizeof
(
aout_filter_sys_t
)
);
p_sys
=
p_filter
->
p_sys
=
malloc
(
sizeof
(
aout_filter_sys_t
)
);
p_sys
->
f_lowf
=
config_GetFloat
(
p_this
,
"param-eq-lowf"
);
p_sys
->
f_lowf
=
config_GetFloat
(
p_this
,
"param-eq-lowf"
);
p_sys
->
f_lowgain
=
config_GetFloat
(
p_this
,
"param-eq-lowgain"
);
p_sys
->
f_lowgain
=
config_GetFloat
(
p_this
,
"param-eq-lowgain"
);
p_sys
->
f_highf
=
config_GetFloat
(
p_this
,
"param-eq-highf"
);
p_sys
->
f_highf
=
config_GetFloat
(
p_this
,
"param-eq-highf"
);
p_sys
->
f_highgain
=
config_GetFloat
(
p_this
,
"param-eq-highgain"
);
p_sys
->
f_highgain
=
config_GetFloat
(
p_this
,
"param-eq-highgain"
);
p_sys
->
f_f1
=
config_GetFloat
(
p_this
,
"param-eq-f1"
);
p_sys
->
f_f1
=
config_GetFloat
(
p_this
,
"param-eq-f1"
);
p_sys
->
f_Q1
=
config_GetFloat
(
p_this
,
"param-eq-q1"
);
p_sys
->
f_Q1
=
config_GetFloat
(
p_this
,
"param-eq-q1"
);
p_sys
->
f_gain1
=
config_GetFloat
(
p_this
,
"param-eq-gain1"
);
p_sys
->
f_gain1
=
config_GetFloat
(
p_this
,
"param-eq-gain1"
);
p_sys
->
f_f2
=
config_GetFloat
(
p_this
,
"param-eq-f2"
);
p_sys
->
f_f2
=
config_GetFloat
(
p_this
,
"param-eq-f2"
);
p_sys
->
f_Q2
=
config_GetFloat
(
p_this
,
"param-eq-q2"
);
p_sys
->
f_Q2
=
config_GetFloat
(
p_this
,
"param-eq-q2"
);
p_sys
->
f_gain2
=
config_GetFloat
(
p_this
,
"param-eq-gain2"
);
p_sys
->
f_gain2
=
config_GetFloat
(
p_this
,
"param-eq-gain2"
);
p_sys
->
f_f3
=
config_GetFloat
(
p_this
,
"param-eq-f3"
);
p_sys
->
f_f3
=
config_GetFloat
(
p_this
,
"param-eq-f3"
);
p_sys
->
f_Q3
=
config_GetFloat
(
p_this
,
"param-eq-q3"
);
p_sys
->
f_Q3
=
config_GetFloat
(
p_this
,
"param-eq-q3"
);
p_sys
->
f_gain3
=
config_GetFloat
(
p_this
,
"param-eq-gain3"
);
p_sys
->
f_gain3
=
config_GetFloat
(
p_this
,
"param-eq-gain3"
);
i_samplerate
=
p_filter
->
input
.
i_rate
;
i_samplerate
=
p_filter
->
input
.
i_rate
;
CalcPeakEQCoeffs
(
p_sys
->
f_f1
,
p_sys
->
f_Q1
,
p_sys
->
f_gain1
,
CalcPeakEQCoeffs
(
p_sys
->
f_f1
,
p_sys
->
f_Q1
,
p_sys
->
f_gain1
,
i_samplerate
,
p_sys
->
coeffs
+
0
*
5
);
i_samplerate
,
p_sys
->
coeffs
+
0
*
5
);
CalcPeakEQCoeffs
(
p_sys
->
f_f2
,
p_sys
->
f_Q2
,
p_sys
->
f_gain2
,
CalcPeakEQCoeffs
(
p_sys
->
f_f2
,
p_sys
->
f_Q2
,
p_sys
->
f_gain2
,
i_samplerate
,
p_sys
->
coeffs
+
1
*
5
);
i_samplerate
,
p_sys
->
coeffs
+
1
*
5
);
CalcPeakEQCoeffs
(
p_sys
->
f_f3
,
p_sys
->
f_Q3
,
p_sys
->
f_gain3
,
CalcPeakEQCoeffs
(
p_sys
->
f_f3
,
p_sys
->
f_Q3
,
p_sys
->
f_gain3
,
i_samplerate
,
p_sys
->
coeffs
+
2
*
5
);
i_samplerate
,
p_sys
->
coeffs
+
2
*
5
);
CalcShelfEQCoeffs
(
p_sys
->
f_lowf
,
1
,
p_sys
->
f_lowgain
,
0
,
CalcShelfEQCoeffs
(
p_sys
->
f_lowf
,
1
,
p_sys
->
f_lowgain
,
0
,
i_samplerate
,
p_sys
->
coeffs
+
3
*
5
);
i_samplerate
,
p_sys
->
coeffs
+
3
*
5
);
CalcShelfEQCoeffs
(
p_sys
->
f_highf
,
1
,
p_sys
->
f_highgain
,
0
,
CalcShelfEQCoeffs
(
p_sys
->
f_highf
,
1
,
p_sys
->
f_highgain
,
0
,
i_samplerate
,
p_sys
->
coeffs
+
4
*
5
);
i_samplerate
,
p_sys
->
coeffs
+
4
*
5
);
p_sys
->
p_state
=
(
float
*
)
calloc
(
p_filter
->
input
.
i_channels
*
5
*
4
,
p_sys
->
p_state
=
(
float
*
)
calloc
(
p_filter
->
input
.
i_channels
*
5
*
4
,
sizeof
(
float
)
);
sizeof
(
float
)
);
return
VLC_SUCCESS
;
return
VLC_SUCCESS
;
}
}
static
void
Close
(
vlc_object_t
*
p_this
)
static
void
Close
(
vlc_object_t
*
p_this
)
{
{
aout_filter_t
*
p_filter
=
(
aout_filter_t
*
)
p_this
;
aout_filter_t
*
p_filter
=
(
aout_filter_t
*
)
p_this
;
free
(
p_filter
->
p_sys
->
p_state
);
free
(
p_filter
->
p_sys
->
p_state
);
free
(
p_filter
->
p_sys
);
free
(
p_filter
->
p_sys
);
}
}
/*****************************************************************************
/*****************************************************************************
* DoWork: process samples buffer
* DoWork: process samples buffer
*****************************************************************************
*****************************************************************************
*
*
*****************************************************************************/
*****************************************************************************/
static
void
DoWork
(
aout_instance_t
*
p_aout
,
aout_filter_t
*
p_filter
,
static
void
DoWork
(
aout_instance_t
*
p_aout
,
aout_filter_t
*
p_filter
,
aout_buffer_t
*
p_in_buf
,
aout_buffer_t
*
p_out_buf
)
aout_buffer_t
*
p_in_buf
,
aout_buffer_t
*
p_out_buf
)
{
{
p_out_buf
->
i_nb_samples
=
p_in_buf
->
i_nb_samples
;
p_out_buf
->
i_nb_samples
=
p_in_buf
->
i_nb_samples
;
p_out_buf
->
i_nb_bytes
=
p_in_buf
->
i_nb_bytes
;
p_out_buf
->
i_nb_bytes
=
p_in_buf
->
i_nb_bytes
;
ProcessEQ
(
(
float
*
)
p_in_buf
->
p_buffer
,
(
float
*
)
p_out_buf
->
p_buffer
,
ProcessEQ
(
(
float
*
)
p_in_buf
->
p_buffer
,
(
float
*
)
p_out_buf
->
p_buffer
,
p_filter
->
p_sys
->
p_state
,
p_filter
->
p_sys
->
p_state
,
p_filter
->
input
.
i_channels
,
p_in_buf
->
i_nb_samples
,
p_filter
->
input
.
i_channels
,
p_in_buf
->
i_nb_samples
,
p_filter
->
p_sys
->
coeffs
,
5
);
p_filter
->
p_sys
->
coeffs
,
5
);
}
}
/*
/*
* Calculate direct form IIR coefficients for peaking EQ
* Calculate direct form IIR coefficients for peaking EQ
* coeffs[0] = b0
* coeffs[0] = b0
* coeffs[1] = b1
* coeffs[1] = b1
* coeffs[2] = b2
* coeffs[2] = b2
* coeffs[3] = a1
* coeffs[3] = a1
* coeffs[4] = a2
* coeffs[4] = a2
*
*
* Equations taken from RBJ audio EQ cookbook
* Equations taken from RBJ audio EQ cookbook
* (http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt)
* (http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt)
*/
*/
static
void
CalcPeakEQCoeffs
(
float
f0
,
float
Q
,
float
gainDB
,
float
Fs
,
static
void
CalcPeakEQCoeffs
(
float
f0
,
float
Q
,
float
gainDB
,
float
Fs
,
float
*
coeffs
)
float
*
coeffs
)
{
{
float
A
;
float
A
;
float
w0
;
float
w0
;
float
alpha
;
float
alpha
;
float
b0
,
b1
,
b2
;
float
b0
,
b1
,
b2
;
float
a0
,
a1
,
a2
;
float
a0
,
a1
,
a2
;
// Provide sane limits to avoid overflow
// Provide sane limits to avoid overflow
if
(
Q
<
0
.
1
f
)
Q
=
0
.
1
f
;
if
(
Q
<
0
.
1
f
)
Q
=
0
.
1
f
;
if
(
Q
>
100
)
Q
=
100
;
if
(
Q
>
100
)
Q
=
100
;
if
(
f0
>
Fs
/
2
*
0
.
95
f
)
f0
=
Fs
/
2
*
0
.
95
f
;
if
(
f0
>
Fs
/
2
*
0
.
95
f
)
f0
=
Fs
/
2
*
0
.
95
f
;
if
(
gainDB
<
-
40
)
gainDB
=
-
40
;
if
(
gainDB
<
-
40
)
gainDB
=
-
40
;
if
(
gainDB
>
40
)
gainDB
=
40
;
if
(
gainDB
>
40
)
gainDB
=
40
;
A
=
pow
(
10
,
gainDB
/
40
);
A
=
pow
(
10
,
gainDB
/
40
);
w0
=
2
*
3
.
141593
f
*
f0
/
Fs
;
w0
=
2
*
3
.
141593
f
*
f0
/
Fs
;
alpha
=
sin
(
w0
)
/
(
2
*
Q
);
alpha
=
sin
(
w0
)
/
(
2
*
Q
);
b0
=
1
+
alpha
*
A
;
b0
=
1
+
alpha
*
A
;
b1
=
-
2
*
cos
(
w0
);
b1
=
-
2
*
cos
(
w0
);
b2
=
1
-
alpha
*
A
;
b2
=
1
-
alpha
*
A
;
a0
=
1
+
alpha
/
A
;
a0
=
1
+
alpha
/
A
;
a1
=
-
2
*
cos
(
w0
);
a1
=
-
2
*
cos
(
w0
);
a2
=
1
-
alpha
/
A
;
a2
=
1
-
alpha
/
A
;
// Store values to coeffs and normalize by 1/a0
// Store values to coeffs and normalize by 1/a0
coeffs
[
0
]
=
b0
/
a0
;
coeffs
[
0
]
=
b0
/
a0
;
coeffs
[
1
]
=
b1
/
a0
;
coeffs
[
1
]
=
b1
/
a0
;
coeffs
[
2
]
=
b2
/
a0
;
coeffs
[
2
]
=
b2
/
a0
;
coeffs
[
3
]
=
a1
/
a0
;
coeffs
[
3
]
=
a1
/
a0
;
coeffs
[
4
]
=
a2
/
a0
;
coeffs
[
4
]
=
a2
/
a0
;
}
}
/*
/*
* Calculate direct form IIR coefficients for low/high shelf EQ
* Calculate direct form IIR coefficients for low/high shelf EQ
* coeffs[0] = b0
* coeffs[0] = b0
* coeffs[1] = b1
* coeffs[1] = b1
* coeffs[2] = b2
* coeffs[2] = b2
* coeffs[3] = a1
* coeffs[3] = a1
* coeffs[4] = a2
* coeffs[4] = a2
*
*
* Equations taken from RBJ audio EQ cookbook
* Equations taken from RBJ audio EQ cookbook
* (http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt)
* (http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt)
*/
*/
static
void
CalcShelfEQCoeffs
(
float
f0
,
float
slope
,
float
gainDB
,
int
high
,
static
void
CalcShelfEQCoeffs
(
float
f0
,
float
slope
,
float
gainDB
,
int
high
,
float
Fs
,
float
*
coeffs
)
float
Fs
,
float
*
coeffs
)
{
{
float
A
;
float
A
;
float
w0
;
float
w0
;
float
alpha
;
float
alpha
;
float
b0
,
b1
,
b2
;
float
b0
,
b1
,
b2
;
float
a0
,
a1
,
a2
;
float
a0
,
a1
,
a2
;
// Provide sane limits to avoid overflow
// Provide sane limits to avoid overflow
if
(
f0
>
Fs
/
2
*
0
.
95
f
)
f0
=
Fs
/
2
*
0
.
95
f
;
if
(
f0
>
Fs
/
2
*
0
.
95
f
)
f0
=
Fs
/
2
*
0
.
95
f
;
if
(
gainDB
<
-
40
)
gainDB
=
-
40
;
if
(
gainDB
<
-
40
)
gainDB
=
-
40
;
if
(
gainDB
>
40
)
gainDB
=
40
;
if
(
gainDB
>
40
)
gainDB
=
40
;
A
=
pow
(
10
,
gainDB
/
40
);
A
=
pow
(
10
,
gainDB
/
40
);
w0
=
2
*
3
.
141593
f
*
f0
/
Fs
;
w0
=
2
*
3
.
141593
f
*
f0
/
Fs
;
alpha
=
sin
(
w0
)
/
2
*
sqrt
(
(
A
+
1
/
A
)
*
(
1
/
slope
-
1
)
+
2
);
alpha
=
sin
(
w0
)
/
2
*
sqrt
(
(
A
+
1
/
A
)
*
(
1
/
slope
-
1
)
+
2
);
if
(
high
)
if
(
high
)
{
{
b0
=
A
*
(
(
A
+
1
)
+
(
A
-
1
)
*
cos
(
w0
)
+
2
*
sqrt
(
A
)
*
alpha
);
b0
=
A
*
(
(
A
+
1
)
+
(
A
-
1
)
*
cos
(
w0
)
+
2
*
sqrt
(
A
)
*
alpha
);
b1
=
-
2
*
A
*
(
(
A
-
1
)
+
(
A
+
1
)
*
cos
(
w0
)
);
b1
=
-
2
*
A
*
(
(
A
-
1
)
+
(
A
+
1
)
*
cos
(
w0
)
);
b2
=
A
*
(
(
A
+
1
)
+
(
A
-
1
)
*
cos
(
w0
)
-
2
*
sqrt
(
A
)
*
alpha
);
b2
=
A
*
(
(
A
+
1
)
+
(
A
-
1
)
*
cos
(
w0
)
-
2
*
sqrt
(
A
)
*
alpha
);
a0
=
(
A
+
1
)
-
(
A
-
1
)
*
cos
(
w0
)
+
2
*
sqrt
(
A
)
*
alpha
;
a0
=
(
A
+
1
)
-
(
A
-
1
)
*
cos
(
w0
)
+
2
*
sqrt
(
A
)
*
alpha
;
a1
=
2
*
(
(
A
-
1
)
-
(
A
+
1
)
*
cos
(
w0
)
);
a1
=
2
*
(
(
A
-
1
)
-
(
A
+
1
)
*
cos
(
w0
)
);
a2
=
(
A
+
1
)
-
(
A
-
1
)
*
cos
(
w0
)
-
2
*
sqrt
(
A
)
*
alpha
;
a2
=
(
A
+
1
)
-
(
A
-
1
)
*
cos
(
w0
)
-
2
*
sqrt
(
A
)
*
alpha
;
}
}
else
else
{
{
b0
=
A
*
(
(
A
+
1
)
-
(
A
-
1
)
*
cos
(
w0
)
+
2
*
sqrt
(
A
)
*
alpha
);
b0
=
A
*
(
(
A
+
1
)
-
(
A
-
1
)
*
cos
(
w0
)
+
2
*
sqrt
(
A
)
*
alpha
);
b1
=
2
*
A
*
(
(
A
-
1
)
-
(
A
+
1
)
*
cos
(
w0
));
b1
=
2
*
A
*
(
(
A
-
1
)
-
(
A
+
1
)
*
cos
(
w0
));
b2
=
A
*
(
(
A
+
1
)
-
(
A
-
1
)
*
cos
(
w0
)
-
2
*
sqrt
(
A
)
*
alpha
);
b2
=
A
*
(
(
A
+
1
)
-
(
A
-
1
)
*
cos
(
w0
)
-
2
*
sqrt
(
A
)
*
alpha
);
a0
=
(
A
+
1
)
+
(
A
-
1
)
*
cos
(
w0
)
+
2
*
sqrt
(
A
)
*
alpha
;
a0
=
(
A
+
1
)
+
(
A
-
1
)
*
cos
(
w0
)
+
2
*
sqrt
(
A
)
*
alpha
;
a1
=
-
2
*
(
(
A
-
1
)
+
(
A
+
1
)
*
cos
(
w0
));
a1
=
-
2
*
(
(
A
-
1
)
+
(
A
+
1
)
*
cos
(
w0
));
a2
=
(
A
+
1
)
+
(
A
-
1
)
*
cos
(
w0
)
-
2
*
sqrt
(
A
)
*
alpha
;
a2
=
(
A
+
1
)
+
(
A
-
1
)
*
cos
(
w0
)
-
2
*
sqrt
(
A
)
*
alpha
;
}
}
// Store values to coeffs and normalize by 1/a0
// Store values to coeffs and normalize by 1/a0
coeffs
[
0
]
=
b0
/
a0
;
coeffs
[
0
]
=
b0
/
a0
;
coeffs
[
1
]
=
b1
/
a0
;
coeffs
[
1
]
=
b1
/
a0
;
coeffs
[
2
]
=
b2
/
a0
;
coeffs
[
2
]
=
b2
/
a0
;
coeffs
[
3
]
=
a1
/
a0
;
coeffs
[
3
]
=
a1
/
a0
;
coeffs
[
4
]
=
a2
/
a0
;
coeffs
[
4
]
=
a2
/
a0
;
}
}
/*
/*
src is assumed to be interleaved
src is assumed to be interleaved
dest is assumed to be interleaved
dest is assumed to be interleaved
size of state is 4*channels*eqCount
size of state is 4*channels*eqCount
samples is not premultiplied by channels
samples is not premultiplied by channels
size of coeffs is 5*eqCount
size of coeffs is 5*eqCount
*/
*/
void
ProcessEQ
(
float
*
src
,
float
*
dest
,
float
*
state
,
void
ProcessEQ
(
float
*
src
,
float
*
dest
,
float
*
state
,
int
channels
,
int
samples
,
float
*
coeffs
,
int
channels
,
int
samples
,
float
*
coeffs
,
int
eqCount
)
int
eqCount
)
{
{
int
i
,
chn
,
eq
;
int
i
,
chn
,
eq
;
float
b0
,
b1
,
b2
,
a1
,
a2
;
float
b0
,
b1
,
b2
,
a1
,
a2
;
float
x
,
y
=
0
;
float
x
,
y
=
0
;
float
*
src1
,
*
dest1
;
float
*
src1
,
*
dest1
;
float
*
coeffs1
,
*
state1
;
float
*
coeffs1
,
*
state1
;
src1
=
src
;
src1
=
src
;
dest1
=
dest
;
dest1
=
dest
;
for
(
i
=
0
;
i
<
samples
;
i
++
)
for
(
i
=
0
;
i
<
samples
;
i
++
)
{
{
state1
=
state
;
state1
=
state
;
for
(
chn
=
0
;
chn
<
channels
;
chn
++
)
for
(
chn
=
0
;
chn
<
channels
;
chn
++
)
{
{
coeffs1
=
coeffs
;
coeffs1
=
coeffs
;
x
=
*
src1
++
;
x
=
*
src1
++
;
/* Direct form 1 IIRs */
/* Direct form 1 IIRs */
for
(
eq
=
0
;
eq
<
eqCount
;
eq
++
)
for
(
eq
=
0
;
eq
<
eqCount
;
eq
++
)
{
{
b0
=
coeffs1
[
0
];
b0
=
coeffs1
[
0
];
b1
=
coeffs1
[
1
];
b1
=
coeffs1
[
1
];
b2
=
coeffs1
[
2
];
b2
=
coeffs1
[
2
];
a1
=
coeffs1
[
3
];
a1
=
coeffs1
[
3
];
a2
=
coeffs1
[
4
];
a2
=
coeffs1
[
4
];
coeffs1
+=
5
;
coeffs1
+=
5
;
y
=
x
*
b0
+
state1
[
0
]
*
b1
+
state1
[
1
]
*
b2
-
state1
[
2
]
*
a1
-
state1
[
3
]
*
a2
;
y
=
x
*
b0
+
state1
[
0
]
*
b1
+
state1
[
1
]
*
b2
-
state1
[
2
]
*
a1
-
state1
[
3
]
*
a2
;
state1
[
1
]
=
state1
[
0
];
state1
[
1
]
=
state1
[
0
];
state1
[
0
]
=
x
;
state1
[
0
]
=
x
;
state1
[
3
]
=
state1
[
2
];
state1
[
3
]
=
state1
[
2
];
state1
[
2
]
=
y
;
state1
[
2
]
=
y
;
x
=
y
;
x
=
y
;
state1
+=
4
;
state1
+=
4
;
}
}
*
dest1
++
=
y
;
*
dest1
++
=
y
;
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment