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

Thread: Tone function - changing the target tone

  1. #1
    Junior Member
    Join Date
    Feb 2021
    Posts
    11

    Tone function - changing the target tone

    Hello,

    I have the tone function working very well in my Teensy code - thank you for making such a useful object!

    Now I want to be able to adjust what tone I am detecting using the tone function and it seems like I can only set the frequency that each tone object looks at in the setup function. Is it possible to re-assign the frequency that a particular tone object is detecting?

    I want the user to have control over what tone is being examined and I would like to give them lots of flexibility which is my reason for not just having a dozen tone's that are observed separately as in the dial-tone examples. Pitch detection like in the note-freq function would not be a good fit because I am not trying to get the fundamental frequency of a sound but rather zero in on the loudness of specific frequencies.

    Thank you for any help you can give me.
    Sasha

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,345
    Have you tried calling the frequecy() method after setup()?

  3. #3
    Junior Member
    Join Date
    Feb 2021
    Posts
    11
    Hi MarkT,

    Do you mean notefreq() which is part of the Audio.h library? If so, this is the description, "Detect with fairly good accuracy the fundamental frequency fo of musical notes, such as electric guitar and bass." That works well if I am looking for the fundamental note but I am trying to analyze the loudness of different partials and I want the user in this interactive work to be able to determine what fequencies to look at.

    Is there another frequency() method that I don't know about? I have done some online searching without finding anything but it is entirely possible that I am missing something.

    Sasha

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,206
    The tone function (specifically audio library AudioAnalyzeToneDetect class) can indeed be reconfigured while your program runs. But it takes time to detect detect a frequency. The default is 10 cycles. The audio library also updates every 2.9 ms (128 samples at 44.1 kHz). So when you reconfigure the detection frequency, your change begins taking effect between 0 (immediately) to 2.9 ms later. Then the Goertzel algorithm it uses takes time to detect.

    You can also try using FFT, but for this sort of use FFT tends to be too imprecise unless the frequency bins happen to line up perfectly, which is usually only the case in analyzing certain very synthetic waveforms.

  5. #5
    Junior Member
    Join Date
    Feb 2021
    Posts
    11
    Hi Paul,

    Thank you for your response. It made me try my code again and I was able to locate another error that was actually causing the change to not work. I really appreciate your help. I am sure you get tired of dumb questions but your answers are really helpful.

    Sasha

Posting Permissions

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