Some minor documentation fixes

- Add a TOC to the Local IPs page.
 - Increase the echo delay in our speaker audio page to 1.5s. This
   sounds much better and is less clashy than 1s. Also add a
   sleep(0) (eww, I know) to fix timeouts on some browsers/computers.
 - Move Lua feature compat to a new "reference" section. Still haven't
   figured out how to structure these docs - open to any ideas really.
 - Mention FFmpeg as an option for converting to DFPWM (closes #1075).
 - Allow data-mount to override built-in files. See my comment in #1069.
This commit is contained in:
Jonathan Coates 2022-05-05 13:24:02 +01:00
parent be45b718b3
commit 87a1c1a525
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
7 changed files with 26 additions and 17 deletions

View File

@ -2,11 +2,15 @@
module: [kind=guide] local_ips
---
# Allowing access to local IPS
# Allowing access to local IPs
By default, ComputerCraft blocks access to local IP addresses for security. This means you can't normally access any
HTTP server running on your computer. However, this may be useful for testing programs without having a remote
server. You can unblock these IPs in the ComputerCraft config.
- [Minecraft 1.13 and later, CC:T 1.87.0 and later](#cc-1.87.0)
- [Minecraft 1.13 and later, CC:T 1.86.2 and earlier](#cc-1.86.2)
- [Minecraft 1.12.2 and earlier](#mc-1.12)
## Minecraft 1.13 and later, CC:T 1.87.0 and later {#cc-1.87.0}
The configuration file can be located at `serverconfig/computercraft-server.toml` inside the world folder on either
single-player or multiplayer. Look for lines that look like this:

View File

@ -125,7 +125,7 @@ ## Storing audio
First, we require the dfpwm module and call @{cc.audio.dfpwm.make_decoder} to construct a new decoder. This decoder
accepts blocks of DFPWM data and converts it to a list of 8-bit amplitudes, which we can then play with our speaker.
As mentioned to above, @{speaker.playAudio} accepts at most 128×1024 samples in one go. DFPMW uses a single bit for each
As mentioned above, @{speaker.playAudio} accepts at most 128×1024 samples in one go. DFPMW uses a single bit for each
sample, which means we want to process our audio in chunks of 16×1024 bytes (16KiB). In order to do this, we use
@{io.lines}, which provides a nice way to loop over chunks of a file. You can of course just use @{fs.open} and
@{fs.BinaryReadHandle.read} if you prefer.
@ -136,22 +136,22 @@ ## Processing audio
samples, etc...
Let's put together a small demonstration here. We're going to add a small delay effect to the song above, so that you
hear a faint echo about a second later.
hear a faint echo a second and a half later.
In order to do this, we'll follow a format similar to the previous example, decoding the audio and then playing it.
However, we'll also add some new logic between those two steps, which loops over every sample in our chunk of audio, and
adds the sample from one second ago to it.
adds the sample from 1.5 seconds ago to it.
For this, we'll need to keep track of the last 48k samples - exactly one seconds worth of audio. We can do this using a
For this, we'll need to keep track of the last 72k samples - exactly 1.5 seconds worth of audio. We can do this using a
[Ring Buffer], which helps makes things a little more efficient.
```lua {data-peripheral=speaker}
local dfpwm = require("cc.audio.dfpwm")
local speaker = peripheral.find("speaker")
-- Speakers play at 48kHz, so one second is 48k samples. We first fill our buffer
-- Speakers play at 48kHz, so 1.5 seconds is 72k samples. We first fill our buffer
-- with 0s, as there's nothing to echo at the start of the track!
local samples_i, samples_n = 1, 48000
local samples_i, samples_n = 1, 48000 * 1.5
local samples = {}
for i = 1, samples_n do samples[i] = 0 end
@ -162,7 +162,7 @@ ## Processing audio
for i = 1, #buffer do
local original_value = buffer[i]
-- Replace this sample with its current amplitude plus the amplitude from one second ago.
-- Replace this sample with its current amplitude plus the amplitude from 1.5 seconds ago.
-- We scale both to ensure the resulting value is still between -128 and 127.
buffer[i] = original_value * 0.6 + samples[samples_i] * 0.4
@ -175,6 +175,11 @@ ## Processing audio
while not speaker.playAudio(buffer) do
os.pullEvent("speaker_audio_empty")
end
-- The audio processing above can be quite slow and preparing the first batch of audio
-- may timeout the computer. We sleep to avoid this.
-- There's definitely better ways of handling this - this is just an example!
sleep(0.05)
end
```

View File

@ -1,5 +1,5 @@
---
module: [kind=guide] feature_compat
module: [kind=reference] feature_compat
---
# Lua 5.2/5.3 features in CC: Tweaked

View File

@ -1,9 +1,7 @@
; -*- mode: Lisp;-*-
(sources
/doc/events/
/doc/guides/
/doc/stub/
/doc/
/build/docs/luaJavadoc/
/src/main/resources/*/computercraft/lua/bios.lua
/src/main/resources/*/computercraft/lua/rom/
@ -29,7 +27,8 @@
(peripheral Peripherals)
(generic_peripheral "Generic Peripherals")
(event Events)
(guide Guides))
(guide Guides)
(reference Reference))
(library-path
/doc/stub/

View File

@ -302,7 +302,7 @@ public final boolean playSound( ILuaContext context, String name, Optional<Doubl
* computer is lagging.
* :::
*
* {@literal @}{speaker_audio} provides a more complete guide in to using speakers
* {@literal @}{speaker_audio} provides a more complete guide to using speakers
*
* @param context The Lua context.
* @param audio The audio data to play.

View File

@ -18,11 +18,12 @@ for each one you write.
## Converting audio to DFPWM
DFPWM is not a popular file format and so standard audio processing tools will not have an option to export to it.
Instead, you can convert audio files online using [music.madefor.cc] or with the [LionRay Wav Converter][LionRay] Java
application.
Instead, you can convert audio files online using [music.madefor.cc], the [LionRay Wav Converter][LionRay] Java
application or development builds of [FFmpeg].
[music.madefor.cc]: https://music.madefor.cc/ "DFPWM audio converter for Computronics and CC: Tweaked"
[LionRay]: https://github.com/gamax92/LionRay/ "LionRay Wav Converter "
[FFmpeg]: https://ffmpeg.org "FFmpeg command-line audio manipulation library"
@see guide!speaker_audio Gives a more general introduction to audio processing and the speaker.
@see speaker.playAudio To play the decoded audio data.

View File

@ -102,7 +102,7 @@ class Window extends Component<WindowProps, WindowState> {
</div>
<div class="computer-container">
<Computer key={exampleIdx} files={{
...example!.files, ...defaultFiles
...defaultFiles, ...example!.files,
}} peripherals={{ back: example!.peripheral }} />
</div>
</div> : <div class="example-window example-window-hidden" />;