Qt 4.8
qaudiooutput_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 "qaudiooutput_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_frames = 0;
70  period_frames = 0;
71  buffer_size = 0;
72  period_size = 0;
73  buffer_time = 100000;
74  period_time = 20000;
75  totalTimeValue = 0;
76  intervalTime = 1000;
77  audioBuffer = 0;
80  audioSource = 0;
81  pullMode = true;
82  resuming = false;
83  opened = false;
84 
85  m_device = device;
86 
87  timer = new QTimer(this);
88  connect(timer,SIGNAL(timeout()),SLOT(userFeed()));
89 }
90 
92 {
93  close();
94  disconnect(timer, SIGNAL(timeout()));
96  delete timer;
97 }
98 
100 {
101  return errorState;
102 }
103 
105 {
106  return deviceState;
107 }
108 
110 {
111  QAudioOutputPrivate* audioOut;
112 
113  audioOut = static_cast<QAudioOutputPrivate*>
114  (snd_async_handler_get_callback_private(ahandler));
115 
116  if((audioOut->deviceState==QAudio::ActiveState)||(audioOut->resuming))
117  audioOut->feedback();
118 }
119 
121 {
122  int count = 0;
123  bool reset = false;
124 
125  if(err == -EPIPE) {
127  err = snd_pcm_prepare(handle);
128  if(err < 0)
129  reset = true;
130 
131  } else if((err == -ESTRPIPE)||(err == -EIO)) {
133  while((err = snd_pcm_resume(handle)) == -EAGAIN){
134  usleep(100);
135  count++;
136  if(count > 5) {
137  reset = true;
138  break;
139  }
140  }
141  if(err < 0) {
142  err = snd_pcm_prepare(handle);
143  if(err < 0)
144  reset = true;
145  }
146  }
147  if(reset) {
148  close();
149  open();
150  snd_pcm_prepare(handle);
151  return 0;
152  }
153  return err;
154 }
155 
157 {
158  snd_pcm_format_t pcmformat = SND_PCM_FORMAT_UNKNOWN;
159 
160  if(settings.sampleSize() == 8) {
161  pcmformat = SND_PCM_FORMAT_U8;
162 
163  } else if(settings.sampleSize() == 16) {
166  pcmformat = SND_PCM_FORMAT_S16_LE;
167  else
168  pcmformat = SND_PCM_FORMAT_S16_BE;
171  pcmformat = SND_PCM_FORMAT_U16_LE;
172  else
173  pcmformat = SND_PCM_FORMAT_U16_BE;
174  }
175  } else if(settings.sampleSize() == 24) {
178  pcmformat = SND_PCM_FORMAT_S24_LE;
179  else
180  pcmformat = SND_PCM_FORMAT_S24_BE;
183  pcmformat = SND_PCM_FORMAT_U24_LE;
184  else
185  pcmformat = SND_PCM_FORMAT_U24_BE;
186  }
187  } else if(settings.sampleSize() == 32) {
190  pcmformat = SND_PCM_FORMAT_S32_LE;
191  else
192  pcmformat = SND_PCM_FORMAT_S32_BE;
195  pcmformat = SND_PCM_FORMAT_U32_LE;
196  else
197  pcmformat = SND_PCM_FORMAT_U32_BE;
198  } else if(settings.sampleType() == QAudioFormat::Float) {
200  pcmformat = SND_PCM_FORMAT_FLOAT_LE;
201  else
202  pcmformat = SND_PCM_FORMAT_FLOAT_BE;
203  }
204  } else if(settings.sampleSize() == 64) {
206  pcmformat = SND_PCM_FORMAT_FLOAT64_LE;
207  else
208  pcmformat = SND_PCM_FORMAT_FLOAT64_BE;
209  }
210 
211  return pcmformat != SND_PCM_FORMAT_UNKNOWN
212  ? snd_pcm_hw_params_set_format( handle, hwparams, pcmformat)
213  : -1;
214 }
215 
217 {
220 
222 
223  // Handle change of mode
224  if(audioSource && pullMode && !device) {
225  // pull -> push
226  close();
227  audioSource = 0;
228  } else if(audioSource && !pullMode && device) {
229  // push -> pull
230  close();
231  delete audioSource;
232  audioSource = 0;
233  }
234 
235  if(device) {
236  //set to pull mode
237  pullMode = true;
238  audioSource = device;
240  } else {
241  //set to push mode
242  if(!audioSource) {
243  audioSource = new OutputPrivate(this);
245  }
246  pullMode = false;
248  }
249 
250  open();
251 
253 
254  return audioSource;
255 }
256 
258 {
260  return;
263  close();
265 }
266 
268 {
269  if(opened)
270  return true;
271 
272 #ifdef DEBUG_AUDIO
273  QTime now(QTime::currentTime());
274  qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
275 #endif
276  timeStamp.restart();
277  elapsedTimeOffset = 0;
278 
279  int dir;
280  int err = 0;
281  int count=0;
282  unsigned int freakuency=settings.frequency();
283 
284  if (!settings.isValid()) {
285  qWarning("QAudioOutput: open error, invalid format.");
286  } else if (settings.frequency() <= 0) {
287  qWarning("QAudioOutput: open error, invalid sample rate (%d).",
288  settings.frequency());
289  } else {
290  err = -1;
291  }
292 
293  if (err == 0) {
296  return false;
297  }
298 
301  if(dev.compare(QLatin1String("default")) == 0) {
302 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
303  dev = QLatin1String(devices.first());
304 #else
305  dev = QLatin1String("hw:0,0");
306 #endif
307  } else {
308 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
309  dev = QLatin1String(m_device);
310 #else
311  int idx = 0;
312  char *name;
313 
314  QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData());
315 
316  while(snd_card_get_name(idx,&name) == 0) {
317  if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0)
318  break;
319  idx++;
320  }
321  dev = QString(QLatin1String("hw:%1,0")).arg(idx);
322 #endif
323  }
324 
325  // Step 1: try and open the device
326  while((count < 5) && (err < 0)) {
327  err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0);
328  if(err < 0)
329  count++;
330  }
331  if (( err < 0)||(handle == 0)) {
334  return false;
335  }
336  snd_pcm_nonblock( handle, 0 );
337 
338  // Step 2: Set the desired HW parameters.
339  snd_pcm_hw_params_alloca( &hwparams );
340 
341  bool fatal = false;
342  QString errMessage;
343  unsigned int chunks = 8;
344 
345  err = snd_pcm_hw_params_any( handle, hwparams );
346  if ( err < 0 ) {
347  fatal = true;
348  errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_any: err = %1").arg(err);
349  }
350  if ( !fatal ) {
351  err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 );
352  if ( err < 0 ) {
353  fatal = true;
354  errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err);
355  }
356  }
357  if ( !fatal ) {
358  err = snd_pcm_hw_params_set_access( handle, hwparams, access );
359  if ( err < 0 ) {
360  fatal = true;
361  errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_access: err = %1").arg(err);
362  }
363  }
364  if ( !fatal ) {
365  err = setFormat();
366  if ( err < 0 ) {
367  fatal = true;
368  errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_format: err = %1").arg(err);
369  }
370  }
371  if ( !fatal ) {
372  err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() );
373  if ( err < 0 ) {
374  fatal = true;
375  errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_channels: err = %1").arg(err);
376  }
377  }
378  if ( !fatal ) {
379  err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 );
380  if ( err < 0 ) {
381  fatal = true;
382  errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
383  }
384  }
385  if ( !fatal ) {
386  unsigned int maxBufferTime = 0;
387  unsigned int minBufferTime = 0;
388  unsigned int maxPeriodTime = 0;
389  unsigned int minPeriodTime = 0;
390 
391  err = snd_pcm_hw_params_get_buffer_time_max(hwparams, &maxBufferTime, &dir);
392  if ( err >= 0)
393  err = snd_pcm_hw_params_get_buffer_time_min(hwparams, &minBufferTime, &dir);
394  if ( err >= 0)
395  err = snd_pcm_hw_params_get_period_time_max(hwparams, &maxPeriodTime, &dir);
396  if ( err >= 0)
397  err = snd_pcm_hw_params_get_period_time_min(hwparams, &minPeriodTime, &dir);
398 
399  if ( err < 0 ) {
400  fatal = true;
401  errMessage = QString::fromLatin1("QAudioOutput: buffer/period min and max: err = %1").arg(err);
402  } else {
403  if (maxBufferTime < buffer_time || buffer_time < minBufferTime || maxPeriodTime < period_time || minPeriodTime > period_time) {
404 #ifdef DEBUG_AUDIO
405  qDebug()<<"defaults out of range";
406  qDebug()<<"pmin="<<minPeriodTime<<", pmax="<<maxPeriodTime<<", bmin="<<minBufferTime<<", bmax="<<maxBufferTime;
407 #endif
408  period_time = minPeriodTime;
409  if (period_time*4 <= maxBufferTime) {
410  // Use 4 periods if possible
411  buffer_time = period_time*4;
412  chunks = 4;
413  } else if (period_time*2 <= maxBufferTime) {
414  // Use 2 periods if possible
415  buffer_time = period_time*2;
416  chunks = 2;
417  } else {
418  qWarning()<<"QAudioOutput: alsa only supports single period!";
419  fatal = true;
420  }
421 #ifdef DEBUG_AUDIO
422  qDebug()<<"used: buffer_time="<<buffer_time<<", period_time="<<period_time;
423 #endif
424  }
425  }
426  }
427  if ( !fatal ) {
428  err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir);
429  if ( err < 0 ) {
430  fatal = true;
431  errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
432  }
433  }
434  if ( !fatal ) {
435  err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir);
436  if ( err < 0 ) {
437  fatal = true;
438  errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err);
439  }
440  }
441  if ( !fatal ) {
442  err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir);
443  if ( err < 0 ) {
444  fatal = true;
445  errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_periods_near: err = %1").arg(err);
446  }
447  }
448  if ( !fatal ) {
449  err = snd_pcm_hw_params(handle, hwparams);
450  if ( err < 0 ) {
451  fatal = true;
452  errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params: err = %1").arg(err);
453  }
454  }
455  if( err < 0) {
456  qWarning()<<errMessage;
459  return false;
460  }
461  snd_pcm_hw_params_get_buffer_size(hwparams,&buffer_frames);
462  buffer_size = snd_pcm_frames_to_bytes(handle,buffer_frames);
463  snd_pcm_hw_params_get_period_size(hwparams,&period_frames, &dir);
464  period_size = snd_pcm_frames_to_bytes(handle,period_frames);
465  snd_pcm_hw_params_get_buffer_time(hwparams,&buffer_time, &dir);
466  snd_pcm_hw_params_get_period_time(hwparams,&period_time, &dir);
467 
468  // Step 3: Set the desired SW parameters.
469  snd_pcm_sw_params_t *swparams;
470  snd_pcm_sw_params_alloca(&swparams);
471  snd_pcm_sw_params_current(handle, swparams);
472  snd_pcm_sw_params_set_start_threshold(handle,swparams,period_frames);
473  snd_pcm_sw_params_set_stop_threshold(handle,swparams,buffer_frames);
474  snd_pcm_sw_params_set_avail_min(handle, swparams,period_frames);
475  snd_pcm_sw_params(handle, swparams);
476 
477  // Step 4: Prepare audio
478  if(audioBuffer == 0)
479  audioBuffer = new char[snd_pcm_frames_to_bytes(handle,buffer_frames)];
480  snd_pcm_prepare( handle );
481  snd_pcm_start(handle);
482 
483  // Step 5: Setup callback and timer fallback
484  snd_async_add_pcm_handler(&ahandler, handle, async_callback, this);
486 
487  // Step 6: Start audio processing
488  timer->start(period_time/1000);
489 
491  timeStamp.restart();
492  elapsedTimeOffset = 0;
494  totalTimeValue = 0;
495  opened = true;
496 
497  return true;
498 }
499 
501 {
502  timer->stop();
503 
504  if ( handle ) {
505  snd_pcm_drain( handle );
506  snd_pcm_close( handle );
507  handle = 0;
508  delete [] audioBuffer;
509  audioBuffer=0;
510  }
511  if(!pullMode && audioSource) {
512  delete audioSource;
513  audioSource = 0;
514  }
515  opened = false;
516 }
517 
519 {
520  if(resuming)
521  return period_size;
522 
524  return 0;
525  int frames = snd_pcm_avail_update(handle);
526  if((int)frames > (int)buffer_frames)
527  frames = buffer_frames;
528 
529  return snd_pcm_frames_to_bytes(handle, frames);
530 }
531 
533 {
534  // Write out some audio data
535  if ( !handle )
536  return 0;
537 #ifdef DEBUG_AUDIO
538  qDebug()<<"frames to write out = "<<
539  snd_pcm_bytes_to_frames( handle, (int)len )<<" ("<<len<<") bytes";
540 #endif
541  int frames, err;
542  int space = bytesFree();
543  if(len < space) {
544  // Just write it
545  frames = snd_pcm_bytes_to_frames( handle, (int)len );
546  err = snd_pcm_writei( handle, data, frames );
547  } else {
548  // Only write space worth
549  frames = snd_pcm_bytes_to_frames( handle, (int)space );
550  err = snd_pcm_writei( handle, data, frames );
551  }
552  if(err > 0) {
553  totalTimeValue += err;
554  resuming = false;
559  }
560  return snd_pcm_frames_to_bytes( handle, err );
561  } else
562  err = xrun_recovery(err);
563 
564  if(err < 0) {
565  close();
569  }
570  return 0;
571 }
572 
574 {
575  return period_size;
576 }
577 
579 {
581  buffer_size = value;
582 }
583 
585 {
586  return buffer_size;
587 }
588 
590 {
591  intervalTime = qMax(0, ms);
592 }
593 
595 {
596  return intervalTime;
597 }
598 
600 {
601  return qint64(1000000) * totalTimeValue / settings.frequency();
602 }
603 
605 {
607  int err = 0;
608 
609  if(handle) {
610  err = snd_pcm_prepare( handle );
611  if(err < 0)
612  xrun_recovery(err);
613 
614  err = snd_pcm_start(handle);
615  if(err < 0)
616  xrun_recovery(err);
617 
618  bytesAvailable = (int)snd_pcm_frames_to_bytes(handle, buffer_frames);
619  }
620  resuming = true;
621 
623 
625  timer->start(period_time/1000);
627  }
628 }
629 
631 {
632  return settings;
633 }
634 
636 {
638  timer->stop();
642  }
643 }
644 
646 {
648  return;
649 #ifdef DEBUG_AUDIO
650  QTime now(QTime::currentTime());
651  qDebug()<<now.second()<<"s "<<now.msec()<<"ms :userFeed() OUT";
652 #endif
655 
656  deviceReady();
657 }
658 
660 {
661  updateAvailable();
662 }
663 
664 
666 {
667 #ifdef DEBUG_AUDIO
668  QTime now(QTime::currentTime());
669  qDebug()<<now.second()<<"s "<<now.msec()<<"ms :updateAvailable()";
670 #endif
672 }
673 
675 {
676  if(pullMode) {
677  int l = 0;
678  int chunks = bytesAvailable/period_size;
679  if(chunks==0) {
681  return false;
682  }
683 #ifdef DEBUG_AUDIO
684  qDebug()<<"deviceReady() avail="<<bytesAvailable<<" bytes, period size="<<period_size<<" bytes";
685  qDebug()<<"deviceReady() no. of chunks that can fit ="<<chunks<<", chunks in bytes ="<<period_size*chunks;
686 #endif
687  int input = period_frames*chunks;
688  if(input > (int)buffer_frames)
689  input = buffer_frames;
690  l = audioSource->read(audioBuffer,snd_pcm_frames_to_bytes(handle, input));
691  if(l > 0) {
692  // Got some data to output
694  return true;
695  qint64 bytesWritten = write(audioBuffer,l);
696  if (bytesWritten != l)
697  audioSource->seek(audioSource->pos()-(l-bytesWritten));
699 
700  } else if(l == 0) {
701  // Did not get any data to output
703  if(bytesAvailable > snd_pcm_frames_to_bytes(handle, buffer_frames-period_frames)) {
704  // Underrun
709  }
710  }
711 
712  } else if(l < 0) {
713  close();
717  }
718  } else {
720  if(bytesAvailable > snd_pcm_frames_to_bytes(handle, buffer_frames-period_frames)) {
721  // Underrun
726  }
727  }
728  }
729 
731  return true;
732 
734  emit notify();
736  timeStamp.restart();
737  }
738  return true;
739 }
740 
742 {
744  return 0;
745 
746  return clockStamp.elapsed()*1000;
747 }
748 
750 {
751  if(handle)
752  snd_pcm_reset(handle);
753 
754  stop();
755 }
756 
758 {
759  audioDevice = qobject_cast<QAudioOutputPrivate*>(audio);
760 }
761 
763 
765 {
766  Q_UNUSED(data)
767  Q_UNUSED(len)
768 
769  return 0;
770 }
771 
773 {
774  int retry = 0;
775  qint64 written = 0;
776  if((audioDevice->deviceState == QAudio::ActiveState)
777  ||(audioDevice->deviceState == QAudio::IdleState)) {
778  while(written < len) {
779  int chunk = audioDevice->write(data+written,(len-written));
780  if(chunk <= 0)
781  retry++;
782  written+=chunk;
783  if(retry > 10)
784  return written;
785  }
786  }
787  return written;
788 
789 }
790 
qint64 write(const char *data, qint64 len)
Error
Definition: qaudio.h:58
snd_async_handler_t * ahandler
int frequency() const
Use sampleRate() instead.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void notify()
This signal is emitted when x ms of audio data has been processed the interval set by setNotifyInterv...
void stateChanged(QAudio::State)
This signal is emitted when the device state has changed.
OutputPrivate(QAudioOutputPrivate *audio)
QAudio::State state() const
Returns the state of audio processing.
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
void resume()
Resumes processing audio data after a suspend()
#define SLOT(a)
Definition: qobjectdefs.h:226
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
Definition: qiodevice.cpp:624
static void async_callback(snd_async_handler_t *ahandler)
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
int sampleSize() const
Returns the current sample size value.
snd_pcm_access_t access
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
QAudio::Error error() const
Returns the error state.
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 reset()
Drops all audio data in the buffers, resets buffers to zero.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
Q_CORE_EXPORT void qDebug(const char *,...)
void setBufferSize(int value)
Sets the audio buffer size to value in bytes.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QAudioFormat::SampleType sampleType() const
Returns the current SampleType value.
The QTime class provides clock time functions.
Definition: qdatetime.h:148
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QAudioOutputPrivate(const QByteArray &device, const QAudioFormat &audioFormat)
qint64 restart()
Restarts the timer and returns the time elapsed since the previous start.
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...
int notifyInterval() const
Returns the notify interval in milliseconds.
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
snd_pcm_hw_params_t * hwparams
const char * name
#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
qint64 elapsedUSecs() const
Returns the milliseconds since start() was called, including time in Idle and suspend states...
qint64 processedUSecs() const
Returns the amount of audio data processed since start() was called in milliseconds.
__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
void suspend()
Stops processing audio data, preserving buffered audio data.
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
int periodSize() const
Returns the period size in bytes.
QAudioFormat format() const
Returns the QAudioFormat being used.
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 bytesFree() const
Returns the free space available in bytes in the audio buffer.
void setNotifyInterval(int milliSeconds)
Sets the interval for notify() signal to be emitted.
snd_pcm_uframes_t period_frames
int qstrncmp(const char *str1, const char *str2, uint len)
Definition: qbytearray.h:101
snd_pcm_format_t pcmformat
QFactoryLoader * l
int bufferSize() const
Returns the audio buffer size in bytes.
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
QIODevice * start(QIODevice *device=0)
Uses the device as the QIODevice to transfer data.
void stop()
Stops the audio output.
The QAudioFormat class stores audio parameter information.
Definition: qaudioformat.h:60
The QTimer class provides repetitive and single-shot timers.
Definition: qtimer.h:56
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
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
Definition: qiodevice.cpp:659
snd_pcm_uframes_t buffer_frames
qint64 writeData(const char *data, qint64 len)
Writes up to maxSize bytes from data to the device.
int channels() const
Use channelCount() instead.