NAP
Public Member Functions | List of all members
PortAudioService Class Referencefinal

#include <audio/service/portaudioservice.h>

Public Member Functions

 PortAudioService (ServiceConfiguration *configuration)
 
 ~PortAudioService ()=default
 
void registerObjectCreators (rtti::Factory &factory) override
 
bool init (nap::utility::ErrorState &errorState) override
 
void shutdown () override
 
void preShutdown () override
 
NodeManagergetNodeManager ()
 
bool getAllowChannelCountFailure ()
 
unsigned int getHostApiCount ()
 
const PaHostApiInfo & getHostApiInfo (unsigned int hostApiIndex)
 
std::vector< const PaHostApiInfo * > getHostApis ()
 
std::string getHostApiName (unsigned int hostApiIndex)
 
unsigned int getDeviceCount (unsigned int hostApiIndex)
 
const PaDeviceInfo & getDeviceInfo (unsigned int hostApiIndex, unsigned int localDeviceIndex)
 
const PaDeviceInfo & getDeviceInfo (unsigned int deviceIndex)
 
std::vector< const PaDeviceInfo * > getDevices (unsigned int hostApiIndex)
 
void printDevices ()
 
std::string getDeviceName (unsigned int hostApiIndex, unsigned int localDeviceIndex)
 
int getInputDeviceIndex (int hostApiIndex, const std::string &device)
 
int getOutputDeviceIndex (int hostApiIndex, const std::string &device)
 
int getDeviceIndex (int hostApiIndex, int hostApiDeviceIndex)
 
int getHostApiIndex (const std::string &hostApi)
 
int getCurrentHostApiIndex () const
 
int getCurrentInputDeviceIndex () const
 
int getCurrentOutputDeviceIndex () const
 
int getCurrentBufferSize () const
 
bool openStream (const PortAudioServiceConfiguration::DeviceSettings &settings, utility::ErrorState &errorState)
 
const PortAudioServiceConfiguration::DeviceSettingsgetDeviceSettings () const
 
bool closeStream (utility::ErrorState &errorState)
 
bool start (utility::ErrorState &errorState)
 
bool stop (utility::ErrorState &errorState)
 
bool isOpened ()
 
bool isActive ()
 
const std::string & getErrorMessage () const
 
- Public Member Functions inherited from Service
UNPREFIXED_MODULE_NAME_INPUTCASE Service (ServiceConfiguration *configuration)
 
virtual void getDependentServices (std::vector< rtti::TypeInfo > &dependencies) override
 
virtual void update (double deltaTime) override
 
 Service (ServiceConfiguration *configuration)
 
virtual ~Service ()
 
CoregetCore ()
 
const CoregetCore () const
 
std::string getTypeName () const
 
const ModulegetModule () const
 
 Service (Service &)=delete
 
Serviceoperator= (const Service &)=delete
 
 Service (Service &&)=delete
 
Serviceoperator= (Service &&)=delete
 

Additional Inherited Members

- Protected Member Functions inherited from Service
virtual void getDependentServices (std::vector< rtti::TypeInfo > &dependencies)
 
virtual void created ()
 
virtual void preUpdate (double deltaTime)
 
virtual void update (double deltaTime)
 
virtual void postUpdate (double deltaTime)
 
virtual void preResourcesLoaded ()
 
virtual void postResourcesLoaded ()
 
template<typename SERVICE_CONFIG >
SERVICE_CONFIG * getConfiguration ()
 
template<typename SERVICE_CONFIG >
const SERVICE_CONFIG * getConfiguration () const
 
std::string getIniFilePath () const
 
std::string getIniFilePath (const std::string &appendix) const
 

Description

Service that provides audio input and output processing directly for hardware audio devices. Provides static methods to poll the current system for available audio devices using portaudio.

Inheritance diagram for PortAudioService:
[legend]
Collaboration diagram for PortAudioService:
[legend]

Constructor & Destructor Documentation

◆ PortAudioService()

PortAudioService ( ServiceConfiguration configuration)

◆ ~PortAudioService()

~PortAudioService ( )
default

Member Function Documentation

◆ closeStream()

bool closeStream ( utility::ErrorState errorState)

Closes the current stream. Assumes that it has been opened successfully.

Returns
true on success.

◆ getAllowChannelCountFailure()

bool getAllowChannelCountFailure ( )
Returns
: returns wether we will allow input and output channel numbers that exceed the current device's maximum channel counts. If so zero signals will be returned for non-existing input channel numbers. If not initialization will fail.

◆ getCurrentBufferSize()

int getCurrentBufferSize ( ) const
Returns
the current buffer size.

◆ getCurrentHostApiIndex()

int getCurrentHostApiIndex ( ) const
Returns
the index of the host API that is currently being used.

◆ getCurrentInputDeviceIndex()

int getCurrentInputDeviceIndex ( ) const
Returns
the index of the current input device.

◆ getCurrentOutputDeviceIndex()

int getCurrentOutputDeviceIndex ( ) const
Returns
the index of the current output device.

◆ getDeviceCount()

unsigned int getDeviceCount ( unsigned int  hostApiIndex)
Parameters
hostApiIndexthe number of the host api
Returns
: the number of all available audio devices for a certain host api, the total number contains both input and output devices separately.

◆ getDeviceIndex()

int getDeviceIndex ( int  hostApiIndex,
int  hostApiDeviceIndex 
)

Returns the device index for a device specified by a local index in the list of devices for a specific host API. Returns -1 if the specified device was not found.

◆ getDeviceInfo() [1/2]

const PaDeviceInfo& getDeviceInfo ( unsigned int  deviceIndex)

Returns information of an audio device in a PaDeviceInfo struct defined by portaudio.

Parameters
deviceIndexthe index of the device.
Returns
reference to a record containing information about the given device

◆ getDeviceInfo() [2/2]

const PaDeviceInfo& getDeviceInfo ( unsigned int  hostApiIndex,
unsigned int  localDeviceIndex 
)

Returns information of an audio device in a PaDeviceInfo struct defined by portaudio.

Parameters
hostApiIndexthe number of the host api
localDeviceIndexthe number of the device counting from 0 to the number of devices belonging to this host api.
Returns
reference to a record containing information about the given device

◆ getDeviceName()

std::string getDeviceName ( unsigned int  hostApiIndex,
unsigned int  localDeviceIndex 
)
Parameters
hostApiIndexthe number of the host api
localDeviceIndexthe number of the devie within the host api
Returns
the name of an available device specified by host api and device number

◆ getDevices()

std::vector<const PaDeviceInfo*> getDevices ( unsigned int  hostApiIndex)

Returns information on all the available devices for a given host API

Parameters
hostApiIndexthe number of the host api
Returns
vector with pointers to records containing information about each device.

◆ getDeviceSettings()

const PortAudioServiceConfiguration::DeviceSettings& getDeviceSettings ( ) const

Returns const ref to current device settings used by service

Returns
const ref to current device settings used by service

◆ getErrorMessage()

const std::string& getErrorMessage ( ) const
Returns
Error message from last call to openStream() in case it was unsuccessful.

◆ getHostApiCount()

unsigned int getHostApiCount ( )
Returns
: the number of available host APIs ont this system

◆ getHostApiIndex()

int getHostApiIndex ( const std::string &  hostApi)

Seatch for the index of a host API by name. Uses case insensitive search.

Returns
the index for a certain host API specified both by name. Returns -1 if the host api specified was not found.

◆ getHostApiInfo()

const PaHostApiInfo& getHostApiInfo ( unsigned int  hostApiIndex)

Returns information about a given host api

Parameters
hostApiIndex
Returns
: struct containing information about the specified host api

◆ getHostApiName()

std::string getHostApiName ( unsigned int  hostApiIndex)
Returns
: name of the specified host API

◆ getHostApis()

std::vector<const PaHostApiInfo*> getHostApis ( )
Returns
information on all available host apis

◆ getInputDeviceIndex()

int getInputDeviceIndex ( int  hostApiIndex,
const std::string &  device 
)

Lookups the index for an input device with a certain name on a host API.

Parameters
hostApiIndexindex of the host API
devicename of the input device
Returns
the device index for a device specified by name for a given host API . Uses case insensitive search. Returns -1 if the device specified was not found.

◆ getNodeManager()

NodeManager& getNodeManager ( )
Returns
the audio node manager owned by the audio service. The NodeManager contains a node system that performs all the DSP.

◆ getOutputDeviceIndex()

int getOutputDeviceIndex ( int  hostApiIndex,
const std::string &  device 
)

Lookups the index for an output device with a certain name on a host API.

Parameters
hostApiIndexindex of the host API
devicename of the output device
Returns
the device index for a device specified by name for a given host API . Uses case insensitive search. Returns -1 if the device specified was not found.

◆ init()

bool init ( nap::utility::ErrorState errorState)
overridevirtual

Initializes portaudio.

Reimplemented from Service.

◆ isActive()

bool isActive ( )
Returns
Whether the audio stream is currently running and not been paused.

◆ isOpened()

bool isOpened ( )
Returns
Whether the audio stream is succesfully initialized

◆ openStream()

bool openStream ( const PortAudioServiceConfiguration::DeviceSettings settings,
utility::ErrorState errorState 
)

Stores the device settings and tries to open audio stream with given device settings, return true on succes The meesage from the errorState will be stored and can be retrieved using AudioService::getErrorMessage()

Parameters
settingsconst ref to DeviceSettings struct
errorStatecontains any errors
Returns
true on success

◆ preShutdown()

void preShutdown ( )
overridevirtual

Called before shutting down the services. Stops the running audio stream if any.

Reimplemented from Service.

◆ printDevices()

void printDevices ( )

Prints the number and name of all available audio devices to the console

◆ registerObjectCreators()

void registerObjectCreators ( rtti::Factory factory)
overridevirtual

Register specific object creators

Reimplemented from Service.

◆ shutdown()

void shutdown ( )
overridevirtual

Called on shutdown of the service. Closes portaudio stream and shuts down portaudio.

Reimplemented from Service.

◆ start()

bool start ( utility::ErrorState errorState)

Restart the audio stream after it has been stopped by calling stop(). Logs errors in the errorState. Assumes the stream has been opened succesfully.

Returns
true on success

◆ stop()

bool stop ( utility::ErrorState errorState)

Stops the audio stream, waits for any running audio callback before returning. Logs errors in the errorState. Assumes the stream has been opened succesfully.

Returns
true on success