Qt 4.8
qaudio_mac.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 #include "qaudio_mac_p.h"
44 
46 
47 // Debugging
48 QDebug operator<<(QDebug dbg, const QAudioFormat& audioFormat)
49 {
50  dbg.nospace() << "QAudioFormat(" <<
51  audioFormat.frequency() << "," <<
52  audioFormat.channels() << "," <<
53  audioFormat.sampleSize()<< "," <<
54  audioFormat.codec() << "," <<
55  audioFormat.byteOrder() << "," <<
56  audioFormat.sampleType() << ")";
57 
58  return dbg.space();
59 }
60 
61 
62 // Conversion
63 QAudioFormat toQAudioFormat(AudioStreamBasicDescription const& sf)
64 {
65  QAudioFormat audioFormat;
66 
67  audioFormat.setFrequency(sf.mSampleRate);
68  audioFormat.setChannels(sf.mChannelsPerFrame);
69  audioFormat.setSampleSize(sf.mBitsPerChannel);
70  audioFormat.setCodec(QString::fromLatin1("audio/pcm"));
71  audioFormat.setByteOrder((sf.mFormatFlags & kAudioFormatFlagIsBigEndian) != 0 ? QAudioFormat::BigEndian : QAudioFormat::LittleEndian);
73  if ((sf.mFormatFlags & kAudioFormatFlagIsSignedInteger) != 0)
75  else if ((sf.mFormatFlags & kAudioFormatFlagIsFloat) != 0)
76  type = QAudioFormat::Float;
77  audioFormat.setSampleType(type);
78 
79  return audioFormat;
80 }
81 
82 AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const& audioFormat)
83 {
84  AudioStreamBasicDescription sf;
85 
86  sf.mFormatFlags = kAudioFormatFlagIsPacked;
87  sf.mSampleRate = audioFormat.frequency();
88  sf.mFramesPerPacket = 1;
89  sf.mChannelsPerFrame = audioFormat.channels();
90  sf.mBitsPerChannel = audioFormat.sampleSize();
91  sf.mBytesPerFrame = sf.mChannelsPerFrame * (sf.mBitsPerChannel / 8);
92  sf.mBytesPerPacket = sf.mFramesPerPacket * sf.mBytesPerFrame;
93  sf.mFormatID = kAudioFormatLinearPCM;
94 
95  switch (audioFormat.sampleType()) {
96  case QAudioFormat::SignedInt: sf.mFormatFlags |= kAudioFormatFlagIsSignedInteger; break;
97  case QAudioFormat::UnSignedInt: /* default */ break;
98  case QAudioFormat::Float: sf.mFormatFlags |= kAudioFormatFlagIsFloat; break;
99  case QAudioFormat::Unknown: default: break;
100  }
101 
102  if (audioFormat.byteOrder() == QAudioFormat::BigEndian)
103  sf.mFormatFlags |= kAudioFormatFlagIsBigEndian;
104 
105  return sf;
106 }
107 
108 // QAudioRingBuffer
110  m_bufferSize(bufferSize)
111 {
112  m_buffer = new char[m_bufferSize];
113  reset();
114 }
115 
117 {
118  delete m_buffer;
119 }
120 
122 {
123  return m_bufferUsed;
124 }
125 
127 {
128  return m_bufferSize - m_bufferUsed;
129 }
130 
132 {
133  return m_bufferSize;
134 }
135 
137 {
138  m_readPos = 0;
139  m_writePos = 0;
140  m_bufferUsed = 0;
141 }
142 
144 
145 
int used() const
Definition: qaudio_mac.cpp:121
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
int type
Definition: qmetatype.cpp:239
int frequency() const
Use sampleRate() instead.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
void setSampleType(QAudioFormat::SampleType sampleType)
Sets the sampleType to sampleType.
int sampleSize() const
Returns the current sample size value.
QAudioFormat::Endian byteOrder() const
Returns the current byteOrder value.
QAudioFormat toQAudioFormat(AudioStreamBasicDescription const &sf)
Definition: qaudio_mac.cpp:63
QAudioFormat::SampleType sampleType() const
Returns the current SampleType value.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setChannels(int channels)
Use setChannelCount() instead.
QString codec() const
Returns the current codec value.
AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const &audioFormat)
Definition: qaudio_mac.cpp:82
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
void setFrequency(int frequency)
Use setSampleRate() instead.
int free() const
Definition: qaudio_mac.cpp:126
The QAudioFormat class stores audio parameter information.
Definition: qaudioformat.h:60
QAtomicInt m_bufferUsed
Definition: qaudio_mac_p.h:135
void setSampleSize(int sampleSize)
Sets the sample size to the sampleSize specified.
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
QDataStream & operator<<(QDataStream &out, const QUrl &url)
Writes url url to the stream out and returns a reference to the stream.
Definition: qurl.cpp:6757
int size() const
Definition: qaudio_mac.cpp:131
void setCodec(const QString &codec)
Sets the codec to codec.
void setByteOrder(QAudioFormat::Endian byteOrder)
Sets the byteOrder to byteOrder.
QAudioRingBuffer(int bufferSize)
Definition: qaudio_mac.cpp:109
int channels() const
Use channelCount() instead.