Shop OBEX P1 Docs P2 Docs Learn Events
Control volume out of chip with pwm — Parallax Forums

Control volume out of chip with pwm

stilgarstilgar Posts: 47
edited 2012-05-07 14:00 in Propeller 1
In my project I have a LED that fades on. I would like to have sound to fade on with the LED. I am using wave player.
I use PWM to fade on the LED, could this be used to control volume? The amp used for the sound has no volume control to it, so I would need another way to do it.

http://www.jbhifi.com.au/images/gumball-3000-portable-speakers-sku-69414-large.gif

I first thought was to use a transistor connected to a extra pin and send the same PWM signal to it as the LED.
Is there a way to do this without adding hardware??

Thanks

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-05-07 11:47
    You can control the volume form this statement in the player routine. Change:
          frqa := byte[addr++] << 24                                ' update dac
    

    to read:
          frqa := ((byte[addr++] - $80) * volume) << 16 + $8000_0000
    

    where volume is a volume level that ranges between 0 (muted) and 255 (full) and can be ramped up and down from your main program. The catch is that it adds some overhead to the playback, which will limit the rate. Hopefully, the rate you're currently using can stand the extra overhead.

    -Phil
  • stilgarstilgar Posts: 47
    edited 2012-05-07 11:56
    You can control the volume form this statement in the player routine. Change:
          frqa := byte[addr++] << 24                                ' update dac
    

    to read:
          frqa := ((byte[addr++] - $80) * volume) << 16 + $8000_0000
    

    where volume is a volume level that ranges between 0 (muted) and 255 (full) and can be ramped up and down from your main program. The catch is that it adds some overhead to the playback, which will limit the rate. Hopefully, the rate you're currently using can stand the extra overhead.

    -Phil

    Ok, this may seem a dumb question. After I change the line in the player, in my main program I add the VAR as volume? then set it as " volume = 127 " near the fade on LED section?? or did I do this wrong again (still learning about variables)
  • stilgarstilgar Posts: 47
    edited 2012-05-07 12:40
    I got the sound to go up, now the qestion is how to make it stop at 64 (same as maxbrite?

    my code:
    wavcog := cognew(playsound(10, @Cylon, 0), @stack) + 1 ' start sound player

    repeat luminosity from 0 to maxbright
    volume := (volume + 1) 'ranp volume up need to stop at 64 (maxbright)

    repeat x from 7 to _numleds-9
    leds[x] := luminosity + 1
    waitcnt(clkfreq / (rtime1 / 1000)+ cnt) ' center LEDs slowly go from 0 to maxbright = 64
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-05-07 12:44
    how to make it stop at 64
    volume := ++volume <# 64
    

    -Phil
  • stilgarstilgar Posts: 47
    edited 2012-05-07 13:00
    volume := ++volume <# 64
    

    -Phil

    Thanks a bunch, I under stand " ++ " means ramp up, but I don't remember seeing " <# " before. does that mean, " less than number "?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-05-07 13:15
    stilgar wrote:
    I don't remember seeing " <# " before. does that mean, " less than number "?
    It's the MAX operator. You can think of it as meaning "but not more than."

    -Phil
  • stilgarstilgar Posts: 47
    edited 2012-05-07 14:00
    thanks, I will have to look into that a bit more
Sign In or Register to comment.