Skip to content

Fix stopping voice keyer messages #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed

Fix stopping voice keyer messages #276

wants to merge 24 commits into from

Conversation

dl1jbe
Copy link
Member

@dl1jbe dl1jbe commented Sep 1, 2021

Start voice keying in an separate process so TLF can look for ESC key and send the play_vk script an TERM signal.

To allow the script to handle that signal the actual sound playing has to be run in background by the added '&'.

You have to adapt the autocq timing as the time the sound is running does no longer add to that time.

Please review and test that sound is stopped and rig switched back to receive mode.

@dl1jbe dl1jbe requested review from N0NB and zcsahok September 1, 2021 08:07
@dl1jbe
Copy link
Member Author

dl1jbe commented Sep 3, 2021

For the SoX version of play this line should be:

play -q $1 &

Thanks for the hint. According to man page you are right.

I do have Sox-14.4.2 here and de facto both version do work. I will change it anyway.

Copy link
Member

@N0NB N0NB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this.

I've yet to try it but will. I noted the syntax for SoX play in the commit for play_vk.

@N0NB
Copy link
Member

N0NB commented Sep 3, 2021

I actually have these lines in my local play_vk:

# play file on the default sound device

# OSS play utility syntax:
#play $1 -q 2>/dev/null

# SoX play utility syntax
play -q $1

scripts/play_vk Outdated
@@ -28,7 +28,7 @@ trap 'kill -s INT $PID' TERM INT

# play file on the default sound device in backgroudn, so signals can be catch
# by the 'trap' instruction above
play $1 -q 2>/dev/null &
play -q $1 2>/dev/null &
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally I found that redirecting stderr to /dev/null was not necessary with the -q option properly placed. Please test that, Tom.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this.

Just found the following in 'man play':

"These options can be specified on the command line at any point before the first effect name."

That may explain the behavior. With -q before the file name it is quite more robust. Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally I found that redirecting stderr to /dev/null was not necessary with the -q option properly placed. Please test that, Tom.

It may be left over from former versions of SoX which left an error message when killed. Just tested it with 'aplay -q' - that would need the redirection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, aplay is the ALSA ply utility.

If we opt to retain play_vk then all examples should be included but commented. If we choose to specify the play utility in logcfg.dat then the alternatives can be documented in the man page.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was basing my placement of -q on the output of play -h which provides a usage output. Yes it says that gopts can be specified any place before the first effect. Earlier in the output is this line:

Usage summary: [gopts] [[fopts] infile]... [fopts] [effect [effopt]]...

So I presumed it would be best to place the -q in front of the filename. However, just testing it now I see it is honored in either place on the command line, so disregard my "advice". :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested the aplay command. But as agreed let us stay with SoX as 'official' supported.

And sure there has to be more documentation. At the moment it is just to test that the sound gets stopped and rig is going back to RX mode.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going through the man page and have noted that area as one that will need to be updated.

- avoids leaving zombies after playing the sound
- respects VK playtime for auto CQ (start again AFTER end of sound file)
@dl1jbe
Copy link
Member Author

dl1jbe commented Sep 7, 2021

Please test and report back again. If no problems we can add some keywords to allow users to specify the commands to use.

@zcsahok
Copy link
Member

zcsahok commented Sep 9, 2021

It does not stop playing on my system (Debian 11 i386). I'm using a plain play_vk script with a single line

play $1 -q 2>/dev/null

Upon Esc "Terminated" is written into the call input field (after the current cursor) and this text can't be cleaned by further Esc's, just by typing it over. Playback continues and terminates normally (not interrupted).
Looks like pkill only kills the play_vk process itself, but the actual play command keeps running.
Replacing the pkill with

pkill -SIGTERM -n play 2>/dev/null

fixes both issues (playback is terminated and there is no extra output). But "play" seems to a bit too generic to me, easy to inflict collateral damage...

@N0NB
Copy link
Member

N0NB commented Sep 9, 2021

While it may seem that play is generic, apparently it doesn't conflict in Debian or they would rename it (that happened some years with the node program in the ax25 packages). Also, as it is a command line program, I doubt that it would be used at the same time tlf is used, at least on the same computer.

To be absolutely certain, its PID or the script's PID needs to be known to kill the correct process that tlf spawned and then kill by PID.

@zcsahok
Copy link
Member

zcsahok commented Sep 9, 2021

If PID is know then

pkill -9 -P <PID>

seems to do the right job. (tested in a terminal)

@dl1jbe
Copy link
Member Author

dl1jbe commented Sep 9, 2021 via email

@N0NB
Copy link
Member

N0NB commented Sep 9, 2021

If I understand things, system() doesn't return the PID. A more manual method is required, I think.

@dl1jbe
Copy link
Member Author

dl1jbe commented Sep 9, 2021 via email

@N0NB
Copy link
Member

N0NB commented Sep 9, 2021

It's the -n option, Tom.

@N0NB
Copy link
Member

N0NB commented Sep 9, 2021

@zcsahok
Copy link
Member

zcsahok commented Sep 9, 2021

OK, with the new play_vk it does stop indeed, all is fine.
Just users need to be reminded to fix their scripts in case they don't use the distributed ones.

@dl1jbe
Copy link
Member Author

dl1jbe commented Sep 9, 2021 via email

Copy link
Member

@zcsahok zcsahok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added 2 comments

@N0NB
Copy link
Member

N0NB commented Sep 10, 2021

There is a slight delay if I hit F1 and then Escape immediately afterward but this much, much better than we had and than what my hack was.

Copy link
Member

@N0NB N0NB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dl1jbe
Copy link
Member Author

dl1jbe commented Sep 10, 2021 via email

@zcsahok
Copy link
Member

zcsahok commented Sep 10, 2021

There is a slight delay if I hit F1 and then Escape immediately afterward but this much, much better than we had and than what my hack was.

Try killing with SIGKILL in play_vk:

trap 'kill -s KILL $PID' TERM INT

For me it resulted in an immediate stopping.

@N0NB
Copy link
Member

N0NB commented Sep 11, 2021

Never mind...

I must have goofed something in my play_vk script. I saved it again and it's killing immediately upon the press of Escape.

Try this, hit F1 a few times in a row...

Copy link
Member

@zcsahok zcsahok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All OK.

@@ -21,13 +21,14 @@
# An executable copy of 'play_vk' in your contest directory (containing the
# logcfg.dat file) can be adapted and has precedence over the standard install

# accept SIGTERM and SIGINT signals and kill play command as soon as possible
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest play_vk and code works just fine for me.

@dl1jbe
Copy link
Member Author

dl1jbe commented Sep 20, 2021

Very well. Let me do some fine tuning (comments, better naming, maybe documentation,..) before I merge it in, Should be done in next one or two days.

@dl1jbe dl1jbe requested review from N0NB and zcsahok November 7, 2021 17:03
@dl1jbe
Copy link
Member Author

dl1jbe commented Nov 7, 2021

It was more than the expected one or two days. I took the chance to rewrite most of the audio handling code to cleanup functionality and improve readability. Furthermore the following changes were made.

  • Dropped the no longer needed SC_DEVICE keyword
  • Added user configuration for commands to record and play back voice key messages and soundlog.
    (see VK_PLAY_COMMAND, VK_RECORD_COMMAND, SOUNDLOG_PLAY_COMMAND and
    SOUNDLOG_RECORD_COMMAND)
  • Added user configuration for the directory containing soundlogs (SOUNDLOG_DIRECTORY).

I would appreciate a review and feedback for the changes so far.

Open points to do and to discuss:

  • Documentation (my part)
  • Should we also make the file ending (and therefore the audio file type) configurable? It is still fixed
    to Sun au format. Other parts of TLF use different formats.
  • Soundlog recording could use an automatic filename suggestion (at the moment still done via the
    'soundlog' shell script). Do we keep the existing format (ddhhmm) or should we choose a different one?
  • The actual 'soundlog' script supports starting a new record any hour or so. Should we keep that in the
    script or code it into TLF.
  • Do we really need the command to replay the soundlog files? I would suggest to drop the command at
    all.
    It seems more appropriate to use an external player which allows to interactively move to interesting
    points in the file, to replay some parts again and so on. There are good solutions out there (graphical
    and also with text UI).

@dl1jbe dl1jbe mentioned this pull request Feb 26, 2022
@dl1jbe
Copy link
Member Author

dl1jbe commented Mar 2, 2022

To complete the started PR and to fix the existing conflicts I did a rebase of the code onto master and split it in two parts.

  • First part enables a really quick stop of running voice keyer messages via stop_tx.
  • The second part has most of the audio code rewritten and makes all sound recording and playing user configurable. It will also move soundlogs to ./soundlogs directory by default.

I will add pull requests for both, link back to these PR for reference and close these PR afterwards.

@dl1jbe dl1jbe mentioned this pull request Mar 2, 2022
@dl1jbe dl1jbe mentioned this pull request Mar 4, 2022
@dl1jbe
Copy link
Member Author

dl1jbe commented Mar 4, 2022

All code from these PR got moved to PR #317 and PR #318. Therefor closing these request now.

@dl1jbe dl1jbe closed this Mar 4, 2022
dl1jbe added a commit that referenced this pull request Mar 24, 2022
These commit gives recording and playing of voice keyer messages and contest soundlogs a thorough overhaul.

The code relies on the tools from the SoX package with some sane default settings but allow user configuration of all play and record commands (See also the discussion in PR #276)

The default directory for recorded soundlogs was changed to ./soundlogs and are therefor contest specific now. These setting can also be overwritten by a configuration keyword (see man page for details).


Co-authored-by: zcsahok <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants