kopia lustrzana https://github.com/OpenRTX/OpenRTX
Improved heap memory management in M17 demodulator class
rodzic
8b5b6ed571
commit
a1888ae19e
|
@ -27,17 +27,15 @@
|
|||
#error This header is C++ only!
|
||||
#endif
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <interfaces/audio_stream.h>
|
||||
#include <hwconfig.h>
|
||||
#include <memory>
|
||||
#include <array>
|
||||
#include <dsp.h>
|
||||
#include <deque>
|
||||
#include <stdio.h>
|
||||
#include <cmath>
|
||||
#include <interfaces/audio_stream.h>
|
||||
#include <M17/M17Datatypes.h>
|
||||
#include <M17/M17Constants.h>
|
||||
#include <cmath>
|
||||
|
||||
namespace M17
|
||||
{
|
||||
|
@ -146,18 +144,18 @@ private:
|
|||
/*
|
||||
* Buffers
|
||||
*/
|
||||
streamId basebandId; ///< Id of the baseband input stream.
|
||||
int16_t *baseband_buffer; ///< Buffer for baseband audio handling.
|
||||
dataBlock_t baseband; ///< Half buffer, free to be processed.
|
||||
uint16_t frame_index; ///< Index for filling the raw frame.
|
||||
frame_t *demodFrame; ///< Frame being demodulated.
|
||||
frame_t *readyFrame; ///< Fully demodulated frame to be returned.
|
||||
bool syncDetected; ///< A syncword was detected.
|
||||
bool locked; ///< A syncword was correctly demodulated.
|
||||
bool newFrame; ///< A new frame has been fully decoded.
|
||||
int16_t basebandBridge[M17_BRIDGE_SIZE] = { 0 }; ///< Bridge buffer
|
||||
int16_t phase; ///< Phase of the signal w.r.t. sampling
|
||||
bool invPhase; ///< Invert signal phase
|
||||
std::unique_ptr< int16_t[] > baseband_buffer; ///< Buffer for baseband audio handling.
|
||||
streamId basebandId; ///< Id of the baseband input stream.
|
||||
dataBlock_t baseband; ///< Data block with samples to be processed.
|
||||
uint16_t frame_index; ///< Index for filling the raw frame.
|
||||
std::unique_ptr<frame_t > demodFrame; ///< Frame being demodulated.
|
||||
std::unique_ptr<frame_t > readyFrame; ///< Fully demodulated frame to be returned.
|
||||
bool syncDetected; ///< A syncword was detected.
|
||||
bool locked; ///< A syncword was correctly demodulated.
|
||||
bool newFrame; ///< A new frame has been fully decoded.
|
||||
int16_t basebandBridge[M17_BRIDGE_SIZE] = { 0 }; ///< Bridge buffer
|
||||
int16_t phase; ///< Phase of the signal w.r.t. sampling
|
||||
bool invPhase; ///< Invert signal phase
|
||||
|
||||
/*
|
||||
* State variables
|
||||
|
|
|
@ -155,8 +155,7 @@ M17Demodulator::M17Demodulator()
|
|||
|
||||
M17Demodulator::~M17Demodulator()
|
||||
{
|
||||
// TODO
|
||||
// terminate();
|
||||
terminate();
|
||||
}
|
||||
|
||||
void M17Demodulator::init()
|
||||
|
@ -167,10 +166,10 @@ void M17Demodulator::init()
|
|||
* placement new.
|
||||
*/
|
||||
|
||||
baseband_buffer = new int16_t[2 * M17_SAMPLE_BUF_SIZE];
|
||||
baseband_buffer = std::make_unique< int16_t[] >(2 * M17_SAMPLE_BUF_SIZE);
|
||||
demodFrame = std::make_unique< frame_t >();
|
||||
readyFrame = std::make_unique< frame_t >();
|
||||
baseband = { nullptr, 0 };
|
||||
demodFrame = new frame_t;
|
||||
readyFrame = new frame_t;
|
||||
frame_index = 0;
|
||||
phase = 0;
|
||||
syncDetected = false;
|
||||
|
@ -193,9 +192,9 @@ void M17Demodulator::terminate()
|
|||
inputStream_stop(basebandId);
|
||||
|
||||
// Delete the buffers and deallocate memory.
|
||||
delete[] baseband_buffer;
|
||||
delete demodFrame;
|
||||
delete readyFrame;
|
||||
baseband_buffer.reset();
|
||||
demodFrame.reset();
|
||||
readyFrame.reset();
|
||||
|
||||
#ifdef ENABLE_DEMOD_LOG
|
||||
logRunning = false;
|
||||
|
@ -205,7 +204,7 @@ void M17Demodulator::terminate()
|
|||
void M17Demodulator::startBasebandSampling()
|
||||
{
|
||||
basebandId = inputStream_start(SOURCE_RTX, PRIO_RX,
|
||||
baseband_buffer,
|
||||
baseband_buffer.get(),
|
||||
2 * M17_SAMPLE_BUF_SIZE,
|
||||
BUF_CIRC_DOUBLE,
|
||||
M17_RX_SAMPLE_RATE);
|
||||
|
@ -555,7 +554,7 @@ bool M17Demodulator::update()
|
|||
// If the frame buffer is full switch demod and ready frame
|
||||
if (frame_index == M17_FRAME_SYMBOLS)
|
||||
{
|
||||
std::swap(demodFrame, readyFrame);
|
||||
demodFrame.swap(readyFrame);
|
||||
frame_index = 0;
|
||||
newFrame = true;
|
||||
}
|
||||
|
|
|
@ -87,5 +87,7 @@ dataBlock_t inputStream_getData(streamId id)
|
|||
void inputStream_stop(streamId id)
|
||||
{
|
||||
(void) id;
|
||||
if(baseband_file == NULL) return;
|
||||
fclose(baseband_file);
|
||||
baseband_file = NULL;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue