| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QAUDIOHELPERS_P_H |
| 5 | #define QAUDIOHELPERS_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/qspan.h> |
| 19 | #include <QtMultimedia/qaudioformat.h> |
| 20 | #include <QtMultimedia/private/qtmultimediaglobal_p.h> |
| 21 | #include <QtMultimedia/private/qaudio_rtsan_support_p.h> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | namespace QAudioHelperInternal { |
| 26 | Q_MULTIMEDIA_EXPORT void qMultiplySamples(float factor, |
| 27 | const QAudioFormat &format, |
| 28 | const void *src, |
| 29 | void *dest, |
| 30 | int len) noexcept QT_MM_NONBLOCKING; |
| 31 | |
| 32 | Q_MULTIMEDIA_EXPORT |
| 33 | void applyVolume(float volume, |
| 34 | const QAudioFormat &, |
| 35 | QSpan<const std::byte> source, |
| 36 | QSpan<std::byte> destination) noexcept QT_MM_NONBLOCKING; |
| 37 | |
| 38 | enum class NativeSampleFormat : uint8_t { |
| 39 | uint8_t, |
| 40 | int16_t, |
| 41 | int32_t, |
| 42 | int24_t_3b, // 3 byte lsb |
| 43 | int24_t_4b_low, // 4 byte |
| 44 | float32_t, |
| 45 | }; |
| 46 | |
| 47 | Q_MULTIMEDIA_EXPORT |
| 48 | void convertSampleFormat(QSpan<const std::byte> source, NativeSampleFormat sourceFormat, |
| 49 | QSpan<std::byte> destination, |
| 50 | NativeSampleFormat destinationFormat) noexcept QT_MM_NONBLOCKING; |
| 51 | |
| 52 | Q_MULTIMEDIA_EXPORT |
| 53 | NativeSampleFormat bestNativeSampleFormat(const QAudioFormat &fmt, |
| 54 | QSpan<const NativeSampleFormat> supportedNativeFormats); |
| 55 | QAudioFormat::SampleFormat bestSampleFormat(NativeSampleFormat); |
| 56 | |
| 57 | NativeSampleFormat toNativeSampleFormat(QAudioFormat::SampleFormat); |
| 58 | |
| 59 | constexpr size_t bytesPerSample(NativeSampleFormat fmt) noexcept QT_MM_NONBLOCKING |
| 60 | { |
| 61 | switch (fmt) { |
| 62 | case NativeSampleFormat::uint8_t: |
| 63 | return 1; |
| 64 | case NativeSampleFormat::int16_t: |
| 65 | return 2; |
| 66 | case NativeSampleFormat::int24_t_3b: |
| 67 | return 3; |
| 68 | case NativeSampleFormat::int24_t_4b_low: |
| 69 | case NativeSampleFormat::float32_t: |
| 70 | case NativeSampleFormat::int32_t: |
| 71 | return 4; |
| 72 | default: |
| 73 | Q_UNREACHABLE_RETURN(0); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | std::optional<float> sanitizeVolume(float volume, float lastVolume); |
| 78 | |
| 79 | } // namespace QAudioHelperInternal |
| 80 | |
| 81 | Q_MULTIMEDIA_EXPORT |
| 82 | QDebug operator<<(QDebug dbg, QAudioHelperInternal::NativeSampleFormat); |
| 83 | |
| 84 | QT_END_NAMESPACE |
| 85 | |
| 86 | #endif // QAUDIOHELPERS_P_H |
| 87 | |