diff options
Diffstat (limited to 'src/multimedia/audio/qaudiohelpers.cpp')
-rw-r--r-- | src/multimedia/audio/qaudiohelpers.cpp | 137 |
1 files changed, 18 insertions, 119 deletions
diff --git a/src/multimedia/audio/qaudiohelpers.cpp b/src/multimedia/audio/qaudiohelpers.cpp index fae591477..c2d8681c6 100644 --- a/src/multimedia/audio/qaudiohelpers.cpp +++ b/src/multimedia/audio/qaudiohelpers.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qaudiohelpers_p.h" @@ -43,49 +7,6 @@ QT_BEGIN_NAMESPACE -// Base implementation of 24 bits number. -// Used to adjust 3 bytes values by a factor. -// TODO: Uses little-endian only. -class Int24 -{ -public: - quint8 data[3]; - Int24(qint32 v) { - data[0] = v & 0xFF; - data[1] = (v & 0xFF00) >> 8; - data[2] = (v & 0xFF0000) >> 16; - } - template<class T> - T multiply(qreal factor, T v = 0) const { - v |= data[0]; - v |= data[1] << 8; - v |= data[2] << 16; - v *= factor; - return v; - } -}; - -class qint24: public Int24 -{ -public: - qint24(qint32 v): Int24(v) {} - qint24 operator*(qreal factor) const { - // Checks if it is a signed value. - qint32 v = (data[2] & 0x80) ? 0xFF000000 : 0; - return multiply(factor, v); - } -}; - -class quint24: public Int24 -{ -public: - quint24(quint32 v): Int24(v) {} - quint24 operator*(qreal factor) const { - return multiply<quint32>(factor); - } -}; - - namespace QAudioHelperInternal { @@ -102,20 +23,8 @@ template<class T> void adjustSamples(qreal factor, const void *src, void *dst, i template<class T> struct signedVersion {}; template<> struct signedVersion<quint8> { - typedef qint8 TS; - enum {offset = 0x80}; -}; - -template<> struct signedVersion<quint16> -{ - typedef qint16 TS; - enum {offset = 0x8000}; -}; - -template<> struct signedVersion<quint32> -{ - typedef qint32 TS; - enum {offset = 0x80000000}; + using TS = qint8; + static constexpr int offset = 0x80; }; template<class T> void adjustUnsignedSamples(qreal factor, const void *src, void *dst, int samples) @@ -129,34 +38,24 @@ template<class T> void adjustUnsignedSamples(qreal factor, const void *src, void void qMultiplySamples(qreal factor, const QAudioFormat &format, const void* src, void* dest, int len) { - int samplesCount = len / (format.sampleSize()/8); + const int samplesCount = len / qMax(1, format.bytesPerSample()); - switch ( format.sampleSize() ) { - case 8: - if (format.sampleType() == QAudioFormat::SignedInt) - QAudioHelperInternal::adjustSamples<qint8>(factor,src,dest,samplesCount); - else if (format.sampleType() == QAudioFormat::UnSignedInt) - QAudioHelperInternal::adjustUnsignedSamples<quint8>(factor,src,dest,samplesCount); + switch (format.sampleFormat()) { + case QAudioFormat::Unknown: + case QAudioFormat::NSampleFormats: + return; + case QAudioFormat::UInt8: + QAudioHelperInternal::adjustUnsignedSamples<quint8>(factor,src,dest,samplesCount); + break; + case QAudioFormat::Int16: + QAudioHelperInternal::adjustSamples<qint16>(factor,src,dest,samplesCount); break; - case 16: - if (format.sampleType() == QAudioFormat::SignedInt) - QAudioHelperInternal::adjustSamples<qint16>(factor,src,dest,samplesCount); - else if (format.sampleType() == QAudioFormat::UnSignedInt) - QAudioHelperInternal::adjustUnsignedSamples<quint16>(factor,src,dest,samplesCount); + case QAudioFormat::Int32: + QAudioHelperInternal::adjustSamples<qint32>(factor,src,dest,samplesCount); break; - case 24: - if (format.sampleType() == QAudioFormat::SignedInt) - QAudioHelperInternal::adjustSamples<qint24>(factor,src,dest,samplesCount); - else if (format.sampleType() == QAudioFormat::UnSignedInt) - QAudioHelperInternal::adjustSamples<quint24>(factor,src,dest,samplesCount); + case QAudioFormat::Float: + QAudioHelperInternal::adjustSamples<float>(factor,src,dest,samplesCount); break; - default: - if (format.sampleType() == QAudioFormat::SignedInt) - QAudioHelperInternal::adjustSamples<qint32>(factor,src,dest,samplesCount); - else if (format.sampleType() == QAudioFormat::UnSignedInt) - QAudioHelperInternal::adjustUnsignedSamples<quint32>(factor,src,dest,samplesCount); - else if (format.sampleType() == QAudioFormat::Float) - QAudioHelperInternal::adjustSamples<float>(factor,src,dest,samplesCount); } } } |