Klang C++
Language Reference (draft)
Loading...
Searching...
No Matches
klang::Generic::Graph< SIZE >::Series

Data series. More...

#include <klang.h>

+ Inheritance diagram for klang::Generic::Graph< SIZE >::Series:

Public Types

using Array = Array<Point, SIZE + 1>
 

Public Member Functions

virtual ~Series ()
 
void add (double y)
 
template<typename SIGNAL , typename... Args>
void plot (Generic::Function< SIGNAL, Args... > &f, const Axis &x_axis)
 
template<typename RETURN , typename ARG >
void plot (RETURN(*f)(ARG), const Axis &x_axis)
 
bool operator== (const Series &in) const
 
bool operator!= (const Series &in) const
 
void clear ()
 
void input () override
 
virtual const SIGNAL & input () const
 
virtual void input (const SIGNAL &source)
 
unsigned int size () const
 The current number of items in the array.
 
void add (const Point &item)
 Add the specified item to the end of the array.
 
Pointadd ()
 Add a blank item to the end of the array, returning a pointer that allows the item to be modified.
 
float max () const
 Find the maximum value in the array.
 
float mean () const
 Find the mean average of values in the array.
 
float rms () const
 Find the root mean squared (RMS) average of values in the array.
 
void normalise (float target=1.f, int mode=Peak)
 Normalises values in the array to the specified target, based on peak, mean, or RMS value;.
 
Pointoperator[] (int index)
 Returns a reference to the array item at the given index.
 
const Pointoperator[] (int index) const
 Returns a read-only reference to the array item at the given index.
 
virtual void input (const signal &source)
 
virtual void operator<< (const signal &source)
 

Static Public Member Functions

static int capacity ()
 The maximum capacity of the array.
 

Public Attributes

void * function = nullptr
 
uint64_t hash = 0
 
Point items [CAPACITY]
 
unsigned int count
 
signal in
 

Detailed Description

template<int SIZE>
struct klang::Generic::Graph< SIZE >::Series

Definition at line 1652 of file klang.h.

Member Typedef Documentation

◆ Array

template<int SIZE>
using klang::Generic::Graph< SIZE >::Series::Array = Array<Point, SIZE + 1>

Definition at line 1658 of file klang.h.

Constructor & Destructor Documentation

◆ ~Series()

template<int SIZE>
virtual klang::Generic::Graph< SIZE >::Series::~Series ( )
inlinevirtual

Definition at line 1653 of file klang.h.

1653{ }

Member Function Documentation

◆ add() [1/3]

Point * klang::Array< Point, CAPACITY >::add ( )
inlineinherited

Definition at line 255 of file klang.h.

255 {
256 if (count < CAPACITY)
257 return &items[count++];
258 return nullptr;
259 }
Point items[CAPACITY]
Definition klang.h:239

◆ add() [2/3]

void klang::Array< Point, CAPACITY >::add ( const Point & item)
inlineinherited

Definition at line 249 of file klang.h.

249 {
250 if(count < CAPACITY)
251 items[count++] = item;
252 }

◆ add() [3/3]

template<int SIZE>
void klang::Generic::Graph< SIZE >::Series::add ( double y)
inline

Definition at line 1663 of file klang.h.

1663 {
1664 add({ (double)Array::size(), y });
1665 }
unsigned int size() const
Definition klang.h:246

◆ capacity()

static int klang::Array< Point, CAPACITY >::capacity ( )
inlinestaticinherited

Definition at line 243 of file klang.h.

243{ return CAPACITY; }

◆ clear()

template<int SIZE>
void klang::Generic::Graph< SIZE >::Series::clear ( )
inline

Definition at line 1713 of file klang.h.

1713 {
1714 function = nullptr;
1715 Array::clear();
1716 }

References klang::Generic::Graph< SIZE >::Series::function.

◆ input() [1/4]

template<int SIZE>
virtual const SIGNAL & klang::Generic::Input< SIGNAL >::input ( ) const
inlinevirtual

Reimplemented from klang::Generic::Input< signal >.

Definition at line 1343 of file klang.h.

1343{ return in; }

◆ input() [2/4]

template<int SIZE>
void klang::Generic::Graph< SIZE >::Series::input ( )
inlineoverridevirtual

Reimplemented from klang::Generic::Input< signal >.

Definition at line 1719 of file klang.h.

1719 {
1720 add(in);
1721 }

◆ input() [3/4]

template<int SIZE>
virtual void klang::Generic::Input< SIGNAL >::input ( const SIGNAL & source)
inline

Definition at line 1347 of file klang.h.

1347{ in = source; input(); }
void input() override
Definition klang.h:1719

◆ input() [4/4]

virtual void klang::Generic::Input< signal >::input ( const signal & source)
inlinevirtualinherited

Definition at line 1347 of file klang.h.

1347{ in = source; input(); }
virtual const signal & input() const
Definition klang.h:1343

◆ max()

float klang::Array< Point, CAPACITY >::max ( ) const
inlineinherited

Definition at line 265 of file klang.h.

265 {
266 float max = 0.f;
267 for (unsigned int i = 0; i < count; i++)
268 if (abs(items[i]) > max)
269 max = items[i];
270 return max;
271 }

◆ mean()

float klang::Array< Point, CAPACITY >::mean ( ) const
inlineinherited

Definition at line 274 of file klang.h.

274 {
275 float sum = 0.f;
276 for (unsigned int i = 0; i < count; i++)
277 sum += abs(items[i]);
278 return sum / count;
279 }

◆ normalise()

void klang::Array< Point, CAPACITY >::normalise ( float target = 1.f,
int mode = Peak )
inlineinherited

Definition at line 290 of file klang.h.

290 {
291 if (!count) return;
292
293 const float current = (mode == Peak) ? max() : (mode == Mean) ? mean() : rms();
294 const float scale = current == 0.f ? 0.f : target / current;
295 for (int i = 0; i < count; i++)
296 items[i] *= scale;
297 }
@ Peak
Definition klang.h:83
@ Mean
Definition klang.h:83

◆ operator!=()

template<int SIZE>
bool klang::Generic::Graph< SIZE >::Series::operator!= ( const Series & in) const
inline

Definition at line 1709 of file klang.h.

1709 {
1710 return !operator==(in);
1711 }
bool operator==(const Series &in) const
Definition klang.h:1701

◆ operator<<()

virtual void klang::Generic::Input< signal >::operator<< ( const signal & source)
inlinevirtualinherited

Definition at line 1346 of file klang.h.

1346{ in = source; input(); }

◆ operator==()

template<int SIZE>
bool klang::Generic::Graph< SIZE >::Series::operator== ( const Series & in) const
inline

Definition at line 1701 of file klang.h.

1701 {
1702 if (count != in.count) return false;
1703 for (unsigned int i = 0; i < count; i++)
1704 if (items[i].x != in.items[i].x || items[i].y != in.items[i].y)
1705 return false;
1706 return true;
1707 }

◆ operator[]() [1/2]

Point & klang::Array< Point, CAPACITY >::operator[] ( int index)
inlineinherited

Definition at line 300 of file klang.h.

300{ return items[index]; }

◆ operator[]() [2/2]

const Point & klang::Array< Point, CAPACITY >::operator[] ( int index) const
inlineinherited

Definition at line 303 of file klang.h.

303{ return items[index]; }

◆ plot() [1/2]

template<int SIZE>
template<typename SIGNAL , typename... Args>
void klang::Generic::Graph< SIZE >::Series::plot ( Generic::Function< SIGNAL, Args... > & f,
const Axis & x_axis )
inline

Definition at line 1668 of file klang.h.

1668 {
1669 constexpr int size = SIZE > 1024 ? 1024 : SIZE;
1670
1671 if (function != (void*)f || hash != f.hash()) {
1672 clear();
1673 function = (void*)f;
1674 hash = f.hash();
1675 double x = 0;
1676 const double dx = x_axis.range() / size;
1677 for (int i = 0; i <= size; i++) {
1678 x = x_axis.min + i * dx;
1679 add({ x, (double)(signal)f(x) });
1680 }
1681 }
1682 }

◆ plot() [2/2]

template<int SIZE>
template<typename RETURN , typename ARG >
void klang::Generic::Graph< SIZE >::Series::plot ( RETURN(* )(ARG),
const Axis & x_axis )
inline

Definition at line 1685 of file klang.h.

1685 {
1686 constexpr int size = SIZE > 1024 ? 1024 : SIZE;
1687
1688 if (function != (void*)f) {
1689 clear();
1690 function = (void*)f;
1691 hash = 0;
1692 double x = 0;
1693 const double dx = x_axis.range() / size;
1694 for (int i = 0; i <= size; i++) {
1695 x = x_axis.min + i * dx;
1696 add({ x, (double)(signal)f((float)x) });
1697 }
1698 }
1699 }

◆ rms()

float klang::Array< Point, CAPACITY >::rms ( ) const
inlineinherited

Definition at line 282 of file klang.h.

282 {
283 float sum = 0.f;
284 for (unsigned int i = 0; i < count; i++)
285 sum += items[i] * items[i];
286 return sqrt(sum / count);
287 }

◆ size()

unsigned int klang::Array< Point, CAPACITY >::size ( ) const
inlineinherited

Definition at line 246 of file klang.h.

246{ return count; }

Member Data Documentation

◆ count

unsigned int klang::Array< Point, CAPACITY >::count
inherited

Definition at line 240 of file klang.h.

◆ function

template<int SIZE>
void* klang::Generic::Graph< SIZE >::Series::function = nullptr

Definition at line 1655 of file klang.h.

Referenced by klang::Generic::Graph< SIZE >::Series::clear().

◆ hash

template<int SIZE>
uint64_t klang::Generic::Graph< SIZE >::Series::hash = 0

Definition at line 1656 of file klang.h.

◆ in

Definition at line 1340 of file klang.h.

1340{ 0.f };

◆ items

Point klang::Array< Point, CAPACITY >::items[CAPACITY]
inherited

Definition at line 239 of file klang.h.