1 #ifndef __SDR_PORTAUDIO_HH__
2 #define __SDR_PORTAUDIO_HH__
61 template <
class Scalar>
102 PaStreamParameters params;
104 params.channelCount =
_is_real ? 1 : 2;
105 params.sampleFormat =
_fmt;
106 params.hostApiSpecificStreamInfo = 0;
107 return paFormatIsSupported == Pa_IsFormatSupported(¶ms, 0, sampleRate);
126 switch (Config::typeId<Scalar>()) {
147 err <<
"Can not configure PortAudio sink: Unsupported format " << Config::typeId<Scalar>()
156 _deviceIndex = idx < 0 ? Pa_GetDefaultInputDevice() : idx;
157 PaStreamParameters params;
159 params.channelCount = numCh;
160 params.sampleFormat =
_fmt;
161 params.suggestedLatency = Pa_GetDeviceInfo(
_deviceIndex)->defaultHighInputLatency;
162 params.hostApiSpecificStreamInfo = 0;
170 err <<
"Can not open PortAudio input stream!";
throw err;
178 msg <<
"Configure PortAudio source: " << std::endl
181 <<
" format " << Config::typeId<Scalar>() << std::endl
182 <<
" num chanels " << numCh;
209 #endif // __SDR_PORTAUDIO_HH__
void _initializeStream(int idx=-1)
Device setup.
Definition: portaudio.hh:119
static bool hasInputStream(int idx)
Returns true of the given device provides an input chanel.
Definition: portaudio.cc:35
A collection of configuration information that is send by a source to all connected sinks to properga...
Definition: node.hh:35
Complex (aka I/Q) type of 32bit floats aka. std::complex.
Definition: node.hh:51
PortAudio playback node.
Definition: portaudio.hh:38
Base class of all buffers, represents an untyped array of bytes.
Definition: buffer.hh:32
bool _streamIsOpen
If true, the PortAudio stream, _stream is open.
Definition: portaudio.hh:192
static int defaultOutputDevice()
Returns the index of the default output device.
Definition: portaudio.cc:30
bool _is_real
If true, the input stream is real (1 chanel), otherwise complex (2 chanels).
Definition: portaudio.hh:202
Real signed 16b ints.
Definition: node.hh:44
virtual void send(const RawBuffer &buffer, bool allow_overwrite=false)
Sends the given buffer to all connected sinks.
Definition: node.cc:67
static void init()
Initializes the PortAudio system, must be called first.
Definition: portaudio.cc:10
Complex (aka I/Q) type of unsigned 16b ints.
Definition: node.hh:49
Definition: autocast.hh:8
static int numDevices()
Returns the number of devices available.
Definition: portaudio.cc:20
Generic source class.
Definition: node.hh:213
PaStream * _stream
The PortAudio input stream.
Definition: portaudio.hh:194
static std::string deviceName(int idx)
Returns the device name.
Definition: portaudio.cc:47
void next()
Reads (blocking) the next buffer from the PortAudio stream.
Definition: portaudio.hh:84
Buffer< Scalar > _buffer
The output buffer.
Definition: portaudio.hh:204
virtual void handleBuffer(const RawBuffer &buffer, bool allow_overwrite)
Playback.
Definition: portaudio.cc:152
size_t size() const
Returns the number of elements of type T in this buffer.
Definition: buffer.hh:166
virtual double sampleRate() const
Returns the configured sample rate or 0 otherwise.
Definition: node.cc:122
Real unsigned 16b ints.
Definition: node.hh:43
double _sampleRate
The current sample rate.
Definition: portaudio.hh:198
virtual void setConfig(const Config &config)
Stores the configuration and propergates it if the configuration has been changed.
Definition: node.cc:98
static bool hasOutputStream(int idx)
Returns true of the given device provides an output chanel.
Definition: portaudio.cc:41
virtual void config(const Config &src_cfg)
Configures the PortAudio output.
Definition: portaudio.cc:70
size_t _frame_size
The frame-size.
Definition: portaudio.hh:55
void setDeviceIndex(int idx=-1)
Selects the input device, throws a ConfigError exception if the device can not be setup as an input d...
Definition: portaudio.hh:96
int _deviceIndex
The current input device index.
Definition: portaudio.hh:200
PaStream * _stream
The PortAudio stream.
Definition: portaudio.hh:53
static void terminate()
Shutdown.
Definition: portaudio.cc:15
void setSampleRate(double sampleRate)
Resets the sample rate of the input device.
Definition: portaudio.hh:112
void log(const LogMessage &message)
Logs a message.
Definition: logger.cc:100
PortAudio input stream as a Source.
Definition: portaudio.hh:62
"Namespace" to collect all static, PortAudio related functions.
Definition: portaudio.hh:14
bool hasSampleRate(double sampleRate)
Checks if the given sample rate is supported by the device.
Definition: portaudio.hh:101
PaSampleFormat _fmt
The current format of the PortAudio stream.
Definition: portaudio.hh:196
static Logger & get()
Returns the singleton instance of the logger.
Definition: logger.cc:89
Real 32b floats aka. "float".
Definition: node.hh:45
The configuration error class.
Definition: exception.hh:24
A log message.
Definition: logger.hh:22
static int defaultInputDevice()
Returns the index of the default input device.
Definition: portaudio.cc:25
Basic interface of all Sinks.
Definition: node.hh:174
virtual ~PortSource()
Destructor.
Definition: portaudio.hh:75
char * ptr() const
Returns the pointer to the data (w/o view).
Definition: buffer.hh:67
Complex (aka I/Q) type of signed 16b ints.
Definition: node.hh:50
void unref()
Dereferences the buffer.
Definition: buffer.cc:63
PortSource(double sampleRate, size_t bufferSize, int dev=-1)
Constructor.
Definition: portaudio.hh:66
PortSink()
Constructor.
Definition: portaudio.cc:57
virtual ~PortSink()
Destructor.
Definition: portaudio.cc:63
int deviceIndex() const
Returns the currently selected input device.
Definition: portaudio.hh:92