Qt 4.8
qaudioinput_alsa_p.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtMultimedia module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 //
43 // W A R N I N G
44 // -------------
45 //
46 // This file is not part of the Qt API. It exists for the convenience
47 // of other Qt classes. This header file may change from version to
48 // version without notice, or even be removed.
49 //
50 // We mean it.
51 //
52 
53 #include <QtCore/qcoreapplication.h>
54 #include "qaudioinput_alsa_p.h"
56 
58 
59 //#define DEBUG_AUDIO 1
60 
62  settings(audioFormat)
63 {
64  bytesAvailable = 0;
65  handle = 0;
66  ahandler = 0;
67  access = SND_PCM_ACCESS_RW_INTERLEAVED;
68  pcmformat = SND_PCM_FORMAT_S16;
69  buffer_size = 0;
70  period_size = 0;
71  buffer_time = 100000;
72  period_time = 20000;
73  totalTimeValue = 0;
74  intervalTime = 1000;
75  audioBuffer = 0;
78  audioSource = 0;
79  pullMode = true;
80  resuming = false;
81 
82  m_device = device;
83 
84  timer = new QTimer(this);
85  connect(timer,SIGNAL(timeout()),SLOT(userFeed()));
86 }
87 
89 {
90  close();
91  disconnect(timer, SIGNAL(timeout()));
93  delete timer;
94 }
95 
97 {
98  return errorState;
99 }
100 
102 {
103  return deviceState;
104 }
105 
106 
108 {
109  return settings;
110 }
111 
113 {
114  int count = 0;
115  bool reset = false;
116 
117  if(err == -EPIPE) {
119  err = snd_pcm_prepare(handle);
120  if(err < 0)
121  reset = true;
122  else {
124  if (bytesAvailable <= 0)
125  reset = true;
126  }
127 
128  } else if((err == -ESTRPIPE)||(err == -EIO)) {
130  while((err = snd_pcm_resume(handle)) == -EAGAIN){
131  usleep(100);
132  count++;
133  if(count > 5) {
134  reset = true;
135  break;
136  }
137  }
138  if(err < 0) {
139  err = snd_pcm_prepare(handle);
140  if(err < 0)
141  reset = true;
142  }
143  }
144  if(reset) {
145  close();
146  open();
147  snd_pcm_prepare(handle);
148  return 0;
149  }
150  return err;
151 }
152 
154 {
155  snd_pcm_format_t format = SND_PCM_FORMAT_UNKNOWN;
156 
157  if(settings.sampleSize() == 8) {
158  format = SND_PCM_FORMAT_U8;
159  } else if(settings.sampleSize() == 16) {
162  format = SND_PCM_FORMAT_S16_LE;
163  else
164  format = SND_PCM_FORMAT_S16_BE;
167  format = SND_PCM_FORMAT_U16_LE;
168  else
169  format = SND_PCM_FORMAT_U16_BE;
170  }
171  } else if(settings.sampleSize() == 24) {
174  format = SND_PCM_FORMAT_S24_LE;
175  else
176  format = SND_PCM_FORMAT_S24_BE;
179  format = SND_PCM_FORMAT_U24_LE;
180  else
181  format = SND_PCM_FORMAT_U24_BE;
182  }
183  } else if(settings.sampleSize() == 32) {
186  format = SND_PCM_FORMAT_S32_LE;
187  else
188  format = SND_PCM_FORMAT_S32_BE;
191  format = SND_PCM_FORMAT_U32_LE;
192  else
193  format = SND_PCM_FORMAT_U32_BE;
194  } else if(settings.sampleType() == QAudioFormat::Float) {
196  format = SND_PCM_FORMAT_FLOAT_LE;
197  else
198  format = SND_PCM_FORMAT_FLOAT_BE;
199  }
200  } else if(settings.sampleSize() == 64) {
202  format = SND_PCM_FORMAT_FLOAT64_LE;
203  else
204  format = SND_PCM_FORMAT_FLOAT64_BE;
205  }
206 
207  return format != SND_PCM_FORMAT_UNKNOWN
208  ? snd_pcm_hw_params_set_format( handle, hwparams, format)
209  : -1;
210 }
211 
213 {
215  close();
216 
217  if(!pullMode && audioSource) {
218  delete audioSource;
219  }
220 
221  if(device) {
222  //set to pull mode
223  pullMode = true;
224  audioSource = device;
226  } else {
227  //set to push mode
228  pullMode = false;
230  audioSource = new InputPrivate(this);
232  }
233 
234  if( !open() )
235  return 0;
236 
238 
239  return audioSource;
240 }
241 
243 {
245  return;
246 
248 
249  close();
251 }
252 
254 {
255 #ifdef DEBUG_AUDIO
256  QTime now(QTime::currentTime());
257  qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
258 #endif
260  timeStamp.restart();
261  elapsedTimeOffset = 0;
262 
263  int dir;
264  int err = 0;
265  int count=0;
266  unsigned int freakuency=settings.frequency();
267 
268  if (!settings.isValid()) {
269  qWarning("QAudioOutput: open error, invalid format.");
270  } else if (settings.frequency() <= 0) {
271  qWarning("QAudioOutput: open error, invalid sample rate (%d).",
272  settings.frequency());
273  } else {
274  err = -1;
275  }
276 
277  if (err == 0) {
280  return false;
281  }
282 
283 
286  if(dev.compare(QLatin1String("default")) == 0) {
287 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
288  dev = QLatin1String(devices.first());
289 #else
290  dev = QLatin1String("hw:0,0");
291 #endif
292  } else {
293 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
294  dev = QLatin1String(m_device);
295 #else
296  int idx = 0;
297  char *name;
298 
299  QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData());
300 
301  while(snd_card_get_name(idx,&name) == 0) {
302  if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0)
303  break;
304  idx++;
305  }
306  dev = QString(QLatin1String("hw:%1,0")).arg(idx);
307 #endif
308  }
309 
310  // Step 1: try and open the device
311  while((count < 5) && (err < 0)) {
312  err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0);
313  if(err < 0)
314  count++;
315  }
316  if (( err < 0)||(handle == 0)) {
320  return false;
321  }
322  snd_pcm_nonblock( handle, 0 );
323 
324  // Step 2: Set the desired HW parameters.
325  snd_pcm_hw_params_alloca( &hwparams );
326 
327  bool fatal = false;
328  QString errMessage;
329  unsigned int chunks = 8;
330 
331  err = snd_pcm_hw_params_any( handle, hwparams );
332  if ( err < 0 ) {
333  fatal = true;
334  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_any: err = %1").arg(err);
335  }
336  if ( !fatal ) {
337  err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 );
338  if ( err < 0 ) {
339  fatal = true;
340  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err);
341  }
342  }
343  if ( !fatal ) {
344  err = snd_pcm_hw_params_set_access( handle, hwparams, access );
345  if ( err < 0 ) {
346  fatal = true;
347  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_access: err = %1").arg(err);
348  }
349  }
350  if ( !fatal ) {
351  err = setFormat();
352  if ( err < 0 ) {
353  fatal = true;
354  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_format: err = %1").arg(err);
355  }
356  }
357  if ( !fatal ) {
358  err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() );
359  if ( err < 0 ) {
360  fatal = true;
361  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_channels: err = %1").arg(err);
362  }
363  }
364  if ( !fatal ) {
365  err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 );
366  if ( err < 0 ) {
367  fatal = true;
368  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
369  }
370  }
371  if ( !fatal ) {
372  err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir);
373  if ( err < 0 ) {
374  fatal = true;
375  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
376  }
377  }
378  if ( !fatal ) {
379  err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir);
380  if ( err < 0 ) {
381  fatal = true;
382  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err);
383  }
384  }
385  if ( !fatal ) {
386  err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir);
387  if ( err < 0 ) {
388  fatal = true;
389  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_periods_near: err = %1").arg(err);
390  }
391  }
392  if ( !fatal ) {
393  err = snd_pcm_hw_params(handle, hwparams);
394  if ( err < 0 ) {
395  fatal = true;
396  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params: err = %1").arg(err);
397  }
398  }
399  if( err < 0) {
400  qWarning()<<errMessage;
404  return false;
405  }
406  snd_pcm_hw_params_get_buffer_size(hwparams,&buffer_frames);
407  buffer_size = snd_pcm_frames_to_bytes(handle,buffer_frames);
408  snd_pcm_hw_params_get_period_size(hwparams,&period_frames, &dir);
409  period_size = snd_pcm_frames_to_bytes(handle,period_frames);
410  snd_pcm_hw_params_get_buffer_time(hwparams,&buffer_time, &dir);
411  snd_pcm_hw_params_get_period_time(hwparams,&period_time, &dir);
412 
413  // Step 3: Set the desired SW parameters.
414  snd_pcm_sw_params_t *swparams;
415  snd_pcm_sw_params_alloca(&swparams);
416  snd_pcm_sw_params_current(handle, swparams);
417  snd_pcm_sw_params_set_start_threshold(handle,swparams,period_frames);
418  snd_pcm_sw_params_set_stop_threshold(handle,swparams,buffer_frames);
419  snd_pcm_sw_params_set_avail_min(handle, swparams,period_frames);
420  snd_pcm_sw_params(handle, swparams);
421 
422  // Step 4: Prepare audio
423  if(audioBuffer == 0)
424  audioBuffer = new char[buffer_size];
425  snd_pcm_prepare( handle );
426  snd_pcm_start(handle);
427 
428  // Step 5: Setup timer
430 
431  if(pullMode)
432  connect(audioSource,SIGNAL(readyRead()),this,SLOT(userFeed()));
433 
434  // Step 6: Start audio processing
435  chunks = buffer_size/period_size;
436  timer->start(period_time*chunks/2000);
437 
439 
440  totalTimeValue = 0;
441 
442  return true;
443 }
444 
446 {
447  timer->stop();
448 
449  if ( handle ) {
450  snd_pcm_drop( handle );
451  snd_pcm_close( handle );
452  handle = 0;
453  delete [] audioBuffer;
454  audioBuffer=0;
455  }
456 }
457 
459 {
460  if(resuming)
464  bytesAvailable = 0;
465  else {
466  int frames = snd_pcm_avail_update(handle);
467  if (frames < 0) {
468  bytesAvailable = frames;
469  } else {
470  if((int)frames > (int)buffer_frames)
471  frames = buffer_frames;
472  bytesAvailable = snd_pcm_frames_to_bytes(handle, frames);
473  }
474  }
475  return bytesAvailable;
476 }
477 
479 {
480  return qMax(bytesAvailable, 0);
481 }
482 
484 {
485  // Read in some audio data and write it to QIODevice, pull mode
486  if ( !handle )
487  return 0;
488 
489  // bytesAvaiable is saved as a side effect of checkBytesReady().
490  int bytesToRead = checkBytesReady();
491 
492  if (bytesToRead < 0) {
493  // bytesAvailable as negative is error code, try to recover from it.
494  xrun_recovery(bytesToRead);
495  bytesToRead = checkBytesReady();
496  if (bytesToRead < 0) {
497  // recovery failed must stop and set error.
498  close();
502  return 0;
503  }
504  }
505 
506  bytesToRead = qMin<qint64>(len, bytesToRead);
507  bytesToRead -= bytesToRead % period_size;
508  int count=0, err = 0;
509  while(count < 5) {
510  int chunks = bytesToRead/period_size;
511  int frames = chunks*period_frames;
512  if(frames > (int)buffer_frames)
513  frames = buffer_frames;
514  int readFrames = snd_pcm_readi(handle, audioBuffer, frames);
515  if (readFrames >= 0) {
516  err = snd_pcm_frames_to_bytes(handle, readFrames);
517 #ifdef DEBUG_AUDIO
518  qDebug()<<QString::fromLatin1("read in bytes = %1 (frames=%2)").arg(err).arg(readFrames).toLatin1().constData();
519 #endif
520  break;
521  } else if((readFrames == -EAGAIN) || (readFrames == -EINTR)) {
523  err = 0;
524  break;
525  } else {
526  if(readFrames == -EPIPE) {
528  err = snd_pcm_prepare(handle);
529  } else if(readFrames == -ESTRPIPE) {
530  err = snd_pcm_prepare(handle);
531  }
532  if(err != 0) break;
533  }
534  count++;
535  }
536  if(err > 0) {
537  // got some send it onward
538 #ifdef DEBUG_AUDIO
539  qDebug()<<"frames to write to QIODevice = "<<
540  snd_pcm_bytes_to_frames( handle, (int)err )<<" ("<<err<<") bytes";
541 #endif
543  return 0;
544  if (pullMode) {
546  if(l < 0) {
547  close();
551  } else if(l == 0) {
556  }
557  } else {
558  bytesAvailable -= err;
559  totalTimeValue += err;
560  resuming = false;
565  }
566  }
567  return l;
568 
569  } else {
570  memcpy(data,audioBuffer,err);
571  bytesAvailable -= err;
572  totalTimeValue += err;
573  resuming = false;
578  }
579  return err;
580  }
581  }
582  return 0;
583 }
584 
586 {
588  int err = 0;
589 
590  if(handle) {
591  err = snd_pcm_prepare( handle );
592  if(err < 0)
593  xrun_recovery(err);
594 
595  err = snd_pcm_start(handle);
596  if(err < 0)
597  xrun_recovery(err);
598 
600  }
601  resuming = true;
603  int chunks = buffer_size/period_size;
604  timer->start(period_time*chunks/2000);
606  }
607 }
608 
610 {
611  buffer_size = value;
612 }
613 
615 {
616  return buffer_size;
617 }
618 
620 {
621  return period_size;
622 }
623 
625 {
626  intervalTime = qMax(0, ms);
627 }
628 
630 {
631  return intervalTime;
632 }
633 
635 {
636  qint64 result = qint64(1000000) * totalTimeValue /
639 
640  return result;
641 }
642 
644 {
646  timer->stop();
649  }
650 }
651 
653 {
655  return;
656 #ifdef DEBUG_AUDIO
657  QTime now(QTime::currentTime());
658  qDebug()<<now.second()<<"s "<<now.msec()<<"ms :userFeed() IN";
659 #endif
660  deviceReady();
661 }
662 
664 {
665  if(pullMode) {
666  // reads some audio data and writes it to QIODevice
667  read(0, buffer_size);
668  } else {
669  // emits readyRead() so user will call read() on QIODevice to get some audio data
671  a->trigger();
672  }
674 
676  return true;
677 
678  if (bytesAvailable < 0) {
679  // bytesAvailable as negative is error code, try to recover from it.
682  if (bytesAvailable < 0) {
683  // recovery failed must stop and set error.
684  close();
688  return 0;
689  }
690  }
691 
693  emit notify();
695  timeStamp.restart();
696  }
697  return true;
698 }
699 
701 {
703  return 0;
704 
705  return clockStamp.elapsed()*1000;
706 }
707 
709 {
710  if(handle)
711  snd_pcm_reset(handle);
712 }
713 
715 {
716  if(handle)
717  snd_pcm_drain(handle);
718 }
719 
721 {
722  audioDevice = qobject_cast<QAudioInputPrivate*>(audio);
723 }
724 
726 {
727 }
728 
730 {
731  return audioDevice->read(data,len);
732 }
733 
735 {
736  Q_UNUSED(data)
737  Q_UNUSED(len)
738  return 0;
739 }
740 
742 {
743  emit readyRead();
744 }
745 
Error
Definition: qaudio.h:58
snd_async_handler_t * ahandler
QAudioFormat format() const
Returns the QAudioFormat being used.
void resume()
Resumes processing audio data after a suspend().
QElapsedTimer clockStamp
void suspend()
Stops processing audio data, preserving buffered audio data.
snd_pcm_hw_params_t * hwparams
int frequency() const
Use sampleRate() instead.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
qint64 processedUSecs() const
Returns the amount of audio data processed since start() was called in milliseconds.
int bufferSize() const
Returns the audio buffer size in milliseconds.
void stop()
Stops the audio input.
void setNotifyInterval(int milliSeconds)
Sets the interval for notify() signal to be emitted.
InputPrivate(QAudioInputPrivate *audio)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QIODevice * start(QIODevice *device=0)
Uses the device as the QIODevice to transfer data.
#define SLOT(a)
Definition: qobjectdefs.h:226
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int msec() const
Returns the millisecond part (0 to 999) of the time.
Definition: qdatetime.cpp:1611
long ASN1_INTEGER_get ASN1_INTEGER * a
The QString class provides a Unicode character string.
Definition: qstring.h:83
snd_pcm_access_t access
T * qobject_cast(QObject *object)
Definition: qobject.h:375
int sampleSize() const
Returns the current sample size value.
int bytesReady() const
Returns the amount of audio data available to read in bytes.
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes all pending events for the calling thread according to the specified flags until there are ...
QAudioFormat::Endian byteOrder() const
Returns the current byteOrder value.
void setBufferSize(int value)
Sets the audio buffer size to value in milliseconds.
void stateChanged(QAudio::State)
This signal is emitted when the device state has changed.
Q_CORE_EXPORT void qDebug(const char *,...)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QAudio::State state() const
Returns the state of audio processing.
QAudioFormat::SampleType sampleType() const
Returns the current SampleType value.
The QTime class provides clock time functions.
Definition: qdatetime.h:148
qint64 read(char *data, qint64 len)
int notifyInterval() const
Returns the notify interval in milliseconds.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
qint64 restart()
Restarts the timer and returns the time elapsed since the previous start.
QAudio::Error errorState
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
const char * name
qint64 elapsedUSecs() const
Returns the milliseconds since start() was called, including time in Idle and suspend states...
#define emit
Definition: qobjectdefs.h:76
Q_CORE_EXPORT void qWarning(const char *,...)
int second() const
Returns the second part (0 to 59) of the time.
Definition: qdatetime.cpp:1600
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void reset()
Drops all audio data in the buffers, resets buffers to zero.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
__int64 qint64
Definition: qglobal.h:942
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
bool isValid() const
Returns true if all of the parameters are valid.
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
snd_pcm_format_t pcmformat
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
snd_pcm_uframes_t buffer_frames
void notify()
This signal is emitted when x ms of audio data has been processed the interval set by setNotifyInterv...
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
int compare(const QString &s) const
Definition: qstring.cpp:5037
State
Definition: qaudio.h:59
static QTime currentTime()
Returns the current time as reported by the system clock.
Definition: qdatetime.cpp:3125
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int qstrncmp(const char *str1, const char *str2, uint len)
Definition: qbytearray.h:101
QFactoryLoader * l
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
int periodSize() const
Returns the period size in bytes.
qint64 writeData(const char *data, qint64 len)
Writes up to maxSize bytes from data to the device.
QAudio::Error error() const
Returns the error state.
snd_pcm_uframes_t period_frames
The QAudioFormat class stores audio parameter information.
Definition: qaudioformat.h:60
qint64 readData(char *data, qint64 len)
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...
The QTimer class provides repetitive and single-shot timers.
Definition: qtimer.h:56
QAudio::State deviceState
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
static QList< QByteArray > availableDevices(QAudio::Mode)
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
void stop()
Stops the timer.
Definition: qtimer.cpp:284
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition: qtimer.cpp:249
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QAudioInputPrivate(const QByteArray &device, const QAudioFormat &audioFormat)
int channels() const
Use channelCount() instead.