8 Replies Latest reply on Nov 26, 2013 3:22 PM by gertvanloo

    Can PWM0 -> GPIO18 handle moderate quality mono audio output?

    aleph1

      My partner (and electrical engineer and bare metal guru) and I (an experienced programmer and data center designer) have a (Wheezy) project, several months in the pipeline, using an RPi(B) that in the end needs simply needs to output stronger audio.  We've amped the PWM 3.5mm, and for some situations, that's adequate.  We also have a version that uses a usb dongle (109/related) out, with some improvement in quality and RMS, and that's working for some installations. 

       

      But for some interfaces, it's just not a strong enough output.  My partner just built an add on board with an NTE823 and enough gadetry to drive 8 or 600 ohms with apparently adequate p2p to it.

       

      This addon-board, which is functional in testing, is intended to be driven by (Alt5) PWM0 (delivering an ALSA/mpg321 out) signal via GPIO18 (pin 12).  Problem is I'm not getting that to happen yet, and would like some advice as to which way to go for 44KHz pwm audio.  I've tried wiringPi, #bin/sh ...export (which just looks inevitably too slow), and am about to try python.GPIO, but need to focus on a direction that can possibly succeed.  I need to accomplish this prior to a series of surgeries I begin late next week.

       

      Anyone actually driven (single chan) audio out that way? I'll take the 11 bit quality in this case, but any dramatic deviations from the complex streaming, scheduling, self-monitoring set of php, c ,python,shell commands and installed packages for both audio and timed external comm that this unit have finally flawlessly came together, are out.

       

      Any pointers, suggestions of directions, flat out statements of fact?  (or even help?)   I have searched this more than any single topic in recent memory, so it's not that I don't know how to use the search button.  Our problem is we have found the hole in our complimentary skills - he can't program other than deep metal, and I am seeing a this I/O assignment class of knowledge as one I don't yet have.  I'm not incapable of learning, but I would appreciate anyone who knows which one of these GPIO access options works for the task listed, to narrow the scope of what I need to learn and do.Thanks.

        • Re: Can PWM0 -> GPIO18 handle moderate quality mono audio output?
          Rushy

          Hi Mark,

           

          Have you seen this add-on board at all. http://www.element14.com/community/community/raspberry-pi/raspberry-pi-accessories/wolfson_pi

           

          I'll see if I can get a datasheet for you with some spec.

          • Re: Can PWM0 -> GPIO18 handle moderate quality mono audio output?
            dweb98

            Hi Mark,

            Don here, I'm not a Programmer. So, allot of your description of the problem, went over my head.
            But, I am an old Audio - Video guy, from way back. And I have my Pi running RaspBMC. Which is based on Debian, too. I have my Analog Stereo Audio Output running to a Preamp and then on to my Amplifiers. This works very well and I have no problems with Audio Output levels, with this setup. Any good Audio Preamp should do. For use with the Audio Output on the Pi, to Boost the Signal to your Amp. I also have a USB Audio Input - Output Adapter. That I got to use on a Desktop and a Laptop with bad OnBoard Audio Chips. The Desktop has noise on the Input. And I blew out the Laptops Output. By unplugging the Cable, while playing Audio. The USB Adapter, works well for a Mic input on both Systems. In Fedora Linux. I run my Sure SM-58 through a Cassette Tape Deck to get some Gain on the Input Signal. This is not needed with my Head Set Mic, though. The Audio Output is a bit weaker, than the Signal that comes from my Onboard Sound Card on my Desktop, though. I checked out that, Wolfson Audio Card. I like it. Looks like it would be great for using with a Pi Camera to Record Audio. But, if my $2 USB Adapter would work. Then it would win out, for that purpose. I noticed that you mentioned, that you want a Mono Audio Output. I'm wondering why. But, what ever the reason. If by chance you are using a Stereo to Mono Y adapter Cable on your Analog Stereo Audio Output. This will not work well. It will cause Phase Canceling and thus Degrade your Audio Signal, allot. Some of these Cables, if not wired correctly. Will even cause a Short in the line and be bad all around. This could end up shorting out your Audio Chip or your whole Pi. You can tell that you have this condition. By simply feeling of the Audio Output Cable. While your Pi is running. If it heats up, you most likely have short in the Adapter Cable. Positive and Negative would be crossed, when combining the two Stereo signals down to Mono. This happens with allot of Store Bought, Stereo to Mono Cables, as well. In the 1970's I use to make up my own converter cables for various setups, on my Car Stereos. And that's how I learned this. But, 70's electronics were allot Tougher than the stuff they make today. So, they could handle more abuse or mistakes. And my last, or actually, first thought. The most obvious thing... Have you checked your Alsa Audio Output Settings in Debian? And if Pulse Audio is running on this System as well. Then there could be conflicting settings. That are simply turning down the Audio Output signal. Obvious, I know. But, worth mentioning. And double - triple checking never hurts. Sometimes the simple stuff, is the answer...

            Don

              • Re: Can PWM0 -> GPIO18 handle moderate quality mono audio output?
                aleph1

                Don - thanks for the good rundown of possible solutions to the general problem.  Ya, we've learned the hard way regarding off the shelf cheap connectors.  We also can preamp and amp this thing fine  (tho the reminder of the alsa settings being reset by non-obvious events was a timely reminder).  

                 

                What we are trying, that is not solved here, is a unique (for proprietary reasons) amp, bypassing the standard PWM circuitry and using PWM0 directly to be acted on via alt5 delivery to GPIO18 (supposedly possible "by the book").  I'm hoping to be able to direct the hardware out stream to the pin, but NOT by a software/script driven "HI/LOW", bit by bit, method - in other words, just let me deliver that already created PWM stream (of a moderate quality audio file) to that pin.  We can handle the rest.  We are onto 2 alt approaches involving the more sophisticated full rail method and a usb w 108/9 type (last resort) method, but don't want to give up on the original concept in question in this thread, just due to lack of time.  If we do figure it out, I'll be glad to repost it here, as it's looking perhaps as if maybe no one has tried this before?

                  • Re: Can PWM0 -> GPIO18 handle moderate quality mono audio output?
                    dweb98

                    Hey Mark,

                    Glad, I was at least able to remind you of the often overlooked, easy stuff. I find what your are doing, interesting. It helps me to learn how the GPIO works. Yes, I would like to see the results of your work. When you get things working, the way you want it.

                    I found a page (perhaps, one you have already read). With, some interesting info...

                    P1-12 GPIO 18 
                    PCM_CLK ALT4 = SPI1_CE0_N ALT5 = PWM0

                     

                    It is also possible to reconfigure GPIO connector pins P1-12 and 13 (chipset GPIO 18 and 21) to provide an I2S (a hardware modification may be required[12]) or PCM interface.[13] However, PCM_FS and PCM_DIN (chipset pins 19 and 20) are needed for I2S or PCM.


                    Read More and see the Graphics too...
                    http://elinux.org/RPi_Low-level_peripherals


                    Hope you get it working, the way you wan it to...

                    Don

                      • Re: Can PWM0 -> GPIO18 handle moderate quality mono audio output?
                        aleph1

                        Hey Don - yes we have an outline of an I2S/I2C project laid out, and board ready to piece together, but the way are skill sets are configured, I'd be looking at the same question, only an order of magnitude larger.   My partner can come up with boards on the fly - he is responsible for some groundbreaking concepts in his industry  (all I can really say is it provides audio in business situations - with an annoying lack of standards as far as input).  The pi handles a sector of what needs delivered excellently, with new capabilities and intelligence and I said "hey why don't we...", so we have a new joining of an old hand at audio and audio delivery via designed bare metal (down to the register level), and an old hand at operating systems and programming.   What we don't have is an old hand at that tiny area "where the twain shall meet" to handle a full OS board and program set being pin ported to a bare metal end solution.   We have alternatives also, but "smallness" is an essential element of the products design - we have several in dealers hands right now, and I'm dealing with a couple of other issues, and this may take care of itself via one of the other options, but brother, I just can't find the thread anywhere (in the time available) that gives me the tiny thing I'm not getting.   The real irony is that it is probably only a snippet of code or single system command, and I've probably already seen it and tried it wrong or failed to see it's utility.   So this will stay open, even if I need to answer it myself eventually and report the (core) answer.

                         

                        Mark