Improved heap memory management in M17 modulator class
This commit is contained in:
parent
a1888ae19e
commit
d2e0b7d940
|
|
@ -28,6 +28,7 @@
|
||||||
#include <interfaces/audio_stream.h>
|
#include <interfaces/audio_stream.h>
|
||||||
#include <M17/M17Constants.h>
|
#include <M17/M17Constants.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <dsp.h>
|
#include <dsp.h>
|
||||||
|
|
||||||
|
|
@ -100,11 +101,11 @@ private:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::array< int16_t, M17_FRAME_SYMBOLS > symbols;
|
std::array< int16_t, M17_FRAME_SYMBOLS > symbols;
|
||||||
stream_sample_t *baseband_buffer; ///< Buffer for baseband audio handling.
|
std::unique_ptr< int16_t[] > baseband_buffer; ///< Buffer for baseband audio handling.
|
||||||
stream_sample_t *idleBuffer; ///< Half baseband buffer, free for processing.
|
stream_sample_t *idleBuffer; ///< Half baseband buffer, free for processing.
|
||||||
streamId outStream; ///< Baseband output stream ID.
|
streamId outStream; ///< Baseband output stream ID.
|
||||||
bool txRunning; ///< Transmission running.
|
bool txRunning; ///< Transmission running.
|
||||||
bool stopTx; ///< Stop transmission request.
|
bool stopTx; ///< Stop transmission request.
|
||||||
|
|
||||||
#if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0)
|
#if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0)
|
||||||
filter_state_t pwmFilterState;
|
filter_state_t pwmFilterState;
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,7 @@ M17Modulator::M17Modulator()
|
||||||
|
|
||||||
M17Modulator::~M17Modulator()
|
M17Modulator::~M17Modulator()
|
||||||
{
|
{
|
||||||
// TODO
|
terminate();
|
||||||
// terminate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void M17Modulator::init()
|
void M17Modulator::init()
|
||||||
|
|
@ -52,8 +51,8 @@ void M17Modulator::init()
|
||||||
* placement new.
|
* placement new.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
baseband_buffer = new int16_t[2 * M17_FRAME_SAMPLES];
|
baseband_buffer = std::make_unique< int16_t[] >(2 * M17_FRAME_SAMPLES);
|
||||||
idleBuffer = baseband_buffer;
|
idleBuffer = baseband_buffer.get();
|
||||||
txRunning = false;
|
txRunning = false;
|
||||||
#if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0)
|
#if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0)
|
||||||
dsp_resetFilterState(&pwmFilterState);
|
dsp_resetFilterState(&pwmFilterState);
|
||||||
|
|
@ -62,8 +61,15 @@ void M17Modulator::init()
|
||||||
|
|
||||||
void M17Modulator::terminate()
|
void M17Modulator::terminate()
|
||||||
{
|
{
|
||||||
|
// Terminate an ongoing stream, if present
|
||||||
|
if(txRunning)
|
||||||
|
{
|
||||||
|
outputStream_terminate(outStream);
|
||||||
|
txRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Deallocate memory.
|
// Deallocate memory.
|
||||||
delete[] baseband_buffer;
|
baseband_buffer.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void M17Modulator::send(const std::array< uint8_t, 2 >& sync,
|
void M17Modulator::send(const std::array< uint8_t, 2 >& sync,
|
||||||
|
|
@ -119,7 +125,7 @@ void M17Modulator::emitBaseband()
|
||||||
// First run, start transmission
|
// First run, start transmission
|
||||||
outStream = outputStream_start(SINK_RTX,
|
outStream = outputStream_start(SINK_RTX,
|
||||||
PRIO_TX,
|
PRIO_TX,
|
||||||
baseband_buffer,
|
baseband_buffer.get(),
|
||||||
2*M17_FRAME_SAMPLES,
|
2*M17_FRAME_SAMPLES,
|
||||||
BUF_CIRC_DOUBLE,
|
BUF_CIRC_DOUBLE,
|
||||||
M17_TX_SAMPLE_RATE);
|
M17_TX_SAMPLE_RATE);
|
||||||
|
|
@ -140,7 +146,7 @@ void M17Modulator::emitBaseband()
|
||||||
outputStream_sync(outStream, false);
|
outputStream_sync(outStream, false);
|
||||||
stopTx = false;
|
stopTx = false;
|
||||||
txRunning = false;
|
txRunning = false;
|
||||||
idleBuffer = baseband_buffer;
|
idleBuffer = baseband_buffer.get();
|
||||||
#if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0)
|
#if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0)
|
||||||
dsp_resetFilterState(&pwmFilterState);
|
dsp_resetFilterState(&pwmFilterState);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue