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

Graph data. More...

#include <klang.h>

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

Public Member Functions

Series * find (void *function)
 
unsigned int size () const
 The current number of items in the array.
 
void add (const Series &item)
 Add the specified item to the end of the array.
 
Series * add ()
 Add a blank item to the end of the array, returning a pointer that allows the item to be modified.
 
void clear ()
 Clear the array contents. Only resets the item count, without wiping memory.
 
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;.
 
Series & operator[] (int index)
 Returns a reference to the array item at the given index.
 
const Series & operator[] (int index) const
 Returns a read-only reference to the array item at the given index.
 

Static Public Member Functions

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

Public Attributes

unsigned int count
 
Series items [CAPACITY]
 

Detailed Description

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

Definition at line 3473 of file klang.h.

Member Function Documentation

◆ add() [1/2]

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

Definition at line 324 of file klang.h.

324 {
325 if (count < CAPACITY)
326 return &items[count++];
327 return nullptr;
328 }

◆ add() [2/2]

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

Definition at line 318 of file klang.h.

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

◆ capacity()

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

Definition at line 312 of file klang.h.

312{ return CAPACITY; }

◆ clear()

void klang::Array< Series, CAPACITY >::clear ( )
inlineinherited

Definition at line 331 of file klang.h.

331{ count = 0; }

◆ find()

template<int SIZE>
Series * klang::Generic::Graph< SIZE >::Data::find ( void * function)
inline

Definition at line 3476 of file klang.h.

3476 {
3477 for (int s = 0; s < GRAPH_SERIES; s++)
3478 if (this->operator[](s).function == function)
3479 return &items[s];
3480 return nullptr;
3481 }

References klang::Array< Series, GRAPH_SERIES >::items.

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

◆ max()

float klang::Array< Series, 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< Series, 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< Series, 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[]() [1/2]

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

Definition at line 369 of file klang.h.

369{ return items[index]; }

◆ operator[]() [2/2]

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

Definition at line 372 of file klang.h.

372{ return items[index]; }

◆ rms()

float klang::Array< Series, 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< Series, CAPACITY >::size ( ) const
inlineinherited

Definition at line 315 of file klang.h.

315{ return count; }

Member Data Documentation

◆ count

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

Definition at line 308 of file klang.h.

◆ items

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

Definition at line 309 of file klang.h.

Referenced by klang::Generic::Graph< SIZE >::Data::find().