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

Thread: Synthesizing sine wave and playing it like a wave sound

  1. #1

    Synthesizing sine wave and playing it like a wave sound

    Dear developers and enthusiasts,
    first of all thanks for this great Teensy device and fantastic audio library.
    I have a question:

    Short version:
    How can I create within Teensy a wave table of a sine wave of a given frequency (which will vary) that I can feed to AudioPlayMemory to play?

    Long version:
    I am doing a psychology experiment and I want Teensy to play a beep whenever somebody taps on an FSR.
    The tricky bit is that there is a set of different beeps I want the Teensy to play (different frequencies). Furthermore they need to be nicely faded in and out. They are pretty short (6615 samples at 44.1 kHz).
    So far I have synthesized them offline, used wav2sketch to create u-law encoded wave tables which I can feed directly to the play function of AudioPlayMemory.
    So far so good! The issue I run into is that I don't have enough memory for 20 or more sounds (only about 15 seem to fit).
    Now I'm playing with the idea of synthesizing the sounds online, writing them to the wave table and playing them whenever somebody taps on the FSR.
    Is that feasible? I was guessing it should be simple, but I can't seem to find where to start creating a sine signal in the u-law encoded format that AudioPlayMemory reads. Can anyone help me get started?

    Thanks!
    Floris

    p.s. I also thought of putting the wave files on an SD card, but I would ideally like to avoid the latency involved in accessing the SD card and reading the wave sound. I guess if there were a way to read the (short) wave files from the SD into memory, and then play them from memory, that could work too.

  2. #2
    Senior Member
    Join Date
    Apr 2014
    Location
    -
    Posts
    9,756
    Why is it needed to use a wavetable for a sine?
    The audiolibrary can generate any sine you want in realtime.

  3. #3
    Thanks Frank for your quick reply!
    The reason I want the wavetable is that I want to control with high precision the duration of the sound, and provide a nice linear fade in and out. And while it's playing, I need my script to be able to go on doing other things (among which, playing another sound in parallel).
    If the audio library can do all of that then I'm sold!

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,753
    I'd use AudioSynthWaveformSine and AudioEffectEnvelope classes. No lack of precision for either I'd say.

    (BTW just checked the Envelope temporal resolution is about 180Ás, 8 sample times)

Posting Permissions

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