File indexing completed on 2024-05-05 04:44:40
0001 /* This file is part of the KDE project 0002 Copyright (C) 2008 Matthias Kretz <kretz@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) version 3, or any 0008 later version accepted by the membership of KDE e.V. (or its 0009 successor approved by the membership of KDE e.V.), Nokia Corporation 0010 (or its successors, if any) and the KDE Free Qt Foundation, which shall 0011 act as a proxy defined in Section 6 of version 3 of the license. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Lesser General Public License for more details. 0017 0018 You should have received a copy of the GNU Lesser General Public 0019 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0020 0021 */ 0022 0023 #include "audioformat.h" 0024 #include "phonondefs_p.h" 0025 0026 namespace Phonon 0027 { 0028 namespace Experimental 0029 { 0030 0031 class AudioFormatPrivate 0032 { 0033 P_DECLARE_PUBLIC(AudioFormat) 0034 protected: 0035 AudioFormat *q_ptr; 0036 }; 0037 0038 AudioFormat::AudioFormat(int sampleRate, int channelCount, Phonon::Experimental::BitRate bitRate, QSysInfo::Endian byteOrder) 0039 { 0040 s.m_sampleRate = sampleRate; 0041 s.m_channelCount = channelCount; 0042 s.m_bitRate = bitRate; 0043 s.m_byteOrder = byteOrder; 0044 } 0045 0046 AudioFormat::~AudioFormat() 0047 { 0048 } 0049 0050 int AudioFormat::sampleRate() const 0051 { 0052 return s.m_sampleRate; 0053 } 0054 0055 int AudioFormat::channelCount() const 0056 { 0057 return s.m_channelCount; 0058 } 0059 0060 Phonon::Experimental::BitRate AudioFormat::bitRate() const 0061 { 0062 return s.m_bitRate; 0063 } 0064 0065 QSysInfo::Endian AudioFormat::byteOrder() const 0066 { 0067 return s.m_byteOrder; 0068 } 0069 0070 AudioFormat::AudioFormat(const AudioFormat &f) 0071 { 0072 s.m_sampleRate = f.sampleRate(); 0073 s.m_channelCount = f.channelCount(); 0074 s.m_bitRate = f.bitRate(); 0075 s.m_byteOrder = f.byteOrder(); 0076 } 0077 0078 AudioFormat &AudioFormat::operator=(const AudioFormat &f) 0079 { 0080 s.m_sampleRate = f.sampleRate(); 0081 s.m_channelCount = f.channelCount(); 0082 s.m_bitRate = f.bitRate(); 0083 s.m_byteOrder = f.byteOrder(); 0084 return *this; 0085 } 0086 0087 bool AudioFormat::operator==(const AudioFormat &f) const 0088 { 0089 return s.m_sampleRate == f.sampleRate() && 0090 s.m_channelCount == f.channelCount() && 0091 s.m_bitRate == f.bitRate() && 0092 s.m_byteOrder == f.byteOrder(); 0093 } 0094 0095 bool AudioFormat::operator<(const AudioFormat &f) const 0096 { 0097 return s.m_bitRate < f.bitRate() || 0098 (s.m_bitRate == f.bitRate() && (s.m_sampleRate < f.sampleRate() || 0099 (s.m_sampleRate == f.sampleRate() && (s.m_channelCount < f.channelCount() || 0100 (s.m_channelCount == f.channelCount() && s.m_byteOrder != QSysInfo::ByteOrder && f.byteOrder() == QSysInfo::ByteOrder))))); 0101 } 0102 0103 quint32 AudioFormat::key() const 0104 { 0105 return (s.m_byteOrder == QSysInfo::ByteOrder ? 1 : 0) + // 1 bit least significant 0106 (s.m_channelCount << 1) + // give it 8 bits 0107 (s.m_sampleRate) + // 192kHz ~ 18 bits (let the (unimportant) lower 9 bits overlap with channels + byteOrder) 0108 (s.m_bitRate << 18); // most significant 0109 } 0110 0111 } // namespace Experimental 0112 } // namespace Phonon