PWM Audio Guide

Various user-contributed guides for hardware-related things
User avatar
joe7dust
Posts: 218
Joined: Mon Jun 06, 2016 4:13 am
Has thanked: 23 times
Been thanked: 7 times

Re: PWM Audio Guide

Post by joe7dust » Sat Jun 25, 2016 7:05 pm

A kind redditor noticed the mistake right away. It is supposed to be func =2 not 4 if you are using the right channel for a mono speaker.
Popcorn wrote:
joe7dust wrote: Wow grats on making this looking somewhat user-friendly. I took one look at the adafruit guide and was like NOPE not worth the effort, but this actually looks quite doable now.

Would someone mind telling me what I would need to change on this if I only wanted mono sound? I don't plan to have a headphone jack at all, just a single speaker that was pulled from an old laptop. I'm not exactly a connoisseur of gameboy beeps and bloops at 8-bit or whatever it was encoded at, and mono will be just perfect for that. Also I don't think the original had stereo speaker output at all, it only affects the headphone jack I think.

edit: Also, I don't need a potentiometer. I plan to keep the volume at a fixed level!
You can follow my circuit above, that is mono.

Just add this to your /boot/config.txt

Code: Select all

dtoverlay=pwm,pin=13,func=4
NOPE! Banged my head against this for a couple hours before giving up and throwing a support request up on reddit.com woke up this morning to an answer. Func=2 not 4 if you are using the right channel for a mono speaker and pin18. Seems strange that the func=# would differ between 13 vs 18...

User avatar
Popcorn
Trailblazer
Trailblazer
Posts: 354
Joined: Thu May 05, 2016 12:58 am
Location: Berlin
Has thanked: 29 times
Been thanked: 71 times

Re: PWM Audio Guide

Post by Popcorn » Sun Jun 26, 2016 11:53 am

^^ It's not really a mistake. You have to pick which side you want outputted as the mono channel. Either the left or the right side sent to the GPIO driver which is either 2 or 4. Both will work.

User avatar
alien0matic
Posts: 102
Joined: Wed Jun 08, 2016 7:20 am
Has thanked: 15 times
Been thanked: 23 times

Re: PWM Audio Guide

Post by alien0matic » Tue Jun 28, 2016 12:08 pm

Please don't kill me if this is a stupid question... does it have to be a 0.033uF capacitor? Only thing I could get was a 0.047uF.

SP33
Posts: 25
Joined: Tue May 17, 2016 5:41 pm
Has thanked: 3 times
Been thanked: 24 times

Re: PWM Audio Guide

Post by SP33 » Tue Jun 28, 2016 12:49 pm

alien0matic wrote:Please don't kill me if this is a stupid question... does it have to be a 0.033uF capacitor? Only thing I could get was a 0.047uF.
I believe it would be fine but I am not quite sure. I do know adafruit used a 0.01uF and claimed they would just have a higher cutoff frequency with nearly no audible change. So you may have a lower cutoff frequency? If someone else knows for sure this is safe to do please help him out. I don't have enough knowledge on this to say if you are good with a 0.047 or not.

User avatar
Popcorn
Trailblazer
Trailblazer
Posts: 354
Joined: Thu May 05, 2016 12:58 am
Location: Berlin
Has thanked: 29 times
Been thanked: 71 times

Re: PWM Audio Guide

Post by Popcorn » Tue Jun 28, 2016 7:06 pm

SP33 wrote:
Ganreizu wrote:So say i'm doing mono sound, is this the code i would use?

Code: Select all

dtoverlay=pwm-1chan,pin=18,func=2
(for left channel?)

vs

Code: Select all

dtoverlay=pwm-2chan,pin=18,func=2,pin2=13,func2=4
I have not tried mono sound myself yet but from my own tests, pin 18 was outputting in the right channel so I believe pin2 and func2 would be for left channel (pin 13)
so either try

Code: Select all

dtoverlay=pwm-1chan,pin2=13,func2=4
or

Code: Select all

dtoverlay=pwm-2chan,pin2=13,func2=4
(I'm unsure if pwm-1chan is valid)
or you could just use the original code and not use pin 18, only hook up pin 13 (left channel) just to be sure.
This is the problem. There is no dtoverlay called pwm-1chan.

It's either "pwm" for mono or "pwm-2chan" for stereo. There is no "pwm-1chan".

poxbox3030
Posts: 10
Joined: Wed May 04, 2016 10:23 pm
Has thanked: 2 times
Been thanked: 2 times

Re: PWM Audio Guide

Post by poxbox3030 » Thu Jun 30, 2016 11:11 pm

I have mono audio working but.....

As an example, playing Sonic the sound of the ring collection alternates between the left and right channel. As its set up now I only get every second ring sound. I thought as mono sound it would mix both left and right and output both mixed to one speaker.

I have it wired up exactly as per Wermys guide with the mono low pass filter.

I have also constructed a stereo low pass filter to install if required.

Could someone help me with either what I am doing wrong with the mono audio, or how to wire up stereo audio to the amp (and the headphone jack)

Thanks in advance

dantheflipman
Posts: 5
Joined: Wed Jun 29, 2016 9:55 am
Location: PA, USA
Been thanked: 1 time
Contact:

Re: PWM Audio Guide

Post by dantheflipman » Fri Jul 01, 2016 6:37 am

Will someone please let me know what GPIO pins we're actually using? e.g. Are we using BOARD numbering? or BCM numbering?

I cannot seem to find this info for the life of me :lol:

User avatar
joe7dust
Posts: 218
Joined: Mon Jun 06, 2016 4:13 am
Has thanked: 23 times
Been thanked: 7 times

Re: PWM Audio Guide

Post by joe7dust » Sat Jul 02, 2016 12:39 am

dantheflipman wrote:Will someone please let me know what GPIO pins we're actually using? e.g. Are we using BOARD numbering? or BCM numbering?

I cannot seem to find this info for the life of me :lol:
13 & 18 for stereo. I use 18 on mono in my guide

Treguard
Posts: 128
Joined: Thu Jul 28, 2016 5:29 am
Has thanked: 40 times
Been thanked: 6 times

Re: PWM Audio Guide

Post by Treguard » Thu Jul 28, 2016 6:18 am

Sorry to sound thick, but just to check that this connects to two GPIO pins at one end (not sure where the ground goes) and then can the other end be straight connected to a 3.5mm stereo jack block?

I'm not sure yet how I'd control volume. Any suggestions would be most appreciated :) Thanks

Also, do you need that blue amplifier board as well that's used in the video?

Edit:- As I'm not using an original gameboy, I don't have anywhere to fix the potentiometer to, so it looks like I might just have to go the usb audio route sadly :(

User avatar
RxBrad
Posts: 278
Joined: Fri Jul 22, 2016 9:10 am
Has thanked: 125 times
Been thanked: 160 times
Contact:

Re: PWM Audio Guide

Post by RxBrad » Sun Aug 28, 2016 1:35 pm

So, I built the stereo circuit. I've been scouring the forum, and for life of me, I can't figure out how I'd wire up the circuit, pot, and headphone jack so I get stereo output through headphones, and the left/right channels are COMBINED through the speaker. While MOST games are mono, as previously mentioned, some are stereo (e.g. Sonic ring collection sound effects). If I only wired one channel to the speaker, some sounds wouldn't play.

Can anyone point me in the right direction.

EDIT 3: I believe that all of the stuff below applies to pre-amped signals, and those resistor values would make the audio from the speaker unusably low. I'm also guessing that the higher resistance across the active signal and ground are already accomplished through the pot. The actual answer appears to be in the diagrams here.

EDIT: Figure 2 on this page looks promising. The input would be coming from the headphone jack, and the output going into the speaker. Looking around, I've seen other similar diagrams that recommend 1k resistors in place of the 475ohm resistors. I'm just not 100% sure how to interpret the diagram. Is the bottom line the ground? (EDIT 2: yes it is .. S = shield/ground)

Image
Image
Image Image

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest