Skip to content

Conversation

@Ericgi231
Copy link

Added an async flag to the existing Lua computer.beep() for non morse code beeps.
While it may introduce the potential for spamming beeps of different frequency, users could likely already exploit the morse code beeps which were already non-blocking by default,

Maintains full backwards compatibility, default behavior without new argument is the same as before.

I have not written tests or done manual testing, which would seem to be the standard.

To use in Lua - computer.beep(340, 0.50, true)

@ReallySecureShell
Copy link

This pull request is in response to Issue #3789

computer.beep() was added in Commit-d5f1280 in response to Issue #1112. The SCALA function for computer.beep() can be found on Lines 446 through 461 in Machine.scala, as referenced by this pull request.

As far as I can tell, computer.beep(frequency, duration) was made to be a blocking call over concerns of potentially high network packet generation, and the processing resources required by clients to generate the tone in real-time source 1. I figure the idea was that by blocking execution on the machine instance while the tone is played would result in more processing resources being available to generate the real-time tone.

In source 1, for the comment talking about *void beep(String pattern); it says "It has the advantage of only generating a single network packet, and generating a single, longer sound sample for the full pattern". Which may explain why computer.beep(string) was decided to be non-blocking.

Furthermore, apart of the comment for **void beep(short frequency, short duration); in source 1 reads "It is therefore recommended to not call this too frequently, and to limit the length of the sound to something relatively short (not longer than a few seconds at most)." So, if making computer.beep(frequency, duration) non-blocking, then putting a limit on the maximum duration of the tone seems to be the best idea.

Because it may also be of interest this is the server-side packet constructor for building the sound packet.

*When referencing void beep(String pattern); in context to source 1, that method is the same as computer.beep(string)

**When referencing void beep(short frequency, short duration); in context to source 1, that method is the same as computer.beep(frequency, duration)

@Ericgi231
Copy link
Author

I agree putting a limit on the maximum duration of the tone would be best practice.
My understanding of the use case is not informed enough to suggest what that max should be, as such I left it un-capped.

I would leave it up to the owners discretion what magic number would best fit.

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.

2 participants