Klang C++ 0.7.15
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 (const 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.
 
Point * add ()
 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;.
 
Point & operator[] (int index)
 Returns a reference to the array item at the given index.
 
const Point & operator[] (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

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

Detailed Description

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

Definition at line 3346 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 3352 of file klang.h.

Constructor & Destructor Documentation

◆ ~Series()

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

Definition at line 3347 of file klang.h.

3347{}

Member Function Documentation

◆ add() [1/3]

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

◆ add() [2/3]

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

Definition at line 318 of file klang.h.

318 {
319 if (count < CAPACITY)
320 items[count++] = item;
321 }

◆ add() [3/3]

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

Definition at line 3357 of file klang.h.

3357 {
3358 add({ (double)Array::size(), y });
3359 }
unsigned int size() const
Definition klang.h:315

References klang::Array< Point, SIZE+1 >::add(), and klang::Array< Point, SIZE+1 >::size().

◆ capacity()

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

Definition at line 312 of file klang.h.

312{ return CAPACITY; }

◆ clear()

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

◆ 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 2947 of file klang.h.

2947{ 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 3413 of file klang.h.

3413 {
3414 add(in);
3415 }

References klang::Array< Point, SIZE+1 >::add(), and klang::Generic::Input< signal >::in.

◆ input() [3/4]

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

Definition at line 2951 of file klang.h.

2951{ in = source; this->input(); }
void input() override
Definition klang.h:3413

◆ input() [4/4]

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

Reimplemented in klang::Debug.

Definition at line 2951 of file klang.h.

2951{ in = source; this->input(); }
virtual const signal & input() const
Definition klang.h:2947

◆ max()

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

Definition at line 334 of file klang.h.

334 {
335 float max = 0.f;
336 for (unsigned int i = 0; i < count; i++)
337 if (abs(items[i]) > max)
338 max = items[i];
339 return max;
340 }

◆ mean()

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

Definition at line 343 of file klang.h.

343 {
344 float sum = 0.f;
345 for (unsigned int i = 0; i < count; i++)
346 sum += abs(items[i]);
347 return sum / count;
348 }

◆ normalise()

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

Definition at line 359 of file klang.h.

359 {
360 if (!count) return;
361
362 const float current = (mode == Peak) ? max() : (mode == Mean) ? mean() : rms();
363 const float scale = current == 0.f ? 0.f : target / current;
364 for (int i = 0; i < count; i++)
365 items[i] *= scale;
366 }
@ Peak
Definition klang.h:149
@ Mean
Definition klang.h:149

◆ operator!=()

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

Definition at line 3403 of file klang.h.

3403 {
3404 return !operator==(in);
3405 }
bool operator==(const Series &in) const
Definition klang.h:3395

References klang::Generic::Input< signal >::in, and klang::Generic::Graph< SIZE >::Series::operator==().

◆ operator<<()

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

Reimplemented in klang::Debug.

Definition at line 2950 of file klang.h.

2950{ in = source; this->input(); }

◆ operator==()

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

Definition at line 3395 of file klang.h.

3395 {
3396 if (count != in.count) return false;
3397 for (unsigned int i = 0; i < count; i++)
3398 if (items[i].x != in.items[i].x || items[i].y != in.items[i].y)
3399 return false;
3400 return true;
3401 }

References klang::Array< Point, SIZE+1 >::count, klang::Generic::Input< signal >::in, and klang::Array< Point, SIZE+1 >::items.

Referenced by klang::Generic::Graph< SIZE >::Series::operator!=().

◆ operator[]() [1/2]

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

Definition at line 369 of file klang.h.

369{ return items[index]; }

◆ operator[]() [2/2]

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

Definition at line 372 of file klang.h.

372{ return items[index]; }

◆ plot() [1/2]

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

Definition at line 3362 of file klang.h.

3362 {
3363 constexpr int size = SIZE > 1024 ? 1024 : SIZE;
3364
3365 if (function != (const void*)&f || hash != f.hash()) {
3366 clear();
3367 function = (const void*)&f;
3368 hash = f.hash();
3369 double x = 0;
3370 const double dx = x_axis.range() / size;
3371 for (int i = 0; i <= size; i++) {
3372 x = x_axis.min + i * dx;
3373 add({ x, (double)(signal)f(x) });
3374 }
3375 }
3376 }

References klang::Array< Point, SIZE+1 >::add(), klang::Generic::Graph< SIZE >::Series::clear(), klang::Generic::Graph< SIZE >::Series::function, klang::Generic::Graph< SIZE >::Series::hash, klang::Generic::Graph< SIZE >::Axis::min, klang::Generic::Graph< SIZE >::Axis::range(), and klang::Array< Point, SIZE+1 >::size().

Referenced by klang::Generic::Graph< SIZE >::plot(), klang::Generic::Graph< SIZE >::plot(), and klang::Generic::Graph< SIZE >::plot().

◆ plot() [2/2]

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

Definition at line 3379 of file klang.h.

3379 {
3380 constexpr int size = SIZE > 1024 ? 1024 : SIZE;
3381
3382 if (function != (void*)f) {
3383 clear();
3384 function = (void*)f;
3385 hash = 0;
3386 double x = 0;
3387 const double dx = x_axis.range() / size;
3388 for (int i = 0; i <= size; i++) {
3389 x = x_axis.min + i * dx;
3390 add({ x, (double)(signal)f((float)x) });
3391 }
3392 }
3393 }

References klang::Array< Point, SIZE+1 >::add(), klang::Generic::Graph< SIZE >::Series::clear(), klang::Generic::Graph< SIZE >::Series::function, klang::Generic::Graph< SIZE >::Series::hash, klang::Generic::Graph< SIZE >::Axis::min, klang::Generic::Graph< SIZE >::Axis::range(), and klang::Array< Point, SIZE+1 >::size().

◆ rms()

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

Definition at line 351 of file klang.h.

351 {
352 float sum = 0.f;
353 for (unsigned int i = 0; i < count; i++)
354 sum += items[i] * items[i];
355 return sqrt(sum / count);
356 }

◆ size()

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

Member Data Documentation

◆ count

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

Definition at line 308 of file klang.h.

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

◆ function

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

◆ hash

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

◆ in

◆ items

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

Definition at line 309 of file klang.h.

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