Skip to content

Commit adc0743

Browse files
committed
Update code
code fixes
1 parent e4da944 commit adc0743

File tree

11 files changed

+368
-48
lines changed

11 files changed

+368
-48
lines changed

Src/Buffer/CAudioBuffer.h

+16-37
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#define noninterleavedAudioBufferOffset(ptr, chl, smpl, fs) *(ptr + (chl + fs) + smpl)
2424

2525

26-
//template <class T> class CSimpleAudioBuffer : public std::vector<T>, public CErrorHandler
2726
template <class T> class CSimpleAudioBuffer : public CErrorHandler
2827
{
2928
unsigned int m_numChannels; // number of channels to buffer
@@ -56,6 +55,18 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
5655
m_pBuffer = nullptr;
5756
}
5857

58+
~CSimpleAudioBuffer()
59+
{
60+
m_bInterleaved = false;
61+
m_blockSize = 0;
62+
m_arraySize = 0;
63+
64+
m_readIdx = 0;
65+
m_writeIdx = 0;
66+
67+
free();
68+
}
69+
5970
void setNumChannels(unsigned int numChls)
6071
{
6172
if (m_bAllocated)
@@ -126,15 +137,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
126137

127138
m_arraySize = (m_blockSize * m_numChannels); // arraySize = total numner of samples in the buffer
128139

129-
// this->resize(m_arraySize);
130-
131-
// if (this->size() < m_arraySize)
132-
// {
133-
// m_arraySize = 0;
134-
135-
// return false;
136-
// }
137-
138140
m_pBuffer = calloc(m_arraySize, sizeof(T));
139141

140142
if (m_pBuffer == nullptr)
@@ -163,9 +165,10 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
163165
{
164166
std::lock_guard<std::mutex> lock(m_ioLock);
165167

166-
//this->clear();
167-
168-
free(m_pBuffer);
168+
if (m_pBuffer != nullptr)
169+
{
170+
free(m_pBuffer);
171+
}
169172

170173
m_pBuffer = nullptr;
171174

@@ -191,12 +194,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
191194
return;
192195
}
193196

194-
if (m_arraySize > this->size())
195-
{
196-
return;
197-
}
198-
199-
//memset((this->data()), 0, (sizeof(T) * m_arraySize));
200197
memset(m_pBuffer, 0, (sizeof(T) * m_arraySize));
201198

202199
m_readIdx = 0;
@@ -210,7 +207,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
210207
return nullptr;
211208
}
212209

213-
//return ((T *)this->data());
214210
return m_pBuffer;
215211
}
216212

@@ -233,7 +229,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
233229
return nullptr;
234230
}
235231

236-
//return ((T *)(this->data() + (offset * sizeof(T))));
237232
return (m_pBuffer + offset);
238233
}
239234

@@ -256,13 +251,11 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
256251

257252
auto offset = chan * m_blockSize; // channel offset = (channel_number * size_of_a_channel_block)
258253

259-
//if (offset >= this->size())
260254
if (offset >= m_arraySize)
261255
{
262256
return nullptr;
263257
}
264258

265-
//return (((T *)(this->data())) + offset);
266259
return (m_pBuffer + offset);
267260
}
268261

@@ -285,13 +278,11 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
285278

286279
auto offset = frame * m_numChannels; // frame offset = (frame_number * size_of_a_frame)
287280

288-
//if (offset >= this->size())
289281
if (offset >= m_arraySize)
290282
{
291283
return nullptr;
292284
}
293285

294-
//return (((T *)(this->data())) + offset);
295286
return (m_pBuffer + offset);
296287
}
297288

@@ -321,13 +312,11 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
321312
else
322313
offset = (chan * m_blockSize) + frame; // non-interleaved offset = (channel_number * size_of_channel_block) + frame_number
323314

324-
//if (offset >= this->size())
325315
if (offset >= m_arraySize)
326316
{
327317
return 0;
328318
}
329319

330-
//return (this->at(offset));
331320
return *(m_pBuffer + offset);
332321
}
333322

@@ -346,13 +335,11 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
346335
else
347336
offset = (chan * m_blockSize) + frame; // non-interleaved offset = (channel_number * size_of_channel_block) + frame_number
348337

349-
//if (offset >= this->size())
350338
if (offset >= m_arraySize)
351339
{
352340
return 0;
353341
}
354342

355-
//this->at(offset) = value;
356343
*(m_pBuffer + offset) = value;
357344
}
358345

@@ -379,13 +366,11 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
379366
return 0;
380367
}
381368

382-
//if (m_readIdx >= this->size())
383369
if (m_readIdx >= m_arraySize)
384370
{
385371
return 0;
386372
}
387373

388-
//return (this->at(m_readIdx++));
389374
return *(m_pBuffer + (m_readIdx++));
390375
}
391376

@@ -416,7 +401,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
416401
return out;
417402
}
418403

419-
//return (this->at(index));
420404
return *(m_pBuffer + index);
421405
}
422406

@@ -438,7 +422,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
438422
}
439423

440424
for (unsigned int x = 0; x < count; x++)
441-
//buf[x] = this->at(m_readIdx + x);
442425
buf[x] = *(m_pBuffer + x);
443426

444427
m_readIdx += count;
@@ -464,7 +447,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
464447
}
465448

466449
for (unsigned int x = 0; x < numSamples; x++)
467-
//buf[x] = this->at(startPos + x);
468450
buf[x] = *(m_pBuffer + (startPos + x));
469451

470452
return startPos + numSamples;
@@ -486,7 +468,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
486468
return 0;
487469
}
488470

489-
//this->at(m_writeIdx++) = value;
490471
*(m_pBuffer + (m_writeIdx++)) = value;
491472

492473
return m_writeIdx;
@@ -508,7 +489,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
508489
return 0;
509490
}
510491

511-
//this->at(index++) = value;
512492
*(m_pBuffer + (index++)) = value;
513493

514494
return index;
@@ -533,7 +513,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
533513
}
534514

535515
for (unsigned int x = 0; x < count; x++)
536-
//this->at(m_writeIdx + x) = buf[x];
537516
*(m_pBuffer + (m_writeIdx + x)) = buf[x];
538517

539518
m_writeIdx += count;

Src/Buffer/CRingBuffer.h

+18-1
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ template <typename T> class CRingBuffer
3030

3131
protected:
3232

33-
bool allocateBuffer(const size_t numEntries)
33+
void free()
3434
{
3535
if (m_pDataBuffer != nullptr)
3636
{
3737
free(m_pDataBuffer);
3838

3939
m_pDataBuffer = nullptr;
4040
}
41+
}
42+
43+
bool allocateBuffer(const size_t numEntries)
44+
{
45+
free();
4146

4247
if (numEntries > 0)
4348
{
@@ -194,6 +199,18 @@ template <typename T> class CRingBuffer
194199
}
195200
}
196201

202+
~CRingBuffer()
203+
{
204+
free();
205+
206+
m_entriesPerBlock = 0;
207+
m_bufferSize = 0;
208+
209+
m_currentDataSize = 0;
210+
m_writeIdx = 0;
211+
m_readIdx = 0;
212+
}
213+
197214
// Set the maximum number of entries that can be stored in the entry array.
198215
// NOTE: Doing this will flush (zero out) the data buffer.
199216
bool setMaxBufferSize(const size_t numEntries)

Src/Buffer/CVRingBuffer.h

+11
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,17 @@ template <typename T> class CVRingBuffer
200200
}
201201
}
202202

203+
~CVRingBuffer()
204+
{
205+
std::lock_guard<std::mutex> lock{m_ioMutex};
206+
207+
m_dataBuffer.clear();
208+
209+
m_currentDataSize = 0;
210+
m_writeIdx = 0;
211+
m_readIdx = 0;
212+
}
213+
203214
// Set the maximum number of entries that can be stored in the entry array.
204215
// NOTE: Doing this will flush (zero out) the data buffer.
205216
bool setMaxBufferSize(const size_t numEntries)

Src/Buffer/CVectorBuffer.h

+35
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ template <typename T> class CVectorBuffer: public CErrorHandler
8989
m_maxSize = buffSize;
9090
}
9191

92+
~CVectorBuffer()
93+
{
94+
clear();
95+
}
96+
97+
void clear()
98+
{
99+
std::lock_guard<std::mutex> lock{m_ioMutex};
100+
101+
m_dataBuffer.clear();
102+
}
103+
92104
// Set the maximum number of entries that can be stored in the entry array.
93105
bool setMaxBufferSize(const size_t buffSize)
94106
{
@@ -114,9 +126,32 @@ template <typename T> class CVectorBuffer: public CErrorHandler
114126
int getCurrentDataSize()
115127
{
116128
std::lock_guard<std::mutex> lock{m_ioMutex};
129+
117130
return (int)m_dataBuffer.size();
118131
}
119132

133+
T get(const unsigned int pos)
134+
{
135+
std::lock_guard<std::mutex> lock{ m_ioMutex };
136+
137+
if (pos >= m_maxSize)
138+
return (T) 0;;
139+
140+
return m_dataBuffer.at(x);
141+
}
142+
143+
bool set(const unsigned int pos, T &val)
144+
{
145+
std::lock_guard<std::mutex> lock{ m_ioMutex };
146+
147+
if (pos >= m_maxSize)
148+
return false;;
149+
150+
m_dataBuffer.at(pos) = val;
151+
152+
return true;
153+
}
154+
120155
// Read "blockSize" entries from the data block (entry array).
121156
int readBlock(T *pTargetBuff, const size_t blockSize, const bool deleteEntries = false)
122157
{

Src/Error/CError.h

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
#include <string>
1414

1515

16+
#ifndef COMPILE_ERROR
17+
#define COMPILE_ERROR(message) #error message
18+
#endif
19+
20+
1621
class CErrorHandler
1722
{
1823
private:
@@ -26,6 +31,11 @@ class CErrorHandler
2631
m_sErrorText = "";
2732
}
2833

34+
~CErrorHandler()
35+
{
36+
ClearError();
37+
}
38+
2939
void ClearError()
3040
{
3141
m_sErrorText = "";

Src/Logging/Logging.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
///
2+
/// \file Logging.h
3+
///
4+
/// Logging header file
5+
///
6+
7+
8+
#ifndef APP_LOGGING_H
9+
#define APP_LOGGING_H
10+
11+
#include "../../../Libs/plog//include/plog/Log.h"
12+
13+
14+
#define LogCritical(m)
15+
#define LogError(m)
16+
#define LogWarning(m)
17+
#define LogInfo(m)
18+
#define LogTrace(m)
19+
20+
21+
#endif // APP_LOGGING_H
22+
23+
24+
25+
26+
27+

Src/PlugIn/CPluginFileMgr.h

+13
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ class CPluginFileMgr
4343
m_pluginFileList.clear();
4444
}
4545

46+
~CPluginFileMgr()
47+
{
48+
clear();
49+
}
50+
51+
void clear()
52+
{
53+
m_sDirPath.clear();
54+
m_sPluginFileExt.clear();
55+
m_pluginFileList.clear();
56+
}
57+
58+
4659
bool setPluginDir(std::string &sDir)
4760
{
4861
if (sDir.empty())

0 commit comments

Comments
 (0)