38 Replies Latest reply on Aug 24, 2016 3:17 AM by saurabh2890

    Read in from the headset jack, and read out to the amplifier

    chamuel

      Hi,

      I've installed the drivers for the Wolfson Audio Card on my raspian, and it works!

      I can play music with a python progeramm, i take the command line music player xmms2.       https://xmms2.org/wiki/Main_Page

       

      Now, I'm engineering a standalone Musicbox, and i want to read in the music (headset jack), and read out the same music the the integrated amplifier.

      It woud be nice to control it from a python programm.

       

      Is that possible ?

       

      Thanks and Regards,

      Chamuel

        • Re: Read in from the headset jack, and read out to the amplifier
          suicidal_orange

          It might be possible but the headset only has one input channel so you'll either get the same sound out of both speakers through the amp or one will be silent... neither would sound very good!

           

          Also depending what you are putting the input through you may only land up with the left or right channel going in - why not use the line in socket which is stereo?

          • Re: Read in from the headset jack, and read out to the amplifier
            ragnar.jensen

            I have made a couple of scripts that connect inputs to outputs directly on the Wolfson card. To just listen, there is no need for aplay, arecord or alsaloop.

            The sound is also routed to the Pi, so you can record it.

            If you run the scripts with the argument "eq", the sound is routed through equalizers.

            • Listen_to_LineIn_on_Lineout.sh
            • Listen_to_LineIn_on_SPDIF.sh
            • Listen_to_LineIn_on_Speakers.sh
            • Listen_to_SPDIF_on_LineOut.sh
            • Listen_to_SPDIF_on_SPDIF.sh
            • Listen_to_SPDIF_on_Speakers.sh

             

            --

            Ragnar

            1 of 1 people found this helpful
            • Re: Read in from the headset jack, and read out to the amplifier
              kjciszewski

              I'm not impressed with this whole Wolfson/Cirrus thing. Wolfson can't set up their PI A/B driver to handle all the sample rates supported by ALSA (down to 8K for sure), and now the PI A+/B+ driver doesn't work right.  Can some one explain to them how to get their act together?  I sent an email to Cirrus' CEO on the corporate site complaining about the sample rate problem.  How do we contact someone in tech support to get their attention?

               

              I asked (in another post) what sample rates the A+/B+ card supported, and was told to look at the data sheet, which gives a 32K minimum for the SPDIF ports, but says nothing about the driver itself.  Why are things being limited based on SPDIF?  Most of the world doesn't care about SPDIF--the interest is in network audio, SIP/Asterisk communications, and so on.

              • Re: Read in from the headset jack, and read out to the amplifier
                kjciszewski

                Even so , a full implementation of ALSA's features would be appreciated for the Wolfson/Cirrus cards.  How do we get tech support motivated to help?

                • Re: Read in from the headset jack, and read out to the amplifier
                  hystrix

                  I have tried to pass the Microphone input to Line out, per the OP's original query, but it doesn't work.  All I get is a chopping noise.

                   

                  I have run the two use scripts - record from headset and playback to line out, and tried this:

                   

                  arecord -Dhw:sndrpiwsp -r 44100 -c 2 -f S32_LE -d0 -vvv  | aplay -Dhw:sndrpiwsp -r 44100 -c 2 -f S32_LE

                   

                  I even tried recording to a null file:


                  arecord -Dhw:sndrpiwsp -r 44100 -c 2 -f S32_LE -d0 -vvv /dev/null  | aplay -Dhw:sndrpiwsp -r 44100 -c 2 -f S32_LE


                  I really want to monitor microphone input at 192kHz, and play back at say 44.1kHz to line-out, but I can't even get it working with the same frequency in and out.


                  Can anyone help?


                  Many thanks.

                    • Re: Read in from the headset jack, and read out to the amplifier
                      pimpmypixel

                      Hey,

                       

                      did you get this (DMIC -> headphones) to work?

                      I'm still such a newbie here - what am I missing?

                       

                      #!/bin/bash
                      CARD="hw:0"
                      BEQUIET=" -q "
                      #BEQUIET=""

                      # Gain Control
                      amixer ${BEQUIET} -D${CARD} cset name='IN2L Digital Volume' 138
                      amixer ${BEQUIET} -D${CARD} cset name='IN2R Digital Volume' 138

                      # Input level
                      amixer ${BEQUIET} -D${CARD} cset name='AIF1TX1 Input 1' IN2R

                      amixer ${BEQUIET} -D${CARD} cset name='AIF1TX1 Input 1 Volume' 30
                      amixer ${BEQUIET} -D${CARD} cset name='AIF1TX2 Input 1' IN2L

                      amixer ${BEQUIET} -D${CARD} cset name='AIF1TX2 Input 1 Volume' 44
                      amixer ${BEQUIET} -D${CARD} cset name='DMIC Switch' on

                       

                      # No EQ, ATTEMPT TO send sound straight from DMIC to headphones
                      amixer ${BEQUIET} -D${CARD} cset name='HPOUT1 Input 1' IN2L

                      amixer ${BEQUIET} -D${CARD} cset name='HPOUT1 Input 1' IN2R

                       

                      #Playback from AP to Headset
                      amixer ${BEQUIET} -D${CARD} cset name='HPOUT1 Digital Switch' on


                      Hope you can help..

                      Thanks so much!

                        • Re: Read in from the headset jack, and read out to the amplifier
                          spambake

                          I was able to playback the Dmics to a headphone by using the Sox utilities:

                           

                          ./Reset_paths.sh

                          ./Record_from_DMIC.sh

                          ./Playback_to_Headset.sh

                          play "|rec -d"

                           

                          I got the solution from this site via Hackaday:

                          http://planet-geek.com/2015/10/29/hacks/using-a-raspberry-pi-as-a-realtime-voice-changer-for-halloween/

                           

                          With a RPI2 and Cirrus card the latency is about 1/10 second I would guess.

                           

                          This should work well for near real time bat detection pitch shifting.

                            • Re: Read in from the headset jack, and read out to the amplifier
                              hystrix

                              It does indeed work well for bat detection using pitch shifting, or "time-expansion".

                               

                              I've been using this method, using sox, this summer.  When you're used to the heterodyne clicks of bats, to hear them pitch-shifted is a revelation.  They sound like birds .

                               

                              Here's a time-expansion bat recording I made using my Pi2 and Cirrus Logic card: https://youtu.be/6evyf_9uZjs

                                • Re: Read in from the headset jack, and read out to the amplifier
                                  spambake

                                  Actually just using "sox -d -d" works fine for sending default in to default out.  You can also add sox effects in to the command.

                                   

                                  Hystrix - I have been following your superb bat detection project (noted on the youtube detail) for a while.  Who would have thought we could have a high quality hackable bat detector for 100USD or so.  Mine is set to automatically record bat calls all night long and upload the spectrograms to Google drive in the morning.

                                   

                                  And now you have a multiuse touch display on yours.  Nice work! 

                                    • Re: Read in from the headset jack, and read out to the amplifier
                                      hystrix

                                      I'm glad you like my bat project.  It sounds like what you're doing with spectrograms is interesting, too.  I would be interested to know how you are extracting the periods of recorded data that contains bat calls in order to create the spectrograms.

                                       

                                      Also, I find sox commands a complete mystery, and not well documented.  It took me ages to work out how to send the mic input out to speakers or line out.  My solution is a lot more complicated than just "sox -d -d"!  Is there a good resource anywhere?

                                        • Re: Read in from the headset jack, and read out to the amplifier
                                          kjciszewski

                                          There's a book entitled "Raspberry Pi for Secret Agents" by Stefan Sjogelid  that uses Sox and explains how some of the commands work. Unfortunately, it was written before the Wolfson Audio Card came into being, so it uses a USB audio interface.  Even so, it might be helpful.

                                          • Re: Read in from the headset jack, and read out to the amplifier
                                            wan1

                                            Looks great! What software did you use to create the spectrogram? Was it executed on RPi, or on your desktop comp?

                                             

                                            I'm asking because I looking for the optimal way to create a real-time spectrograms on RPi during recording. (Actually, the idea is to make a compact autonomous field recorder based on RPi+CLAC with lcd, wich shows r-t spectrogram to monitor killer whale sounds, as a part of my research work.)

                                            • Re: Read in from the headset jack, and read out to the amplifier
                                              spambake

                                              @hystrix

                                              I don’t know of any really good resources for sox.  I mostly use their online man page and, like you, gradually tease out what they mean. Good Google-fu can be helpful.  This site can be useful:

                                              http://sox.10957.n7.nabble.com/

                                              Beware: popups!!

                                               

                                              The automated system works pretty well except rain and some insects set it off, too.  It is still very much a work in progress and I am not an expert. Some things I use:

                                              Homebuilt preamp that rolls off lower frequencies and seems less noisy.

                                              Use the Cirrus card high pass filter coefficients to roll off lower frequencies.  The lines in the use case scripts look like this:

                                              amixer $1 -Dhw:sndrpiwsp cset name='LHPF1 Coefficients' 248,31
                                              
                                              

                                              Roll off below 10K =  244,139

                                              Below 20K = 248,31

                                              Below 30k=251,41

                                               

                                              To automate the recording I use the sox silence function to record sound above a certain volume level and split each detection into separate files.  Fortunately bats are loud.  Here is the command I currently use:

                                              rec -V3 -b 32 -r 192000 /home/pi/bats/test.wav remix 2 silence 1 0 1% 1 2.0 1% : newfile : restart
                                              
                                              

                                              Adjust the percents to get above the noise level on your setup

                                               

                                              Morning processing involves deleting files smaller than 1 meg and larger than 10 meg.  A meg equates to about one second.  This gets rid of most of the worst clutter.  File names are changed to reflect the times they were first created and then sox is used to bulk create the spectrograms.  I use this to upload the spectrograms to Google drive:

                                              https://github.com/prasmussen/gdrive

                                               

                                              As you know all of this required a lot of research, experimentation and troubleshooting and there is much more to do.

                                               

                                              Feel free to ask more about this.

                                               

                                              I have not yet found a way to have two simultaneous outputs in real time.  For instance record and listen at the same time, or record at full spectrum while listening to a pitch shifted version or produce a spectrogram while recording.

                                  • Re: Read in from the headset jack, and read out to the amplifier
                                    saurabh2890

                                    hi, Ragnar ,,

                                                       I AM USING cirrus logic ,,,in which I feed input through Line and able to make a file....I want to listen live through Line out....through the command u  given...

                                    • Listen_to_LineIn_on_Lineout.sh ,,,,,,,,,,but this shows the error : command not found ,,will u please help me..