47QSoundEffectPrivateWithPlayer::getEngineFor(
const QAudioDevice &device,
const QAudioFormat &format)
49 if (device.isNull()) {
50 qWarning() <<
"QRtAudioEngine needs to be called with a valid device";
54 if (format.sampleFormat() != QAudioFormat::Float) {
55 qWarning() <<
"QRtAudioEngine requires floating point samples";
59 if (!device.isFormatSupported(format)) {
60 qWarning() <<
"QRtAudioEngine needs to be called with a supported fromat";
64 static QMutex s_playerRegistryMutex;
65 static std::map<std::pair<QAudioDevice, QAudioFormat>, std::weak_ptr<QRtAudioEngine>,
66 AudioDeviceFormatLess>
69 auto guard = std::lock_guard{ s_playerRegistryMutex };
71 auto key =
std::pair{ device, format };
72 auto found = s_playerRegistry.find(key);
73 if (found != s_playerRegistry.end()) {
74 auto player = found->second.lock();
80 q20::erase_if(s_playerRegistry, [](
auto &&keyValuePair) {
81 return keyValuePair.second.expired();
85 auto endpointRole = AudioEndpointRole::SoundEffect;
87 auto player = std::shared_ptr<QRtAudioEngine>(
88 new QRtAudioEngine{ device, format, endpointRole }, [](QRtAudioEngine *engine) {
89 if (engine->thread()->isCurrentThread())
92 engine->deleteLater();
94 s_playerRegistry.emplace(key, player);
102 float volume,
bool muted,
int totalLoopCount,
103 QAudioFormat engineFormat)
104 : QRtAudioEngineVoice{ voiceId },
105 m_sample{ std::move(sample) },
106 m_engineFormat{ engineFormat },
109 m_loopsRemaining{ totalLoopCount }