element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Wolfson audio paths & how to use EQ and LHPF
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Marki555
  • Date Created: 17 Aug 2014 1:42 PM Date Created
  • Views 2469 views
  • Likes 0 likes
  • Comments 6 comments
Related
Recommended
  • wolfson
  • audio
  • alsa
  • raspberry_pi
  • wm5102
  • dsp
  • raspeberry_pi_accessories

Wolfson audio paths & how to use EQ and LHPF

Marki555
Marki555
17 Aug 2014

Audio paths

 

Note: I don't have the card yet, so I don't know actual alsa names for these settings, but they are very similar to those in the datasheet.

 

You can check the diagrams on page 57-58 of WM5102 datasheet Data Sheet of WM5102.

WM5102 is a versatile device and you can set different audio paths within its digital core. Furtunately it seems almost all of it is possible via alsamixer.

Outputs

WM5102 has many outputs, most of them available on our card. The most usable outputs are OUT1L/P (Line out, HPOUT2L/P in alsa), OUT2L/P (headphones, HPOUT1L/P in alsa) and OUT4L/P (speaker outputs via integrated 2W amplifier, SPKOUTL/P in alsa). Other outputs are OUT3 (earpiece) and OUT5L/P (PDM digital speakers) and there is also SPDIF output (AIF2TX1/2 - stereo).

Each of these outputs have its own mixer with 4 sources, each source having its own input volume. Output then have its own master volume. So you can output combination of any 4 sources into each output.

 

Inputs

WM5102 is connected to our RPi via AIF1 bus running in i2s mode. AIF1RX (stereo) is audio going from RPi to card, AIF1TX is audio from card to RPi (if you want to record anything on RPi, you need to route audio to this output).

WM5102 has several physical inputs: SPDIF (AIF2RX1/2 - stereo), Line-in (IN3L/R), Headset microphone, integrated digital mics. Each input has both analog PGA "volume" (gain of input amplifier) and digital *_VOL volume.

WM5102 has also internal "inputs": 1kHz tone generator, white noise generator and all DSP functions act as inputs also.

 

Effects

It has 4x parametric equaliser (EQ1/2/3/4 - each is mono, so you can use 2 different equaliser for 2 stereo signals),

4x low/high pass filters (LHPF1/2/3/4) and dynamic range controller (DRC1). These also have their internal 4-way mixers, so their input can be combination of any 4 signals (each with own volume control).

 

Routing

You can for example route signal from Line-in throught EQ, from EQ to LHPF and from there to another EQ and finally either to RPi or to Line-out/SPDIF (or to both).

 

Here is picture of how looks a output with its 4-way own mixer:

image

In alsa, for each output there is a setting with names "xyz Input 1" to "xyz Input 4". Usually you will use just the first input, but you can use all 4 to mix them. Each of them also has Volume setting "xyz Input 1 Volume"(??). So to route signal from Line-in to EQ and from there to Line-out, you can use these commands:

# Route LineIn input IN3{1,2} through equalizers EQ{1,2} to Line Out.

# IN3 --> EQ --> HPOUT2

amixer -Dhw:0 cset name='EQ1 Input 1' IN3L

amixer -Dhw:0 cset name='EQ2 Input 1' IN3R

amixer -Dhw:0 cset name='HPOUT2L Input 2' EQ1

amixer -Dhw:0 cset name='HPOUT2R Input 2' EQ2

 

Using Parametric EQ and Low/High-Pass filters

 

To use these filters you have to first route some audio to them and from them to some output (see above). (It seems that alsa implements these only as 1-input and not 4-input).

The next step is to configure them.

For EQ, you can configure 5 frequency bands. First band can be either shelving or peak filter, last band is a shelving filter. Each peak filter has a gain (-12 dB to +12 dB; alsa name "EQx Bz Volume" with values 0-24, z is band 1-5), frequency and width (also called Q value). Shelving filters have only gain and frequency. Frequency and band are set in "EQx Bz Coefficients" (see next section).

 

For LHPF, you can only set cut-off frequency and set the filter as low- or high-pass. It seems that the filter is Butterworth. At cut-off freq it will have -3 dB, with -6 dB/octave slope. Alsa name is "LHPFx" as source and "LHPF1 Coefficients" for the settings and "LHPF1 Mode" to set low/high-pass.

 

How to get those magical coefficients

 

Datasheet refers to the "WISCE evaluation board control software". Fortunately this is free, however it is not so straightforward to get to the WM5102 device profile as it is not listed between eval boards to download.

First download & install the WISCE software from http://www.wolfsonmicro.com/support/wisce/

Then from http://www.wolfsonmicro.com/products/evaluation-boards/wm5102ev1m/ download the "WISCEimage Install kitDevice Pack for WM5102EV1M" (last one on the right grey column).

When you start WISCE it will load a profile for our WM5102 and display a warning that it can't find the eval board and will run in standalone mode. That is OK. To configure EQ, just click on EQ1/2/3/4 in the top menu (after the toolbar, with labels only). You will see screen like this:

image

There you can play with the settings and see the result on graph. However it seems that the graph is weird when combining overlapping bands. I don't know if it issue only on this simulator or also in the device itself. According to graph when I have 2 filters on the same freq with -12 dB, it won't be -24 dB but something like -6 dB. The "B P" checkbox changes the first band to be either shelving or band-pass filter.

When you are happy with your selection, change the view in top menu to "Registers" and find registers for you EQ/LHPF (for EQ they are around R-E10h, for LHPF around R-EC1h; look at datasheet from page 68). You will know from the register name that it is the correct one image . Then use the value from register in your alsa command (but alsa requires value in decimal format, not hex - so either convert manually or change appl settings to display in dec, but then also register addrs will be in dec).

image

So to get set LHPF2, you take the value of "MODE=1" in Reg-EC4h and value F8ADh from Reg-EC5h. The coefficients need to be entered as 2 byte values separated by comma in alsa. So we convert from hex F8,AD to decimal 248,173 and set this as value to "LHPF2 Coefficients".

 

For EQ it is little more complicated, as there are multiple gains stored in one register:

image

For example for EQ1, the gains are in registers R-E10h and R-E11h. You need to take value of each gain separately and convert it from binary to decimal (for EQ1_B1_GAIN it would be from 01100 binary to 12 decimal, which is 0 dB). The coefficients for each band are in 3 registers (EQ1_B1_A / B / PG). So for EQ1 Band1, you get values FC8h, 404h and E0h (4040, 1028, 224 in decimal).

But I'm not sure how to set these values in alsa as alsa has only one parameter "EQ1 Coefficients" for all 5 bands. You can check with command "amixer -Dhw:0 cget name='EQ1 Coefficients' ". I will check & try once I get the card delivered.

  • Sign in to reply
  • choff
    choff over 4 years ago in reply to psyj

    Hello all,

     

    I am not sure if this information is still helpful after such a long time, but nevertheless I decided to share it. The information from John on how to calculate the coefficients for the high-pass/low-pass filter of the card can be found here

    To easily calculate these filter coefficients, I created my own Octave script which I will post inline as I cannot attach any files to my post:

    %
    % Octave / Matlab script to calculate the filter coefficient for the
    % low-pass and high-pass filters of the Cirrus Logic Audio Card
    %
    % The formulas are documented here:
    % - https://www.st.com/resource/en/application_note/cd00222512-bqd-filter-design-equations-stmicroelectronics.pdf
    % - https://www.element14.com/community/message/220493/l/re-new-reworked-driver-for-wolfsoncirrus-logic-audio-card
    % - https://www.element14.com/community/community/raspberry-pi/raspberry-pi-accessories/wolfson_pi/blog/2014/08/17/wolfson-audio-paths-how-to-use-eq-and-lhpf
    %
    
    
    %
    % Calculates the filter coefficient string of the low-pass and high-pass filters
    % of the Cirrus Logic Audio Card. This string can be passed to ALSA.
    %
    % fc: desired cut-off frequency of filter in Hz
    % fs: sample rate in Hz
    %
    function coeff_string = calculate_filter_coefficient(fc, fs)
        fc_normalized = 2 * pi * (fc / fs); % normalized cut-off frequency of Butterworth filter
        K = tan(fc_normalized / 2);
        a1 = (K - 1) / (K + 1);
    
    
        % convert a1 to 16 bit signed integer register value (in two's complement format)
        a1_reg = to_int16(round(a1 * 4096));
    
    
        % ALSA expects that the coefficient is specified as 2 byte values separated by comma. The
        % byte values must be in decimal notation.
        coeff_string=sprintf("%d,%d", idivide(a1_reg, 256, "fix"), mod(a1_reg, 256));
    end
    
    
    %
    % Converts a signed integer to 16-bit two's complement format.
    %
    function int16 = to_int16(int)
        if int >= 0
            int16 = int;
        else
            int16 = 0xffff + int + 1;
        end
    end

     

    I have also created a shell script that inserts a low-pass filter when audio is output to the headphone jack. It calls the Matlab/Octave script above.

    #! /bin/sh
    set -e
    set -u
    
    
    card="RPiCirrus"
    mixer() {
        amixer -q -c "$card" cset name="$1" "$2"
    }
    
    
    scriptPath="$0"
    scriptDir="$(dirname "$scriptPath")"
    
    
    # cut-off frequency of the filter in Hz
    cutOffFrequency="$1"
    # sample rate in Hz
    sampleRate="$2"
    
    
    filterCoefficients="$(octave-cli --path "$scriptDir" --eval "printf(\"%s\n\", calculate_filter_coefficient($cutOffFrequency, $sampleRate));")"
    
    
    mixer "LHPF3 Input 1" AIF1RX1
    mixer "LHPF4 Input 1" AIF1RX2
    mixer "LHPF3 Mode" Low-pass
    mixer "LHPF4 Mode" Low-pass
    mixer "LHPF3 Coefficients" "$filterCoefficients"
    mixer "LHPF4 Coefficients" "$filterCoefficients"
    
    
    mixer "HPOUT1L Input 1" LHPF3
    mixer "HPOUT1R Input 1" LHPF4

     

    It took me quite some time to get there, but the information in this blog post from "Marki5555" and then the formulas from John helped to get me going. Many thanks to both of them for sharing this information!

     

     

    Best regards,

     

      Christian

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • psyj
    psyj over 8 years ago in reply to rmd6502

    Robert

     

    Perhaps better late than never.  Over on another thread, I have documented some of what I know about the parameters in question.  I have documented how to calculate the parameter for the Low/High Pass filters. I have also fathomed out the A and B parameters of the EQ units (essential for setting band pass frequency and Q).  I have yet to get a definitive handle on the C and PG parameters, which largely determine the gain charecteristic.  The EQ units are classic second order band pass (or rather filters 2,3,4 and optionally filter 1 are 2nd order band pass).  I am not sure how much more time I shall spend digging around  ... in part it depends on how useful it is to others!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • rmd6502
    rmd6502 over 9 years ago

    Are the formulas for the coefficients available outside Cirrus' offices?  I have a mac, and don't want to pay for a windows license + vmware (nor pirate them)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 10 years ago

    You can set the Parameters for the EQ Coefficients by the instruction

    amixer${Bequiet} -D${Card} cset name='EQ1 Coefficients'

    followed by the 38 decimal values comma seperated from the registers EQX_3 to EQX_21, you can easily generate the values with the wisce Software, but be careful, if the simulated eq curve not correct, the eq won't work, especially frequencies below 100Hz!    

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to bwhitejr

    Hi,Bob,

      I had known that you want to wiite the EQ to the wm5102, and from the code of Raspberry Pi "wm5102.c",in the code, there a patch include something like can do it.

      I`m a student in China,and want to make some foreign friends,if you interest,please mail me,xiaoren113244(a)126.com.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube