lib-ai 1_0_704
lib-ai automated documentation
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
WS::AudioModel Class Reference

Main entry point class to handle AI audio processing. More...

#include <AudioModel.h>

Public Member Functions

 AudioModel (std::string const &activation="tanh", unsigned int sampleRate=44100)
 Constructor for AudioModel.
 
 ~AudioModel ()
 Destructor for AudioModel.
 
 AudioModel (const AudioModel &)=delete
 
AudioModeloperator= (const AudioModel &)=delete
 
bool prepare (std::string const &modelName)
 Loads and prepares the model for processing.
 
void setNewParam (std::string const &param)
 Adds a new parameter to the model.
 
bool setLicense (std::string const &license)
 Adds license.
 
void setParamValueAt (size_t param, double value)
 Sets the value of a parameter by index.
 
void setParamValueAt (size_t param, float value)
 Sets the value of a parameter by index.
 
void setParamValueAt (std::string const &param, double value)
 Sets the value of a parameter by name.
 
void setParamValueAt (std::string const &param, float value)
 Sets the value of a parameter by name.
 
bool process (const float *input, float *output)
 Processes audio through the model.
 
bool loadJsonEQParameters (std::string const &inJsonConfigPathName, int samplingRate)
 Loads EQ parameters from a JSON configuration file.
 
size_t getFrameLength () const
 Gets the frame length required for processing.
 
size_t getNumberOfFilters () const
 Gets the number of filters in the model.
 
size_t getDenseLocalSize () const
 Gets the dense local size of the model.
 
size_t getMaxPoolingPoolSize () const
 Gets the max pooling pool size.
 
size_t getNumberOfParams () const
 Gets the number of parameters supported by the model.
 
void setLogger (WS::Logger *logger)
 Sets a logger for the model.
 
float * getValidationValues (const std::string &bufferName, size_t &filterCnt, size_t &sampleCnt)
 Gets validation values for a specific buffer.
 

Private Member Functions

float oneminus (float x)
 
float softplus (float x)
 
float * getBreakPoints (size_t numBreakPoints)
 

Private Attributes

Impl * pImpl
 
WS::Logger * mLogger {nullptr}
 

Friends

class ::AudioModelUT
 

Detailed Description

Main entry point class to handle AI audio processing.

The AudioModel class provides the primary interface for loading and using AI models for audio processing. It supports various activation functions, parameter setting, and model processing capabilities.

// Basic usage example
static const std::string ACTIVATION{"tanh"};
std::unique_ptr<AudioModel> audioModel{new AudioModel(ACTIVATION)};
// Load and prepare the model binaries (.dat files)
std::string modelName = "/path/to/model/";
if(!audioModel->prepare(modelName)) {
std::cout << "ERROR: Could not prepare the model properly." << std::endl;
return 1;
}
// Set parameters if needed
if(audioModel->getNumberOfParams() > 0) {
audioModel->setParamValueAt(0, 0.5f);
}
// Process audio
audioModel->process(inputBuffer, outputBuffer);
Main entry point class to handle AI audio processing.
Definition: AudioModel.h:56
void setParamValueAt(size_t param, double value)
Sets the value of a parameter by index.

Constructor & Destructor Documentation

◆ AudioModel() [1/2]

WS::AudioModel::AudioModel ( std::string const &  activation = "tanh",
unsigned int  sampleRate = 44100 
)

Constructor for AudioModel.

Parameters
activationThe activation function to use (default: "tanh")

Creates a new AudioModel instance with the specified activation function. Unless otherwise stated, most of the WS AI models use "tanh"

◆ ~AudioModel()

WS::AudioModel::~AudioModel ( )

Destructor for AudioModel.

◆ AudioModel() [2/2]

WS::AudioModel::AudioModel ( const AudioModel )
delete

Member Function Documentation

◆ getBreakPoints()

float * WS::AudioModel::getBreakPoints ( size_t  numBreakPoints)
private

◆ getDenseLocalSize()

size_t WS::AudioModel::getDenseLocalSize ( ) const

Gets the dense local size of the model.

Returns
Dense local size

◆ getFrameLength()

size_t WS::AudioModel::getFrameLength ( ) const

Gets the frame length required for processing.

Returns
Number of samples per frame

◆ getMaxPoolingPoolSize()

size_t WS::AudioModel::getMaxPoolingPoolSize ( ) const

Gets the max pooling pool size.

Returns
Max pooling pool size

◆ getNumberOfFilters()

size_t WS::AudioModel::getNumberOfFilters ( ) const

Gets the number of filters in the model.

Returns
Number of filters

◆ getNumberOfParams()

size_t WS::AudioModel::getNumberOfParams ( ) const

Gets the number of parameters supported by the model.

Returns
Number of parameters

◆ getValidationValues()

float * WS::AudioModel::getValidationValues ( const std::string &  bufferName,
size_t &  filterCnt,
size_t &  sampleCnt 
)

Gets validation values for a specific buffer.

Parameters
bufferNameName of the buffer
filterCntOutput parameter to receive filter count
sampleCntOutput parameter to receive sample count
Returns
Pointer to the validation values array

◆ loadJsonEQParameters()

bool WS::AudioModel::loadJsonEQParameters ( std::string const &  inJsonConfigPathName,
int  samplingRate 
)

Loads EQ parameters from a JSON configuration file.

Parameters
inJsonConfigPathNamePath to the JSON configuration file
samplingRateSample rate of the audio to be processed
Returns
true for success, false otherwise (no EQ effects will be applied on failure)

If EQ effects are to be applied, a JSON formatted config file for the parameters needs to be loaded prior to calling process().

std::string eqConfigFile = "eq_settings.json";
if(!audioModel->loadJsonEQParameters(eqConfigFile, 44100)) {
std::cout << "Warning: Could not load EQ parameters." << std::endl;
}

◆ oneminus()

float WS::AudioModel::oneminus ( float  x)
private

◆ operator=()

AudioModel & WS::AudioModel::operator= ( const AudioModel )
delete

◆ prepare()

bool WS::AudioModel::prepare ( std::string const &  modelName)

Loads and prepares the model for processing.

Parameters
modelNamePath to the model directory
Returns
true if successful, false if the model cannot be found or loaded

Prepare needs to be called once to allocate the proper layers before calling process() multiple times for processing audio frames.

std::string modelPath = "/path/to/model/";
if(!audioModel->prepare(modelPath)) {
std::cout << "Error: Could not prepare the model properly." << std::endl;
return 1;
}

◆ process()

bool WS::AudioModel::process ( const float *  input,
float *  output 
)

Processes audio through the model.

Parameters
inputPointer to input buffer of audio samples (size must match getFrameLength())
outputPointer to output buffer where processed audio will be stored
Returns
true if processing was successful, false otherwise
// Process example
float* inputBuffer = new float[audioModel->getFrameLength()];
float* outputBuffer = new float[audioModel->getFrameLength()];
// Fill inputBuffer with audio samples...
if(audioModel->process(inputBuffer, outputBuffer)) {
// Use processed audio in outputBuffer...
}

◆ setLicense()

bool WS::AudioModel::setLicense ( std::string const &  license)

Adds license.

Parameters
licenseLicense to use

This is just a placeholder for a license checker We need a way to manage the license

◆ setLogger()

void WS::AudioModel::setLogger ( WS::Logger *  logger)

Sets a logger for the model.

Parameters
loggerPointer to a Logger instance

◆ setNewParam()

void WS::AudioModel::setNewParam ( std::string const &  param)

Adds a new parameter to the model.

Parameters
paramName of the parameter

Parameters will be added in order and indexed according to their order:

  • First parameter added is index 0
  • Second parameter added is index 1
  • And so on...

◆ setParamValueAt() [1/4]

void WS::AudioModel::setParamValueAt ( size_t  param,
double  value 
)

Sets the value of a parameter by index.

Parameters
paramIndex of the parameter
valueDouble value to set (0.0 to 1.0 recommended)

◆ setParamValueAt() [2/4]

void WS::AudioModel::setParamValueAt ( size_t  param,
float  value 
)

Sets the value of a parameter by index.

Parameters
paramIndex of the parameter
valueFloat value to set (0.0 to 1.0 recommended)

◆ setParamValueAt() [3/4]

void WS::AudioModel::setParamValueAt ( std::string const &  param,
double  value 
)

Sets the value of a parameter by name.

Parameters
paramName of the parameter
valueDouble value to set (0.0 to 1.0 recommended)

◆ setParamValueAt() [4/4]

void WS::AudioModel::setParamValueAt ( std::string const &  param,
float  value 
)

Sets the value of a parameter by name.

Parameters
paramName of the parameter
valueFloat value to set (0.0 to 1.0 recommended)

◆ softplus()

float WS::AudioModel::softplus ( float  x)
private

Friends And Related Function Documentation

◆ ::AudioModelUT

friend class ::AudioModelUT
friend

Member Data Documentation

◆ mLogger

WS::Logger* WS::AudioModel::mLogger {nullptr}
private

◆ pImpl

Impl* WS::AudioModel::pImpl
private

The documentation for this class was generated from the following file: