Workbench Library  0.1b
Audio

Audio system initialization and deinitialization for Workbench applications. More...

Typedefs

typedef SAMPLE AudioSample_t
 Defines AudioSample_t as the type for audio samples. More...
 
typedef void(* AudioCallback) (const void *, void *, unsigned long, void *)
 Type definition for audio callback functions. More...
 

Functions

void audio_init ()
 Initializes the audio system. More...
 
void audio_deinit ()
 Deinitializes the audio system. More...
 

Detailed Description

Audio system initialization and deinitialization for Workbench applications.

This header file defines functions for initializing and deinitializing the audio system using the PortAudio library. It includes the type definition for audio callback functions that are used to process audio data.

The audio_init function sets up and starts the audio stream based on configuration settings, while the audio_deinit function stops and closes the audio stream, and terminates the PortAudio library.

Typedef Documentation

◆ AudioCallback

typedef void(* AudioCallback) (const void *, void *, unsigned long, void *)

Type definition for audio callback functions.

An AudioCallback function is called during audio processing to handle input and output audio buffers. It takes the following parameters:

  • input_buffer: A pointer to the input audio buffer.
  • output_buffer: A pointer to the output audio buffer.
  • block_size: The number of frames in the buffer.
  • user_data: A pointer to user-defined data passed to the callback function.

Example usage:

void my_audio_callback(const void *input_buffer, void *output_buffer,
unsigned long block_size, void *user_data) {
const float *in = (const float *)input_buffer;
float *out = (float *)output_buffer;
for (unsigned long i = 0; i < block_size; ++i) {
*out++ = in[i];
}
}

◆ AudioSample_t

Defines AudioSample_t as the type for audio samples.

This typedef defines AudioSample_t to be the type corresponding to SAMPLE_FORMAT. For example, if SAMPLE_FORMAT is paFloat32, AudioSample_t will be defined as float.

Function Documentation

◆ audio_deinit()

void audio_deinit ( )

Deinitializes the audio system.

This function stops and closes the audio stream, and then terminates the PortAudio library. It logs any errors that occur during the deinitialization process.

◆ audio_init()

void audio_init ( )

Initializes the audio system.

This function initializes the PortAudio library, sets up the audio input and output devices based on the configuration settings, and starts the audio stream. It also configures the audio stream parameters such as sample rate, block size, and channel counts.

If an error occurs during initialization, it logs the error message and deinitializes the audio system.