Skip to content

Commit b39dd1a

Browse files
DSheirerDennis Sheirer
andauthored
#648 Resolves issue with audio panel sometimes displaying stale metadata that doesn't clear until the next audio segment is loaded. (#1545)
Co-authored-by: Dennis Sheirer <[email protected]>
1 parent 0af5963 commit b39dd1a

File tree

2 files changed

+49
-35
lines changed

2 files changed

+49
-35
lines changed

src/main/java/io/github/dsheirer/audio/playback/AudioOutput.java

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public abstract class AudioOutput implements LineListener, Listener<IdentifierUp
7979
private boolean mRunning = false;
8080
private ScheduledExecutorService mScheduledExecutorService;
8181
private ScheduledFuture<?> mProcessorFuture;
82+
private boolean mDropDuplicates;
8283
private long mOutputLastTimestamp = 0;
8384
private static final long STALE_PLAYBACK_THRESHOLD_MS = 500;
8485

@@ -104,6 +105,7 @@ public AudioOutput(Mixer mixer, MixerChannel mixerChannel, AudioFormat audioForm
104105
mScheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new NamingThreadFactory(
105106
"sdrtrunk audio output " + mixerChannel.name()));
106107
mUserPreferences = userPreferences;
108+
mDropDuplicates = mUserPreferences.getDuplicateCallDetectionPreference().isDuplicatePlaybackSuppressionEnabled();
107109

108110
try
109111
{
@@ -163,7 +165,7 @@ public AudioOutput(Mixer mixer, MixerChannel mixerChannel, AudioFormat audioForm
163165

164166
updateToneInsertionAudioClips();
165167

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
167169
MyEventBus.getGlobalEventBus().register(this);
168170
}
169171

@@ -226,6 +228,10 @@ public void preferenceUpdated(PreferenceType preferenceType)
226228
{
227229
updateToneInsertionAudioClips();
228230
}
231+
else if(preferenceType == PreferenceType.DUPLICATE_CALL_DETECTION)
232+
{
233+
mDropDuplicates = mUserPreferences.getDuplicateCallDetectionPreference().isDuplicatePlaybackSuppressionEnabled();
234+
}
229235
}
230236

231237
/**
@@ -301,6 +307,7 @@ private void disposeCurrentAudioSegment()
301307
mCurrentAudioSegment.decrementConsumerCount();
302308
mCurrentAudioSegment.removeIdentifierUpdateNotificationListener(this);
303309
mCurrentAudioSegment = null;
310+
broadcast(null);
304311
}
305312
}
306313

@@ -352,10 +359,7 @@ private void loadNextAudioSegment()
352359
*/
353360
private boolean isThrowaway(AudioSegment audioSegment)
354361
{
355-
return audioSegment != null &&
356-
(audioSegment.isDoNotMonitor() ||
357-
(audioSegment.isDuplicate() && mUserPreferences.getDuplicateCallDetectionPreference()
358-
.isDuplicatePlaybackSuppressionEnabled()));
362+
return audioSegment != null && (audioSegment.isDoNotMonitor() || mDropDuplicates && (audioSegment.isDuplicate()));
359363
}
360364

361365
/**
@@ -371,8 +375,8 @@ private void processAudio()
371375
loadNextAudioSegment();
372376
}
373377

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))
376380
{
377381
if(mCurrentBufferIndex > 0)
378382
{
@@ -385,29 +389,42 @@ private void processAudio()
385389

386390
while(mCurrentAudioSegment != null && mCurrentBufferIndex < mCurrentAudioSegment.getAudioBufferCount())
387391
{
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))
389394
{
390-
playAudio(mAudioSegmentStartTone);
391-
}
395+
if(mCurrentBufferIndex > 0)
396+
{
397+
playAudio(mAudioSegmentDropTone);
398+
}
392399

393-
try
400+
disposeCurrentAudioSegment();
401+
}
402+
else
394403
{
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++);
396412

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)
398421
{
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);
402423
}
403424
}
404-
catch(Exception e)
405-
{
406-
mLog.error("Error while processing audio for [" + mMixerChannel.name() + "]", e);
407-
}
408425
}
409426

410-
//Check for completed and fully-played audio segment -- load next audio segment
427+
//Check for completed and fully-played audio segment to closeout
411428
if(mCurrentAudioSegment != null &&
412429
mCurrentAudioSegment.isComplete() &&
413430
(mCurrentBufferIndex >= mCurrentAudioSegment.getAudioBufferCount()))
@@ -649,16 +666,6 @@ public void run()
649666
{
650667
try
651668
{
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-
662669
processAudio();
663670
}
664671
catch(Throwable t)

src/main/java/io/github/dsheirer/gui/playlist/alias/identifier/TalkgroupRangeEditor.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* *****************************************************************************
3-
* Copyright (C) 2014-2020 Dennis Sheirer
3+
* Copyright (C) 2014-2023 Dennis Sheirer
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -27,6 +27,8 @@
2727
import io.github.dsheirer.preference.UserPreferences;
2828
import io.github.dsheirer.preference.identifier.IntegerFormat;
2929
import io.github.dsheirer.protocol.Protocol;
30+
import java.util.ArrayList;
31+
import java.util.List;
3032
import javafx.beans.value.ChangeListener;
3133
import javafx.beans.value.ObservableValue;
3234
import javafx.geometry.HPos;
@@ -38,9 +40,6 @@
3840
import org.slf4j.Logger;
3941
import org.slf4j.LoggerFactory;
4042

41-
import java.util.ArrayList;
42-
import java.util.List;
43-
4443
/**
4544
* Editor for talkgroup range alias identifiers
4645
*/
@@ -291,6 +290,10 @@ private TalkgroupDetail getTalkgroupDetail(Protocol protocol, IntegerFormat inte
291290
private List<TalkgroupDetail> createTalkgroupDetails()
292291
{
293292
List<TalkgroupDetail> details = new ArrayList<>();
293+
details.add(new TalkgroupDetail(Protocol.AM, IntegerFormat.DECIMAL, new IntegerFormatter(0,65535),
294+
new IntegerFormatter(0,65535), "Format 0 - 65535"));
295+
details.add(new TalkgroupDetail(Protocol.AM, IntegerFormat.HEXADECIMAL, new IntegerFormatter(0,65535),
296+
new IntegerFormatter(0,65535), "Format 0 - FFFF"));
294297
details.add(new TalkgroupDetail(Protocol.APCO25, IntegerFormat.DECIMAL, new IntegerFormatter(0,65535),
295298
new IntegerFormatter(0,65535), "Format: 0 - 65535"));
296299
details.add(new TalkgroupDetail(Protocol.APCO25, IntegerFormat.HEXADECIMAL, new HexFormatter(0,65535),
@@ -307,6 +310,10 @@ private List<TalkgroupDetail> createTalkgroupDetails()
307310
details.add(new TalkgroupDetail(Protocol.MPT1327, IntegerFormat.FORMATTED,
308311
new PrefixIdentFormatter(0,0xFFFFF), new PrefixIdentFormatter(0,0xFFFFF),
309312
"Format: PPP-IIII = Prefix (0-127), Ident (1-8191)"));
313+
details.add(new TalkgroupDetail(Protocol.NBFM, IntegerFormat.DECIMAL, new IntegerFormatter(0,65535),
314+
new IntegerFormatter(0,65535), "Format 0 - 65535"));
315+
details.add(new TalkgroupDetail(Protocol.NBFM, IntegerFormat.HEXADECIMAL, new IntegerFormatter(0,65535),
316+
new IntegerFormatter(0,65535), "Format 0 - FFFF"));
310317
details.add(new TalkgroupDetail(Protocol.PASSPORT, IntegerFormat.DECIMAL, new IntegerFormatter(0,0xFFFF),
311318
new IntegerFormatter(0,0xFFFF), "Format: 0 - 65535"));
312319
details.add(new TalkgroupDetail(Protocol.PASSPORT, IntegerFormat.HEXADECIMAL, new HexFormatter(0,0xFFFF),

0 commit comments

Comments
 (0)