![]() |
:)
|
Handles all run-time execution of audio code. More...
#include <RustyAudioEngine.hpp>
Public Member Functions | |
| RustyAudioEngine () | |
| Audio Engine constructor - Handles startup. | |
| ~RustyAudioEngine () | |
| Audio Engine destructor - Handles proper shutdown. | |
| int | audioCallback (const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData) |
| Non-static audio callback. | |
| bool | init () |
| Initialisation function for RustyAudioEngine. | |
| template<typename DSPType > | |
| void | addProcessor (DSPType *dspUnit) |
| Adds a RustyProcessor to signal chain. | |
| void | addSettings (SettingsIO settings) |
| Passes user settings into engine. | |
Static Public Member Functions | |
| static int | audioCallbackWrapper (const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData) |
| Static audio callback. | |
Private Member Functions | |
| bool | initInputDevice (std::string inputDevice) |
| Initialises audio stream to chosen input device. | |
| bool | initOutputDevice (std::string outputDevice) |
| Initialises audio stream to chosen output device. | |
| bool | terminate () |
| Begins audio engine shutdown process. | |
| bool | setupStream () |
| Starts streams when all IO preparation is successful. | |
Private Attributes | |
| PaError | _err |
| PortAudio object to catch PA errors. | |
| PaStream * | _stream |
| PortAudio stream. | |
| PaStreamParameters | _inputParameters |
| PortAudio input parameters. | |
| PaStreamParameters | _outputParameters |
| PortAudio output parameters. | |
| bool | _streaming |
| Keeps track of audio engine streaming state. | |
| RustyUserData * | _data = nullptr |
| Pointer to instance of engine for audioCallback workaround. | |
| SettingsIO | _settings |
| User IO settings object. | |
| std::vector< RustyProcessor * > | _processingUnits |
| A map of all instantiated RustyProcessors in the audio chain. | |
Handles all run-time execution of audio code.
From managing the signal chain to initialising the IO with device drivers. This class handles all things audio.
Makes use of PortAudio to open IO streams to devices and to create an audioCallback() on a high priority interrupt thread.
RustyAudioEngine cannot be instantiated more than once due to the audioCallback from PortAudio's IO stream being static.
Instantiated inside RustyAudioLibAPI as a private member.
Definition at line 57 of file RustyAudioEngine.hpp.
| RustyAudioEngine::RustyAudioEngine | ( | ) |
Audio Engine constructor - Handles startup.
Definition at line 3 of file RustyAudioEngine.cpp.
| RustyAudioEngine::~RustyAudioEngine | ( | ) |
Audio Engine destructor - Handles proper shutdown.
Definition at line 8 of file RustyAudioEngine.cpp.
| int RustyAudioEngine::audioCallback | ( | const void * | inputBuffer, |
| void * | outputBuffer, | ||
| unsigned long | framesPerBuffer, | ||
| const PaStreamCallbackTimeInfo * | timeInfo, | ||
| PaStreamCallbackFlags | statusFlags, | ||
| void * | userData | ||
| ) |
Non-static audio callback.
Non-static audio callback used to perform any manipulation of the audio signal. DSP units are passed audio samples from this function.
Called by static audioCallbackWrapper().
| inputBuffer | Pointer to buffer of input audio samples from PaStream. |
| ouputBuffer | Pointer to buffer of output audio samples to be sent to PaStream. |
| framesPerBuffer | Frames refers to number of samples without multiplying by the number of interweaved samples. |
| timeInfo | Pointer to information about ADC and DAC capture times - Callback is required to meet it's time deadlines. |
| statusFlags | PaStatus flags. |
| userData | Raw pointer to user data. |
Definition at line 22 of file RustyAudioEngine.cpp.
|
static |
Static audio callback.
Static audio callback used as workaround. In current implementation (and seemingly all IO device libraries) the callback function is written in C meaning it is static. This meant I was unable to call members from my non-static RustyAudioEngine class. This wrapper layer allowed for a workaround, by passing a reference to the static function I could essentially trick it into calling non-static member functions. I then use that to call the other audioCallback() function and process audio there.
| inputBuffer | Pointer to buffer of input audio samples from PaStream. |
| ouputBuffer | Pointer to buffer of output audio samples to be sent to PaStream. |
| framesPerBuffer | Frames refers to number of samples without multiplying by the number of interweaved samples. |
| timeInfo | Pointer to information about ADC and DAC capture times - Callback is required to meet it's time deadlines. |
| statusFlags | PaStatus flags. |
| userData | Raw pointer to user data. |
Definition at line 82 of file RustyAudioEngine.cpp.
| bool RustyAudioEngine::init | ( | ) |
Initialisation function for RustyAudioEngine.
Init() function used to initialise audio to chosen IO devices. Opening streams to user selected drivers.
| PortAudioErrors | PortAudio exceptions related to IO streaming and initialisation. |
Definition at line 96 of file RustyAudioEngine.cpp.
|
inline |
Adds a RustyProcessor to signal chain.
Allows user to pass in a pointer to any object that inherits from RustyProcessor. Processor will then be added to the signal chain via the _processingUnit vector.
Realised later on that the template wasn't necessary and I could just use RustyProcessor as the argument but I like static_assert macro to check the type so kept this function as is.
| DSPType | Must be derived from RustyProcessor. |
| INVALID_DSP | Object was not derived from RustyProcessor |
| dspUnit | Adds processor to audio engine signal chain |
Definition at line 158 of file RustyAudioEngine.hpp.
|
inline |
Passes user settings into engine.
User decides their IO devices via the setIO() function, that function eventually results in an object of user settings being handed to the engine.
| settings | SettingsIO object of user IO parameters |
Definition at line 176 of file RustyAudioEngine.hpp.
|
private |
Initialises audio stream to chosen input device.
Creates necessary PortAudio objects and opens a stream to the device with name chosen by user.
| inputDevice | String of users input device |
Definition at line 122 of file RustyAudioEngine.cpp.
|
private |
Initialises audio stream to chosen output device.
Creates necessary PortAudio objects and opens a stream to the device with name chosen by user.
| outputDevice | String of users output device |
Definition at line 153 of file RustyAudioEngine.cpp.
|
private |
Begins audio engine shutdown process.
Shutdowns down PortAudio streams and deletes any allocated data that needs to be removed.
Definition at line 183 of file RustyAudioEngine.cpp.
|
private |
Starts streams when all IO preparation is successful.
Opens stream between users IO devices and audio engine.
Definition at line 205 of file RustyAudioEngine.cpp.
|
private |
PortAudio object to catch PA errors.
Definition at line 225 of file RustyAudioEngine.hpp.
|
private |
PortAudio stream.
Definition at line 226 of file RustyAudioEngine.hpp.
|
private |
PortAudio input parameters.
Definition at line 227 of file RustyAudioEngine.hpp.
|
private |
PortAudio output parameters.
Definition at line 228 of file RustyAudioEngine.hpp.
|
private |
Keeps track of audio engine streaming state.
Definition at line 229 of file RustyAudioEngine.hpp.
|
private |
Pointer to instance of engine for audioCallback workaround.
Definition at line 231 of file RustyAudioEngine.hpp.
|
private |
User IO settings object.
Definition at line 232 of file RustyAudioEngine.hpp.
|
private |
A map of all instantiated RustyProcessors in the audio chain.
Definition at line 234 of file RustyAudioEngine.hpp.