Skip to content

Commit 49f67fe

Browse files
authored
Merge pull request #1 from 3DTune-In/develop
Develop
2 parents 54a06b7 + 1b271cf commit 49f67fe

5 files changed

Lines changed: 45 additions & 38 deletions

File tree

3dti_AudioToolkit_Plugin.jucer

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pluginVST3Category="Spatial" pluginRTASCategory="512" pluginAAXCategory="512"
77
pluginVSTCategory="kPlugCategSpacializer" pluginAUMainType="'aupn'"
88
pluginFormats="buildVST" pluginManufacturer="3D Tune-In" aaxIdentifier="eu.3d-tune-in.toolkitplugin"
9-
bundleIdentifier="eu.3d-tune-in.toolkitplugin" version="1.0.0"
9+
bundleIdentifier="eu.3d-tune-in.toolkitplugin" version="1.0.1"
1010
companyWebsite="http://3d-tune-in.eu">
1111
<MAINGROUP id="J6xy11" name="3D Tune-In Toolkit">
1212
<GROUP id="{7E66D3A7-5BFC-CA2F-8ED8-8DEFC273D8EA}" name="Resources">

Source/Toolkit3dtiProcessor.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
* \b Acknowledgement: This project has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No 644051 and 726765.
1919
*/
2020

21+
#include <thread>
2122
#include "Utils.h"
2223
#include "Toolkit3dtiProcessor.h"
2324

24-
std::mutex mtx;
25-
2625
void copySourceSettings(CSingleSourceRef oldSource, CSingleSourceRef newSource);
2726

28-
ScopedPointer<Toolkit3dtiProcessorImpl> CreateImpl(double sampleRate, int samplesPerBlock) {
29-
ScopedPointer<Toolkit3dtiProcessorImpl> impl( new Toolkit3dtiProcessorImpl );
27+
Toolkit3dtiProcessor::Impl::Ptr CreateImpl(double sampleRate, int samplesPerBlock) {
28+
Toolkit3dtiProcessor::Impl::Ptr impl( new Toolkit3dtiProcessor::Impl );
3029

3130
// Declaration and initialization of stereo buffer
3231
impl->mOutputBuffer.left.resize(samplesPerBlock);
@@ -96,10 +95,10 @@ void Toolkit3dtiProcessor::setup(double sampleRate, int samplesPerBlock) {
9695
int brirIndex = pimpl ? pimpl->brirIndex : 0;
9796
File brir = getBundledBRIR(brirIndex, sampleRate);
9897

99-
reset(impl, hrtf, brir);
98+
reset(std::move(impl), hrtf, brir);
10099
}
101100

102-
void Toolkit3dtiProcessor::reset(ScopedPointer<Toolkit3dtiProcessorImpl> impl, const File& hrtf, const File& brir) {
101+
void Toolkit3dtiProcessor::reset(Impl::Ptr impl, const File& hrtf, const File& brir) {
103102
if ( !hrtf.existsAsFile() ) {
104103
DBG("HRTF file doesn't exist");
105104
}
@@ -132,7 +131,7 @@ void Toolkit3dtiProcessor::reset(ScopedPointer<Toolkit3dtiProcessorImpl> impl, c
132131

133132
// Add a sound source
134133
auto position = getSourcePosition();
135-
addSoundSource(*impl, position);
134+
addSoundSource(*impl.get(), position);
136135

137136
if ( pimpl != nullptr ) {
138137
for ( int i = 0; i < pimpl->sources.size(); i++ ) {
@@ -146,19 +145,21 @@ void Toolkit3dtiProcessor::reset(ScopedPointer<Toolkit3dtiProcessorImpl> impl, c
146145
while (true) {
147146
if ( mtx.try_lock() ) {
148147

149-
pimpl = impl;
148+
pimpl = std::move(impl);
149+
150150
mtx.unlock();
151151
break;
152152

153153
} else {
154154
// Failed to aquire lock for assigning new implementation
155155
// Try again
156+
std::this_thread::yield();
156157
}
157158
}
158159
}
159160

160161
void Toolkit3dtiProcessor::processBlock(AudioBuffer<float>& buffer, MidiBuffer& midiMessages) {
161-
if ( pimpl.get() == nullptr ) {
162+
if ( pimpl == nullptr ) {
162163
return;
163164
}
164165

@@ -237,7 +238,7 @@ void Toolkit3dtiProcessor::processBlock(AudioBuffer<float>& buffer, MidiBuffer&
237238
mtx.unlock();
238239
}
239240

240-
void Toolkit3dtiProcessor::updateParameters(Toolkit3dtiProcessorImpl& impl) {
241+
void Toolkit3dtiProcessor::updateParameters(Impl& impl) {
241242
if ( enableCustomizedITD ) {
242243
impl.mListener->EnableCustomizedITD();
243244
} else {
@@ -285,7 +286,7 @@ bool Toolkit3dtiProcessor::loadHRTF(const File& file) {
285286
}
286287

287288
// TODO: Move to private implmentation
288-
bool Toolkit3dtiProcessor::loadHRTF(Toolkit3dtiProcessorImpl& impl, const File& file) {
289+
bool Toolkit3dtiProcessor::loadHRTF(Impl& impl, const File& file) {
289290
DBG("Loading HRTF: " << file.getFullPathName());
290291
bool success = false;
291292
success = loadResourceFile(impl, file, true);
@@ -298,7 +299,7 @@ bool Toolkit3dtiProcessor::loadHRTF_ILD(const File& file) {
298299
return loadHRTF_ILD(*pimpl, file);
299300
}
300301

301-
bool Toolkit3dtiProcessor::loadHRTF_ILD(Toolkit3dtiProcessorImpl& impl, const File& file) {
302+
bool Toolkit3dtiProcessor::loadHRTF_ILD(Impl& impl, const File& file) {
302303
auto path = file.getFullPathName().toStdString();
303304
DBG("Loading HRTF ILD: " << path);
304305
auto fileSampleRate = ILD::GetSampleRateFrom3dti(path);
@@ -329,15 +330,15 @@ bool Toolkit3dtiProcessor::loadBRIR(const File& file) {
329330
return true;
330331
}
331332

332-
bool Toolkit3dtiProcessor::loadBRIR(Toolkit3dtiProcessorImpl &impl, const File& file) {
333+
bool Toolkit3dtiProcessor::loadBRIR(Impl &impl, const File& file) {
333334
DBG("Loading BRIR: " << file.getFullPathName());
334335
bool success = loadResourceFile(impl, file, false);
335336
impl.brirIndex = brirPathToBundledIndex(file);
336337
impl.brirPath = file;
337338
return success;
338339
}
339340

340-
bool Toolkit3dtiProcessor::loadResourceFile(Toolkit3dtiProcessorImpl &impl, const File& file, bool isHRTF) {
341+
bool Toolkit3dtiProcessor::loadResourceFile(Impl &impl, const File& file, bool isHRTF) {
341342
int sampleRate = impl.mCore.GetAudioState().sampleRate;
342343
int fileSampleRate = checkResourceSampleRate(file, isHRTF);
343344
// TODO: Throw exception / return error and trigger warning from editor
@@ -358,7 +359,7 @@ bool Toolkit3dtiProcessor::loadResourceFile(Toolkit3dtiProcessorImpl &impl, cons
358359
return false;
359360
}
360361

361-
void Toolkit3dtiProcessor::addSoundSource(Toolkit3dtiProcessorImpl &impl, Common::CVector3& position) {
362+
void Toolkit3dtiProcessor::addSoundSource(Impl &impl, Common::CVector3& position) {
362363
if ( impl.sources.size() == 1 ) {
363364
DBG("Only one source allowed at this time.");
364365
return;

Source/Toolkit3dtiProcessor.h

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,24 @@ using CEnvironmentRef = shared_ptr<Binaural::CEnvironment>;
3333
using CSingleSourceRef = shared_ptr<Binaural::CSingleSourceDSP>;
3434
using CMonoBufferPairf = Common::CEarPair<CMonoBuffer<float>>;
3535

36-
struct Toolkit3dtiProcessorImpl {
37-
Binaural::CCore mCore;
38-
CEnvironmentRef mEnvironment;
39-
CListenerRef mListener;
40-
CMonoBufferPairf mOutputBuffer;
41-
std::vector<CSingleSourceRef> sources;
42-
int hrtfIndex;
43-
int brirIndex;
44-
File hrtfPath;
45-
File brirPath;
46-
};
47-
4836
class Toolkit3dtiProcessor {
4937
public:
38+
39+
struct Impl {
40+
using Ptr = std::unique_ptr<Impl>;
41+
42+
Binaural::CCore mCore;
43+
CEnvironmentRef mEnvironment;
44+
CListenerRef mListener;
45+
CMonoBufferPairf mOutputBuffer;
46+
std::vector<CSingleSourceRef> sources;
47+
int hrtfIndex;
48+
int brirIndex;
49+
File hrtfPath;
50+
File brirPath;
51+
};
52+
53+
//============================================================================
5054
Toolkit3dtiProcessor();
5155

5256
//============================================================================
@@ -101,17 +105,19 @@ class Toolkit3dtiProcessor {
101105
AudioParameterFloat reverbDistanceAttenuation; // ranges from -6 to 0 dB
102106

103107
private:
108+
109+
std::mutex mtx;
104110

105-
void reset(ScopedPointer<Toolkit3dtiProcessorImpl>, const File& hrtf, const File& brir);
106-
void updateParameters(Toolkit3dtiProcessorImpl& impl);
107-
void addSoundSource(Toolkit3dtiProcessorImpl& impl, Common::CVector3& position);
108-
bool loadResourceFile(Toolkit3dtiProcessorImpl& impl, const File& file, bool isHRTF);
109-
bool loadHRTF(Toolkit3dtiProcessorImpl& impl, const File& file);
110-
bool loadHRTF_ILD(Toolkit3dtiProcessorImpl& impl, const File& file);
111-
bool loadBRIR(Toolkit3dtiProcessorImpl& impl, const File& file);
111+
void reset(Impl::Ptr p, const File& hrtf, const File& brir);
112+
void updateParameters(Impl& impl);
113+
void addSoundSource(Impl& impl, Common::CVector3& position);
114+
bool loadResourceFile(Impl& impl, const File& file, bool isHRTF);
115+
bool loadHRTF(Impl& impl, const File& file);
116+
bool loadHRTF_ILD(Impl& impl, const File& file);
117+
bool loadBRIR(Impl& impl, const File& file);
112118

113119
//============================================================================
114-
ScopedPointer<Toolkit3dtiProcessorImpl> pimpl;
120+
Impl::Ptr pimpl;
115121

116122
Common::CTransform mTransform; // Source transform
117123

libs/JUCE

Submodule JUCE updated from ccbcc41 to 4048a5f

0 commit comments

Comments
 (0)