Ardour  8.7-15-gadf511264b
circular_buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef _ardour_circular_buffer_h_
20 #define _ardour_circular_buffer_h_
21 
22 #include <atomic>
23 #include <cstdint>
24 
25 #include "pbd/ringbuffer.h"
26 
28 #include "ardour/types.h"
29 
30 namespace ARDOUR {
31 
38 {
39 public:
40  CircularSampleBuffer (size_t size);
41 
42  void silence (size_t);
43  void write (Sample const*, size_t);
44  bool read (Sample& s_min, Sample& s_max, size_t n_samples);
45 
46 private:
49 };
50 
52 {
53 public:
54  struct Event {
55  /* up to 3 byte MIDI events, 32bit aligned */
56  Event (uint8_t const* buf = 0, size_t sz = 0);
57  uint8_t data[3];
58  uint8_t pad;
59  };
60 
61  typedef std::vector<Event> EventList;
62 
63  CircularEventBuffer (size_t size);
65 
66  void reset ();
67  void write (uint8_t const*, size_t);
68  bool read (EventList&);
69 
70 private:
72 
74  size_t _size;
75  size_t _size_mask;
76 
77  std::atomic<size_t> _idx;
78  std::atomic<size_t> _ack;
79 };
80 
81 }
82 #endif
bool read(EventList &)
std::atomic< size_t > _idx
std::atomic< size_t > _ack
std::vector< Event > EventList
CircularEventBuffer(size_t size)
void write(uint8_t const *, size_t)
CircularEventBuffer(CircularEventBuffer const &)
PBD::RingBuffer< Sample > _rb
CircularSampleBuffer(CircularSampleBuffer const &)
void write(Sample const *, size_t)
bool read(Sample &s_min, Sample &s_max, size_t n_samples)
#define LIBARDOUR_API
Event(uint8_t const *buf=0, size_t sz=0)