Shop OBEX P1 Docs P2 Docs Learn Events
Sound "beep" — Parallax Forums

Sound "beep"

TexFlyTexFly Posts: 26
edited 2010-10-25 02:00 in Propeller 1
Hello,

What's the easiest and least memory consuming way of playing a simple sound?

Like BEEP!

I need to play few different alert sounds...not a 3D orchestra!

Thanks.

Tex
www.createandsolve.com

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-13 18:45
    There's a big difference between a beep and a few different alert sounds. In the one case, you're creating a simple sine wave or pulse train at one frequency with on/off modulation. In the other case, you may be "playing notes" with different frequencies, different wave shapes. The method you use for making the sound depends on its complexity.

    There are objects like Freq Synth for synthesizing a pulse train of a particular frequency. That's a very simple technique that creates very simple rough tones (because of the pulses). If you want something smoother, you will need some kind of sine wave synthesizer which has also been done and takes more memory and processor usage than a simple pulse train. There's a WAV player in the OBEX for complex recorded sounds, but it takes more memory, mostly for the WAV file.

    You decide what you want, look through the OBEX, and decide how much in the way of resources you are willing to devote to your alert sounds.
  • T ChapT Chap Posts: 4,223
    edited 2010-10-13 18:52
    If you can find a buzzer, maybe even a little speaker and connect to a pin. You can vary the alerts by frequency, duration, or arranging repeated beeps with variations per beep if you want.

    Ex. beep(1, 2500, 100)
    PUB beep(pinn, freqq, durr)
        if durr <> 0                                                       
          durr--
          ctrb[30..26] := %00100
          ctrb[8..0] := pinn
          frqb := calcfrq(freqq)
          if durr <> -2
            phsb := 0
          dira[pinn]~~                                            
          if durr <> -2
            repeat durr * 100  ''''until phsa => durr
            waitpeq(0, |< pinn, 0)                                        
            ctrb := 0
            ctrb := frqb := 0
            durr := 0             
    
    pri calcfrq(f)
    
      repeat 33
        result <<= 1
        if f => clkfreq
          f -= clkfreq
          result++
        f <<= 1
    
    
                                     
    
    
  • Clock LoopClock Loop Posts: 2,069
    edited 2010-10-13 23:25
    TexFly wrote: »
    Hello,

    What's the easiest and least memory consuming way of playing a simple sound?

    Like BEEP!

    I need to play few different alert sounds...not a 3D orchestra!

    Thanks.

    Tex
    www.createandsolve.com

    Although the HSS code isn't "easy" to understand if your trying to understand the object...

    The code to get it running IS easy to understand and get going.

    The HSS sound system is a simple object that lets you create a very wide variety of sounds using the FX channels.

    It is NOT wave data, it is sound generated on the fly from an audio engine, so it doesn't require large amounts of memory. http://www.andrewarsenault.com/hss/

    I use it in my black box sequencer to generate all the sounds you hear in the videos at the project link.
    http://forums.parallax.com/showthread.php?t=115258
  • TexFlyTexFly Posts: 26
    edited 2010-10-14 03:15
    Thank you all.


    T_Chap I like your method. Unfortunately it is missing the calcfrq function...

    Would you publish that as well?

    Thanks.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2010-10-14 03:35
    BTW, some thought about the hardware you choose to drive may be helpful.

    The minimum is a piezoelectric speaker that puts out a fraction of a watt and requires that you create the frequency within the Propeller.

    But there are 'beeper' and 'buzzer' devices that look quite similar and just have to be toggled on and off. Some of these will drive directly from a Propeller pin as they are also a fraction of watt output, but others might require a 2N2222 transistor to switch them as they require more power and/or a higher voltage (+5, +6, or +12).

    Finally there are real 8 ohm speakers with something like 5 watts output. A darlington transistor - like a TIP120 will drive one of these directly from a Propeller and may even require a resistor to limit current to 5 watts output. This is a real wake up beep. Admittedly, nothing is considered here to reshape the square wave or limit the harmonics, just make an attention getting noise. But after all, you requested minimal.
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2010-10-14 05:12
    I use the Freq Synth object. You can come up with a number of different sounds just by varying the frequency. Writing a zero stops sound.
  • T ChapT Chap Posts: 4,223
    edited 2010-10-14 07:54
    OK I added the missing method. This is a modified version from the piezo object which originally used two counters, I did not want to sacrifice two counters so tweaked it a little to use one.
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-10-14 08:59
    I would go with a piezo speaker. They are cheap and very easy to hook up, but they are not very loud..
  • RaymanRayman Posts: 14,889
    edited 2010-10-14 09:06
    I've got some ideas for you!

    I have an 8-bit mono wav player in OBEX (and my website) that you can use with the wave files embedded in your app. But, this takes up a lot of memory...

    I've got a simple MIDI player that should use less space:
    http://forums.parallax.com/showthread.php?t=108673&highlight=sine

    I've got a couple sine wave generators:
    http://forums.parallax.com/showthread.php?t=98763&highlight=sine
    http://forums.parallax.com/showthread.php?t=112389&highlight=sine

    BTW: This new forums search is great! (this is the first nice thing I've said about the new forum)
  • TexFlyTexFly Posts: 26
    edited 2010-10-19 02:41
    Thanks again for your help.

    T_Chap code works well and it uses minimum memory...so I'm going to try that.

    Tex
  • T ChapT Chap Posts: 4,223
    edited 2010-10-19 07:43
    Here is something Phil came up with that adds volume control to the beep, which makes for even better Beep FX. The Start is not required, it is just a test method for Beep.
    CON
    
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    
      AUDOUT        = 11
      FREQ          = 880
    
    PUB start | vol
    
      repeat
        repeat vol from 1 to 11
          beep(AUDOUT, FREQ, 500, vol)
          waitcnt(cnt + clkfreq / 2)
    
    PUB beep(pinn, freqq, durr, voll) | period, cycles, frqhi, frqlo, t
    
    '' Send a squarewave to pinn of frequency freqq for durr milliseconds.
    '' Volume level is determined by voll (0 - 11) and exponentially increasing.
    
      if ((period := clkfreq / (freqq << 1)) < 4000)
        return
      cycles := freqq * durr / 1000
      if (voll)
        frqhi := $10_0000 << (voll #> 0 <# 11) - 1
      else
        frqhi := 0
      frqlo := 0
      frqb~
      ctrb := %00110 << 26 | pinn
      dira[pinn]~~
      t := cnt
      repeat cycles
        waitcnt(t += period)
        frqb := frqhi
        waitcnt(t += period)
        frqb := frqlo
      dira[pinn]~
      ctrb~
    
    
  • John A. ZoidbergJohn A. Zoidberg Posts: 514
    edited 2010-10-19 09:15
    Bit-banging a pin will work all the time, if you want a beep sound.

    A smooth sine-wave can be done by using DDS (digital direct synthesis). :)
  • bazibazi Posts: 29
    edited 2010-10-24 16:40
    I'm using this code, really easy and small:
    PRI sound(f,delay_ms) | waittime
      dira[14..15]~~
      waittime := (clkfreq/f)
      delay_ms := delay_ms * (clkfreq/1000)
      repeat while delay_ms > waittime
        waitcnt(waittime+cnt)
        !outa[14]
        !outa[15]
        delay_ms := delay_ms - waittime
    
    f = frequency
    delay_ms = time of "beep" in milliseconds
    The pins 14 and 15 are my audio-pins, you should change this to your needs. If you have only mono audio, drop one of them.
  • william chanwilliam chan Posts: 1,326
    edited 2010-10-24 23:08
    How about a really simple beep
    PRI beep | i, j
    
        j := clkfreq/1500
        i := cnt
        repeat 100              
          !outa[spkr_pin]                   '  Toggle Speaker
          waitcnt(i += j)                    '  1.5 Khz sound
        outa[spkr_pin] := 0               '  set to low before exit
    
  • bazibazi Posts: 29
    edited 2010-10-25 02:00
    If i cut out the second channel, mine is only 1 line longer than yours, but you can give the length and the frequency as an argument. If you need a fixed beep with a fixed length, yours is better.

    Unfortunately i did'nt anything with Prop-Assembler, but on a 8051 i can do this job within 15bytes of machine-code :)
Sign In or Register to comment.