Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qaudioformat_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 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 QAUDIOFORMAT_P_H
5#define QAUDIOFORMAT_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 <QtMultimedia/qtmultimediaglobal.h>
19#include <QtMultimedia/qaudioformat.h>
20
21#include <array>
22
23QT_BEGIN_NAMESPACE
24
25namespace QtMultimediaPrivate {
26
27inline constexpr std::array allSupportedSampleRates{
28 8'000, 11'025, 12'000, 16'000, 22'050, 24'000, 32'000, 44'100,
29 48'000, 64'000, 88'200, 96'000, 128'000, 176'400, 192'000,
30};
31
38
39template <typename T>
40int findClosestSamplingRate(int rate, QSpan<const T> supportedRates)
41{
42 Q_ASSERT(!supportedRates.empty());
43
44 auto exactMatchIt = std::find(supportedRates.begin(), supportedRates.end(), T(rate));
45 if (exactMatchIt != supportedRates.end())
46 return int(*exactMatchIt);
47
48 // find supported rate, which is closest to the default pipewire sampling rate (using a
49 // logarithmic scaling)
50 auto ratioToRate = [&](int arg) {
51 return arg > rate ? float(arg) / rate : rate / float(arg);
52 };
53
54 return *std::min_element(supportedRates.begin(), supportedRates.end(), [&](auto lhs, auto rhs) {
55 return ratioToRate(lhs) < ratioToRate(rhs);
56 });
57}
58
59} // namespace QtMultimediaPrivate
60
61QT_END_NAMESPACE
62
63#endif // QAUDIOFORMAT_P_H
constexpr std::array allSupportedSampleRates
constexpr std::array allSupportedSampleFormats
int findClosestSamplingRate(int rate, QSpan< const T > supportedRates)