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:
44 DirectSoundEffect(float sampleRate,
45 uint32 numSourceChannels,
46 uint32 numOutputChannels,
47 const simd initialFilterGains,
48 float initialDelayTimeInSeconds,
49 std::span<const float> initialMixMap);
51
61 void ProcessInterleaved(std::span<const float> input, std::span<float> output, uint32 numFrames);
62
65 void UpdateParameters(const simd& filterGains, float delayTimeSeconds, std::span<const float> channelMixMap);
66
67 private:
68 //==============================================================================
69 // Data modified by non-realtime thread
70 struct DirectEffectTargetData
71 {
72 explicit DirectEffectTargetData(std::pmr::memory_resource* memoryResource)
73 : FilterGains(1.0f)
74 , DelayTime(0.0f)
75 , ChannelGains(memoryResource)
76 {
77 }
78
79 JPL::simd FilterGains;
80 float DelayTime; // in samples
81
82 std::pmr::vector<float> ChannelGains;
83 };
84
85 //==============================================================================
86 // Data modified by realtime thread
87 class ChannelRTData final
88 {
89 public:
90 static constexpr uint32 cScratchSize = 480;
91
94
95 ChannelRTData() = default;
96 ~ChannelRTData() = default;
97
98 public:
99 // Propagation delay
100 TapType Tap;
102
103 // Propagation filtering
105 };
106
107 //==============================================================================
108 static constexpr uint32 cScratchSize = ChannelRTData::cScratchSize;
109
111 using SafeDirectEffectTDWrite = typename SafeDirectEffectTD::ScopedAccess<JPL::ThreadType::nonRealtime>;
112 using SafeDirectEffectTDRead = typename SafeDirectEffectTD::ScopedAccess<JPL::ThreadType::realtime>;
113
114 private:
115 SafeDirectEffectTD mTargetData;
116
117 float mSampleRate;
118
119 // After initialization must be accessed only from RT thread
120 std::span<ChannelRTData> mChannels;
121 JPL::SmoothedValue<float> mDelayTime;
122 std::pmr::vector<float> mCurrentGains;
123 simd mFilterGains;
124
125 };
126} // 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)
Definition RealtimeObject.h:69
Definition AcousticMaterial.h:36
std::uint32_t uint32
Definition Core.h:311
std::unique_ptr< T, PmrDeleter< T > > pmr_unique_ptr
Alias for unique ptr using pmr allocator and deleter.
Definition Memory.h:233
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