src/multimedia/audio/qaudioformat.cpp
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtMultimedia module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QtMultimedia/qaudioformat.h>
       
    43 
       
    44 
       
    45 QT_BEGIN_NAMESPACE
       
    46 
       
    47 
       
    48 class QAudioFormatPrivate : public QSharedData
       
    49 {
       
    50 public:
       
    51     QAudioFormatPrivate()
       
    52     {
       
    53         frequency = -1;
       
    54         channels = -1;
       
    55         sampleSize = -1;
       
    56         byteOrder = QAudioFormat::Endian(QSysInfo::ByteOrder);
       
    57         sampleType = QAudioFormat::Unknown;
       
    58     }
       
    59 
       
    60     QAudioFormatPrivate(const QAudioFormatPrivate &other):
       
    61         QSharedData(other),
       
    62         codec(other.codec),
       
    63         byteOrder(other.byteOrder),
       
    64         sampleType(other.sampleType),
       
    65         frequency(other.frequency),
       
    66         channels(other.channels),
       
    67         sampleSize(other.sampleSize)
       
    68     {
       
    69     }
       
    70 
       
    71     QAudioFormatPrivate& operator=(const QAudioFormatPrivate &other)
       
    72     {
       
    73         codec = other.codec;
       
    74         byteOrder = other.byteOrder;
       
    75         sampleType = other.sampleType;
       
    76         frequency = other.frequency;
       
    77         channels = other.channels;
       
    78         sampleSize = other.sampleSize;
       
    79 
       
    80         return *this;
       
    81     }
       
    82 
       
    83     QString codec;
       
    84     QAudioFormat::Endian byteOrder;
       
    85     QAudioFormat::SampleType sampleType;
       
    86     int frequency;
       
    87     int channels;
       
    88     int sampleSize;
       
    89 };
       
    90 
       
    91 /*!
       
    92     \class QAudioFormat
       
    93     \brief The QAudioFormat class stores audio parameter information.
       
    94 
       
    95     \inmodule QtMultimedia
       
    96     \ingroup  multimedia
       
    97     \since 4.6
       
    98 
       
    99     An audio format specifies how data in an audio stream is arranged,
       
   100     i.e, how the stream is to be interpreted. The encoding itself is
       
   101     specified by the codec() used for the stream.
       
   102 
       
   103     In addition to the encoding, QAudioFormat contains other
       
   104     parameters that further specify how the audio data is arranged.
       
   105     These are the frequency, the number of channels, the sample size,
       
   106     the sample type, and the byte order. The following table describes
       
   107     these in more detail.
       
   108 
       
   109     \table
       
   110         \header
       
   111             \o Parameter
       
   112             \o Description
       
   113         \row
       
   114             \o Frequency
       
   115             \o Samples per second of audio data in Hertz.
       
   116         \row
       
   117             \o Number of channels
       
   118             \o The number of audio channels (typically one for mono
       
   119                or two for stereo)
       
   120         \row
       
   121             \o Sample size
       
   122             \o How much data is stored in each sample (typically 8
       
   123                or 16)
       
   124         \row
       
   125             \o Sample type
       
   126             \o Numerical representation of sample (typically signed integer,
       
   127                unsigned integer or float)
       
   128         \row
       
   129             \o Byte order
       
   130             \o Byte ordering of sample (typically little endian, big endian)
       
   131     \endtable
       
   132 
       
   133     You can obtain audio formats compatible with the audio device used
       
   134     through functions in QAudioDeviceInfo. This class also lets you
       
   135     query available parameter values for a device, so that you can set
       
   136     the parameters yourself. See the QAudioDeviceInfo class
       
   137     description for details. You need to know the format of the audio
       
   138     streams you wish to play. Qt does not set up formats for you.
       
   139 */
       
   140 
       
   141 /*!
       
   142     Construct a new audio format.
       
   143 
       
   144     Values are initialized as follows:
       
   145     \list
       
   146     \o frequency()  = -1
       
   147     \o channels()   = -1
       
   148     \o sampleSize() = -1
       
   149     \o byteOrder()  = QAudioFormat::Endian(QSysInfo::ByteOrder)
       
   150     \o sampleType() = QAudioFormat::Unknown
       
   151     \c codec()      = ""
       
   152     \endlist
       
   153 */
       
   154 
       
   155 QAudioFormat::QAudioFormat():
       
   156     d(new QAudioFormatPrivate)
       
   157 {
       
   158 }
       
   159 
       
   160 /*!
       
   161     Construct a new audio format using \a other.
       
   162 */
       
   163 
       
   164 QAudioFormat::QAudioFormat(const QAudioFormat &other):
       
   165     d(other.d)
       
   166 {
       
   167 }
       
   168 
       
   169 /*!
       
   170     Destroy this audio format.
       
   171 */
       
   172 
       
   173 QAudioFormat::~QAudioFormat()
       
   174 {
       
   175 }
       
   176 
       
   177 /*!
       
   178     Assigns \a other to this QAudioFormat implementation.
       
   179 */
       
   180 
       
   181 QAudioFormat& QAudioFormat::operator=(const QAudioFormat &other)
       
   182 {
       
   183     d = other.d;
       
   184     return *this;
       
   185 }
       
   186 
       
   187 /*!
       
   188   Returns true if this QAudioFormat is equal to the \a other
       
   189   QAudioFormat; otherwise returns false.
       
   190 
       
   191   All elements of QAudioFormat are used for the comparison.
       
   192 */
       
   193 
       
   194 bool QAudioFormat::operator==(const QAudioFormat &other) const
       
   195 {
       
   196     return d->frequency == other.d->frequency &&
       
   197             d->channels == other.d->channels &&
       
   198             d->sampleSize == other.d->sampleSize &&
       
   199             d->byteOrder == other.d->byteOrder &&
       
   200             d->codec == other.d->codec &&
       
   201             d->sampleType == other.d->sampleType;
       
   202 }
       
   203 
       
   204 /*!
       
   205   Returns true if this QAudioFormat is not equal to the \a other
       
   206   QAudioFormat; otherwise returns false.
       
   207 
       
   208   All elements of QAudioFormat are used for the comparison.
       
   209 */
       
   210 
       
   211 bool QAudioFormat::operator!=(const QAudioFormat& other) const
       
   212 {
       
   213     return !(*this == other);
       
   214 }
       
   215 
       
   216 /*!
       
   217     Returns true if any of the parameters are invalid.
       
   218 */
       
   219 
       
   220 bool QAudioFormat::isNull() const
       
   221 {
       
   222     return d->frequency == -1 && d->channels == -1 &&
       
   223             d->sampleSize == -1 &&
       
   224             d->byteOrder == QAudioFormat::Endian(QSysInfo::ByteOrder) &&
       
   225             d->sampleType == QAudioFormat::Unknown &&
       
   226             d->codec.isNull();
       
   227 }
       
   228 
       
   229 /*!
       
   230    Sets the frequency to \a frequency.
       
   231 */
       
   232 
       
   233 void QAudioFormat::setFrequency(int frequency)
       
   234 {
       
   235     d->frequency = frequency;
       
   236 }
       
   237 
       
   238 /*!
       
   239     Returns the current frequency value.
       
   240 */
       
   241 
       
   242 int QAudioFormat::frequency() const
       
   243 {
       
   244     return d->frequency;
       
   245 }
       
   246 
       
   247 /*!
       
   248    Sets the channels to \a channels.
       
   249 */
       
   250 
       
   251 void QAudioFormat::setChannels(int channels)
       
   252 {
       
   253     d->channels = channels;
       
   254 }
       
   255 
       
   256 /*!
       
   257     Returns the current channel value.
       
   258 */
       
   259 
       
   260 int QAudioFormat::channels() const
       
   261 {
       
   262     return d->channels;
       
   263 }
       
   264 
       
   265 /*!
       
   266    Sets the sampleSize to \a sampleSize.
       
   267 */
       
   268 
       
   269 void QAudioFormat::setSampleSize(int sampleSize)
       
   270 {
       
   271     d->sampleSize = sampleSize;
       
   272 }
       
   273 
       
   274 /*!
       
   275     Returns the current sampleSize value.
       
   276 */
       
   277 
       
   278 int QAudioFormat::sampleSize() const
       
   279 {
       
   280     return d->sampleSize;
       
   281 }
       
   282 
       
   283 /*!
       
   284    Sets the codec to \a codec.
       
   285 
       
   286    \sa QAudioDeviceInfo::supportedCodecs()
       
   287 */
       
   288 
       
   289 void QAudioFormat::setCodec(const QString &codec)
       
   290 {
       
   291     d->codec = codec;
       
   292 }
       
   293 
       
   294 /*!
       
   295     Returns the current codec value.
       
   296 
       
   297    \sa QAudioDeviceInfo::supportedCodecs()
       
   298 */
       
   299 
       
   300 QString QAudioFormat::codec() const
       
   301 {
       
   302     return d->codec;
       
   303 }
       
   304 
       
   305 /*!
       
   306    Sets the byteOrder to \a byteOrder.
       
   307 */
       
   308 
       
   309 void QAudioFormat::setByteOrder(QAudioFormat::Endian byteOrder)
       
   310 {
       
   311     d->byteOrder = byteOrder;
       
   312 }
       
   313 
       
   314 /*!
       
   315     Returns the current byteOrder value.
       
   316 */
       
   317 
       
   318 QAudioFormat::Endian QAudioFormat::byteOrder() const
       
   319 {
       
   320     return d->byteOrder;
       
   321 }
       
   322 
       
   323 /*!
       
   324    Sets the sampleType to \a sampleType.
       
   325 */
       
   326 
       
   327 void QAudioFormat::setSampleType(QAudioFormat::SampleType sampleType)
       
   328 {
       
   329     d->sampleType = sampleType;
       
   330 }
       
   331 
       
   332 /*!
       
   333     Returns the current SampleType value.
       
   334 */
       
   335 
       
   336 QAudioFormat::SampleType QAudioFormat::sampleType() const
       
   337 {
       
   338     return d->sampleType;
       
   339 }
       
   340 
       
   341 /*!
       
   342     \enum QAudioFormat::SampleType
       
   343 
       
   344     \value Unknown       Not Set
       
   345     \value SignedInt     samples are signed integers
       
   346     \value UnSignedInt   samples are unsigned intergers
       
   347     \value Float         samples are floats
       
   348 */
       
   349 
       
   350 /*!
       
   351     \enum QAudioFormat::Endian
       
   352 
       
   353     \value BigEndian     samples are big endian byte order
       
   354     \value LittleEndian  samples are little endian byte order
       
   355 */
       
   356 
       
   357 QT_END_NAMESPACE
       
   358