JPL Spatial
Sound spatialization and propagation library
Loading...
Searching...
No Matches
DirectSound.h
Go to the documentation of this file.
1//
2// ██╗██████╗ ██╗ ██╗██████╗ ███████╗
3// ██║██╔══██╗ ██║ ██║██╔══██╗██╔════╝ ** JPLSpatial **
4// ██║██████╔╝ ██║ ██║██████╔╝███████╗
5// ██ ██║██╔═══╝ ██║ ██║██╔══██╗╚════██║ https://github.com/Jaytheway/JPLSpatial
6// ╚█████╔╝██║ ███████╗██║██████╔╝███████║
7// ╚════╝ ╚═╝ ╚══════╝╚═╝╚═════╝ ╚══════╝
8//
9// Copyright Jaroslav Pevno, JPLSpatial is offered under the terms of the ISC license:
10//
11// Permission to use, copy, modify, and/or distribute this software for any purpose with or
12// without fee is hereby granted, provided that the above copyright notice and this permission
13// notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
14// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
16// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#pragma once
21
22#include <JPLSpatial/Core.h>
29
30#include <vector>
31#include <span>
32
33namespace JPL
34{
35 //==================================================================================
42 {
43 public:
49 std::span<const float> initialMixMap);
51
58 void ProcessInterleaved(std::span<const float> input, std::span<float> output, uint32 numFrames);
59
61 void UpdateParameters(const simd& filterGains, float delayTimeSeconds, std::span<const float> channelMixMap);
62
63 private:
64 //==============================================================================
65 // Data modified by non-realtime thread
66 struct DirectEffectTargetData
67 {
68 explicit DirectEffectTargetData(std::pmr::memory_resource* memoryResource)
69 : FilterGains(1.0f)
70 , DelayTime(0.0f)
71 , ChannelGains(memoryResource)
72 {
73 }
74
75 JPL::simd FilterGains;
76 float DelayTime; // in samples
77
78 std::pmr::vector<float> ChannelGains;
79 };
80
81 //==============================================================================
82 // Data modified by realtime thread
83 class ChannelRTData final
84 {
85 public:
86 static constexpr uint32 cScratchSize = 480;
87
90
91 ChannelRTData() = default;
92 ~ChannelRTData() = default;
93
94 public:
95 // Propagation delay
96 TapType Tap;
98
99 // Propagation filtering
101 };
102
103 //==============================================================================
104 static constexpr uint32 cScratchSize = ChannelRTData::cScratchSize;
105
107 using SafeDirectEffectTDWrite = typename SafeDirectEffectTD::ScopedAccess<JPL::ThreadType::nonRealtime>;
108 using SafeDirectEffectTDRead = typename SafeDirectEffectTD::ScopedAccess<JPL::ThreadType::realtime>;
109
110 private:
111 SafeDirectEffectTD mTargetData;
112
113 float mSampleRate;
114
115 // After initialization must be accessed only from RT thread
116 std::span<ChannelRTData> mChannels;
117 JPL::SmoothedValue<float> mDelayTime;
118 std::pmr::vector<float> mCurrentGains;
119 simd mFilterGains;
120
121 };
122} // namespace JPL
Forward declaration.
Definition DelayLine.h:131
Definition DirectSound.h:42
void ProcessInterleaved(std::span< const float > input, std::span< float > output, uint32 numFrames)
DirectSoundEffect(float sampleRate, uint32 numSourceChannels, uint32 numOutputChannels, const simd initialFilterGains, float initialDelayTimeInSeconds, std::span< const float > initialMixMap)
void UpdateParameters(const simd &filterGains, float delayTimeSeconds, std::span< const float > channelMixMap)
Must be called from non-RT thread.
Definition RealtimeObject.h:69
Definition AcousticMaterial.h:36
std::uint32_t uint32
Definition Core.h:311
JPL_INLINE simd min(const simd &a, const simd &b) noexcept
Element-wise min.
Definition SIMD.h:1813
Definition DelayLine.h:45
4th order Linkwitz-Riley 4-band crossover
Definition CrossoverFilter.h:417
Definition SmoothedValue.h:29
Minimal 4-wide 32-bit float vector implementation for SIMD.
Definition SIMD.h:60