@@ -53,17 +53,25 @@ AnechoicProcessor::AnechoicProcessor (Binaural::CCore& core)
5353
5454AnechoicProcessor::~AnechoicProcessor ()
5555{
56- stopTimer ();
5756}
5857
5958void AnechoicProcessor::setup (double sampleRate)
6059{
60+ auto position = getSourcePosition ();
61+
62+ if (! mSources .empty ())
63+ {
64+ mSources .clear ();
65+ mTransforms .clear ();
66+ }
67+
68+ addSoundSource (position);
69+
6170 auto blockSize = mCore .GetAudioState ().bufferSize ;
6271
6372 // Declaration and initialization of stereo buffer
6473 mOutputBuffer .left .resize (blockSize);
6574 mOutputBuffer .right .resize (blockSize);
66- // Load HRTF
6775
6876 auto loadedHrtf = getHrtfPath ();
6977
@@ -74,9 +82,7 @@ void AnechoicProcessor::setup (double sampleRate)
7482 int index = hrtfPathToBundledIndex (loadedHrtf);
7583
7684 if (index >= 0 )
77- {
7885 loadHRTF (getBundledHRTF (index, sampleRate));
79- }
8086 }
8187
8288 mSampleRate = sampleRate;
@@ -87,36 +93,17 @@ void AnechoicProcessor::setup (double sampleRate)
8793 loadHRTF (getBundledHRTF (0 , sampleRate));
8894
8995 mSampleRate = sampleRate;
90-
91- JUCE_ASSERT_MESSAGE_MANAGER_EXISTS;
92- startTimerHz (2 );
93-
94- timerCallback ();
95- }
96-
97- void AnechoicProcessor::timerCallback ()
98- {
99- if (mHRTFsToLoad .size () > 0 )
100- {
101- if (isLoading.load ())
102- return ;
103-
104- auto path = mHRTFsToLoad [0 ];
105- reset (path);
106-
107- mHRTFsToLoad .removeAllInstancesOf (path);
108- }
10996}
11097
111- void AnechoicProcessor::reset (const File& hrtf)
98+ bool AnechoicProcessor::loadHRTF (const File& hrtf)
11299{
113100 isLoading.store (true );
114101
115102 if (! hrtf.existsAsFile ())
116103 {
117104 DBG (" HRTF file doesn't exist" );
118105 isLoading.store (false );
119- return ;
106+ return false ;
120107 }
121108
122109 __loadHRTF (hrtf);
@@ -129,7 +116,7 @@ void AnechoicProcessor::reset (const File& hrtf)
129116 {
130117 DBG (" HRTF ILD file doesn't exist" );
131118 isLoading.store (false );
132- return ;
119+ return false ;
133120 }
134121
135122 __loadHRTF_ILD (hrtfILD);
@@ -139,19 +126,22 @@ void AnechoicProcessor::reset (const File& hrtf)
139126 if (! nearFieldConf.existsAsFile () ) {
140127 DBG (" Near field ILD file doesn't exist" );
141128 isLoading.store (false );
142- return ;
129+ return false ;
143130 }
144131
145132
146133 DBG (" Loading ILD (near field): " + nearFieldConf.getFullPathName ());
147134 if ( !ILD::CreateFrom3dti_ILDNearFieldEffectTable ( nearFieldConf.getFullPathName ().toStdString (), mListener )) {
148135 DBG (" Unable to load ILD Near Field Effect simulation file. Near (ILD) will not work" );
136+ return false ;
149137 }
150138
151139 // Re-enable processing
152140 isLoading.store (false );
153141
154142 sendChangeMessage ();
143+
144+ return true ;
155145}
156146
157147void AnechoicProcessor::processBlock (AudioBuffer<float >& monoIn, AudioBuffer<float >& stereoOut)
@@ -215,7 +205,7 @@ void AnechoicProcessor::parameterChanged (const String& parameterID, float newVa
215205 {
216206 String fileTypes = index == BundledHRTFs.size () ? " *.sofa" : " *.3dti-hrtf" ;
217207
218- loadCustomHrtf (fileTypes, [this ] (File hrtf) {
208+ loadCustomHRTF (fileTypes, [this ] (File hrtf) {
219209 loadHRTF (hrtf);
220210 });
221211 }
@@ -265,14 +255,6 @@ void AnechoicProcessor::updateParameters()
265255 mCore .SetMagnitudes (magnitudes);
266256}
267257
268- bool AnechoicProcessor::loadHRTF (const File& file)
269- {
270- if (file == hrtfPath)
271- return false ;
272-
273- return mHRTFsToLoad .addIfNotAlreadyThere (file);
274- }
275-
276258bool AnechoicProcessor::__loadHRTF (const File& file)
277259{
278260 DBG (" Loading HRTF: " << file.getFullPathName ());
@@ -333,7 +315,7 @@ void AnechoicProcessor::addSoundSource (const Common::CVector3& position) {
333315 mTransforms .back ().SetPosition (Common::CVector3 (1 ,0 ,0 ));
334316}
335317
336- void AnechoicProcessor::loadCustomHrtf (String fileTypes, std::function<void (File)> callback)
318+ void AnechoicProcessor::loadCustomHRTF (String fileTypes, std::function<void (File)> callback)
337319{
338320 fc.reset (new FileChooser (" Choose a file to open..." ,
339321 HRTFDirectory (),
0 commit comments