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

Thread: Bypass equivalence

  1. #1
    Junior Member
    Join Date
    Jul 2018
    Posts
    10

    Bypass equivalence

    Hi dear Teensy friends,

    When building audio components with the Teensy Audio Library, what would be the equivalent for bypassing some modules? for example, in this configuration, what would be the best way to bypass the reverb or the "noteFreq" module to reduce CPU usage? As far as I see, the only way I can see now is to "disconnect" the modules, but there is no "bypass" or "enable" property or method in the objects.

    For example I want to draw two buttons in the touch display and by pressing them enable or disable the reverb or the noteFreq. What would be the best way to do it via software?

    Here the config, thanks!

    Click image for larger version. 

Name:	Screen Shot 2019-12-09 at 10.02.58 AM.png 
Views:	5 
Size:	59.6 KB 
ID:	18391

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,213
    Add a mixer to bypass each effect.
    Click image for larger version. 

Name:	mixer_bypass_58647.gif 
Views:	2 
Size:	5.1 KB 
ID:	18393
    Set the gain of one input to one and the other input to zero.
    Naming each one "switch", as I've done, instead of "mixer" will help to keep track of which are used as switches and which really are mixers.

    Pete

  3. #3
    "what would be the best way to bypass the reverb or the "noteFreq" module to reduce CPU usage? "

    Does bypass using a mixer reduce CPU usage?

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,213
    Ah. Good question. Not the way I've shown it.
    I think another mixer between i2s1 and reverb1, which is turned on or off as well as switch1, should do the trick. The mixer won't output anything and reverb will use practically no cpu.
    Click image for larger version. 

Name:	mixer_bypass_58647_1.gif 
Views:	2 
Size:	6.9 KB 
ID:	18395

    Pete

  5. #5
    Junior Member
    Join Date
    Jul 2018
    Posts
    10
    Quote Originally Posted by tele_player View Post
    "what would be the best way to bypass the reverb or the "noteFreq" module to reduce CPU usage? "

    Does bypass using a mixer reduce CPU usage?
    I think this is not a good approach as the reverb or any module will still processing audio and consuming memory and CPU usage. As far as my research goes, all audio modules extend the AudioStream Class, located here.

    A method that I can see that free some memory is AudioConnection::disconnect and that one could be an option.

    Maybe AudioStream::update_stop?

    I just want to know what would be the "Correct" way to disable and enable the modules dinamically to improve memory and CPU usage.

    Thanks.

  6. #6
    I haven’t looked at audio library source code, but I would be surprised if turning down a mixer before a reverb has any effect on the reverbs cpu utilization .

  7. #7
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,213
    Ah. Good question. Not the way I've shown it.
    I think another mixer between i2s1 and reverb1, which is turned on or off at the same time as switch1, should do the trick. The mixer won't output anything and reverb will use practically no cpu.
    Click image for larger version. 

Name:	mixer_bypass_58647_1.gif 
Views:	2 
Size:	6.9 KB 
ID:	18395

    Pete

  8. #8
    I don't expect that anything you can do with the level controls on a mixer object will affect CPU utilization of anything before or after. Maybe I'll test it to satisfy my curiosity.

  9. #9
    Junior Member
    Join Date
    Jul 2018
    Posts
    10
    Quote Originally Posted by tele_player View Post
    I don't expect that anything you can do with the level controls on a mixer object will affect CPU utilization of anything before or after. Maybe I'll test it to satisfy my curiosity.
    I think this thread gives an interesting approach, as I supposed, using disconnect in the audio connection, please check it out.

    Best regards,

  10. #10
    Senior Member
    Join Date
    Nov 2017
    Location
    Belgium
    Posts
    211
    @daspuru
    In order to have an audio object with an input to stop processing you need to stop the audiostream going to it's input.
    There are 2 ways to achieve this:

    use AudioConnection::disconnect

    or

    insert an AudioAmplifier object before the one you want to disable and set it's gain to zero. This will effectively stop the AudioAmplifier to output any data.

  11. #11
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,213
    I've realized that what is needed using this method is an amplifier and a mixer - not two mixers. A mixer always outputs an audio buffer even when all inputs are zero gain.
    Click image for larger version. 

Name:	mixer_bypass_58647_2.gif 
Views:	2 
Size:	6.1 KB 
ID:	18398
    When the amplifier is set to zero gain, it will not output an audio buffer, so the effect which follows won't do anything.

    The connect/disconnect in the link given by @daspuru looks good too, especially since it wouldn't require any mixers/amps to be added which would simplify the design.

    Pete

  12. #12
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,288
    Quote Originally Posted by tele_player View Post
    I don't expect that anything you can do with the level controls on a mixer object will affect CPU utilization of anything before or after.
    That is a wrong assumption. The mixer and amp handle zero gain as a special case. They stop sending data, which does affect the CPU usage of most (but not all) objects connected to their outputs.

    All objects in the audio library handle no data at their input as if it were silence. For many of them, the result is no CPU usage.

    I believe the reverb (not freeverb) may currently have a bug where it immediately stops all processing when the input has no data. Obviously it should not do that that if it has previously had sound which should still create reverberation for quite some time after the input goes silent. I'm pretty sure freeverb handles this correctly.

  13. #13
    I realized that after reading #10, then looking at the code.

    Well, AudioAmplifier transmits nothing if mult==0.
    But, AudioMixer4 will call transmit() if there is input on any channel, regardless of multiplier.
    Last edited by tele_player; 12-09-2019 at 10:56 PM.

  14. #14
    Senior Member
    Join Date
    Nov 2017
    Location
    Belgium
    Posts
    211
    Quote Originally Posted by PaulStoffregen View Post
    The mixer and amp handle zero gain as a special case. They stop sending data, which does affect the CPU usage of most (but not all) objects connected to their outputs.
    Are you sure about that?
    I was under impression(looking at the code but i might be wrong) that unity gain is handled as a special case in both the mixer and the amp, but that zero gain is only handled as a special case by the amp.

  15. #15
    Junior Member
    Join Date
    Jul 2018
    Posts
    10
    Thanks all!

    Then I think I will code my control logic in a class that will encapsulate connections and disconnections of object instances of the audio library and that should solve the needs of freeing/allocating resources while activating or deactivating objects from the audio library. I just wanted to have a clear perspective before going into the wrong path with this delicate part of this particular audio application.

    Best regards!

Posting Permissions

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