Klang C++
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

Seriesfind (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.
 
Seriesadd ()
 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;.
 
Seriesoperator[] (int index)
 Returns a reference to the array item at the given index.
 
const Seriesoperator[] (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

Series items [CAPACITY]
 
unsigned int count
 

Detailed Description

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

Definition at line 1779 of file klang.h.

Member Function Documentation

◆ add() [1/2]

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

Definition at line 255 of file klang.h.

255 {
256 if (count < CAPACITY)
257 return &items[count++];
258 return nullptr;
259 }

◆ add() [2/2]

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

Definition at line 249 of file klang.h.

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

◆ capacity()

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

Definition at line 243 of file klang.h.

243{ return CAPACITY; }

◆ clear()

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

Definition at line 262 of file klang.h.

262{ count = 0; }

◆ find()

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

Definition at line 1782 of file klang.h.

1782 {
1783 for (int s = 0; s < GRAPH_SERIES; s++)
1784 if (this->operator[](s).function == function)
1785 return &items[s];
1786 return nullptr;
1787 }

◆ max()

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

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

Definition at line 300 of file klang.h.

300{ return items[index]; }

◆ operator[]() [2/2]

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

Definition at line 303 of file klang.h.

303{ return items[index]; }

◆ rms()

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

Definition at line 246 of file klang.h.

246{ return count; }

Member Data Documentation

◆ count

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

Definition at line 240 of file klang.h.

◆ items

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

Definition at line 239 of file klang.h.