1 /*  This file is part of the KDE project
2     Copyright (C) 2008 Matthias Kretz <kretz@kde.org>
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License as published by the Free Software Foundation; either
7     version 2.1 of the License, or (at your option) version 3, or any
8     later version accepted by the membership of KDE e.V. (or its
9     successor approved by the membership of KDE e.V.), Nokia Corporation
10     (or its successors, if any) and the KDE Free Qt Foundation, which shall
11     act as a proxy defined in Section 6 of version 3 of the license.
12 
13     This library is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16     Lesser General Public License for more details.
17 
18     You should have received a copy of the GNU Lesser General Public
19     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #include "audioformat.h"
24 #include "phonondefs_p.h"
25 
26 namespace Phonon
27 {
28 namespace Experimental
29 {
30 
31 class AudioFormatPrivate
32 {
33     P_DECLARE_PUBLIC(AudioFormat)
34     protected:
35         AudioFormat *q_ptr;
36 };
37 
AudioFormat(int sampleRate,int channelCount,Phonon::Experimental::BitRate bitRate,QSysInfo::Endian byteOrder)38 AudioFormat::AudioFormat(int sampleRate, int channelCount, Phonon::Experimental::BitRate bitRate, QSysInfo::Endian byteOrder)
39 {
40     s.m_sampleRate = sampleRate;
41     s.m_channelCount = channelCount;
42     s.m_bitRate = bitRate;
43     s.m_byteOrder = byteOrder;
44 }
45 
~AudioFormat()46 AudioFormat::~AudioFormat()
47 {
48 }
49 
sampleRate() const50 int AudioFormat::sampleRate() const
51 {
52     return s.m_sampleRate;
53 }
54 
channelCount() const55 int AudioFormat::channelCount() const
56 {
57     return s.m_channelCount;
58 }
59 
bitRate() const60 Phonon::Experimental::BitRate AudioFormat::bitRate() const
61 {
62     return s.m_bitRate;
63 }
64 
byteOrder() const65 QSysInfo::Endian AudioFormat::byteOrder() const
66 {
67     return s.m_byteOrder;
68 }
69 
AudioFormat(const AudioFormat & f)70 AudioFormat::AudioFormat(const AudioFormat &f)
71 {
72     s.m_sampleRate = f.sampleRate();
73     s.m_channelCount = f.channelCount();
74     s.m_bitRate = f.bitRate();
75     s.m_byteOrder = f.byteOrder();
76 }
77 
operator =(const AudioFormat & f)78 AudioFormat &AudioFormat::operator=(const AudioFormat &f)
79 {
80     s.m_sampleRate = f.sampleRate();
81     s.m_channelCount = f.channelCount();
82     s.m_bitRate = f.bitRate();
83     s.m_byteOrder = f.byteOrder();
84     return *this;
85 }
86 
operator ==(const AudioFormat & f) const87 bool AudioFormat::operator==(const AudioFormat &f) const
88 {
89     return s.m_sampleRate == f.sampleRate() &&
90         s.m_channelCount == f.channelCount() &&
91         s.m_bitRate == f.bitRate() &&
92         s.m_byteOrder == f.byteOrder();
93 }
94 
operator <(const AudioFormat & f) const95 bool AudioFormat::operator<(const AudioFormat &f) const
96 {
97     return s.m_bitRate < f.bitRate() ||
98         (s.m_bitRate == f.bitRate() && (s.m_sampleRate < f.sampleRate() ||
99                                       (s.m_sampleRate == f.sampleRate() && (s.m_channelCount < f.channelCount() ||
100                                                                           (s.m_channelCount == f.channelCount() && s.m_byteOrder != QSysInfo::ByteOrder && f.byteOrder() == QSysInfo::ByteOrder)))));
101 }
102 
key() const103 quint32 AudioFormat::key() const
104 {
105     return (s.m_byteOrder == QSysInfo::ByteOrder ? 1 : 0) + // 1 bit  least significant
106         (s.m_channelCount << 1) + // give it 8 bits
107         (s.m_sampleRate) + // 192kHz ~ 18 bits (let the (unimportant) lower 9 bits overlap with channels + byteOrder)
108         (s.m_bitRate << 18); //                                       most significant
109 }
110 
111 } // namespace Experimental
112 } // namespace Phonon
113