15 Replies Latest reply on Aug 16, 2016 3:08 PM by jcjc

    My success with the Cirrus Logic Audio Card




      I've had a successful year building and using devices using the CLAC (cirrus logic audio card) since my last visit (http://www.element14.com/community/message/151149/l/re-cirrus-logic-audio-card-working-on-the-raspberry-pi-2#151149).  Returning to this discussion area a year later, I still see lots of good work by individuals, and still some frustration.  I thought I'd quickly recount my experience to those who helped me - I used Ragnar Jensen's .deb's and got help from him that was invaluable.  It is remarkable what is achieved here - on the back of volunteer help - despite people's frustrations and little (no?) input from the manufacturer. 

      The device I build is an outdoor audio recorder in a waterproof box with a battery.  In 2014 it was used with a USB microphone, until I found the Cirrus Logic card.  It's been used in 2015 to monitor bird populations by ornithologists.  They have collected several terabytes of audio data used for research.  The performance has been good - the only device that had to be replaced was literally lost-in-the-forest (the deployer forgot where it was located - so it is surrendered to future archaeology).  There have been no hardware failures (20 devices deployed over about 6 months, each recording permanently for as long as the USB battery pack allowed - about 5 days then cycled every week).

      The device stores audio in 10-minute long audio files on the SD card, timestamped, and divided into folders one-per-day.  I use the really basic "arecord" to do the recording, sending a signal (USR1 via a cronjob) to it every 10 minutes to split the audio file.  There is no break in the recording at file-boundaries so you can subsequently concatenate the wav files seamlessly (no clicks, no gaps, no overlaps) - this is necessary for the stats which the ornithologists want.  The time-of-day is read at boot-time from the "piface shim" RTC, which works in conjunction with the CLAC without doing anything clever.  I found a good source of microphones for outdoor use recently (micbooster.com in the UK) which use the Primo EM172.Z1 capsule, which I hope to use widely in the coming season (2016).

      The "user experience" is to flash a SD card with my customised ".img", plug it into the unit, turn on the power bank, close the waterproof lid and walk away.  Data recovery involves visiting the recorder, collecting (or swapping) the SD card (and battery), and then copying to your PC back in the lab.  This is easy on Mac and Linux, but windows is a nuisance as it won't read my bespoke third FAT partition containing the audio.  (This partition is created and formatted at first-boot and uses up all the remainder of the SD card space thereby fully utilising any size of SD card - I recommend 32 or 64Gb cards).  Users can pre-customize their images by replacing a special /boot/recorder.conf file (which is read/write-able from Windows - nice). Config options include mic-gain, sample-rate (16/32/44.1KHz).  It will have to support stereo/mono for this year (see below).

      Plans for the coming year:

      (*top priority*) leaarn how to emulate!!!. Developing by ferrying SD cards between my PC and the Raspberry Pi hardware is unmanageably tedious. (looking at pilfs.  XEC design has vanished, I find this whole topic hard to get into). I just want to run a few commands on a stock raspbian to install my code, and upgrade to the CLAC-enabled kernel - to produce a ship-able "img" to users, but I currently boot a bare metal Raspberry pi to do this).

      1) try the WittyPi (from UUgear)  power manager so we can have a calendar of when to record.  Hopefully shut down the pi when not in use, and reboot when recording should re-start.

      2) move to stereo recording with microphones separated by a meter or so - this will allow direction-of-source analysis to be done back in the lab (x-correlation between L+R).  With a pair of such devices pointing at the same outdoor scene, we can triangulate to find the location of the source of the sound (bird, or whatever).  (Ironically I spent a lot of time fussing with .asoundrc files to get mono working last year)

      3) Integrate using larger 12v batteries (SLA or vehicle batteries) to get deployments of a month or more.  This needs a low-loss 12v to 5V (or 3.3v?) regulator.

      4) losslessly compress (flac) audio files to increase storage capacity on SD card. (tricky with arecord + kill -USR1) - consider move to gstreamer.

      5) move to latest raspbian - integrating 4.? kernel, systemd (does rc.local still work?).

      6) Power : does the raspberry pi zero give any saving on power usage (crikey! - no header pins, what a hassle).

      7) ultrasound for bats.


      I'm sticking with the arm-V6 raspberry pi's (version A+) as the pi-2 (V7) is too power hungry.  I'll shortly have to catch up with all the posts on this site regarding what has changed since a year ago.  HiassofT's stuff looks interesting and good old Ragnar is hopefully still around.  Systemd, jessie, kernel-4.1, device-tree are on my mind.


      Note that I don't sell these.  I've built a few for friends, but most are assembled by users (they are pretty easy to assemble with my guidance on the phone and email). I'll upload a public copy of the .img if there is any interest - but it is a year old (based on raspbian from February 2015, I think...)


      So life is good, and these devices work well.  A huge thanks to those who have made this happen.  There are real consequences of this work (for a few PhD students, and some British birds at least).


      Happy new year to you all.




      Images for fun: 

      First is the bare recorder.

      Second is the B+ with piface shim RTC ready for CLAC installation.

      Third is the unit in waterproof box, ready to deploy (this is an older version using USB microphone - so no cirrus card on this one).

      Fourth is another of the old-fashioned USB mics  - this time the anatomy.  Note: I've given up on the power-off switch - nobody used it.


      audio recorder in labPi A+ with shim RTC ready for CLAC installation

      In waterproof box - older USB mic version (no CLAC)anatomy of old fashioned USB-microphone model (pre-cirrus)

        • Re: My success with the Cirrus Logic Audio Card

          Well I for one say Bravo that man and yes please to the image. I was cynical about these and thought these were audio boards going to totally die when Wolfson got taken over by Cirrus and Raspberry went and changed the physical interface, Although it looks like manufacturer support still stinks and you get stuck on some old version of Raspian I had good results when I tested the old-skool Wolfson one and I'm well chuffed to see there's life in the board yet! I want to make a few of these by Spring.

          Glad to see those funky pogo pins have gone, too.


          Kudos on having solved all the mechanical issues too - mine ended up stuck on the bench, because I wanted to record in stereo so had to amp up the mics to run line in and do the electret powering, and I couldn't see how to keep the water out.


          Where do you get those waterproof boxes from, I have box envy...


          For your 12V to 5V conversion, the Chinese make those 12V to USB converters in their zillions on ebay for ~£2 a throw, and they are reasonably efficient (idle at 7mA ISTR) Be aware that these things toss out ~350mV of hash on the 5V line at a couple hundred kHz, but you can't bash the price.

          1 of 1 people found this helpful
          • Re: My success with the Cirrus Logic Audio Card

            Congrats - and thanks for posting this.


            I have a similar story to yours.  I've been using the CLACs now for about 4 months with success after following all the instructions by Ragnar on that post. 


            I am also recording environmental audio.


            I found a custom case here for my initial prototype:



            • Re: My success with the Cirrus Logic Audio Card


              The image for the audio recorder is here (http://jdmc2.com/e14forum/)

              To use it:

              1) assemble a Raspberry Pi (A+, B+, or Pi2) and a Cirrus Logic Audio Card.

              2) flash the (unzipped) image to an SD card (the bigger the better).

              3) plug it into the Pi and turn on.

              5) sit back and dictate your memoirs.

              6) or put it in a forest to record wildlife.


              The audio recorder is called "Solo".  It will record permanently 24/7 at 16kHz/mono until something runs out (disk space on SD card, probably).  It records through the dmic (onboard microphone) so you don't need to attach a mic (but you can).  When finished just yank the power (yeah, I know, I know).  Move the SD card to your PC and mount partition p3 (called solo-data) (on Windows you'll need http://www.diskinternals.com/linuxreader ).  The audio is there - in 10 minute snippets, one directory per day.  (Windows needs the extra tool because it refuses to see any partition beyond p1, the /boot partition).


              And that's it! An off-the-shelf audio recorder.  Bye!



              But I suspect most of you want more things to do:

              • if you network your raspi, you can login: "ssh 192.168.1.xxx -l amon", password is "amon").  At bash prompt type "amon log", to find out how the audiomonitor (amon) is doing. (amon help) for more commands.
              • see "crontab -l" for the watchdog that runs every minute to keep an eye on things.
              • look in /mnt/sdcard to see partition3, containing all the audio data.
              • to change to external mic, stereo/mono or samplerate, look in /boot/amon.conf (which you can access from the flashed SD card, even from Windows).  Then restart the recording with "amon off ; amon on" check with "amon log".
              • If you install a Piface Shim RTC (below the CLAC) the wav files will be named sensibly, if not, they will contain dates in 1970 [ set the system time with "sudo rdate time.nist.gov" if you are networked].

              These devices don't often get rebooted, so I haven't tested how well things work on second (third...) reboot.  Treat SD cards as "one shot" - re-flash regularly.  I haven't worked on this because they usually get shut down by yanking the power, or through the battery running out, so I don't care about reboots because disk-corruption / fsck is a bigger issue.  It'll probably just work fine, though.  sudo reboot works if you are networked, of course.


              Behind the scenes:

              All code is in : https://github.com/solosystem

              amon repository for the software that runs the audio recording (using arecord).

              solo repository configures the underlying machine (raspi) and ADC (CLAC) and sets up alsa hw (.asoundrc).

              The script boot-solo.sh (in solo.git) is run from rc.local - worth looking at to see how things get set up.

              The script provision.sh (in solo.git) is used to make bootable images. The readme in solo.git says more about this.

              The script amon (in amon.git) is the main interface to starting and stopping the recorder.


              I like the following:
              1) there is no break in audio between audio files.  They are sample-perfect if concatenated.
              2) p3 (the partition for the storage of audio) is built on the fly at boot time - so it can fill all of the remainder of the SD card.  Bigger cards automatically give you longer record time.


              I am embarrased by:

              1) RTC stuff was written very recently, and badly (see setup-rtc.sh in solo.git).  I have purged fake-hwclock.sh, and have not got ntpd working properly to grab the date from the internet to set the system time.  It's annoying me and I've wasted days of my life on this.

              2) The software I'm using is from Feb 2015 - I haven't upgraded it yet.

              3) There is no poweroff switch.  There used to be one when I used USB microphones, but the pins aren't obviously available with the CLAC.  And most units run out of battery in the field, so who cares (see switchoff.py in solo.git for how it used to work).


              Thanks to Ragnar Jensen, who's tar-balls and .debs I used (I took copies last year, and the above scripts grab them and install them.  See solo.git's provision.sh for where this happens).


              Questions and comments welcome.



              2 of 2 people found this helpful
              • Re: My success with the Cirrus Logic Audio Card

                J C,


                In your first photo you show the Primo EM172.Z1 connected directly to the Cirrus line in port. Are you running ./Record_from_lineIn_Micbias.sh to power the mic? I took over a research project that uses an RPi with the CLAC and an electret microphone wired to a DAQ (powered by 2xAA batteries) that is in turn plugged into the CLAC's line in. I assume the student who designed this must have wired the microphone to the DAQ at least for the power option, and possibly for the preamp on the DAQ, but it seems like it should be possible to use the bias through the line in port to eliminate the need for batteries. My knowledge of circuits is virtually zero, so my questions may be stupid, but your setup looks promising. Does the EM172.Z1 get enough power through the CLAC's line in to record at a decent volume? I attempted to use my iPhone earbud/mic through the line in, but those recordings are so quiet they are useless. I hope that microphone is simply not compatible. The former student may have opted for his external DAQ with batteries configuration to minimize noise. Is there more noise in recordings when a mic is powered via line in bias vs. an external power source? Maybe I'm going in the wrong direction and should stick with his designs. Unfortunately I'm having to learn a lot of this stuff on my own.


                Ultimately, if quality recordings are possible, I'd like to set up something as simple as this electret capsule microphone (or maybe the EM172.Z1) soldered to the wiring of a 3.5 mm plug (this one could be cut in half for a 2-for-1 deal!). The microphone will be fixed to my custom RPi case only a few inches from the line in port, so as nice as this ready-made mic is, it's way too much wire for the small footprint I'm trying to maintain. Plus, eventually I'll set up 20-30 of these RPi recorders, so cost is a factor. I think I can handle a little soldering.



                  • Re: My success with the Cirrus Logic Audio Card

                    I see the use of Record_from_lineIn_Micbias.sh in your code now. I think the rest of my questions still stand though.


                    By the way, excellent work on your code! The amon package seems quite robust. After I read through it some more, if it would work well for us I may implement it for our project. If I take that route I'll definitely get in touch with you again about citation.


                    Also, to be clear, the capsule type microphone is important for my application. I've looked at a lot of alternatives, and for a while was set on finding a USB microphone as the simplest option, but all of those are intended for Skype type applications (i.e. long cords and/or handles that would never fit my RPi case). I'm trying to record fruit flies in 10 mm wide chambers that will sit directly on the microphone, which will be only a few inches above the RPi. Gotta keep those little guys as close as possible to the microphone to capture their songs.

                    • Re: My success with the Cirrus Logic Audio Card

                      Dear Matt Nalley,

                      The Primo EM172 microphone capsule works very well connected directly to the line in of the Cirrus Logic Audio Card, with micbias turned ON, so that the mic is provided with a few volts of power (I measured it once... I think it's 2.75 volts, and it's applied to both left and right channels).  The proper name for this is Plug-in Power (PiP) and is covered halfway down this wikipedia article.  PiP is not to be confused with the commonplace "phantom power" used by studio musicians which is 48 volts. 


                      So I don't use a pre-amp, or a battery in my microphones.  I just bought 35 Primo EM-172's for deployment this year, and am impressed so far.  I bought them from micbooster in the UK.  The microphone capsules you link to also look plausible.


                      If you are having volume problems, there are 2 volume controls on the line input:  one appears to be a "preamp" and the other is a digital volume (I'm guessing a bit here, but this is my best educated guess).  Look in the script Record_from_lineIn_Micbias.sh for these volumes.  Or see the last 10 lines of https://github.com/solosystem/amon/blob/master/amon.conf#L53 for my comments about these, their ranges and meanings.  In short: increase the "Volume" first, then the "Digital Volume" until you reach your desired input levels.  (On the solo you can do this by editing amon.conf in /boot.) If you want are changing it on a live system (which sounds probable if you are in a lab, not in a forest) then restart the recorder with "amon stop; amon start".


                      I'm happy to discuss more - in particular, are you aware that there are _on board_ stereo microphones already on the CLAC selected using the other startup script (the one with DMIC in the name) - they might be better quality and less hassle to use than your capsule idea - your chamber might fit straight over the board?  Also - have you also considered ultrasound?  The CLAC will record up to 96kHz. Fruit flies are small, and possibly emit frequencies higher than 20kHz (which is your capsule's stated cut-off)  - particularly if they really are "singing" and it's not just the noise of their wings flapping.  But I am way out of my league here, and perhaps you were being euphemistic.


                      Good luck and keep in touch.


                        • Re: My success with the Cirrus Logic Audio Card

                          Thanks for the swift reply, James!


                          I think I'll test one of those ready-made EM172 mics to see if it can capture fly "song" with appropriate sensitivity after adjusting the volume settings.


                          Yes, fly people use the term singing to refer to wing buzzing. We also call ourselves fly people haha. I do like the ultrasound idea. I'll see if anyone has attempted to record fruit flies at those frequencies. I have no idea if they have other modes of making sound. Our current setup is actually only recording at 6 kHz because that is plenty to capture the "songs" they make with their wings.


                          I played with DMIC a few times by accident. I mistook that usecase script for the mic-in script before I noticed those MEMS mics on the CLAC. I'm not sure if I could design a case for the RPi to hold our fly courtship chambers close to those mics (right now the whole RPi/CLAC is encased in acrylic so I can't easily test it), but if that is possible and they are sensitive enough, then it could be a viable alternative.


                          I'm not sure if you do any work in the realm of building electrical circuits, but I never went beyond a couple college physics labs so a lot of this is new to me. If it turns out that the signals from a the micbooster EM172 mic are too weak, I'm wondering if a mic with a preamp like this MX4466 could be wired in essentially the same way, with the line in port supplying 2.7-2.8 V. According to the specs it needs 2.4-5.5 V, and "somewhere in the middle" like 3 V is considered ideal, so maybe that would be a relatively simple alternative if I need to boost gain?




                      • Re: My success with the Cirrus Logic Audio Card

                        That's an interesting post as I'm doing something similar, but to record ultrasound from bats and display a sonogram.  This all works very well with a Pi2 and CLAC and a USB touch screen, but I can't for the life of me get the Piface RTC (or any other RTC for that matter) to work.  I've wasted hours of my life - the RTC shows up with i2cdetect and the drivers are loaded, but I keep getting I/O errors when trying to set the time.  Did you have to do anything 'different' to get it to work with the CLAC?





                          • Re: My success with the Cirrus Logic Audio Card

                            Dear Paul,


                            I did this:  https://github.com/solosystem/solo/blob/master/setup-rtc.sh


                            I don't think it's special, except in 2 ways that are not relevant here.  Firstly, I get the RTC enabled as early as possible in the boot process (the above is called from /etc/init.d/hwclock.sh (I dump fake-hwclock.sh because it leads to misleading timestamps).  Secondly, it is _so_ early in the boot sequence that "/" is not mounted yet, so I need to wrap it in a utility (new to me) called "logsave".


                            I mention the above so you don't go chasing things that are irrelevant.  The commands within the above script could equally well be run at the command line once the system is fully booted and you have logged in.  One thing I did notice is that one _does_ get errors (warnings, really) when one tries to read the time from an UNSET (new or new battery) RTC clock.  But your problem sounds more serious than that.


                            You did put a battery into your piface shim, right ?  And it's not a dead battery?  Sorry to state the obvious.



                            PS - to interrogate and set the clock I have the rather ugly: https://github.com/solosystem/solo/blob/master/test-rtc.sh but again, nothing special there.

                              • Re: My success with the Cirrus Logic Audio Card


                                Thanks for your help which eventually led me to the source of the problem.  Some time ago I tried a DS1307 RTC unsuccessfully and the driver was still being loaded, plus I found an error in my rc.local which was preventing it from running.  So, after a whole evening I now have the RTC running with my CLAC and USB touchscreen on my Pi2.

                                Just waiting on some fine weather for some bats!


                                Many thanks,



                            • Re: My success with the Cirrus Logic Audio Card

                              Hi James,
                              Excellent work! As a PhD student studying soundscape ecology you're indeed correct that this work could have real consequences as currently off the shelf solutions (e.g. Wildlife Acoustics SM3 and SM4) are too expensive for many project operating on a budget. I have therefore been looking into putting together an autonomous field audio recorder on a budget over the last few weeks myself and have also decided on using the Primo EM172.Z1 capsule (which looks like the same/similar spec as Wildlife Acoustics use in their SM3 recorder) and the EC Tech USB battery shown in your pic (it seems to be one of the few batteries of this type which doesn't vastly over exaggerate its capacity) but am struggling to find a digital recorder that combines the ability to record in mono, runs off USB battery and can take a 64 GB SD card. So far the Tascam DR-70D has looked most promising but it's £200 and still only gives about 5 days battery life with the EC Tech. I've also been looking into using mobile phones as an alternative but am concerned their pre-amps aren't up to the job and have read something about a 2 GB file size limit.


                              I was therefore very interested to find your blog and was wondering if you could tell me what kind of battery life you get with your EC tech (assuming it's a 22,400 mAh model?) and what kind of data life would you get on for a 64 GB SD card, assuming it will take up to 64?

                              Many Thanks,

                                • Re: My success with the Cirrus Logic Audio Card

                                  Hi Rich, (sorry for late response)


                                  I get 5 days from the EC tech 22.4mAh battery  - recording 16kHz, mono audio 24 hours a day.  However, that was last year - this season, the deployments are using (40 UK pounds each) car batteries.  I expect to get about 4 weeks from them.  One came back from the field yesterday and had conked out after 42 days (6 weeks) - but I think that's freakishly long, and don't expect it to be representative


                                  The system will accept any capacity of micro-SD memory card - this year I am using 128Gb cards which can hold about 6 weeks of audio at 16kHz - which matches well with the car battery.


                                  The system happily accepts any size of SD-card (raspberry pi supports both SDHC and SDXC, so in principle up to 2TB, but I don't see anything bigger than 256GB on sale).  I deployed 128GB cards in the 40 units I built this year, and that accommodates 6 weeks of data at 16kHz, 16 bit, mono uncompressed (thereabouts).


                                  So far the quality of the Primo microphones seems great, but that's just subjective - I haven't compared with SM2/3/4 yet, because I'm not sure how to do it meaningfully (in my house - unfortunately


                                  I agree with your opinion of the EC Tech battery - I did a few capacity experiments some time ago, and it does actually seem to have the stated capacity.


                                  Let me know if I you remain interested.



                                • Re: My success with the Cirrus Logic Audio Card

                                  Hello all,


                                  The Solo outdoor recorder project (based on the Cirrus Logic Audio Card) now has a website at  https://solo-system.github.io/

                                  Including a video of the assembly process (blush).


                                  I now have it additionally working with the Pi Zero (albeit at 80mA rather than 70mA for the A+ boards).  And we are using car batteries this year, and getting deployment times of around 40 days of permanent recording (arecord running non-stop for 40 days) - a good data-point to have in the "Is it stable?"  debate.


                                  A few new people have picked it up recently and broadly found it useful.