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

Thread: Feature Request/Suggestion: flush/release audio blocks in FFT

Hybrid View

  1. #1
    Junior Member
    Join Date
    May 2022
    Location
    WA state
    Posts
    1

    Feature Request/Suggestion: flush/release audio blocks in FFT

    I've been using the audio library for some interesting non-audio things. In one of the processes I've written, I've had a need to flush an FFT of all data and start putting new and different data in it. I'd first tried to dynamically delete and allocate new instances when I needed to restart the FFT. The compiler gave be a pretty big warning about this, something about the destructor being or not being a "virtual method", and indeed there were issues. This caused a memory leak of available audio blocks, eventually exhausting my supply of them and hanging the program.

    I modified the FFT1024 code on my machine to include the method shown below. With this, I was able to "flush" the audio blocks out before I deleted the instance and (appear to) not have a memory leak. (Still trying to fully verify this.) I eventually found that it seems that this "flush" approach worked for my need to reset the state of the FFT and purge all previous data, and thus moved to not dynamically allocating FFT instances.

    Code:
    	void flush() {
    		for (uint8_t i = 0; i < state; i++) {
    			release(blocklist[i]);
    		}
    		state = 0;
    	}
    This seems to work, but I'm not fully sure of it. Review by someone who has a better grasp of this code would be appreciated. If this does work, I suggest adding it as a method to both FFT libraries, and call it in the class destructor to ease this memory leak issue for others who may be dynamically creating these.

    And to get cute with extra compact code...
    Code:
    	void flush() {
    		while (state) release(blocklist[--state]);
    	}
    Last edited by trevormarvinlab; 05-20-2022 at 09:41 PM.

  2. #2
    Senior Member
    Join Date
    Apr 2021
    Location
    Cambridgeshire, UK
    Posts
    388
    You might want to give my Dynamic Audio Library a try out: the updated audio objects are on github, and you also need AudioStream.cpp and .h from cores, which can be found here. I started a thread on the updated library, which is at https://forum.pjrc.com/threads/66840...ffort-going-on - if you encounter any issues, please post there or on github. I must confess I haven't tested the FFT changes...

    The audio library as-is is not designed for use with new and delete, just static allocation at compile time, hence your problems. Paul has said he'd like to roll my changes into a mainstream Teensyduino update at some point, but as there seem to be many more urgent changes in the pipeline I'm not expecting it any time soon. That's fine, gives more time to find gremlins.

    If it's not "obvious" how to use it, do ask - ideally on the "dynamic updates" thread as that's more likely to serve as a general resource for future users than your more specific FFT query.

Posting Permissions

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