kwave  18.07.70
Kwave::RecordQt Class Reference

#include <Record-Qt.h>

Inheritance diagram for Kwave::RecordQt:
Inheritance graph
Collaboration diagram for Kwave::RecordQt:
Collaboration graph

Signals

void sigCreateRequested (QAudioFormat &format, unsigned int buffer_size)
 
void sigCloseRequested ()
 

Public Member Functions

 RecordQt ()
 
virtual ~RecordQt () Q_DECL_OVERRIDE
 
virtual QString open (const QString &dev) Q_DECL_OVERRIDE
 
virtual Kwave::byte_order_t endianness () Q_DECL_OVERRIDE
 
virtual Kwave::SampleFormat::Format sampleFormat () Q_DECL_OVERRIDE
 
virtual int setSampleFormat (Kwave::SampleFormat::Format new_format) Q_DECL_OVERRIDE
 
virtual QList< Kwave::SampleFormat::FormatdetectSampleFormats () Q_DECL_OVERRIDE
 
virtual int bitsPerSample () Q_DECL_OVERRIDE
 
virtual int setBitsPerSample (unsigned int new_bits) Q_DECL_OVERRIDE
 
virtual QList< unsigned int > supportedBits () Q_DECL_OVERRIDE
 
virtual Kwave::Compression::Type compression () Q_DECL_OVERRIDE
 
virtual int setCompression (Kwave::Compression::Type new_compression) Q_DECL_OVERRIDE
 
virtual QList< Kwave::Compression::TypedetectCompressions () Q_DECL_OVERRIDE
 
virtual double sampleRate () Q_DECL_OVERRIDE
 
virtual int setSampleRate (double &new_rate) Q_DECL_OVERRIDE
 
virtual QList< double > detectSampleRates () Q_DECL_OVERRIDE
 
virtual int tracks () Q_DECL_OVERRIDE
 
virtual int setTracks (unsigned int &tracks) Q_DECL_OVERRIDE
 
virtual int detectTracks (unsigned int &min, unsigned int &max) Q_DECL_OVERRIDE
 
virtual int close () Q_DECL_OVERRIDE
 
virtual int read (QByteArray &buffer, unsigned int offset) Q_DECL_OVERRIDE
 
virtual QStringList supportedDevices () Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::RecordDevice
 RecordDevice ()
 
virtual ~RecordDevice ()
 
virtual QString fileFilter ()
 

Private Slots

void createInMainThread (QAudioFormat &format, unsigned int buffer_size)
 
void closeInMainThread ()
 
void notified ()
 

Private Member Functions

int initialize (unsigned int buffer_size)
 
void scanDevices ()
 
QAudioDeviceInfo deviceInfo (const QString &device) const
 

Private Attributes

QMutex m_lock
 
QMap< QString, QString > m_device_name_map
 
QList< QAudioDeviceInfo > m_available_devices
 
QAudioInput * m_input
 
QIODevice * m_source
 
Kwave::SampleFormat::Format m_sample_format
 
quint8 m_tracks
 
double m_rate
 
Kwave::Compression::Type m_compression
 
unsigned int m_bits_per_sample
 
QString m_device
 
bool m_initialized
 
QSemaphore m_sem
 

Detailed Description

Definition at line 46 of file Record-Qt.h.

Constructor & Destructor Documentation

◆ RecordQt()

Kwave::RecordQt::RecordQt ( )

Constructor

Definition at line 60 of file Record-Qt.cpp.

References closeInMainThread(), Kwave::connect(), createInMainThread(), sigCloseRequested(), and sigCreateRequested().

61  :QObject(Q_NULLPTR),
63  m_lock(QMutex::Recursive),
66  m_input(Q_NULLPTR),
67  m_source(Q_NULLPTR),
69  m_tracks(0),
70  m_rate(0.0),
73  m_device(),
74  m_initialized(false),
75  m_sem(0)
76 {
77  connect(this, SIGNAL(sigCreateRequested(QAudioFormat&,uint)),
78  this, SLOT(createInMainThread(QAudioFormat&,uint)),
79  Qt::BlockingQueuedConnection);
80  connect(this, SIGNAL(sigCloseRequested()),
81  this, SLOT(closeInMainThread()),
82  Qt::BlockingQueuedConnection);
83 }
QIODevice * m_source
Definition: Record-Qt.h:256
QList< QAudioDeviceInfo > m_available_devices
Definition: Record-Qt.h:250
void createInMainThread(QAudioFormat &format, unsigned int buffer_size)
Definition: Record-Qt.cpp:492
bool m_initialized
Definition: Record-Qt.h:277
void sigCloseRequested()
void closeInMainThread()
Definition: Record-Qt.cpp:327
QSemaphore m_sem
Definition: Record-Qt.h:280
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
Kwave::Compression::Type m_compression
Definition: Record-Qt.h:268
unsigned int m_bits_per_sample
Definition: Record-Qt.h:271
Kwave::SampleFormat::Format m_sample_format
Definition: Record-Qt.h:259
void sigCreateRequested(QAudioFormat &format, unsigned int buffer_size)
quint8 m_tracks
Definition: Record-Qt.h:262
QAudioInput * m_input
Definition: Record-Qt.h:253
QString m_device
Definition: Record-Qt.h:274
QMap< QString, QString > m_device_name_map
Definition: Record-Qt.h:247
Here is the call graph for this function:

◆ ~RecordQt()

Kwave::RecordQt::~RecordQt ( )
virtual

Destructor

Definition at line 86 of file Record-Qt.cpp.

References close().

87 {
88  close();
89 }
virtual int close() Q_DECL_OVERRIDE
Definition: Record-Qt.cpp:344
Here is the call graph for this function:

Member Function Documentation

◆ bitsPerSample()

int Kwave::RecordQt::bitsPerSample ( )
virtual

Returns the current resolution in bits per sample or a negative error code if failed

Implements Kwave::RecordDevice.

Definition at line 164 of file Record-Qt.cpp.

References m_bits_per_sample.

165 {
166  return m_bits_per_sample;
167 }
unsigned int m_bits_per_sample
Definition: Record-Qt.h:271

◆ close()

int Kwave::RecordQt::close ( )
virtual

Close the device

Implements Kwave::RecordDevice.

Definition at line 344 of file Record-Qt.cpp.

References closeInMainThread(), m_lock, and sigCloseRequested().

Referenced by open(), setBitsPerSample(), setCompression(), setSampleFormat(), setSampleRate(), setTracks(), and ~RecordQt().

345 {
346  QMutexLocker _lock(&m_lock);
347 
348  if (QThread::currentThread() == qApp->thread())
350  else
351  emit sigCloseRequested();
352 
353  return 0;
354 }
void sigCloseRequested()
void closeInMainThread()
Definition: Record-Qt.cpp:327
Here is the call graph for this function:
Here is the caller graph for this function:

◆ closeInMainThread

void Kwave::RecordQt::closeInMainThread ( )
privateslot

handles the request to close the device, running in the context of the main thread

Definition at line 327 of file Record-Qt.cpp.

References m_initialized, m_input, and m_source.

Referenced by close(), and RecordQt().

328 {
329  if (m_source) {
330  m_source->close();
331  m_source = Q_NULLPTR;
332  }
333  if (m_input) {
334  m_input->stop();
335  m_input->reset();
336  delete m_input;
337  m_input = Q_NULLPTR;
338  }
339 
340  m_initialized = false;
341 }
QIODevice * m_source
Definition: Record-Qt.h:256
bool m_initialized
Definition: Record-Qt.h:277
QAudioInput * m_input
Definition: Record-Qt.h:253
Here is the caller graph for this function:

◆ compression()

Kwave::Compression::Type Kwave::RecordQt::compression ( )
virtual

Returns the current compression type (0==none)

Implements Kwave::RecordDevice.

Definition at line 201 of file Record-Qt.cpp.

References m_compression.

202 {
203  return m_compression;
204 }
Kwave::Compression::Type m_compression
Definition: Record-Qt.h:268

◆ createInMainThread

void Kwave::RecordQt::createInMainThread ( QAudioFormat &  format,
unsigned int  buffer_size 
)
privateslot

handles the request to create the device, running in the context of the main thread

Parameters
formatreference to the audio format specification
buffer_sizesize of the audio buffer in bytes

Definition at line 492 of file Record-Qt.cpp.

References BUFFER_SIZE_OVERCOMMIT, Kwave::connect(), m_input, m_lock, m_sem, m_source, and notified().

Referenced by initialize(), and RecordQt().

494 {
495  QMutexLocker _lock(&m_lock);
496 
497  // reset the semaphore to zero
498  m_sem.acquire(m_sem.available());
499 
500  // create a new audio device for the selected format
501  m_input = new QAudioInput(format, this);
502  Q_ASSERT(m_input);
503  if (!m_input) return;
504  connect(m_input, SIGNAL(notify()), this, SLOT(notified()));
505 
506  // set the buffer size, before starting to record
507  m_input->setBufferSize(buffer_size * BUFFER_SIZE_OVERCOMMIT);
508 
509  // start recording engine
510  m_source = m_input->start();
511 }
QIODevice * m_source
Definition: Record-Qt.h:256
QSemaphore m_sem
Definition: Record-Qt.h:280
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
QAudioInput * m_input
Definition: Record-Qt.h:253
#define BUFFER_SIZE_OVERCOMMIT
Definition: Record-Qt.cpp:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ detectCompressions()

QList< Kwave::Compression::Type > Kwave::RecordQt::detectCompressions ( )
virtual

Gets a list of supported compression types. If no compression is supported, the list might be empty.

Implements Kwave::RecordDevice.

Definition at line 217 of file Record-Qt.cpp.

References Kwave::Compression::NONE.

218 {
219  QList<Kwave::Compression::Type> list;
220  list.append(Kwave::Compression::NONE);
221  return list;
222 }

◆ detectSampleFormats()

QList< Kwave::SampleFormat::Format > Kwave::RecordQt::detectSampleFormats ( )
virtual

Gets a list of supported sample formats.

Note
this depends on the current setting of the compression!

Implements Kwave::RecordDevice.

Definition at line 107 of file Record-Qt.cpp.

References deviceInfo(), Kwave::SampleFormat::Float, m_device, m_lock, Kwave::SampleFormat::Signed, and Kwave::SampleFormat::Unsigned.

108 {
109  QList<Kwave::SampleFormat::Format> list;
110  QMutexLocker _lock(&m_lock); // context: main thread
111 
112  const QAudioDeviceInfo info(deviceInfo(m_device));
113 
114  // no devices at all -> empty
115  if (info.isNull()) return list;
116 
117  // iterate over all supported bits per sample
118  foreach (QAudioFormat::SampleType t, info.supportedSampleTypes()) {
119  switch (t) {
120  case QAudioFormat::SignedInt:
121  list.append(Kwave::SampleFormat::Signed);
122  break;
123  case QAudioFormat::UnSignedInt:
124  list.append(Kwave::SampleFormat::Unsigned);
125  break;
126  case QAudioFormat::Float:
127  list.append(Kwave::SampleFormat::Float);
128  break;
129  default:
130  break;
131  }
132  }
133 
134  return list;
135 }
QString m_device
Definition: Record-Qt.h:274
QAudioDeviceInfo deviceInfo(const QString &device) const
Definition: Record-Qt.cpp:304
Here is the call graph for this function:

◆ detectSampleRates()

QList< double > Kwave::RecordQt::detectSampleRates ( )
virtual

get a list of supported sample rates

Implements Kwave::RecordDevice.

Definition at line 241 of file Record-Qt.cpp.

References deviceInfo(), m_device, and m_lock.

242 {
243  QList<double> list;
244  QMutexLocker _lock(&m_lock); // context: main thread
245 
246  const QAudioDeviceInfo info(deviceInfo(m_device));
247 
248  // no devices at all -> empty
249  if (info.isNull()) return list;
250 
251  // iterate over all supported sample sizes
252  foreach (int rate, info.supportedSampleRates()) {
253  if (rate <= 0) continue;
254  list.append(static_cast<double>(rate));
255  }
256 
257  std::sort(list.begin(), list.end(), std::less<double>());
258  return list;
259 }
QString m_device
Definition: Record-Qt.h:274
QAudioDeviceInfo deviceInfo(const QString &device) const
Definition: Record-Qt.cpp:304
Here is the call graph for this function:

◆ detectTracks()

int Kwave::RecordQt::detectTracks ( unsigned int &  min,
unsigned int &  max 
)
virtual

Detect the minimum and maximum number of tracks. If the detection fails, minimum and maximum are set to zero.

Parameters
minreceives the lowest supported number of tracks
maxreceives the highest supported number of tracks
Returns
zero or positive if ok, negative error number if failed

Implements Kwave::RecordDevice.

Definition at line 279 of file Record-Qt.cpp.

References deviceInfo(), m_device, m_lock, and Kwave::toUint().

280 {
281  QMutexLocker _lock(&m_lock); // context: main thread
282 
283  const QAudioDeviceInfo info(deviceInfo(m_device));
284 
285  max = std::numeric_limits<unsigned int>::min();
286  min = std::numeric_limits<unsigned int>::max();
287 
288  // no devices at all -> empty
289  if (info.isNull()) return -1;
290 
291  // iterate over all supported sample sizes
292  foreach (int channels, info.supportedChannelCounts()) {
293  if (channels <= 0) continue;
294  unsigned int c = Kwave::toUint(channels);
295  if (c < 1) continue;
296  if (c < min) min = c;
297  if (c > max) max = c;
298  }
299 
300  return (max > 0) ? max : -1;
301 }
unsigned int toUint(T x)
Definition: Utils.h:109
QString m_device
Definition: Record-Qt.h:274
QAudioDeviceInfo deviceInfo(const QString &device) const
Definition: Record-Qt.cpp:304
Here is the call graph for this function:

◆ deviceInfo()

QAudioDeviceInfo Kwave::RecordQt::deviceInfo ( const QString &  device) const
private

Gets the full device info of a playback device, identified by the device name.

Parameters
devicename of the device or empty string for default
Returns
a QAudioDeviceInfo

Definition at line 304 of file Record-Qt.cpp.

References DEFAULT_DEVICE, m_available_devices, and m_device_name_map.

Referenced by detectSampleFormats(), detectSampleRates(), detectTracks(), endianness(), initialize(), open(), and supportedBits().

305 {
306  // check for default device
307  if (!device.length() || (device == DEFAULT_DEVICE))
308  return QAudioDeviceInfo::defaultInputDevice();
309 
310  // check if the device name is known
311  if (m_device_name_map.isEmpty() || !m_device_name_map.contains(device))
312  return QAudioDeviceInfo();
313 
314  // translate the path into a Qt audio output device name
315  // iterate over all available devices
316  const QString dev_name = m_device_name_map[device];
317  foreach (const QAudioDeviceInfo &dev, m_available_devices) {
318  if (dev.deviceName() == dev_name)
319  return QAudioDeviceInfo(dev);
320  }
321 
322  // fallen through: return empty info
323  return QAudioDeviceInfo();
324 }
QList< QAudioDeviceInfo > m_available_devices
Definition: Record-Qt.h:250
#define DEFAULT_DEVICE
Definition: Record-Qt.cpp:48
QMap< QString, QString > m_device_name_map
Definition: Record-Qt.h:247
Here is the caller graph for this function:

◆ endianness()

Kwave::byte_order_t Kwave::RecordQt::endianness ( )
virtual

Returns the current endianness (big/little)

Implements Kwave::RecordDevice.

Definition at line 138 of file Record-Qt.cpp.

References Kwave::BigEndian, deviceInfo(), Kwave::LittleEndian, m_device, m_lock, and Kwave::UnknownEndian.

139 {
141  QMutexLocker _lock(&m_lock); // context: main thread
142 
143  const QAudioDeviceInfo info(deviceInfo(m_device));
144 
145  // no devices at all -> empty
146  if (info.isNull()) return byte_order;
147 
148  // iterate over all supported bits per sample
149  switch (info.preferredFormat().byteOrder()) {
151  byte_order = Kwave::LittleEndian;
152  break;
154  byte_order = Kwave::BigEndian;
155  break;
156  default:
157  break;
158  }
159 
160  return byte_order;
161 }
byte_order_t
Definition: ByteOrder.h:25
QString m_device
Definition: Record-Qt.h:274
QAudioDeviceInfo deviceInfo(const QString &device) const
Definition: Record-Qt.cpp:304
Here is the call graph for this function:

◆ initialize()

int Kwave::RecordQt::initialize ( unsigned int  buffer_size)
private

Initialize the audio device with current parameters and prepare it for recording.

Parameters
buffer_sizesize of the audio buffer in bytes
Returns
zero on success or negative error code -EINVAL or -EIO

Definition at line 432 of file Record-Qt.cpp.

References _, createInMainThread(), deviceInfo(), m_bits_per_sample, m_device, m_rate, m_tracks, sigCreateRequested(), and Kwave::toInt().

Referenced by read().

433 {
434  // do sanity checks of the current parameters, otherwise Qt crashes
435  // with floating point errors or similar
436  if (m_rate < 1.0) return -EINVAL;
437  if (m_bits_per_sample < 1) return -EINVAL;
438  if (m_tracks < 1) return -EINVAL;
439  if (!m_device.length()) return -EINVAL;
440 
441  const QAudioDeviceInfo info(deviceInfo(m_device));
442 
443  // find a supported sample format
444  const QAudioFormat preferred_format(info.preferredFormat());
445  QAudioFormat format(preferred_format);
446  format.setSampleSize(Kwave::toInt(m_bits_per_sample));
447  format.setChannelCount(Kwave::toInt(m_tracks));
448  format.setSampleRate(Kwave::toInt(m_rate));
449  format.setCodec(_("audio/pcm"));
450 
451  // find a replacement format with matching codec, tracks, bits and rate
452  if (!format.isValid() || !info.isFormatSupported(format))
453  format = info.nearestFormat(format);
454 
455  if (format.codec() != _("audio/pcm")) {
456  qWarning("PCM encoding is not supported");
457  return -EIO;
458  }
459 
460  if (format.sampleSize() != Kwave::toInt(m_bits_per_sample)) {
461  qWarning("%d bits per sample are not supported", m_bits_per_sample);
462  return -EIO;
463  }
464 
465  if (format.channelCount() != Kwave::toInt(m_tracks)) {
466  qWarning("recording with %d channels is not supported", m_tracks);
467  return -EIO;
468  }
469 
470  if (format.sampleRate() != Kwave::toInt(m_rate)) {
471  qWarning("sample rate %d Hz is not supported", Kwave::toInt(m_rate));
472  return -EIO;
473  }
474 
475  if ( (format.sampleType() != QAudioFormat::SignedInt) &&
476  (format.sampleType() != QAudioFormat::UnSignedInt) )
477  {
478  qWarning("integer sample format is not supported");
479  return -EIO;
480  }
481 
482  // create a new Qt output device
483  if (QThread::currentThread() == qApp->thread())
484  createInMainThread(format, buffer_size);
485  else
486  emit sigCreateRequested(format, buffer_size);
487 
488  return 0;
489 }
void createInMainThread(QAudioFormat &format, unsigned int buffer_size)
Definition: Record-Qt.cpp:492
unsigned int m_bits_per_sample
Definition: Record-Qt.h:271
int toInt(T x)
Definition: Utils.h:127
void sigCreateRequested(QAudioFormat &format, unsigned int buffer_size)
quint8 m_tracks
Definition: Record-Qt.h:262
#define _(m)
Definition: memcpy.c:66
QString m_device
Definition: Record-Qt.h:274
QAudioDeviceInfo deviceInfo(const QString &device) const
Definition: Record-Qt.cpp:304
Here is the call graph for this function:
Here is the caller graph for this function:

◆ notified

void Kwave::RecordQt::notified ( )
privateslot

called when recorded data gets available

Definition at line 514 of file Record-Qt.cpp.

References m_sem.

Referenced by createInMainThread().

515 {
516  m_sem.release();
517 }
QSemaphore m_sem
Definition: Record-Qt.h:280
Here is the caller graph for this function:

◆ open()

QString Kwave::RecordQt::open ( const QString &  dev)
virtual

Open the record device.

Parameters
devpath of the record device
Return values
QString()if successful
QString::number(ENODEV)if device not found
QString::number(EBUSY)if device is busy
QString(...)device specific error message (already translated)

Implements Kwave::RecordDevice.

Definition at line 391 of file Record-Qt.cpp.

References close(), deviceInfo(), m_device, m_lock, and scanDevices().

392 {
393 
394  // close the previous device
395  close();
396 
397  QMutexLocker _lock(&m_lock);
398 
399  // make sure we have a valid list of devices
400  scanDevices();
401 
402  const QAudioDeviceInfo info(deviceInfo(device));
403  if (info.isNull()) {
404  return QString::number(ENODEV);
405  }
406 
407  m_device = device;
408  return QString();
409 }
virtual int close() Q_DECL_OVERRIDE
Definition: Record-Qt.cpp:344
void scanDevices()
Definition: Record-Qt.cpp:520
QString m_device
Definition: Record-Qt.h:274
QAudioDeviceInfo deviceInfo(const QString &device) const
Definition: Record-Qt.cpp:304
Here is the call graph for this function:

◆ read()

int Kwave::RecordQt::read ( QByteArray &  buffer,
unsigned int  offset 
)
virtual

Read the raw audio data from the record device.

Parameters
bufferarray of bytes to receive the audio data might be resized for alignment
offsetoffset in bytes within the buffer
Returns
number of bytes read, zero or negative if failed

Implements Kwave::RecordDevice.

Definition at line 357 of file Record-Qt.cpp.

References BUFFER_SIZE_OVERCOMMIT, initialize(), m_initialized, m_input, m_sem, m_source, RECORD_POLL_TIMEOUT, and Kwave::toInt().

358 {
359  if (buffer.isNull() || buffer.isEmpty())
360  return 0; // no buffer, nothing to do
361 
362  int buffer_size = buffer.size();
363 
364  // we configure our device at a late stage, otherwise we would not
365  // know the internal buffer size
366  if (!m_initialized) {
367  int err = initialize(buffer_size);
368  if (err < 0) return -EAGAIN;
369  m_initialized = true;
370  }
371  Q_ASSERT(m_source);
372  Q_ASSERT(m_input);
373  if (!m_source || !m_input)
374  return -ENODEV;
375 
376  // adjust the buffer size if is has been changed in the plugin
377  if ((buffer_size > 0) && (m_input->bufferSize() != buffer_size))
378  m_input->setBufferSize(buffer_size * BUFFER_SIZE_OVERCOMMIT);
379 
380  // wait until some data gets available (with timeout)
381  m_sem.tryAcquire(1, RECORD_POLL_TIMEOUT);
382 
383  char *p = buffer.data() + offset;
384  unsigned int len = buffer.length() - offset;
385  qint64 length = m_source->read(p, len);
386 
387  return (length < 1) ? -EAGAIN : Kwave::toInt(length);
388 }
QIODevice * m_source
Definition: Record-Qt.h:256
bool m_initialized
Definition: Record-Qt.h:277
QSemaphore m_sem
Definition: Record-Qt.h:280
int toInt(T x)
Definition: Utils.h:127
int initialize(unsigned int buffer_size)
Definition: Record-Qt.cpp:432
QAudioInput * m_input
Definition: Record-Qt.h:253
#define RECORD_POLL_TIMEOUT
Definition: Record-Qt.cpp:51
#define BUFFER_SIZE_OVERCOMMIT
Definition: Record-Qt.cpp:57
Here is the call graph for this function:

◆ sampleFormat()

Kwave::SampleFormat::Format Kwave::RecordQt::sampleFormat ( )
virtual

Returns the current sample format (signed/unsigned)

Implements Kwave::RecordDevice.

Definition at line 92 of file Record-Qt.cpp.

References m_sample_format.

93 {
94  return m_sample_format;
95 }
Kwave::SampleFormat::Format m_sample_format
Definition: Record-Qt.h:259

◆ sampleRate()

double Kwave::RecordQt::sampleRate ( )
virtual

Returns the current sample rate of the device

Implements Kwave::RecordDevice.

Definition at line 225 of file Record-Qt.cpp.

References m_rate.

226 {
227  return m_rate;
228 }

◆ scanDevices()

void Kwave::RecordQt::scanDevices ( )
private

scan all PulseAudio source, re-creates m_device_list

Definition at line 520 of file Record-Qt.cpp.

References _, DBG, m_available_devices, and m_device_name_map.

Referenced by open(), and supportedDevices().

521 {
522  m_available_devices.clear();
523  m_device_name_map.clear();
524 
525  // get the list of available audio output devices from Qt
526  foreach (const QAudioDeviceInfo &device,
527  QAudioDeviceInfo::availableDevices(QAudio::AudioInput))
528  {
529  QString qt_name = device.deviceName();
530 
531  // for debugging: list all devices
532 // qDebug(" name='%s'", DBG(qt_name));
533 
534  // device name not available ?
535  if (!qt_name.length()) {
536  qWarning("RecordQt::supportedDevices() "
537  "=> BUG: device with no name?");
538  continue;
539  }
540 
541  QString gui_name = qt_name + _("|sound_note");
542  if (m_device_name_map.contains(gui_name)) {
543  qWarning("RecordQt::supportedDevices() "
544  "=> BUG: duplicate device name: '%s'", DBG(gui_name));
545  continue;
546  }
547 
548  m_available_devices.append(device);
549  m_device_name_map[gui_name] = qt_name;
550  }
551 }
QList< QAudioDeviceInfo > m_available_devices
Definition: Record-Qt.h:250
#define _(m)
Definition: memcpy.c:66
#define DBG(qs)
Definition: String.h:55
QMap< QString, QString > m_device_name_map
Definition: Record-Qt.h:247
Here is the caller graph for this function:

◆ setBitsPerSample()

int Kwave::RecordQt::setBitsPerSample ( unsigned int  new_bits)
virtual

Set the resolution in bits per sample

Parameters
new_bitsresolution [bits/sample]
Returns
zero on success, negative error code if failed

Implements Kwave::RecordDevice.

Definition at line 170 of file Record-Qt.cpp.

References close(), and m_bits_per_sample.

171 {
172  if (new_bits == m_bits_per_sample) return 0;
173 
174  close();
175  m_bits_per_sample = new_bits;
176  return 0;
177 }
virtual int close() Q_DECL_OVERRIDE
Definition: Record-Qt.cpp:344
unsigned int m_bits_per_sample
Definition: Record-Qt.h:271
Here is the call graph for this function:

◆ setCompression()

int Kwave::RecordQt::setCompression ( Kwave::Compression::Type  new_compression)
virtual

Try to set a new compression type.

Parameters
new_compressionthe identifier of the new compression
Returns
zero on success, negative error code if failed
See also
class Compression

Implements Kwave::RecordDevice.

Definition at line 207 of file Record-Qt.cpp.

References close(), and m_compression.

208 {
209  if (new_compression != m_compression) {
210  close();
211  m_compression = new_compression;
212  }
213  return 0;
214 }
virtual int close() Q_DECL_OVERRIDE
Definition: Record-Qt.cpp:344
Kwave::Compression::Type m_compression
Definition: Record-Qt.h:268
Here is the call graph for this function:

◆ setSampleFormat()

int Kwave::RecordQt::setSampleFormat ( Kwave::SampleFormat::Format  new_format)
virtual

Try to set a new sample format (signed/unsigned)

Parameters
new_formatthe identifier for the new format
Returns
zero on success, negative error code if failed
See also
class SampleFormat

Implements Kwave::RecordDevice.

Definition at line 98 of file Record-Qt.cpp.

References close(), and m_sample_format.

99 {
100  if (m_sample_format == new_format) return 0;
101  close();
102  m_sample_format = new_format;
103  return 0;
104 }
virtual int close() Q_DECL_OVERRIDE
Definition: Record-Qt.cpp:344
Kwave::SampleFormat::Format m_sample_format
Definition: Record-Qt.h:259
Here is the call graph for this function:

◆ setSampleRate()

int Kwave::RecordQt::setSampleRate ( double &  new_rate)
virtual

Try to set a new sample rate.

Parameters
new_ratethe sample rate to be set [samples/second], can be modified and rounded up/down to the nearest supported sample rate if the underlying driver supports that.
Returns
zero on success, negative error code if failed

Implements Kwave::RecordDevice.

Definition at line 231 of file Record-Qt.cpp.

References close(), and m_rate.

232 {
233  if (qFuzzyCompare(new_rate, m_rate)) return 0;
234 
235  close();
236  m_rate = new_rate;
237  return 0;
238 }
virtual int close() Q_DECL_OVERRIDE
Definition: Record-Qt.cpp:344
Here is the call graph for this function:

◆ setTracks()

int Kwave::RecordQt::setTracks ( unsigned int &  tracks)
virtual

Try to set a new number of tracks.

Note
the device must be open
Parameters
tracksthe number of tracks to be set, can be modified and decreased to the next supported number of tracks if the underlying driver supports that.
Returns
zero on success, negative error code if failed

Implements Kwave::RecordDevice.

Definition at line 268 of file Record-Qt.cpp.

References close(), m_tracks, and tracks().

269 {
270  if (tracks == m_tracks) return 0;
271  if (tracks > 255) tracks = 255;
272 
273  close();
274  m_tracks = static_cast<quint8>(tracks);
275  return 0;
276 }
virtual int close() Q_DECL_OVERRIDE
Definition: Record-Qt.cpp:344
quint8 m_tracks
Definition: Record-Qt.h:262
virtual int tracks() Q_DECL_OVERRIDE
Definition: Record-Qt.cpp:262
Here is the call graph for this function:

◆ sigCloseRequested

void Kwave::RecordQt::sigCloseRequested ( )
signal

request closeInMainThread()

Referenced by close(), and RecordQt().

Here is the caller graph for this function:

◆ sigCreateRequested

void Kwave::RecordQt::sigCreateRequested ( QAudioFormat &  format,
unsigned int  buffer_size 
)
signal

request createInMainThread()

Parameters
formatreference to the audio format specification
buffer_sizesize of the audio buffer in bytes

Referenced by initialize(), and RecordQt().

Here is the caller graph for this function:

◆ supportedBits()

QList< unsigned int > Kwave::RecordQt::supportedBits ( )
virtual

Detect a list of supported bits per sample.

Note
this depends on the compression type
Returns
a list of bits per sample, empty if failed

Implements Kwave::RecordDevice.

Definition at line 180 of file Record-Qt.cpp.

References deviceInfo(), m_device, m_lock, and Kwave::toUint().

181 {
182  QList<unsigned int> list;
183  QMutexLocker _lock(&m_lock); // context: main thread
184 
185  const QAudioDeviceInfo info(deviceInfo(m_device));
186 
187  // no devices at all -> empty
188  if (info.isNull()) return list;
189 
190  // iterate over all supported bits per sample
191  foreach (int bits, info.supportedSampleSizes()) {
192  if (bits <= 0) continue;
193  list.append(Kwave::toUint(bits));
194  }
195 
196  std::sort(list.begin(), list.end(), std::less<unsigned int>());
197  return list;
198 }
unsigned int toUint(T x)
Definition: Utils.h:109
QString m_device
Definition: Record-Qt.h:274
QAudioDeviceInfo deviceInfo(const QString &device) const
Definition: Record-Qt.cpp:304
Here is the call graph for this function:

◆ supportedDevices()

QStringList Kwave::RecordQt::supportedDevices ( )
virtual

return a string list with supported device names

Implements Kwave::RecordDevice.

Definition at line 412 of file Record-Qt.cpp.

References _, DEFAULT_DEVICE, m_available_devices, m_device_name_map, m_lock, and scanDevices().

413 {
414  QMutexLocker _lock(&m_lock); // context: main thread
415 
416  // re-validate the list if necessary
417  if (m_device_name_map.isEmpty() || m_available_devices.isEmpty())
418  scanDevices();
419 
420  QStringList list = m_device_name_map.keys();
421 
422  // move the "default" device to the start of the list
423  if (list.contains(DEFAULT_DEVICE))
424  list.move(list.indexOf(DEFAULT_DEVICE), 0);
425 
426  if (!list.isEmpty()) list.append(_("#TREE#"));
427 
428  return list;
429 }
QList< QAudioDeviceInfo > m_available_devices
Definition: Record-Qt.h:250
#define DEFAULT_DEVICE
Definition: Record-Qt.cpp:48
void scanDevices()
Definition: Record-Qt.cpp:520
#define _(m)
Definition: memcpy.c:66
QMap< QString, QString > m_device_name_map
Definition: Record-Qt.h:247
Here is the call graph for this function:

◆ tracks()

int Kwave::RecordQt::tracks ( )
virtual

Returns the current number of tracks

Implements Kwave::RecordDevice.

Definition at line 262 of file Record-Qt.cpp.

References m_tracks.

Referenced by setTracks().

263 {
264  return m_tracks;
265 }
quint8 m_tracks
Definition: Record-Qt.h:262
Here is the caller graph for this function:

Member Data Documentation

◆ m_available_devices

QList<QAudioDeviceInfo> Kwave::RecordQt::m_available_devices
private

list of available Qt output devices

Definition at line 250 of file Record-Qt.h.

Referenced by deviceInfo(), scanDevices(), and supportedDevices().

◆ m_bits_per_sample

unsigned int Kwave::RecordQt::m_bits_per_sample
private

resolution [bits per sample]

Definition at line 271 of file Record-Qt.h.

Referenced by bitsPerSample(), initialize(), and setBitsPerSample().

◆ m_compression

Kwave::Compression::Type Kwave::RecordQt::m_compression
private

compression mode

Definition at line 268 of file Record-Qt.h.

Referenced by compression(), and setCompression().

◆ m_device

QString Kwave::RecordQt::m_device
private

encoded name of the sink

Definition at line 274 of file Record-Qt.h.

Referenced by detectSampleFormats(), detectSampleRates(), detectTracks(), endianness(), initialize(), open(), and supportedBits().

◆ m_device_name_map

QMap<QString, QString> Kwave::RecordQt::m_device_name_map
private

dictionary for translating verbose device names into Qt audio output device names (key = verbose name, data = Qt output device name)

Definition at line 247 of file Record-Qt.h.

Referenced by deviceInfo(), scanDevices(), and supportedDevices().

◆ m_initialized

bool Kwave::RecordQt::m_initialized
private

true if initialize() has been successfully been run

Definition at line 277 of file Record-Qt.h.

Referenced by closeInMainThread(), and read().

◆ m_input

QAudioInput* Kwave::RecordQt::m_input
private

Qt audio input instance

Definition at line 253 of file Record-Qt.h.

Referenced by closeInMainThread(), createInMainThread(), and read().

◆ m_lock

QMutex Kwave::RecordQt::m_lock
private

mutex for locking the streaming thread against main thread

Definition at line 240 of file Record-Qt.h.

Referenced by close(), createInMainThread(), detectSampleFormats(), detectSampleRates(), detectTracks(), endianness(), open(), supportedBits(), and supportedDevices().

◆ m_rate

double Kwave::RecordQt::m_rate
private

sample rate

Definition at line 265 of file Record-Qt.h.

Referenced by initialize(), sampleRate(), and setSampleRate().

◆ m_sample_format

Kwave::SampleFormat::Format Kwave::RecordQt::m_sample_format
private

sample format (signed int, unsigned int, float, ...

Definition at line 259 of file Record-Qt.h.

Referenced by sampleFormat(), and setSampleFormat().

◆ m_sem

QSemaphore Kwave::RecordQt::m_sem
private

semaphore for signaling "data available"

Definition at line 280 of file Record-Qt.h.

Referenced by createInMainThread(), notified(), and read().

◆ m_source

QIODevice* Kwave::RecordQt::m_source
private

QIODevice for reading the data

Definition at line 256 of file Record-Qt.h.

Referenced by closeInMainThread(), createInMainThread(), and read().

◆ m_tracks

quint8 Kwave::RecordQt::m_tracks
private

number of tracks [0...N-1]

Definition at line 262 of file Record-Qt.h.

Referenced by initialize(), setTracks(), and tracks().


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