replace delete in AudioThread.h with std::unique_ptr (#9651)
Is part of the unique_ptr modernization effort.
This commit is contained in:
+10
-13
@@ -4,6 +4,7 @@
|
|||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "sleep.h"
|
#include "sleep.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#ifdef HAS_I2S
|
#ifdef HAS_I2S
|
||||||
#include <AudioFileSourcePROGMEM.h>
|
#include <AudioFileSourcePROGMEM.h>
|
||||||
@@ -29,9 +30,9 @@ class AudioThread : public concurrency::OSThread
|
|||||||
io.digitalWrite(EXPANDS_AMP_EN, HIGH);
|
io.digitalWrite(EXPANDS_AMP_EN, HIGH);
|
||||||
#endif
|
#endif
|
||||||
setCPUFast(true);
|
setCPUFast(true);
|
||||||
rtttlFile = new AudioFileSourcePROGMEM(data, len);
|
rtttlFile = std::unique_ptr<AudioFileSourcePROGMEM>(new AudioFileSourcePROGMEM(data, len));
|
||||||
i2sRtttl = new AudioGeneratorRTTTL();
|
i2sRtttl = std::unique_ptr<AudioGeneratorRTTTL>(new AudioGeneratorRTTTL());
|
||||||
i2sRtttl->begin(rtttlFile, audioOut);
|
i2sRtttl->begin(rtttlFile.get(), audioOut.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also handles actually playing the RTTTL, needs to be called in loop
|
// Also handles actually playing the RTTTL, needs to be called in loop
|
||||||
@@ -47,12 +48,10 @@ class AudioThread : public concurrency::OSThread
|
|||||||
{
|
{
|
||||||
if (i2sRtttl != nullptr) {
|
if (i2sRtttl != nullptr) {
|
||||||
i2sRtttl->stop();
|
i2sRtttl->stop();
|
||||||
delete i2sRtttl;
|
|
||||||
i2sRtttl = nullptr;
|
i2sRtttl = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rtttlFile != nullptr) {
|
if (rtttlFile != nullptr) {
|
||||||
delete rtttlFile;
|
|
||||||
rtttlFile = nullptr;
|
rtttlFile = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,16 +65,14 @@ class AudioThread : public concurrency::OSThread
|
|||||||
{
|
{
|
||||||
if (i2sRtttl != nullptr) {
|
if (i2sRtttl != nullptr) {
|
||||||
i2sRtttl->stop();
|
i2sRtttl->stop();
|
||||||
delete i2sRtttl;
|
|
||||||
i2sRtttl = nullptr;
|
i2sRtttl = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef T_LORA_PAGER
|
#ifdef T_LORA_PAGER
|
||||||
io.digitalWrite(EXPANDS_AMP_EN, HIGH);
|
io.digitalWrite(EXPANDS_AMP_EN, HIGH);
|
||||||
#endif
|
#endif
|
||||||
ESP8266SAM *sam = new ESP8266SAM;
|
auto sam = std::unique_ptr<ESP8266SAM>(new ESP8266SAM);
|
||||||
sam->Say(audioOut, text);
|
sam->Say(audioOut.get(), text);
|
||||||
delete sam;
|
|
||||||
setCPUFast(false);
|
setCPUFast(false);
|
||||||
#ifdef T_LORA_PAGER
|
#ifdef T_LORA_PAGER
|
||||||
io.digitalWrite(EXPANDS_AMP_EN, LOW);
|
io.digitalWrite(EXPANDS_AMP_EN, LOW);
|
||||||
@@ -96,15 +93,15 @@ class AudioThread : public concurrency::OSThread
|
|||||||
private:
|
private:
|
||||||
void initOutput()
|
void initOutput()
|
||||||
{
|
{
|
||||||
audioOut = new AudioOutputI2S(1, AudioOutputI2S::EXTERNAL_I2S);
|
audioOut = std::unique_ptr<AudioOutputI2S>(new AudioOutputI2S(1, AudioOutputI2S::EXTERNAL_I2S));
|
||||||
audioOut->SetPinout(DAC_I2S_BCK, DAC_I2S_WS, DAC_I2S_DOUT, DAC_I2S_MCLK);
|
audioOut->SetPinout(DAC_I2S_BCK, DAC_I2S_WS, DAC_I2S_DOUT, DAC_I2S_MCLK);
|
||||||
audioOut->SetGain(0.2);
|
audioOut->SetGain(0.2);
|
||||||
};
|
};
|
||||||
|
|
||||||
AudioGeneratorRTTTL *i2sRtttl = nullptr;
|
std::unique_ptr<AudioGeneratorRTTTL> i2sRtttl = nullptr;
|
||||||
AudioOutputI2S *audioOut = nullptr;
|
std::unique_ptr<AudioOutputI2S> audioOut = nullptr;
|
||||||
|
|
||||||
AudioFileSourcePROGMEM *rtttlFile = nullptr;
|
std::unique_ptr<AudioFileSourcePROGMEM> rtttlFile = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user