53 #include <QtCore/qcoreapplication.h> 67 access = SND_PCM_ACCESS_RW_INTERLEAVED;
114 (snd_async_handler_get_callback_private(ahandler));
127 err = snd_pcm_prepare(
handle);
131 }
else if((err == -ESTRPIPE)||(err == -EIO)) {
133 while((err = snd_pcm_resume(
handle)) == -EAGAIN){
142 err = snd_pcm_prepare(
handle);
158 snd_pcm_format_t
pcmformat = SND_PCM_FORMAT_UNKNOWN;
161 pcmformat = SND_PCM_FORMAT_U8;
166 pcmformat = SND_PCM_FORMAT_S16_LE;
168 pcmformat = SND_PCM_FORMAT_S16_BE;
171 pcmformat = SND_PCM_FORMAT_U16_LE;
173 pcmformat = SND_PCM_FORMAT_U16_BE;
178 pcmformat = SND_PCM_FORMAT_S24_LE;
180 pcmformat = SND_PCM_FORMAT_S24_BE;
183 pcmformat = SND_PCM_FORMAT_U24_LE;
185 pcmformat = SND_PCM_FORMAT_U24_BE;
190 pcmformat = SND_PCM_FORMAT_S32_LE;
192 pcmformat = SND_PCM_FORMAT_S32_BE;
195 pcmformat = SND_PCM_FORMAT_U32_LE;
197 pcmformat = SND_PCM_FORMAT_U32_BE;
200 pcmformat = SND_PCM_FORMAT_FLOAT_LE;
202 pcmformat = SND_PCM_FORMAT_FLOAT_BE;
206 pcmformat = SND_PCM_FORMAT_FLOAT64_LE;
208 pcmformat = SND_PCM_FORMAT_FLOAT64_BE;
211 return pcmformat != SND_PCM_FORMAT_UNKNOWN
285 qWarning(
"QAudioOutput: open error, invalid format.");
287 qWarning(
"QAudioOutput: open error, invalid sample rate (%d).",
302 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) 308 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) 316 while(snd_card_get_name(idx,&name) == 0) {
326 while((count < 5) && (err < 0)) {
331 if (( err < 0)||(
handle == 0)) {
336 snd_pcm_nonblock(
handle, 0 );
339 snd_pcm_hw_params_alloca( &
hwparams );
343 unsigned int chunks = 8;
379 err = snd_pcm_hw_params_set_rate_near(
handle,
hwparams, &freakuency, 0 );
386 unsigned int maxBufferTime = 0;
387 unsigned int minBufferTime = 0;
388 unsigned int maxPeriodTime = 0;
389 unsigned int minPeriodTime = 0;
391 err = snd_pcm_hw_params_get_buffer_time_max(
hwparams, &maxBufferTime, &dir);
393 err = snd_pcm_hw_params_get_buffer_time_min(
hwparams, &minBufferTime, &dir);
395 err = snd_pcm_hw_params_get_period_time_max(
hwparams, &maxPeriodTime, &dir);
397 err = snd_pcm_hw_params_get_period_time_min(
hwparams, &minPeriodTime, &dir);
405 qDebug()<<
"defaults out of range";
406 qDebug()<<
"pmin="<<minPeriodTime<<
", pmax="<<maxPeriodTime<<
", bmin="<<minBufferTime<<
", bmax="<<maxBufferTime;
408 period_time = minPeriodTime;
409 if (period_time*4 <= maxBufferTime) {
413 }
else if (period_time*2 <= maxBufferTime) {
418 qWarning()<<
"QAudioOutput: alsa only supports single period!";
431 errMessage =
QString::fromLatin1(
"QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err = %1").
arg(err);
438 errMessage =
QString::fromLatin1(
"QAudioOutput: snd_pcm_hw_params_set_period_time_near: err = %1").
arg(err);
442 err = snd_pcm_hw_params_set_periods_near(
handle,
hwparams, &chunks, &dir);
469 snd_pcm_sw_params_t *swparams;
470 snd_pcm_sw_params_alloca(&swparams);
471 snd_pcm_sw_params_current(
handle, swparams);
475 snd_pcm_sw_params(
handle, swparams);
480 snd_pcm_prepare(
handle );
525 int frames = snd_pcm_avail_update(
handle);
529 return snd_pcm_frames_to_bytes(
handle, frames);
538 qDebug()<<
"frames to write out = "<<
539 snd_pcm_bytes_to_frames(
handle, (
int)len )<<
" ("<<len<<
") bytes";
545 frames = snd_pcm_bytes_to_frames(
handle, (
int)len );
546 err = snd_pcm_writei(
handle, data, frames );
549 frames = snd_pcm_bytes_to_frames(
handle, (
int)space );
550 err = snd_pcm_writei(
handle, data, frames );
560 return snd_pcm_frames_to_bytes(
handle, err );
610 err = snd_pcm_prepare(
handle );
614 err = snd_pcm_start(
handle);
685 qDebug()<<
"deviceReady() no. of chunks that can fit ="<<chunks<<
", chunks in bytes ="<<period_size*chunks;
696 if (bytesWritten != l)
778 while(written < len) {
779 int chunk = audioDevice->write(data+written,(len-written));
qint64 write(const char *data, qint64 len)
snd_async_handler_t * ahandler
#define QT_END_NAMESPACE
This macro expands to.
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.
int length() const
Returns the number of characters in this string.
void resume()
Resumes processing audio data after a suspend()
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
static void async_callback(snd_async_handler_t *ahandler)
QAudio::State deviceState
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int msec() const
Returns the millisecond part (0 to 999) of the time.
The QString class provides a Unicode character string.
T * qobject_cast(QObject *object)
friend class OutputPrivate
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)
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes all pending events for the calling thread according to the specified flags until there are ...
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...
Q_CORE_EXPORT void qDebug(const char *,...)
void setBufferSize(int value)
Sets the audio buffer size to value in bytes.
The QTime class provides clock time functions.
#define QT_BEGIN_NAMESPACE
This macro expands to.
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...
snd_pcm_hw_params_t * hwparams
int xrun_recovery(int err)
Q_CORE_EXPORT void qWarning(const char *,...)
int second() const
Returns the second part (0 to 59) of the time.
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
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.
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
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.
void suspend()
Stops processing audio data, preserving buffered audio data.
T & first()
Returns a reference to the first item in the list.
const char * constData() const
Returns a pointer to the data stored in the byte array.
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.
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
int compare(const QString &s) const
static QTime currentTime()
Returns the current time as reported by the system clock.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
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)
snd_pcm_format_t pcmformat
int bufferSize() const
Returns the audio buffer size in bytes.
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
QIODevice * start(QIODevice *device=0)
Uses the device as the QIODevice to transfer data.
void stop()
Stops the audio output.
The QTimer class provides repetitive and single-shot timers.
static QList< QByteArray > availableDevices(QAudio::Mode)
The QIODevice class is the base interface class of all I/O devices in Qt.
void stop()
Stops the timer.
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
snd_pcm_uframes_t buffer_frames
qint64 writeData(const char *data, qint64 len)
Writes up to maxSize bytes from data to the device.