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 private:
38  static constexpr unsigned BUFFER_SIZE = 1 << 14;
39  static constexpr unsigned BUFFER_MASK = BUFFER_SIZE - 1;
40  float buffer[BUFFER_SIZE];
41  unsigned offset;
42  float accum;
43  int availSamp;
44 };
45 
46 } // namespace openmsx
47 
48 #endif
bool readSamples(float *out, unsigned samples)
Definition: BlipBuffer.cc:154
static constexpr int BLIP_PHASE_BITS
Definition: BlipBuffer.hh:19
void addDelta(TimeIndex time, float delta)
Definition: BlipBuffer.cc:101
A fixed point number, implemented by a 32-bit signed integer.
Definition: FixedPoint.hh:15
This file implemented 3 utility functions:
Definition: Autofire.cc:9