mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 13:42:59 +00:00 
			
		
		
		
	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:
		| @@ -2,11 +2,15 @@ | |||||||
| module: [kind=guide] local_ips | 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 | 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 | 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. | 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} | ## 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 | 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: | single-player or multiplayer. Look for lines that look like this: | ||||||
|   | |||||||
| @@ -125,7 +125,7 @@ different. | |||||||
| First, we require the dfpwm module and call @{cc.audio.dfpwm.make_decoder} to construct a new decoder. This decoder | 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. | 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 | 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 | @{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. | @{fs.BinaryReadHandle.read} if you prefer. | ||||||
| @@ -136,22 +136,22 @@ You can mix together samples from different streams by adding their amplitudes, | |||||||
| samples, etc... | 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 | 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. | 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 | 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. | [Ring Buffer], which helps makes things a little more efficient. | ||||||
| 
 | 
 | ||||||
| ```lua {data-peripheral=speaker} | ```lua {data-peripheral=speaker} | ||||||
| local dfpwm = require("cc.audio.dfpwm") | local dfpwm = require("cc.audio.dfpwm") | ||||||
| local speaker = peripheral.find("speaker") | 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! | -- 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 = {} | local samples = {} | ||||||
| for i = 1, samples_n do samples[i] = 0 end | for i = 1, samples_n do samples[i] = 0 end | ||||||
| 
 | 
 | ||||||
| @@ -162,7 +162,7 @@ for chunk in io.lines("data/example.dfpwm", 16 * 1024) do | |||||||
|     for i = 1, #buffer do |     for i = 1, #buffer do | ||||||
|         local original_value = buffer[i] |         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. |         -- 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 |         buffer[i] = original_value * 0.6 + samples[samples_i] * 0.4 | ||||||
| 
 | 
 | ||||||
| @@ -175,6 +175,11 @@ for chunk in io.lines("data/example.dfpwm", 16 * 1024) do | |||||||
|     while not speaker.playAudio(buffer) do |     while not speaker.playAudio(buffer) do | ||||||
|         os.pullEvent("speaker_audio_empty") |         os.pullEvent("speaker_audio_empty") | ||||||
|     end |     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 | end | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| --- | --- | ||||||
| module: [kind=guide] feature_compat | module: [kind=reference] feature_compat | ||||||
| --- | --- | ||||||
| 
 | 
 | ||||||
| # Lua 5.2/5.3 features in CC: Tweaked | # Lua 5.2/5.3 features in CC: Tweaked | ||||||
| @@ -1,9 +1,7 @@ | |||||||
| ; -*- mode: Lisp;-*- | ; -*- mode: Lisp;-*- | ||||||
|  |  | ||||||
| (sources | (sources | ||||||
|   /doc/events/ |   /doc/ | ||||||
|   /doc/guides/ |  | ||||||
|   /doc/stub/ |  | ||||||
|   /build/docs/luaJavadoc/ |   /build/docs/luaJavadoc/ | ||||||
|   /src/main/resources/*/computercraft/lua/bios.lua |   /src/main/resources/*/computercraft/lua/bios.lua | ||||||
|   /src/main/resources/*/computercraft/lua/rom/ |   /src/main/resources/*/computercraft/lua/rom/ | ||||||
| @@ -29,7 +27,8 @@ | |||||||
|     (peripheral Peripherals) |     (peripheral Peripherals) | ||||||
|     (generic_peripheral "Generic Peripherals") |     (generic_peripheral "Generic Peripherals") | ||||||
|     (event Events) |     (event Events) | ||||||
|     (guide Guides)) |     (guide Guides) | ||||||
|  |     (reference Reference)) | ||||||
|  |  | ||||||
|   (library-path |   (library-path | ||||||
|     /doc/stub/ |     /doc/stub/ | ||||||
|   | |||||||
| @@ -302,7 +302,7 @@ public abstract class SpeakerPeripheral implements IPeripheral | |||||||
|      * computer is lagging. |      * 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 context The Lua context. | ||||||
|      * @param audio   The audio data to play. |      * @param audio   The audio data to play. | ||||||
|   | |||||||
| @@ -18,11 +18,12 @@ for each one you write. | |||||||
|  |  | ||||||
| ## Converting audio to DFPWM | ## 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. | 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 | Instead, you can convert audio files online using [music.madefor.cc], the [LionRay Wav Converter][LionRay] Java | ||||||
| application. | application or development builds of [FFmpeg]. | ||||||
|  |  | ||||||
| [music.madefor.cc]: https://music.madefor.cc/ "DFPWM audio converter for Computronics and CC: Tweaked" | [music.madefor.cc]: https://music.madefor.cc/ "DFPWM audio converter for Computronics and CC: Tweaked" | ||||||
| [LionRay]: https://github.com/gamax92/LionRay/ "LionRay Wav Converter " | [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 guide!speaker_audio Gives a more general introduction to audio processing and the speaker. | ||||||
| @see speaker.playAudio To play the decoded audio data. | @see speaker.playAudio To play the decoded audio data. | ||||||
|   | |||||||
| @@ -102,7 +102,7 @@ class Window extends Component<WindowProps, WindowState> { | |||||||
|             </div> |             </div> | ||||||
|             <div class="computer-container"> |             <div class="computer-container"> | ||||||
|                 <Computer key={exampleIdx} files={{ |                 <Computer key={exampleIdx} files={{ | ||||||
|                     ...example!.files, ...defaultFiles |                     ...defaultFiles, ...example!.files, | ||||||
|                 }} peripherals={{ back: example!.peripheral }} /> |                 }} peripherals={{ back: example!.peripheral }} /> | ||||||
|             </div> |             </div> | ||||||
|         </div> : <div class="example-window example-window-hidden" />; |         </div> : <div class="example-window example-window-hidden" />; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jonathan Coates
					Jonathan Coates