PaulStoffregen / cores

Teensy Core Libraries for Arduino
507 stars 372 forks source link

AudioStream: Add destructor. Enables dynamic creation and destruction. #755

Open chipaudette opened 1 week ago

chipaudette commented 1 week ago

There's been great work on dynamic creation and destruction of AudioConnection instances. But, one has not been able to dynamically destroy AudioStream instances. This pull request seeks to remove this limitation.

In my view, the primary issue preventing dynamic destruction of AudioStream instancs is that the user had no way of removing an AudioStream instance from the AudioStream update list. You could go ahead and delete your instance, but the update list would still try to use that stale pointer. That would cause the system to hang.

This pull request adds a destructor to AudioStream. Now, when an AudioStream instance is destroyed, it removes the instance from the AudioStream update list.

The user must still remember to close out all of the AudioConnections that use the destroyed AudioStream instance, but that's at least possible for the user to do. Without AudioStream having a destructor, there is no way for the user to remove the instance to the update list.

This pull request includes both Teensy3 and Teensy4. It has been tested on a Teensy 4.1 and a Teensy 3.6.

A-Dunstan commented 1 week ago

I think the list removal has a couple of errors:

chipaudette commented 1 week ago

I believe that I have now addressed the last two bullets ("first_update" and "break"). All of the latest edits have been tested on Teensy 4.1 and Teensy 3.6.