| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#ifndef BLIPBUFFER_HH |
| 8 |
#define BLIPBUFFER_HH |
| 9 |
|
| 10 |
#include "FixedPoint.hh" |
| 11 |
#include <array> |
| 12 |
|
| 13 |
namespace openmsx { |
| 14 |
|
| 15 |
class BlipBuffer |
| 16 |
{ |
| 17 |
public: |
| 18 |
|
| 19 |
|
| 20 |
static constexpr int BLIP_PHASE_BITS = 10; |
| 21 |
|
| 22 |
using TimeIndex = FixedPoint<BLIP_PHASE_BITS>; |
| 23 |
|
| 24 |
BlipBuffer(); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
void addDelta(TimeIndex time, float delta); |
| 29 |
|
| 30 |
|
| 31 |
template<size_t PITCH> |
| 32 |
bool readSamples(float* out, size_t samples); |
| 33 |
|
| 34 |
private: |
| 35 |
template<size_t PITCH> |
| 36 |
void readSamplesHelper(float* out, size_t samples); |
| 37 |
|
| 38 |
private: |
| 39 |
static constexpr size_t BUFFER_SIZE = 1 << 14; |
| 40 |
static constexpr size_t BUFFER_MASK = BUFFER_SIZE - 1; |
| 41 |
std::array<float, BUFFER_SIZE> buffer; |
| 42 |
size_t offset = 0; |
| 43 |
ptrdiff_t availSamp = 0; |
| 44 |
float accum = 0.0f; |
| 45 |
}; |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
#endif |