@@ -79,6 +79,7 @@ public abstract class AudioOutput implements LineListener, Listener<IdentifierUp
79
79
private boolean mRunning = false ;
80
80
private ScheduledExecutorService mScheduledExecutorService ;
81
81
private ScheduledFuture <?> mProcessorFuture ;
82
+ private boolean mDropDuplicates ;
82
83
private long mOutputLastTimestamp = 0 ;
83
84
private static final long STALE_PLAYBACK_THRESHOLD_MS = 500 ;
84
85
@@ -104,6 +105,7 @@ public AudioOutput(Mixer mixer, MixerChannel mixerChannel, AudioFormat audioForm
104
105
mScheduledExecutorService = Executors .newSingleThreadScheduledExecutor (new NamingThreadFactory (
105
106
"sdrtrunk audio output " + mixerChannel .name ()));
106
107
mUserPreferences = userPreferences ;
108
+ mDropDuplicates = mUserPreferences .getDuplicateCallDetectionPreference ().isDuplicatePlaybackSuppressionEnabled ();
107
109
108
110
try
109
111
{
@@ -163,7 +165,7 @@ public AudioOutput(Mixer mixer, MixerChannel mixerChannel, AudioFormat audioForm
163
165
164
166
updateToneInsertionAudioClips ();
165
167
166
- //Register to receive directory preference update notifications so we can update the preference items
168
+ //Register to receive preference update notifications so we can update the preference items
167
169
MyEventBus .getGlobalEventBus ().register (this );
168
170
}
169
171
@@ -226,6 +228,10 @@ public void preferenceUpdated(PreferenceType preferenceType)
226
228
{
227
229
updateToneInsertionAudioClips ();
228
230
}
231
+ else if (preferenceType == PreferenceType .DUPLICATE_CALL_DETECTION )
232
+ {
233
+ mDropDuplicates = mUserPreferences .getDuplicateCallDetectionPreference ().isDuplicatePlaybackSuppressionEnabled ();
234
+ }
229
235
}
230
236
231
237
/**
@@ -301,6 +307,7 @@ private void disposeCurrentAudioSegment()
301
307
mCurrentAudioSegment .decrementConsumerCount ();
302
308
mCurrentAudioSegment .removeIdentifierUpdateNotificationListener (this );
303
309
mCurrentAudioSegment = null ;
310
+ broadcast (null );
304
311
}
305
312
}
306
313
@@ -352,10 +359,7 @@ private void loadNextAudioSegment()
352
359
*/
353
360
private boolean isThrowaway (AudioSegment audioSegment )
354
361
{
355
- return audioSegment != null &&
356
- (audioSegment .isDoNotMonitor () ||
357
- (audioSegment .isDuplicate () && mUserPreferences .getDuplicateCallDetectionPreference ()
358
- .isDuplicatePlaybackSuppressionEnabled ()));
362
+ return audioSegment != null && (audioSegment .isDoNotMonitor () || mDropDuplicates && (audioSegment .isDuplicate ()));
359
363
}
360
364
361
365
/**
@@ -371,8 +375,8 @@ private void processAudio()
371
375
loadNextAudioSegment ();
372
376
}
373
377
374
- //Reevaluate current audio segment to see if the status has changed for duplicate or do-not-monitor.
375
- if (isThrowaway (mCurrentAudioSegment ))
378
+ //Evaluate current audio segment to see if the status has changed for duplicate or do-not-monitor.
379
+ while (isThrowaway (mCurrentAudioSegment ))
376
380
{
377
381
if (mCurrentBufferIndex > 0 )
378
382
{
@@ -385,29 +389,42 @@ private void processAudio()
385
389
386
390
while (mCurrentAudioSegment != null && mCurrentBufferIndex < mCurrentAudioSegment .getAudioBufferCount ())
387
391
{
388
- if (mCurrentBufferIndex == 0 )
392
+ //Continuously evaluate current audio segment to see if the status has changed for duplicate or do-not-monitor.
393
+ if (isThrowaway (mCurrentAudioSegment ))
389
394
{
390
- playAudio (mAudioSegmentStartTone );
391
- }
395
+ if (mCurrentBufferIndex > 0 )
396
+ {
397
+ playAudio (mAudioSegmentDropTone );
398
+ }
392
399
393
- try
400
+ disposeCurrentAudioSegment ();
401
+ }
402
+ else
394
403
{
395
- float [] audioBuffer = mCurrentAudioSegment .getAudioBuffers ().get (mCurrentBufferIndex ++);
404
+ if (mCurrentBufferIndex == 0 )
405
+ {
406
+ playAudio (mAudioSegmentStartTone );
407
+ }
408
+
409
+ try
410
+ {
411
+ float [] audioBuffer = mCurrentAudioSegment .getAudioBuffers ().get (mCurrentBufferIndex ++);
396
412
397
- if (audioBuffer != null )
413
+ if (audioBuffer != null )
414
+ {
415
+ ByteBuffer audio = convert (audioBuffer );
416
+ //This call blocks until all audio bytes are dumped into the data line.
417
+ playAudio (audio );
418
+ }
419
+ }
420
+ catch (Exception e )
398
421
{
399
- ByteBuffer audio = convert (audioBuffer );
400
- //This call blocks until all audio bytes are dumped into the data line.
401
- playAudio (audio );
422
+ mLog .error ("Error while processing audio for [" + mMixerChannel .name () + "]" , e );
402
423
}
403
424
}
404
- catch (Exception e )
405
- {
406
- mLog .error ("Error while processing audio for [" + mMixerChannel .name () + "]" , e );
407
- }
408
425
}
409
426
410
- //Check for completed and fully-played audio segment -- load next audio segment
427
+ //Check for completed and fully-played audio segment to closeout
411
428
if (mCurrentAudioSegment != null &&
412
429
mCurrentAudioSegment .isComplete () &&
413
430
(mCurrentBufferIndex >= mCurrentAudioSegment .getAudioBufferCount ()))
@@ -649,16 +666,6 @@ public void run()
649
666
{
650
667
try
651
668
{
652
- //TODO: Debug hooks - remove after testing
653
- if (mMixerChannel .name ().equals ("LEFT" ))
654
- {
655
- int a = 0 ;
656
- }
657
- else if (mMixerChannel .name ().equals ("RIGHT" ))
658
- {
659
- int a = 0 ;
660
- }
661
-
662
669
processAudio ();
663
670
}
664
671
catch (Throwable t )
0 commit comments