ToneBuffer.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * ToneBuffer.h - Support for simple tone generation via I2S
8  *
9  * @author Sept 2019 mikee47 <mike@sillyhouse.net>
10  *
11  ****/
12 
13 #pragma once
14 
15 #include <cstdint>
16 
17 class ToneBufferQueue;
18 
24 {
25 public:
26  typedef uint32_t Sample;
27  static constexpr auto sampleSize = sizeof(Sample);
28 
30  {
31  delete next;
32  delete data;
33  }
34 
35  bool allocate(unsigned sampleCount)
36  {
37  if(capacity < sampleCount) {
38  delete data;
39  data = new Sample[sampleCount];
40  if(data == nullptr) {
41  this->sampleCount = 0;
42  return false;
43  }
44  }
45 
46  this->sampleCount = sampleCount;
47  return true;
48  }
49 
51  {
52  return data;
53  }
54 
55  unsigned getCapacity()
56  {
57  return capacity;
58  }
59 
60  unsigned getSampleCount()
61  {
62  return sampleCount;
63  }
64 
65  unsigned repeatCount = 0;
66 
67 private:
68  friend ToneBufferQueue;
69  ToneBuffer* next = nullptr;
70  Sample* data = nullptr;
71  unsigned capacity = 0;
72  unsigned sampleCount = 0;
73 };
Definition: ToneBufferQueue.h:19
Contains samples for one full signal cycle at a specific frequency.
Definition: ToneBuffer.h:24
unsigned getCapacity()
Definition: ToneBuffer.h:55
bool allocate(unsigned sampleCount)
Definition: ToneBuffer.h:35
static constexpr auto sampleSize
Definition: ToneBuffer.h:27
unsigned getSampleCount()
Definition: ToneBuffer.h:60
unsigned repeatCount
Definition: ToneBuffer.h:65
Sample * getData()
Definition: ToneBuffer.h:50
uint32_t Sample
Definition: ToneBuffer.h:26
~ToneBuffer()
Definition: ToneBuffer.h:29