23
23
#define noninterleavedAudioBufferOffset (ptr, chl, smpl, fs ) *(ptr + (chl + fs) + smpl)
24
24
25
25
26
- // template <class T> class CSimpleAudioBuffer : public std::vector<T>, public CErrorHandler
27
26
template <class T > class CSimpleAudioBuffer : public CErrorHandler
28
27
{
29
28
unsigned int m_numChannels; // number of channels to buffer
@@ -56,6 +55,18 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
56
55
m_pBuffer = nullptr ;
57
56
}
58
57
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
+
59
70
void setNumChannels (unsigned int numChls)
60
71
{
61
72
if (m_bAllocated)
@@ -126,15 +137,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
126
137
127
138
m_arraySize = (m_blockSize * m_numChannels); // arraySize = total numner of samples in the buffer
128
139
129
- // this->resize(m_arraySize);
130
-
131
- // if (this->size() < m_arraySize)
132
- // {
133
- // m_arraySize = 0;
134
-
135
- // return false;
136
- // }
137
-
138
140
m_pBuffer = calloc (m_arraySize, sizeof (T));
139
141
140
142
if (m_pBuffer == nullptr )
@@ -163,9 +165,10 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
163
165
{
164
166
std::lock_guard<std::mutex> lock (m_ioLock);
165
167
166
- // this->clear();
167
-
168
- free (m_pBuffer);
168
+ if (m_pBuffer != nullptr )
169
+ {
170
+ free (m_pBuffer);
171
+ }
169
172
170
173
m_pBuffer = nullptr ;
171
174
@@ -191,12 +194,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
191
194
return ;
192
195
}
193
196
194
- if (m_arraySize > this ->size ())
195
- {
196
- return ;
197
- }
198
-
199
- // memset((this->data()), 0, (sizeof(T) * m_arraySize));
200
197
memset (m_pBuffer, 0 , (sizeof (T) * m_arraySize));
201
198
202
199
m_readIdx = 0 ;
@@ -210,7 +207,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
210
207
return nullptr ;
211
208
}
212
209
213
- // return ((T *)this->data());
214
210
return m_pBuffer;
215
211
}
216
212
@@ -233,7 +229,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
233
229
return nullptr ;
234
230
}
235
231
236
- // return ((T *)(this->data() + (offset * sizeof(T))));
237
232
return (m_pBuffer + offset);
238
233
}
239
234
@@ -256,13 +251,11 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
256
251
257
252
auto offset = chan * m_blockSize; // channel offset = (channel_number * size_of_a_channel_block)
258
253
259
- // if (offset >= this->size())
260
254
if (offset >= m_arraySize)
261
255
{
262
256
return nullptr ;
263
257
}
264
258
265
- // return (((T *)(this->data())) + offset);
266
259
return (m_pBuffer + offset);
267
260
}
268
261
@@ -285,13 +278,11 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
285
278
286
279
auto offset = frame * m_numChannels; // frame offset = (frame_number * size_of_a_frame)
287
280
288
- // if (offset >= this->size())
289
281
if (offset >= m_arraySize)
290
282
{
291
283
return nullptr ;
292
284
}
293
285
294
- // return (((T *)(this->data())) + offset);
295
286
return (m_pBuffer + offset);
296
287
}
297
288
@@ -321,13 +312,11 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
321
312
else
322
313
offset = (chan * m_blockSize) + frame; // non-interleaved offset = (channel_number * size_of_channel_block) + frame_number
323
314
324
- // if (offset >= this->size())
325
315
if (offset >= m_arraySize)
326
316
{
327
317
return 0 ;
328
318
}
329
319
330
- // return (this->at(offset));
331
320
return *(m_pBuffer + offset);
332
321
}
333
322
@@ -346,13 +335,11 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
346
335
else
347
336
offset = (chan * m_blockSize) + frame; // non-interleaved offset = (channel_number * size_of_channel_block) + frame_number
348
337
349
- // if (offset >= this->size())
350
338
if (offset >= m_arraySize)
351
339
{
352
340
return 0 ;
353
341
}
354
342
355
- // this->at(offset) = value;
356
343
*(m_pBuffer + offset) = value;
357
344
}
358
345
@@ -379,13 +366,11 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
379
366
return 0 ;
380
367
}
381
368
382
- // if (m_readIdx >= this->size())
383
369
if (m_readIdx >= m_arraySize)
384
370
{
385
371
return 0 ;
386
372
}
387
373
388
- // return (this->at(m_readIdx++));
389
374
return *(m_pBuffer + (m_readIdx++));
390
375
}
391
376
@@ -416,7 +401,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
416
401
return out;
417
402
}
418
403
419
- // return (this->at(index));
420
404
return *(m_pBuffer + index );
421
405
}
422
406
@@ -438,7 +422,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
438
422
}
439
423
440
424
for (unsigned int x = 0 ; x < count; x++)
441
- // buf[x] = this->at(m_readIdx + x);
442
425
buf[x] = *(m_pBuffer + x);
443
426
444
427
m_readIdx += count;
@@ -464,7 +447,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
464
447
}
465
448
466
449
for (unsigned int x = 0 ; x < numSamples; x++)
467
- // buf[x] = this->at(startPos + x);
468
450
buf[x] = *(m_pBuffer + (startPos + x));
469
451
470
452
return startPos + numSamples;
@@ -486,7 +468,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
486
468
return 0 ;
487
469
}
488
470
489
- // this->at(m_writeIdx++) = value;
490
471
*(m_pBuffer + (m_writeIdx++)) = value;
491
472
492
473
return m_writeIdx;
@@ -508,7 +489,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
508
489
return 0 ;
509
490
}
510
491
511
- // this->at(index++) = value;
512
492
*(m_pBuffer + (index ++)) = value;
513
493
514
494
return index ;
@@ -533,7 +513,6 @@ template <class T> class CSimpleAudioBuffer : public CErrorHandler
533
513
}
534
514
535
515
for (unsigned int x = 0 ; x < count; x++)
536
- // this->at(m_writeIdx + x) = buf[x];
537
516
*(m_pBuffer + (m_writeIdx + x)) = buf[x];
538
517
539
518
m_writeIdx += count;
0 commit comments