Discman
Loading...
Searching...
No Matches
AudioOutput< T > Class Template Reference

Abstracts PortAudio using a given audio sample data type. More...

#include <audio_output.h>

Inheritance diagram for AudioOutput< T >:
Collaboration diagram for AudioOutput< T >:

Static Public Member Functions

static AudioOutputinstance ()
 Factory method to return the AudioOutput. It may be called one or more times. Be sure to destroy() the instance in order to avoid leaks. It is suggested to do so in the teardown of the first caller.
 
static void init ()
 Initializes PortAudio.
 
static void destroy ()
 Tears down PortAudio.
 
static void restart ()
 Restarts PortAudio.
 
static void start ()
 Starts the invokation of the PortAudio callback.
 
static void stop ()
 Stops the invokation of the PortAudio callback.
 
static bool isDefault ()
 Returns whether the default audio output device is used. This indicates that a Bluetooth device is not being used. The default output is typically an audio jack or an HDMI port on the host.
 

Static Public Attributes

static constexpr int SAMPLE_RATE = 44100
 The AudioOutput sample rate, which is matched to the sample rate of CD audio.
 

Static Private Member Functions

static int pa_callback (const void *input_buffer, void *output_buffer, unsigned long frames_per_buffer, const PaStreamCallbackTimeInfo *time_info, PaStreamCallbackFlags status_flags, void *user_data)
 The PortAudio callback.
 

Static Private Attributes

static AudioOutput_instance
 The global AudioOutput instance.
 
static PaError _pa_error
 The most recent PortAudio error.
 
static PaStream * _pa_stream
 The PortAudio stream.
 

Additional Inherited Members

- Public Member Functions inherited from Consumer< T >
 Consumer ()
 Consumer constructor.
 
virtual ~Consumer ()
 Consumer destructor.
 
virtual void producer (Producer< T > *const producer)
 Sets the producer from which to retrieve data.
 
- Protected Member Functions inherited from Consumer< T >
consume () const
 Returns one datum from the producer.
 

Detailed Description

template<typename T>
class AudioOutput< T >

Abstracts PortAudio using a given audio sample data type.

See also
Producer/Consumer.
Template Parameters
TThe audio sample format. Must be int16_t or float.

Definition at line 20 of file audio_output.h.

Member Function Documentation

◆ destroy()

template<typename T>
void AudioOutput< T >::destroy ( )
static

Tears down PortAudio.

Definition at line 129 of file audio_output.h.

◆ init()

template<typename T>
void AudioOutput< T >::init ( )
static

Initializes PortAudio.

Definition at line 93 of file audio_output.h.

◆ instance()

template<typename T>
AudioOutput< T > * AudioOutput< T >::instance ( )
static

Factory method to return the AudioOutput. It may be called one or more times. Be sure to destroy() the instance in order to avoid leaks. It is suggested to do so in the teardown of the first caller.

Returns
The AudioOutput.

Definition at line 84 of file audio_output.h.

◆ isDefault()

template<typename T>
bool AudioOutput< T >::isDefault ( )
static

Returns whether the default audio output device is used. This indicates that a Bluetooth device is not being used. The default output is typically an audio jack or an HDMI port on the host.

Returns
Whether the default audio output device is used.

Definition at line 181 of file audio_output.h.

◆ pa_callback()

template<typename T>
int AudioOutput< T >::pa_callback ( const void * input_buffer,
void * output_buffer,
unsigned long frames_per_buffer,
const PaStreamCallbackTimeInfo * time_info,
PaStreamCallbackFlags status_flags,
void * user_data )
staticprivate

The PortAudio callback.

See also
PortAudio documentation.
Parameters
[in]input_bufferNot used. Normally used for audio recording.
[in]output_bufferPointer to a buffer of audio samples to be filled. Sent to the audio device upon the method's return.
[in]frames_per_bufferThe number of frames (left + right sample) in the output_buffer.
[in]time_infoNot used.
[in]status_flagsNot used.
[in]user_dataNot used.
Returns
0 for the successful filling of the output_buffer.

Definition at line 186 of file audio_output.h.

◆ restart()

template<typename T>
void AudioOutput< T >::restart ( )
static

Restarts PortAudio.

Definition at line 164 of file audio_output.h.

◆ start()

template<typename T>
void AudioOutput< T >::start ( )
static

Starts the invokation of the PortAudio callback.

Definition at line 146 of file audio_output.h.

◆ stop()

template<typename T>
void AudioOutput< T >::stop ( )
static

Stops the invokation of the PortAudio callback.

Definition at line 155 of file audio_output.h.

Member Data Documentation

◆ _instance

template<typename T>
AudioOutput* AudioOutput< T >::_instance
staticprivate

The global AudioOutput instance.

Definition at line 48 of file audio_output.h.

◆ _pa_error

template<typename T>
PaError AudioOutput< T >::_pa_error
staticprivate

The most recent PortAudio error.

Definition at line 50 of file audio_output.h.

◆ _pa_stream

template<typename T>
PaStream* AudioOutput< T >::_pa_stream
staticprivate

The PortAudio stream.

Definition at line 51 of file audio_output.h.

◆ SAMPLE_RATE

template<typename T>
int AudioOutput< T >::SAMPLE_RATE = 44100
staticconstexpr

The AudioOutput sample rate, which is matched to the sample rate of CD audio.

Definition at line 45 of file audio_output.h.


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