@@ -85,18 +85,18 @@ namespace Audio {
8585
8686 for (int i = 0 ; i < nSources; i++) {
8787 if (sources[i].active ) {
88- auto sound = sources[i].usingSound ;
88+ std::shared_ptr<Sound> sound = sources[i].usingSound ;
8989
9090 // Update and Emitter::UpdateSound can call Sound::Stop
91- if (not sound->IsStopped () ) {
91+ if ( sound->playing ) {
9292 sound->Update ();
9393 }
9494
95- if (not sound->IsStopped () ) {
96- sound->GetEmitter () ->UpdateSound (*sound);
95+ if ( sound->playing ) {
96+ sound->emitter ->UpdateSound (*sound);
9797 }
9898
99- if (sound->IsStopped () ) {
99+ if ( ! sound->playing ) {
100100 sources[i].active = false ;
101101 sources[i].usingSound = nullptr ;
102102 }
@@ -126,7 +126,7 @@ namespace Audio {
126126 if (source) {
127127 // Make the source forget if it was a "static" or a "streaming" source.
128128 source->source .ResetBuffer ();
129- sound->SetEmitter ( emitter) ;
129+ sound->emitter = emitter ;
130130 sound->AcquireSource (source->source );
131131 source->usingSound = sound;
132132 source->priority = priority;
@@ -188,40 +188,6 @@ namespace Audio {
188188 playing = false ;
189189 }
190190
191- bool Sound::IsStopped () {
192- return not playing;
193- }
194-
195- void Sound::SetPositionalGain (float gain) {
196- positionalGain = gain;
197- }
198-
199- void Sound::SetSoundGain (float gain) {
200- soundGain = gain;
201- }
202-
203- float Sound::GetCurrentGain () {
204- return currentGain;
205- }
206-
207- void Sound::SetVolumeModifier (const Cvar::Range<Cvar::Cvar<float >>& volumeMod)
208- {
209- this ->volumeModifier = &volumeMod;
210- }
211-
212- float Sound::GetVolumeModifier () const
213- {
214- return volumeModifier->Get ();
215- }
216-
217- void Sound::SetEmitter (std::shared_ptr<Emitter> emitter) {
218- this ->emitter = emitter;
219- }
220-
221- std::shared_ptr<Emitter> Sound::GetEmitter () {
222- return emitter;
223- }
224-
225191 void Sound::AcquireSource (AL::Source& source) {
226192 this ->source = &source;
227193
@@ -231,19 +197,15 @@ namespace Audio {
231197 emitter->SetupSound (*this );
232198 }
233199
234- AL::Source& Sound::GetSource () {
235- return *source;
236- }
237-
238200 // Set the gain before the source is started to avoid having a few milliseconds of very loud sound
239201 void Sound::FinishSetup () {
240- currentGain = positionalGain * soundGain * SliderToAmplitude (GetVolumeModifier ());
202+ currentGain = positionalGain * soundGain * SliderToAmplitude (volumeModifier-> Get ());
241203 source->SetGain (currentGain);
242204 }
243205
244206 void Sound::Update () {
245207 // Fade the Gain update to avoid "ticking" sounds when there is a gain discontinuity
246- float targetGain = positionalGain * soundGain * SliderToAmplitude (GetVolumeModifier ());
208+ float targetGain = positionalGain * soundGain * SliderToAmplitude (volumeModifier-> Get ());
247209
248210 // TODO make it framerate independent and fade out in about 1/8 seconds ?
249211 if (currentGain > targetGain) {
@@ -267,15 +229,15 @@ namespace Audio {
267229
268230 void OneShotSound::SetupSource (AL::Source& source) {
269231 source.SetBuffer (sample->GetBuffer ());
270- SetSoundGain ( GetVolumeModifier () );
232+ soundGain = volumeModifier-> Get ( );
271233 }
272234
273235 void OneShotSound::InternalUpdate () {
274- if (GetSource (). IsStopped ()) {
236+ if ( source-> IsStopped () ) {
275237 Stop ();
276238 return ;
277239 }
278- SetSoundGain ( GetVolumeModifier () );
240+ soundGain = volumeModifier-> Get ( );
279241 }
280242
281243 // Implementation of LoopingSound
@@ -289,7 +251,7 @@ namespace Audio {
289251
290252 void LoopingSound::FadeOutAndDie () {
291253 fadingOut = true ;
292- SetSoundGain ( 0 .0f ) ;
254+ soundGain = 0 .0f ;
293255 }
294256
295257 void LoopingSound::SetupSource (AL::Source& source) {
@@ -298,23 +260,23 @@ namespace Audio {
298260 } else {
299261 SetupLoopingSound (source);
300262 }
301- SetSoundGain ( GetVolumeModifier () );
263+ soundGain = volumeModifier-> Get ( );
302264 }
303265
304266 void LoopingSound::InternalUpdate () {
305- if (fadingOut and GetCurrentGain () == 0 .0f ) {
267+ if (fadingOut and currentGain == 0 .0f ) {
306268 Stop ();
307269 }
308270
309271 if (not fadingOut) {
310272 if (leadingSample) {
311- if (GetSource (). IsStopped ()) {
312- SetupLoopingSound (GetSource () );
313- GetSource (). Play ();
273+ if ( source-> IsStopped () ) {
274+ SetupLoopingSound ( *source );
275+ source-> Play ();
314276 leadingSample = nullptr ;
315277 }
316278 }
317- SetSoundGain ( GetVolumeModifier () );
279+ soundGain = volumeModifier-> Get ( );
318280 }
319281 }
320282
@@ -335,32 +297,25 @@ namespace Audio {
335297 }
336298
337299 void StreamingSound::InternalUpdate () {
338- AL::Source& source = GetSource ();
339-
340- while (source.GetNumProcessedBuffers () > 0 ) {
341- source.PopBuffer ();
300+ while ( source->GetNumProcessedBuffers () > 0 ) {
301+ source->PopBuffer ();
342302 }
343303
344- if (source. GetNumQueuedBuffers () == 0 ) {
304+ if ( source-> GetNumQueuedBuffers () == 0 ) {
345305 Stop ();
346306 }
347307 }
348308
349309 // TODO somehow try to catch back when data is coming faster than we consume (e.g. capture data)
350310 void StreamingSound::AppendBuffer (AL::Buffer buffer) {
351- if (IsStopped () ) {
311+ if ( !playing ) {
352312 return ;
353313 }
354314
355- AL::Source& source = GetSource ();
356- source.QueueBuffer (std::move (buffer));
315+ source->QueueBuffer (std::move (buffer));
357316
358- if (source. IsStopped ()) {
359- source. Play ();
317+ if ( source-> IsStopped () ) {
318+ source-> Play ();
360319 }
361320 }
362-
363- void StreamingSound::SetGain (float gain) {
364- SetSoundGain (gain);
365- }
366321}
0 commit comments