openMSX
BlipBuffer.hh
Go to the documentation of this file.
1// Heavily based on:
2//
3// Band-limited sound synthesis and buffering
4// Blip_Buffer 0.4.0
5// http://www.slack.net/~ant/
6
7#ifndef BLIPBUFFER_HH
8#define BLIPBUFFER_HH
9
10#include "FixedPoint.hh"
11#include <array>
12
13namespace openmsx {
14
16{
17public:
18 // Number of bits in phase offset. Fewer than 6 bits (64 phase offsets) results
19 // in noticeable broadband noise when synthesizing high frequency square waves.
20 static constexpr int BLIP_PHASE_BITS = 10;
21
23
24 BlipBuffer();
25
26 // Update amplitude of waveform at given time. Time is in output sample
27 // units and since the last time readSamples() was called.
28 void addDelta(TimeIndex time, float delta);
29
30 // Read the given amount of samples into destination buffer.
31 template<size_t PITCH>
32 bool readSamples(float* out, size_t samples);
33
34private:
35 template<size_t PITCH>
36 void readSamplesHelper(float* out, size_t samples);
37
38private:
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} // namespace openmsx
48
49#endif
bool readSamples(float *out, size_t samples)
static constexpr int BLIP_PHASE_BITS
Definition BlipBuffer.hh:20
void addDelta(TimeIndex time, float delta)
Definition BlipBuffer.cc:98
A fixed point number, implemented by a 32-bit signed integer.
Definition FixedPoint.hh:16
This file implemented 3 utility functions:
Definition Autofire.cc:11