Language Guide / Signal Flow
buffer
klang::buffer
Mono audio storage or a view of existing samples.
Construct buffer(n) to allocate storage for n mono samples, or pass a pointer and a sample count to view existing storage. A view borrows that storage for its lifetime. Copying a buffer creates a view of the same samples. Use the cursor for sequential access and call rewind() before another pass through the block.
Example ยท Apply gain to a whole buffer
while (!block.finished())
block++ *= 0.5;
See also stereo::buffer.
Audio buffer (mono)
More...
#include <klang.h>
Definition at line 2610 of file klang.h.
◆ signal
◆ buffer() [1/4]
| klang::buffer::buffer |
( |
float * | buffer, |
|
|
int | size ) |
|
inline |
Definition at line 2633 of file klang.h.
2636 }
buffer(float *buffer, int size)
void rewind(int offset=0)
References rewind().
◆ buffer() [2/4]
| klang::buffer::buffer |
( |
float * | buffer, |
|
|
int | size, |
|
|
float | initial ) |
|
inline |
◆ buffer() [3/4]
| klang::buffer::buffer |
( |
int | size = 1, |
|
|
float | initial = 0 ) |
|
inline |
Definition at line 2644 of file klang.h.
2648 }
constexpr unsigned int capacity(unsigned int n)
References rewind(), and set().
◆ buffer() [4/4]
| klang::buffer::buffer |
( |
const buffer & | buf | ) |
|
|
inline |
◆ ~buffer()
| virtual klang::buffer::~buffer |
( |
| ) |
|
|
inlinevirtual |
◆ attach()
| void klang::buffer::attach |
( |
const buffer & | buffer, |
|
|
int | size = 0 ) |
|
inline |
◆ capacity()
| unsigned int klang::buffer::capacity |
( |
unsigned int | n | ) |
|
|
inlineconstexprprotected |
Definition at line 2612 of file klang.h.
2612 {
2613
2614 n--;
2615 n |= n >> 1;
2616 n |= n >> 2;
2617 n |= n >> 4;
2618 n |= n >> 8;
2619 n |= n >> 16;
2620
2621 n++;
2622 return n;
2623 }
◆ clear() [1/2]
| void klang::buffer::clear |
( |
| ) |
|
|
inline |
◆ clear() [2/2]
| void klang::buffer::clear |
( |
int | size | ) |
|
|
inline |
◆ data() [1/2]
| float * klang::buffer::data |
( |
| ) |
|
|
inline |
◆ data() [2/2]
| const float * klang::buffer::data |
( |
| ) |
const |
|
inline |
◆ finished()
| bool klang::buffer::finished |
( |
| ) |
const |
|
inline |
◆ level()
| float klang::buffer::level |
( |
| ) |
const |
|
inline |
◆ offset()
| int klang::buffer::offset |
( |
| ) |
const |
|
inline |
◆ operator const signal &()
| klang::buffer::operator const signal & |
( |
| ) |
const |
|
inline |
◆ operator double()
| klang::buffer::operator double |
( |
| ) |
const |
|
inlineexplicit |
◆ operator signal &()
| klang::buffer::operator signal & |
( |
| ) |
|
|
inline |
◆ operator*=()
Definition at line 2747 of file klang.h.
2747 {
2749 return *this;
2750 }
References ptr.
◆ operator++()
| signal & klang::buffer::operator++ |
( |
int | | ) |
|
|
inline |
◆ operator+=()
Definition at line 2742 of file klang.h.
2742 {
2744 return *this;
2745 }
References ptr.
◆ operator<<()
Definition at line 2757 of file klang.h.
2757 {
2759 return *this;
2760 }
References ptr.
◆ operator=() [1/2]
Definition at line 2752 of file klang.h.
2752 {
2753 memcpy(
samples, in.samples, min(
size, in.size) *
sizeof(
float));
2754 return *this;
2755 }
References samples, and size.
◆ operator=() [2/2]
◆ operator[]() [1/5]
| signal klang::buffer::operator[] |
( |
float | offset | ) |
|
|
inline |
◆ operator[]() [2/5]
| signal klang::buffer::operator[] |
( |
float | offset | ) |
const |
|
inline |
Definition at line 2704 of file klang.h.
2704 {
2705 const float f = floorf(
offset);
2706 const float frac =
offset - f;
2707
2708 const int i = (int)
offset;
2709 const int j = (i == (
size - 1)) ? 0 : (i + 1);
2710
2712 }
References offset(), samples, and size.
◆ operator[]() [3/5]
| const signal & klang::buffer::operator[] |
( |
int | index | ) |
const |
|
inline |
◆ operator[]() [4/5]
| signal & klang::buffer::operator[] |
( |
int | offset | ) |
|
|
inline |
◆ operator[]() [5/5]
| signal & klang::buffer::operator[] |
( |
unsigned int | offset | ) |
|
|
inline |
◆ rewind()
| void klang::buffer::rewind |
( |
int | offset = 0 | ) |
|
|
inline |
Definition at line 2665 of file klang.h.
2665 {
2666#ifdef _MSC_VER
2667 _controlfp_s(nullptr, _DN_FLUSH, _MCW_DN);
2668#endif
2671 }
References end, offset(), ptr, samples, and size.
Referenced by buffer(), buffer(), buffer(), buffer(), attach(), klang::Envelope::Follower::Window< WINDOW >::mean(), klang::Stereo::buffer::rewind(), and klang::Envelope::Follower::Window< WINDOW >::rms().
◆ rms()
| float klang::buffer::rms |
( |
| ) |
const |
|
inline |
◆ set()
| void klang::buffer::set |
( |
float | value = 0 | ) |
|
|
inline |
◆ end
◆ mask
| const unsigned int klang::buffer::mask = 0xFFFFFFFF |
|
protected |
◆ owned
| const bool klang::buffer::owned = false |
|
protected |
◆ ptr
Definition at line 2627 of file klang.h.
Referenced by finished(), offset(), operator const signal &(), operator double(), operator signal &(), operator*=(), operator++(), operator+=(), operator<<(), operator=(), and rewind().
◆ samples
| float* klang::buffer::samples |
|
protected |
Definition at line 2626 of file klang.h.
Referenced by ~buffer(), attach(), clear(), clear(), data(), data(), level(), offset(), operator=(), operator[](), operator[](), operator[](), operator[](), rewind(), rms(), and set().
◆ size
| const int klang::buffer::size |
Definition at line 2631 of file klang.h.
Referenced by attach(), clear(), clear(), level(), operator=(), klang::variable::buffer::operator=(), klang::File::operator>>(), operator[](), rewind(), rms(), and set().