sdr::PortSource< Scalar > Class Template Reference
Data sources.

PortAudio input stream as a `Source`. More...

`#include <portaudio.hh>`

Inheritance diagram for sdr::PortSource< Scalar >:

## Public Member Functions

| PortSource (double sampleRate, size_t bufferSize, int dev=-1)
| Constructor. More...
virtual | ~PortSource ()
| Destructor. More...
void | next ()
| Reads (blocking) the next buffer from the PortAudio stream. More...
int | deviceIndex () const
| Returns the currently selected input device. More...
void | setDeviceIndex (int idx=-1)
| Selects the input device, throws a `ConfigError` exception if the device can not be setup as an input device. More...
bool | hasSampleRate (double sampleRate)
| Checks if the given sample rate is supported by the device. More...
void | setSampleRate (double sampleRate)
| Resets the sample rate of the input device. More...
Public Member Functions inherited from sdr::Source
| Source ()
| Constructor. More...
virtual | ~Source ()
| Destructor. More...
virtual void | send (const RawBuffer &buffer, bool allow_overwrite=false)
| Sends the given buffer to all connected sinks. More...
void | connect (SinkBase *sink, bool direct=false)
| Connect this source to a sink. More...
void | disconnect (SinkBase *sink)
| Disconnect a sink again. More...
virtual void | setConfig (const Config &config)
| Stores the configuration and propergates it if the configuration has been changed. More...
virtual double | sampleRate () const
| Returns the configured sample rate or `0` otherwise. More...
virtual Config::Type | type () const
| Returns the configured source type or `Config::Type_UNDEFINED` otherwise. More...
template<class T >
void | addEOS (T *instance, void(T::*function)())
| Adds a callback to the end-of-stream signal of the source. More...

## Protected Member Functions

void | _initializeStream (int idx=-1)
| Device setup. More...
Protected Member Functions inherited from sdr::Source
void | signalEOS ()
| Signals the EOS. More...
void | propagateConfig (const Config &config)
| Propagates the given configuration to all connected sinks. More...

## Protected Attributes

bool | _streamIsOpen
| If true, the PortAudio stream, `_stream` is open. More...
PaStream * | _stream
| The PortAudio input stream. More...
PaSampleFormat | _fmt
| The current format of the PortAudio stream. More...
double | _sampleRate
| The current sample rate. More...
int | _deviceIndex
| The current input device index. More...
bool | _is_real
| If `true`, the input stream is real (1 chanel), otherwise complex (2 chanels). More...
Buffer< Scalar > | _buffer
| The output buffer. More...
Protected Attributes inherited from sdr::Source
Config | _config
| Holds the source configuration, this can be updated by calling `setConfig`. More...
std::map< SinkBase *, bool > | _sinks
| The connected sinks. More...
std::list< DelegateInterface * > | _eos
| The connected EOS singal handlers. More...

## Detailed Description

### template<class Scalar>
class sdr::PortSource< Scalar >

PortAudio input stream as a `Source`.

## Constructor & Destructor Documentation

template<class Scalar >

sdr::PortSource< Scalar >::PortSource | ( | double | sampleRate,
|  | size_t | bufferSize,
|  | int | dev = `-1`
| ) |  |

inline

Constructor.

template<class Scalar >

virtual sdr::PortSource< Scalar >::~PortSource | ( |  | ) |

inlinevirtual

Destructor.

## Member Function Documentation

template<class Scalar >

void sdr::PortSource< Scalar >::_initializeStream | ( | int | idx = `-1` | ) |

inlineprotected

Device setup.

template<class Scalar >

int sdr::PortSource< Scalar >::deviceIndex | ( |  | ) | const

inline

Returns the currently selected input device.

template<class Scalar >

bool sdr::PortSource< Scalar >::hasSampleRate | ( | double | sampleRate | ) |

inline

Checks if the given sample rate is supported by the device.

template<class Scalar >

void sdr::PortSource< Scalar >::next | ( |  | ) |

inline

Reads (blocking) the next buffer from the PortAudio stream.

This function can be connected to the idle event of the `Queue`.

Todo:
  Signal loss of samples in debug mode.

Bug:
  Drop data if output buffer is in use.

template<class Scalar >

void sdr::PortSource< Scalar >::setDeviceIndex | ( | int | idx = `-1` | ) |

inline

Selects the input device, throws a `ConfigError` exception if the device can not be setup as an input device.

Do not call this function, while the `Queue` is running.

template<class Scalar >

void sdr::PortSource< Scalar >::setSampleRate | ( | double | sampleRate | ) |

inline

Resets the sample rate of the input device.

Do not call this function, while the `Queue` is running.

## Member Data Documentation

template<class Scalar >

Buffer<Scalar> sdr::PortSource< Scalar >::_buffer

protected

The output buffer.

template<class Scalar >

int sdr::PortSource< Scalar >::_deviceIndex

protected

The current input device index.

template<class Scalar >

PaSampleFormat sdr::PortSource< Scalar >::_fmt

protected

The current format of the PortAudio stream.

template<class Scalar >

bool sdr::PortSource< Scalar >::_is_real

protected

If `true`, the input stream is real (1 chanel), otherwise complex (2 chanels).

template<class Scalar >

double sdr::PortSource< Scalar >::_sampleRate

protected

The current sample rate.

template<class Scalar >

PaStream* sdr::PortSource< Scalar >::_stream

protected

The PortAudio input stream.

template<class Scalar >

bool sdr::PortSource< Scalar >::_streamIsOpen

protected

If true, the PortAudio stream, `_stream` is open.

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

- /Users/hannes/Uni/Elektronik/sdr/libsdr/src/portaudio.hh