From c3684a2f8c716354211366b119e41a0a064ac869 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 29 Sep 2019 00:47:47 +0200 Subject: [PATCH] Ref T731, added namespace for utility functions --- src/blackcore/afv/audio/input.cpp | 1 + src/blacksound/audioutilities.cpp | 77 ++++++++++++++++++------------- src/blacksound/audioutilities.h | 27 ++++++++--- 3 files changed, 66 insertions(+), 39 deletions(-) diff --git a/src/blackcore/afv/audio/input.cpp b/src/blackcore/afv/audio/input.cpp index 9fab4ae63..bca3ed718 100644 --- a/src/blackcore/afv/audio/input.cpp +++ b/src/blackcore/afv/audio/input.cpp @@ -18,6 +18,7 @@ #include using namespace BlackMisc; +using namespace BlackSound; namespace BlackCore { diff --git a/src/blacksound/audioutilities.cpp b/src/blacksound/audioutilities.cpp index 52e30c53b..2c8d4fdc4 100644 --- a/src/blacksound/audioutilities.cpp +++ b/src/blacksound/audioutilities.cpp @@ -1,44 +1,55 @@ +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + #include "audioutilities.h" -QVector convertBytesTo16BitPCM(const QByteArray input) +namespace BlackSound { - int inputSamples = input.size() / 2; // 16 bit input, so 2 bytes per sample - QVector output; - output.fill(0, inputSamples); - - for (int n = 0; n < inputSamples; n++) + QVector convertBytesTo16BitPCM(const QByteArray input) { - output[n] = *reinterpret_cast(input.data() + n * 2); + int inputSamples = input.size() / 2; // 16 bit input, so 2 bytes per sample + QVector output; + output.fill(0, inputSamples); + + for (int n = 0; n < inputSamples; n++) + { + output[n] = *reinterpret_cast(input.data() + n * 2); + } + return output; } - return output; -} -QVector convertFloatBytesTo16BitPCM(const QByteArray input) -{ - Q_UNUSED(input); - qFatal("Not implemented"); - return {}; -} - -QVector convertFromMonoToStereo(const QVector &mono) -{ - QVector stereo; - stereo.reserve(mono.size() * 2); - for (qint16 sample : mono) + QVector convertFloatBytesTo16BitPCM(const QByteArray input) { - stereo << sample; - stereo << sample; + Q_UNUSED(input) + qFatal("Not implemented"); + return {}; } - return stereo; -} -QVector convertFromStereoToMono(const QVector &stereo) -{ - QVector mono; - mono.reserve(stereo.size() / 2); - for (int i = 0; i < stereo.size(); i = i + 2) + QVector convertFromMonoToStereo(const QVector &mono) { - mono.append(stereo.at(i)); + QVector stereo; + stereo.reserve(mono.size() * 2); + for (qint16 sample : mono) + { + stereo << sample; + stereo << sample; + } + return stereo; } - return mono; -} + + QVector convertFromStereoToMono(const QVector &stereo) + { + QVector mono; + mono.reserve(stereo.size() / 2); + for (int i = 0; i < stereo.size(); i = i + 2) + { + mono.append(stereo.at(i)); + } + return mono; + } +} // ns diff --git a/src/blacksound/audioutilities.h b/src/blacksound/audioutilities.h index b28ea434c..a82aa3cd6 100644 --- a/src/blacksound/audioutilities.h +++ b/src/blacksound/audioutilities.h @@ -1,13 +1,28 @@ -#ifndef AUDIOUTILITIES_H -#define AUDIOUTILITIES_H +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKSOUND_AUDIOUTILITIES_H +#define BLACKSOUND_AUDIOUTILITIES_H #include "blacksound/blacksoundexport.h" #include #include -BLACKSOUND_EXPORT QVector convertBytesTo16BitPCM(const QByteArray input); -BLACKSOUND_EXPORT QVector convertFloatBytesTo16BitPCM(const QByteArray input); -BLACKSOUND_EXPORT QVector convertFromMonoToStereo(const QVector &mono); -BLACKSOUND_EXPORT QVector convertFromStereoToMono(const QVector &stereo); +namespace BlackSound +{ + //! Conversion functions @{ + BLACKSOUND_EXPORT QVector convertBytesTo16BitPCM(const QByteArray input); + BLACKSOUND_EXPORT QVector convertFloatBytesTo16BitPCM(const QByteArray input); + BLACKSOUND_EXPORT QVector convertFromMonoToStereo(const QVector &mono); + BLACKSOUND_EXPORT QVector convertFromStereoToMono(const QVector &stereo); + //! @} +} // ns #endif // guard