Dynamic AudioInputAnalog/AudioAnalyzeFFT1024/AudioConnection instances

Status
Not open for further replies.

chris.nz

Well-known member
Is it possible to allocate new AudioInputAnalog/AudioAnalyzeFFT1024/AudioConnection instances then release them again once finished? I have a C++ class that renders a spectrum analyzer to an LED matrix using FastLED, but I only want to use that functionality a small part of the time, and release the memory otherwise.

If I have something like the following:

Code:
  // class fields
  AudioInputAnalog *adc1;
  AudioAnalyzeFFT1024 *fft;
  AudioConnection *patchCord1;

  // in the class constructor:
  AudioMemory(12);
  adc1 = new AudioInputAnalog(A4);
  fft = new AudioAnalyzeFFT1024();
  patchCord1 = new AudioConnection(*adc1, *fft);

  // in the class destructor:
  delete patchCord1;
  delete fft;
  delete adc1;

I get the following warnings:

Code:
src\effect\AudioNoise.cpp:23:10: warning: deleting object of polymorphic class type 'AudioAnalyzeFFT1024' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
delete fft;
^
src\effect\AudioNoise.cpp:24:10: warning: deleting object of polymorphic class type 'AudioInputAnalog' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
delete adc1;
^

It also makes my program unstable after I have created/destroyed the class a couple of times. Is there a solution, or do I need to keep these objects around for the entire time?
 
No, the connection objects must not be destroyed. Other objects hold pointers to them, and currently there's no way to make the rest of the system "forget" a connection.
 
Thanks for the very quick reply and for confirming my suspicions. Sounds like it's time for me to do a bit of refactoring of my code to take that into account...
 
Status
Not open for further replies.
Back
Top