Shop OBEX P1 Docs P2 Docs Learn Events
Any interesting waveforms besides the sine and square? — Parallax Forums

Any interesting waveforms besides the sine and square?

John A. ZoidbergJohn A. Zoidberg Posts: 514
edited 2011-06-21 02:17 in General Discussion
Hey there,

Been doing a cheap DDS solution for a little music box, but the sine and square wave seems to sound dull or boring after a few plays.

When I'm searching for more ideas of how to spice up the sound in a microcontroller, I found this in youtube: http://www.youtube.com/watch?v=qetnEUlbY-c&feature=related

Yeah - it isn't a microcontroller, but a generic wall-clock with some pretty good melodies. Plus, it's nice, it would be a great addition to some microcontroller projects!

I wonder what kind of waveform, or what kind of technique they used on these. I'm thinking of using Inverse FFT for all that, but would like to hear your opinions first. :)

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-06-12 08:15
    Chords, JAZ.
    Single-note plinking is what's "dull or boring."
    You have to do chords.
  • John A. ZoidbergJohn A. Zoidberg Posts: 514
    edited 2011-06-12 08:39
    PJ Allen wrote: »
    Chords, JAZ.
    Single-note plinking is what's "dull or boring."
    You have to do chords.

    By the way, my DDS unit has two simultaneous tones for now, which is polyphonic.

    Tried chords, but chords of square waves and sine waves didn't really worked that well. Sounds a bit awful. I don't know whether it's some sampling issues or other things. :)
  • localrogerlocalroger Posts: 3,452
    edited 2011-06-12 09:30
    Sine waves have no harmonics. Square waves have the maximum amount of all the odd harmonics, and so much energy at high frequencies that the electronics mangle them. An easy alternative to try would be a triangle wave; like the square wave it has only odd harmonics but they fall off a lot faster at higher orders.

    Musical instruments tend to have even as well as odd harmonics. This is emulated in synthesizers by adding up sine waves of the appropriate fundamental and harmonic frequencies at properly falling-off amplitude to create a composite waveform.

    Musical instruments also have a characteristic pattern by which the total sound level intensifies and falls off, called ADSR for Attack (quickly building to a high amplitude), Decay (quickly falling to an intermediate amplitude), Sustain, and Release (time to fall from sustain level back to zero). Applying ADSR to a sine wave will get you a pretty decent imitation of a flute.
  • John A. ZoidbergJohn A. Zoidberg Posts: 514
    edited 2011-06-12 09:34
    localroger wrote: »
    Sine waves have no harmonics. Square waves have the maximum amount of all the odd harmonics, and so much energy at high frequencies that the electronics mangle them. An easy alternative to try would be a triangle wave; like the square wave it has only odd harmonics but they fall off a lot faster at higher orders.

    Musical instruments tend to have even as well as odd harmonics. This is emulated in synthesizers by adding up sine waves of the appropriate fundamental and harmonic frequencies at properly falling-off amplitude to create a composite waveform.

    Musical instruments also have a characteristic pattern by which the total sound level intensifies and falls off, called ADSR for Attack (quickly building to a high amplitude), Decay (quickly falling to an intermediate amplitude), Sustain, and Release (time to fall from sustain level back to zero). Applying ADSR to a sine wave will get you a pretty decent imitation of a flute.

    Thanks, I'll try to put the ADSR inside, to simulate a music-box chime effect. It's not easy, but my dsPIC could handle all that okay.

    Also, will be trying the triangle wave. Need to write up a look-up wavetable on the triangle too.

    I'm still wondering whether IFFT and some filtering will actually make them sound better or not. However, I haven't tried a convolution/filtering algorithm inside before on a microcontroller. Maybe I will test it in Matlab first.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-12 09:39
    One easy way to get the music box effect is to use two sine waves, very close in frequency. Start them out in phase, and stop them when their phases cancel. The closer in frequency the two sines are, the longer the decay but the less pronounced the attack. This method has even been used with the BASIC Stamp, which can produce biphonic sound.

    In addition, by setting the amplitude of one sine wave higher than the other and separating their frequencies more widely, you can get a vibrato effect.

    Also, take a look at the [url=http://forums.parallax.com/showthread.php?131306[/url]Karplus-Strong thread[/url], which shows how to get a guitar strumming effect.

    -Phil
  • John A. ZoidbergJohn A. Zoidberg Posts: 514
    edited 2011-06-12 09:42
    One easy way to get the music box effect is to use two sine waves, very close in frequency. Start them out in phase, and stop them when their phases cancel. The closer in frequency the two sines are, the longer the decay but the less pronounced the attack. This method has even been used with the BASIC Stamp, which can produce biphonic sound.

    -Phil

    Clever idea here. Will try that as well. Would that work on square waves too? :)

    edit : Phil - yeah, saw your latest edited post. I'm also looking on that too. :)
  • PliersPliers Posts: 280
    edited 2011-06-12 13:56
    Those are cool clocks. Thanks for the link.
  • bradharperbradharper Posts: 64
    edited 2011-06-12 17:04
    The Hydra audio driver (part of this archive) contains an elegant ADSR implementation that supports sine, square, sawtooth and triangle forms.
  • Mark_TMark_T Posts: 1,981
    edited 2011-06-12 18:27
    Don't know if you'd call it a waveform, but noise (white or pink or band limited) is useful. I think the magic search tag is 'LFSR noise generation'
  • jazzedjazzed Posts: 11,803
    edited 2011-06-12 18:57
    Saw tooth and triangular waves were also used in the old MOOG synthesizers. They produced a very hard edge sound.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-12 19:22
    You might also take a look at the audio code for the S2 object, which includes biphonic sine, square, triangle, and sawtooth waves. The object is part of the default S2 program, available here:

    -Phil
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2011-06-12 19:43
    A couple of days ago I came across this youtube video of SID emulation on the Propeller and thought it was pretty cool...

    http://www.youtube.com/watch?v=EJcbxrdErkY

    There's a thread about the project somewhere on the old forum. I'm not sure if search will find it or not, but google does.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-12 19:49
    SidCOG is alive and well in the current forum:

    -Phil
  • Ahle2Ahle2 Posts: 1,179
    edited 2011-06-16 12:18
    Like the real SID, SIDcog has got:
    - 3 Independent audio channels
    - 4 selectable waveforms on each channel (Triangle, Saw, Noise, Square)
    - Variable pulse width
    - Each channel has got an ADSR envelope
    - Ring modulation
    - Oscillator synchronisation
    - An "analog" 12db multi-mode filter (any combination of lp, bp, hp)
    - Selectable resonance amount
    - Selectable cutoff frequency
    (Did I say it uses only one cog for everything?!)

    The propeller is fast and has got little memory so doing waveforms on the fly is the way to go.
    Using samples for "easy to do waveforms" is unnecessary, eats memory and produces audiable aliasing.

    /Ahle2
  • Ahle2Ahle2 Posts: 1,179
    edited 2011-06-16 12:53
    Btw, the sound generated in the YouTube clip at the top is FM synthesis (at least my ear says so).
    The nearest thing on the propeller is the phase modulation synthesis object made by Ariba.
    I think a "chime like" sound should be possible to generate with that object.

    /Ahle2
  • John A. ZoidbergJohn A. Zoidberg Posts: 514
    edited 2011-06-17 20:42
    Ahle2 wrote: »
    Btw, the sound generated in the YouTube clip at the top is FM synthesis (at least my ear says so).
    The nearest thing on the propeller is the phase modulation synthesis object made by Ariba.
    I think a "chime like" sound should be possible to generate with that object.

    /Ahle2

    Thanks. I did guessed that too previously, but my ears aren't sharp enough, so I may need others to hear it for me. :)

    I'll try to write it in dsPIC later. Right now been flooded with research work in office, so may be writing routines when I'm free.
  • tonyp12tonyp12 Posts: 1,951
    edited 2011-06-18 09:11
    How about Gaussian waveform

    image009.gif
  • John A. ZoidbergJohn A. Zoidberg Posts: 514
    edited 2011-06-21 02:17
    I took a sample of the chime from the youtube of the Seiko clocks, and by using a primitive spectrum analyser (Audacity), I managed to find some interesting peaks and patterns inside.

    Then, from reconstruction, by adding all the major frequencies present in the data, and also discarding the rest of it, I got the sound reaching close to 70% of the original chime, but it sounds mellow instead of the sharp one.

    I will post details of the each frequencies and the power inside for that specific chime later. :)
Sign In or Register to comment.