Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: pure tone generation and output to speaker

  1. #1
    Junior Member
    Join Date
    Jan 2021
    Posts
    3

    pure tone generation and output to speaker

    Hey folks,

    my goal is to use a Teensy 4.0 to generate simultanious one to three (maybe more if achievable) pure tones and output these to an speaker.
    There should be three switches to turning the tones on/off and potentiometers to control the tone height.

    Maybe later i will add a display via SPI to show the the states and (k)Hz for each tone.

    But ... first of all. Is the Teensy capable to generate three (or more) tones and output these combined to one speaker?

    Thank you in advance for your time!

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,234
    Yes, Teensy 4.0 can certainly generate 3 sine waves and mix them in software. You would use the audio library with 3 instance of the waveform synth, and a mixer to combine them.

    Getting the signal output to a speaker requires additional hardware. The best way would use the audio shield and an amplifier.

    Teensy 4.0 also has an output called MQS (medium quality sound) which creates sequences of pulses. You can buffer those with transistors and drive a speaker, or perhaps drive a very small speaker if done carefully with an extra resistor and capacitor in series. MQS sounds pretty good for casual listening, but because it's made with digital output pulses, it's a compromise in quality.

    The audio shield of other audio DAC gives the best output signal.

  3. #3
    Junior Member
    Join Date
    Jan 2021
    Posts
    3
    Hey Paul,

    thank you for your suggestions/explanations.

    Perhaps I should describe in more detail what I have in mind.

    I want to stick a mirror on the speaker, which will deflect the light beam of a laser pointer onto a wall (or the ceiling, depending on how you point the laser).

    Primarily, I want my children to play around with it a bit and maybe they will want to learn a bit more about sound waves, light and/or electronics.
    But I also want to finally give the Teensy, which has been living on my desk for far too long, a task.
    Based on the different frequencies or maybe even the voice (via mic) you can draw some nice figures.

    I think that even if the quality of the MQS is sufficient, I will probably go for the Audio Shield for the sake of simplicity. (Mic/SDCard)

    In another thread, you recommended the LM4871 to a user. This is already available on a small board with the corresponding caps and resistors.
    Unfortunately I have little knowledge of the audio world ... but would this amp be enough to drive a 4ohm/20w speaker.
    What would happen if i used an 8ohm speaker?

    with every new buzzword comes a thousand new questions

  4. #4
    Hi Hirnwunde,
    sounds like a fun project!

    Info on the LM4871 can be found in the datasheet: https://www.ti.com/lit/ds/symlink/lm4871.pdf

    As you can see, this chip can drive an 8ohm or 4ohm speaker but only delivers 3W maximum. I'm not sure if this will move your speaker enough for the laser pattern (I guess this depends on the angle and distance?)

    To find how how much power you will actually need, you can prototype with a regular stereo amplifier or receiver - feed your teensy audio shield output into the stereo amp and connector speaker and see how loud you have to turn the volume knob up to get the patterns you need and then find an appropriate standalone audio amplifier chip that can deliver that amount of power. Have fun!

  5. #5
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,748
    Quote Originally Posted by Hirnwunde View Post
    Perhaps I should describe in more detail what I have in mind.

    I want to stick a mirror on the speaker, which will deflect the light beam of a laser pointer onto a wall (or the ceiling, depending on how you point the laser).
    I'd worry about the MQS (which has ultrasonic components) perhaps generating visible artifacts for this, but its
    worth trying
    I think that even if the quality of the MQS is sufficient, I will probably go for the Audio Shield for the sake of simplicity. (Mic/SDCard)

    In another thread, you recommended the LM4871 to a user. This is already available on a small board with the corresponding caps and resistors.
    Unfortunately I have little knowledge of the audio world ... but would this amp be enough to drive a 4ohm/20w speaker.
    What would happen if i used an 8ohm speaker?

    with every new buzzword comes a thousand new questions
    20W is a lot, room-fillingly loud, for a continuous tone. Music is very peaky so a 20W system might actually be running at
    an average less than 1W, with the headroom only needed for the peaks and transients.

    I suspect you are wanting a large excursion of the speaker to provide large mirror deflection, which is more a case of
    driving the speaker at/near its resonant frequency, and at low frequency anyway (displacement goes down as frequency
    goes up with sound).

    Speakers vary in their sensitivity too - choosing a sensitive speaker will give more displacement for a given power, all
    else being equal.

  6. #6
    Member
    Join Date
    Dec 2021
    Location
    No. 1s Business, USA
    Posts
    62
    Hi! I'm a laser artist, here to learn about the Teensy audio library in preparation towards building my own midi laser control desk, using Teensy. I played around with HeNe lasers and small mirrors on speakers back in ~1978. You can simply connect the Teensy audio output to the 'aux in' of any amp.
    But be very careful with laser beams around kids. Lasers can blind, if shown directly into eyes. I suggest putting the speakers inside a box with a hole to limit the beam path and make sure that everyone is positioned on the opposite side of the box.
    Having said that, you're onto a fun project, once you're to the point of generating waveforms with the Teensy. At that point, I suggest that you kick up th fun factor with some real X/Y galvanometers, like these inexpensive ones.

    https://www.ebay.com/itm/26237534700...75.c101224.m-1
    There are also RGB laser diode modules, which only require 3 voltage levels to produce full color imagery.
    Hope this helps to kick you off to a great fun project for 2022.��

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •