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 
12 namespace openmsx {
13 
15 {
16 public:
17  // Number of bits in phase offset. Fewer than 6 bits (64 phase offsets) results
18  // in noticeable broadband noise when synthesizing high frequency square waves.
19  static constexpr int BLIP_PHASE_BITS = 10;
20 
22 
23  BlipBuffer();
24 
25  // Update amplitude of waveform at given time. Time is in output sample
26  // units and since the last time readSamples() was called.
27  void addDelta(TimeIndex time, float delta);
28 
29  // Read the given amount of samples into destination buffer.
30  template <unsigned PITCH>
31  bool readSamples(float* out, unsigned samples);
32 
33 private:
34  template <unsigned PITCH>
35  void readSamplesHelper(float* out, unsigned samples) __restrict;
36 
37  static constexpr unsigned BUFFER_SIZE = 1 << 14;
38  static constexpr unsigned BUFFER_MASK = BUFFER_SIZE - 1;
39  float buffer[BUFFER_SIZE];
40  unsigned offset;
41  float accum;
42  int availSamp;
43 };
44 
45 } // namespace openmsx
46 
47 #endif
static constexpr int BLIP_PHASE_BITS
Definition: BlipBuffer.hh:19
A fixed point number, implemented by a 32-bit signed integer.
Definition: FixedPoint.hh:15
void addDelta(TimeIndex time, float delta)
Definition: BlipBuffer.cc:107
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
bool readSamples(float *out, unsigned samples)
Definition: BlipBuffer.cc:160