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

Thread: Why can't I intstantiate a new AudioEffectWaveshaper

  1. #1
    Junior Member
    Join Date
    Mar 2021
    Posts
    14

    Why can't I intstantiate a new AudioEffectWaveshaper

    I'm trying to code an effect chain (programmable by user) so I need to be able to instantiate different effects and connections. For now I've been able to code a delay and a reverb effect, but when I got to add a WaveShaper I'm running into a runtime error.

    The thing is, if I use it like as follows it works good:

    Code:
    AudioEffectWaveshaper waveshaper;
    EffectWaveshaper::EffectWaveshaper() {
        // ... 
    
        this->effectLeft = &waveshaper;
    
        // ...
    }

    But if I instntiate it using new, the program breaks:
    Code:
    EffectWaveshaper::EffectWaveshaper() {
        // ... 
    
        this->effectLeft = new AudioEffectWaveshaper();
    
        // ...
    }

    Any ideas?

    Thanks

  2. #2
    Senior Member h4yn0nnym0u5e's Avatar
    Join Date
    Apr 2021
    Location
    Cambridgeshire, UK
    Posts
    901
    Yup. The constructor for the object is badly written, and fails to initialise the waveshape pointer to a NULL value. If the object is statically declared then it's guaranteed to be initialised to zero, but using new just allocates a chunk of heap, possibly full of junk, so on the first updated the junk pointer is used with less-than-hilarious consequences.

    You could edit the class definition in AudioEffectWaveshaper.h thus:
    Code:
      public:
        AudioEffectWaveshaper(void): AudioStream(1, inputQueueArray), waveshape(nullptr) {}
        ~AudioEffectWaveshaper();
    Note that the audio library as shipped with current Teensyduino does not support deleting any audio object.

  3. #3
    Junior Member
    Join Date
    Mar 2021
    Posts
    14
    Ok! Thank you for your response, I was going crazy looking at my code ��

    Why Teensy doesn't support deleting audio objects? Is it just because its not coded or is there something else going on?

  4. #4
    Senior Member h4yn0nnym0u5e's Avatar
    Join Date
    Apr 2021
    Location
    Cambridgeshire, UK
    Posts
    901
    It wasn’t designed in from the start, for some reason. I’ve had a go at remedying this, see https://forum.pjrc.com/threads/66840...ffort-going-on. If you give it a try, please do report on that thread how it works out for you!

  5. #5
    Junior Member
    Join Date
    Mar 2021
    Posts
    14
    I would like to help with that, but I've tried before to understand the Audio library, but I don't even know where to start.
    The truth is that I've been using it a lot, and someday I would like to deep into it to understand it more. If you have any link where I can read and help introduce me into it, I would really appreciate it, and maybe some day I can contribute

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    28,485
    Indeed, the original design goal was for all instances to be static. The main issue with deleting instances is the input queue can "own" audio blocks at the end of an update, which then get used on the next update. Hardware input and output instances also have internal ownership of blocks. So do some effects, like delay and FFT.

    I must admit, several times I've merged people's contributions to the audio library without as much review as I really should have done. Waveshaper is one of those cases. More recently, I've been waiting to merge most contributions, because I just don't have time to properly review while PJRC is swamped with a lot of urgent business matters (which has been pretty much non-stop since the pandemic followed by component shortages).

  7. #7
    Senior Member h4yn0nnym0u5e's Avatar
    Join Date
    Apr 2021
    Location
    Cambridgeshire, UK
    Posts
    901
    The best introduction is probably at https://www.pjrc.com/teensy/td_libs_Audio.html, but then it’s mostly a case of looking at the existing objects, figuring out how a simple one works, and having a go at modifying it or whatever.

    My dynamic mods have been stable for a while: I think a few people have made use of them, and I’ve not got a lot of bug reports so hopefully they’re pretty much OK. I tried to make sure all the “internal ownership” issues got addressed, as mentioned by Paul, though I’d never assert it’s bug-free! And of course the waveshaper bug only shows up when dynamically created, which hasn’t historically been a thing, so it’s easy to miss.

    The beauty of the open source model is that we can fix these things … and the frustration is that it can then take a while for the fixes to get merged … because of urgent business matters, and making a living so Paul can eat … who knew?!

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    28,485
    Quote Originally Posted by h4yn0nnym0u5e View Post
    You could edit the class definition in AudioEffectWaveshaper.h thus:
    I've committed this on github.

    https://github.com/PaulStoffregen/Au...d3c4dd2cb62c67

Posting Permissions

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