Audio & PWM


29 posts   Page 1 of 2   1, 2
by gordon@drogon.net » Tue May 01, 2012 9:23 pm
I may have missed some information about the audio system on the Pi and goggle isn't helping me right now - am I correct in thinking that the PWM audio out of the 3.5mm jack is currently not used/programmed/developed yet, and the ALSA drivers are for HDMI output only?

Thanks,

Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1544
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by dom » Tue May 01, 2012 9:47 pm
No ALSA supports PWM audio. If HDMI supports audio it will output to HDMI. If not then PWM audio.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4104
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by gordon@drogon.net » Tue May 01, 2012 9:55 pm
dom said:


No ALSA supports PWM audio. If HDMI supports audio it will output to HDMI. If not then PWM audio.



Ah. OK. So the current driver will use either... So if I actually use the PWM outputs via GPIO (as I'm doing right now),  it'll screw up audio... (or if I play any audio, it'll screw up my PWM outputs! (I think I can live with that - Others may not be able to, however) It is a shame there are only 2 PWM channels on the chip... I'm suspecting the PWM output really is going to be of limited use...

Thanks,

Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1544
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by dom » Tue May 01, 2012 10:19 pm
You can force audio to either PWM or HDMI through the audio mux device. If set to HDMI then the PWM pins shouldn"t be touched.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4104
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by gordon@drogon.net » Tue May 01, 2012 10:25 pm
dom said:


You can force audio to either PWM or HDMI through the audio mux device. If set to HDMI then the PWM pins shouldn"t be touched.



WIll look into that, thanks. (But then again, I'm curious to hear how good the PWM audio sounds now - but not tonight)!

Cheers,

Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1544
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by arno-b » Thu May 03, 2012 10:56 am
Hi,

As I don't have RPi yet, I am wondering what will be the audio quality too.

The simplest case is a small amplifier plugged into 3.5 jack output with a high bitrate mp3 file.

On the other hand, maybe a HDMI Audio to DAC chip would certainly provide a good "HIFI player".

looking forward to have some info from audio specialists ...

Regards, Arno
Posts: 4
Joined: Fri Feb 24, 2012 8:57 pm
by Neil » Thu May 03, 2012 12:41 pm
arno-b said:


As I don't have RPi yet, I am wondering what will be the audio quality too.


Good enough for cheap headphones.  As Gert said in a thread a long time ago it is about 11-bit quality.  Certainly not CD quality, but still pretty good (certainly better than you got with a BBC Model B for sure).  And anyway the PCB layout is not exactly "hi-fi", but again good enough for what it is designed for.

Neil
Posts: 91
Joined: Thu Sep 29, 2011 7:10 am
by caulktel » Thu May 03, 2012 1:00 pm
What is the sample rate of the RPI? 96Khz would be great but I could settle for 48Khz on my SDR radio project.
Posts: 17
Joined: Wed Feb 08, 2012 8:59 pm
by arno-b » Thu May 03, 2012 1:31 pm
caulktel said:


What is the sample rate of the RPI? 96Khz would be great but I could settle for 48Khz on my SDR radio project.


Well Neil, If the PCB layout is good enough to twist RPi to a Web Radio device without to much noise, it sounds good to me (hi-fi was exaggerated for a small inexpensive board !).

Arno
Posts: 4
Joined: Fri Feb 24, 2012 8:57 pm
by caulktel » Fri May 04, 2012 12:55 pm
So, I'll ask again, does anybody know what the sample rate of the sound chip on the raspberry Pi?
Posts: 17
Joined: Wed Feb 08, 2012 8:59 pm
by Neil » Fri May 04, 2012 1:00 pm
caulktel said:


So, I'll ask again, does anybody know what the sample rate of the sound chip on the raspberry Pi?


Umm, there is no separate sound chip on the Raspberry Pi.  Audio is handled by the 2835 SoC.

In principle the software can handle whatever sample rate your audio files are by converting to what it needs internally.  PWM playback will take the audio at the base sample rate (lets say 44.1kHz, but it could be 48kHz), and converts it into a high-frequency train of 0s and 1s, which is then filtered by a simple RC filter to give you the analogue audio signal.

Oh, yes, and there is no audio input.  Only audio output.

Cheers,

Neil
Posts: 91
Joined: Thu Sep 29, 2011 7:10 am
by gordon@drogon.net » Fri May 04, 2012 1:41 pm
~Neil~ said:


Oh, yes, and there is no audio input.  Only audio output.


Actually ;-)

I've just had a look at the circuit diagram and I think it could be made to take audio input into the same 3.5mm jack... However you then have to sample it in software using PWM sampling techniques. ie. it's effectively a 1-bit ADC.

And if you think it's far-fetched, then note that this was done 30+ years ago on the Apple II - audio input and output using PWM techniques purely in software - on a 1MHz 6502. Search for Appletalker if you're interested...

However it would probably need coding in assembler and need to run with interrupts disabled to absolutely guarantee the sampling interval - so it's probably possible as a pure academic excercise, but not for something general purpose!

Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1544
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by arno-b » Fri May 04, 2012 5:42 pm
Hi,

An other way could be (maybe out of this topic ?) a "Arduino shield like" little board plugged to the I/O connector with a good DAC chip ...

Arno
Posts: 4
Joined: Fri Feb 24, 2012 8:57 pm
by gordon@drogon.net » Fri May 04, 2012 5:52 pm
arno-b said:


Hi,

An other way could be (maybe out of this topic ?) a "Arduino shield like" little board plugged to the I/O connector with a good DAC chip ...

Arno



That would certianly work - getting the sample rate might be tricky though. - remember it's a multi-tasking OS we're dealing with, so you're probably looking at some thing at the kernel level to do the sampling - maybe via the SPI interface and DMA if it's possible...

Much as it hates me to say it, Probably easier to just plug in a USB sound card...

Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1544
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by error404 » Fri May 04, 2012 6:51 pm
The chip has an I2S interface and rumour has it that it's available with a simple mod (haven't checked the schematic on this...). You could then run it asynchronously and generate your clocks externally. This was something I originally planned to design and build myself for use with SDR, but without easy access to a Pi and with a mod required I don't think it will happen.

So yeah, go USB.
Posts: 351
Joined: Wed Dec 21, 2011 11:49 pm
by arno-b » Fri May 04, 2012 7:04 pm
OK for the USB for audio output : which one  ?

Regards,

Arno
Posts: 4
Joined: Fri Feb 24, 2012 8:57 pm
by mahjongg » Fri May 04, 2012 10:27 pm
error404 said:


The chip has an I2S interface and rumour has it that it's available with a simple mod (haven't checked the schematic on this...). You could then run it asynchronously and generate your clocks externally. This was something I originally planned to design and build myself for use with SDR, but without easy access to a Pi and with a mod required I don't think it will happen.

So yeah, go USB.


A simple mod maybe, for the person designing a revised R-PI PCB yes it might be, but impossible to mod on the current board. The pins (balls) underneath the SoC that carry the I2S signals were not routed out from the ball grid array on the current boards.

If you have done any layout work on a ball grid array you will know how difficult it can be to route out the inner balls of the array, on a "simple" six layer board it might be impossible, without the help of buried and blind via's, and these significantly increase the price of the PCB, so are not useable. Perhaps in a re-design it will be possible to route these signals to the GPIO pin header.

http://en.wikipedia.org/wiki/B.....grid_array

http://en.wikipedia.org/wiki/Blind_via
User avatar
Forum Moderator
Forum Moderator
Posts: 6016
Joined: Sun Mar 11, 2012 12:19 am
by jbeale » Sat May 05, 2012 1:13 am
arno-b said:


OK for the USB for audio output : which one  ?


This one has been reported to work with Linux. Hard to beat that price! http://www.dealextreme.com/p/u.....orted-5831

but be aware shipping from dealextreme can be quite slow.
User avatar
Posts: 2120
Joined: Tue Nov 22, 2011 11:51 pm
by jbeale » Sat May 05, 2012 1:13 am
(not specifically checked on the R-Pi as far as I know, but all standard USB audio devices are supposed to be compatible )
User avatar
Posts: 2120
Joined: Tue Nov 22, 2011 11:51 pm
by error404 » Sat May 05, 2012 4:41 am
mahjongg said:


A simple mod maybe, for the person designing a revised R-PI PCB yes it might be, but impossible to mod on the current board. The pins (balls) underneath the SoC that carry the I2S signals were not routed out from the ball grid array on the current boards.


Okay, I wanted to confirm this, so I actually checked the schematics and datasheet.

I2S is available on GPIO 18-21 or 28-31. GPIO19 and 20 aren't broken out of the BGA, so they're a no go. However, all of GPIO 28-31 is brought out, with each pin attached to a voltage divider that seems to have no current purpose (I guess it's to detect board versions). If the resistors (R3-R10) were removed and the pads tapped, you could have I2S.

So yes, a fairly simple mod.
Posts: 351
Joined: Wed Dec 21, 2011 11:49 pm
by caulktel » Sat May 05, 2012 12:03 pm
Thanks for all the good info, I believe at least for the time being I will go the USB route. I just bought a adapter from China for $1.50 with free shipping, it got here yesterday and I plugged into my old PPC Mac Mini and it worked great for Skype. It says that it works with Linux also, so I will check the specs on the chipset for the sample rate. I'm almost finished building my Softrock SDR for 40 meters and can't wait to try this out. The higher the sample rate the greater tuning bandwidth. I would really like to use the RPI for this project, there is even SDR software that runs on Linux, not sure about ARM though.
Posts: 17
Joined: Wed Feb 08, 2012 8:59 pm
by mahjongg » Sat May 05, 2012 12:40 pm
error404 said:


mahjongg said:


A simple mod maybe, for the person designing a revised R-PI PCB yes it might be, but impossible to mod on the current board. The pins (balls) underneath the SoC that carry the I2S signals were not routed out from the ball grid array on the current boards.


Okay, I wanted to confirm this, so I actually checked the schematics and datasheet.

I2S is available on GPIO 18-21 or 28-31. GPIO19 and 20 aren"t broken out of the BGA, so they"re a no go. However, all of GPIO 28-31 is brought out, with each pin attached to a voltage divider that seems to have no current purpose (I guess it"s to detect board versions). If the resistors (R3-R10) were removed and the pads tapped, you could have I2S.

So yes, a fairly simple mod.


Yes, four GPIO's are used to auto detect the revision version, as is indicated in the schematic, (sheet to, location 7D)  with 10K resistors either mounted or unmounted the pins are either pulled low or high, giving a four bit condition that can be read, with currently only two of the sixteen possible combinations used, one (code ''0'') for the model A and the other (code ''1'') for the model B, with codes ''2'' to ''F'' reserved for future use.

more about the GPIO uses can be found here:

http://elinux.org/RPi_BCM2835_GPIOs

Probably the kernel code reads these resistors, and when it reads something it does not expect it might crash, or misfunction. But it might be that it only reads the model code at boot time, and after that you can program the four pins as a I2S port. If you are unlucky though it might try to read the code each time it want to establish ethernet connectivity or use USB connectivity, to see if its supported on board. So you probably have to leave the resistors in place for the model code readout, and for pins that are reprogrammed as outputs (bit clock and word clock, output data) that isn't a problem, but at least one of the I/O lines (the input data line) might try to put something on its GPIO pin which might disturb the model code. It remains to be seen how well this will work, perhaps depending also on the codex you want to attach to it (whether or not it will not disturb the model code readout at boot time).

Also, in the future its probable that this won''t be the pins that are used for I2S, but instead the two missing GPIO's (19 and 20) for the primary I2S port will be routed out to the pinheader, so as to also enabling a second SPI interface.

In that case this solution will not be compatible with a future "official" solution.
User avatar
Forum Moderator
Forum Moderator
Posts: 6016
Joined: Sun Mar 11, 2012 12:19 am
by dom » Sat May 05, 2012 12:58 pm
The original PCB was designed to read the board revision from GPIO.

However that seems a waste of valuable resources, so we've duplicated that information in the OTP bits.

I think with recent firmware (start.elf) that those GPIO pins are no longer looked at, so you'll probably get away with repurposing those lines.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4104
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by mahjongg » Sat May 05, 2012 1:10 pm
Ah, that is great! :-) Perhaps the next board revision will then simply repurpose these pins and connect them to currently NC positions on the pinheader?

It would remove part of the problem of trying to route out the pins.
User avatar
Forum Moderator
Forum Moderator
Posts: 6016
Joined: Sun Mar 11, 2012 12:19 am
by Neil » Sat May 05, 2012 4:53 pm
This post from Gert explains in more detail about access to the I2S pins:

http://www.raspberrypi.org/for.....-4/#p60468

Neil
Posts: 91
Joined: Thu Sep 29, 2011 7:10 am