Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://mcjack123.github.io/AUKit/

AUKit: Audio decoding and processing framework for ComputerCraft
https://mcjack123.github.io/AUKit/

Last synced: 3 months ago
JSON representation

AUKit: Audio decoding and processing framework for ComputerCraft

Lists

README

        

# AUKit
AUKit: Audio decoding and processing framework for ComputerCraft

## Supported audio formats
All sample rates and channel counts are supported. Functions to convert to ComputerCraft's expected 48kHz are provided, and handled automatically while streaming.
- Raw linear PCM, 8-, 16-, 24-, or 32-bit signed/unsigned little/big endian
- Raw linear PCM, 32-bit floating point little/big endian
- Raw DFPWM
- Raw Microsoft ADPCM
- Raw IMA ADPCM
- Raw G.711, A-law or µ-law
- MDFPWMv3
- WAV, PCM, 8-bit, 16-bit, 24-bit, 32-bit, or float
- WAV, DFPWM
- WAV, Microsoft ADPCM
- WAV, IMA ADPCM
- WAV, G.711, A-law or µ-law
- AIFF, PCM, 8-bit, 16-bit, 24-bit, or 32-bit
- AIFC, PCM, 32-bit float
- AIFC, G.711, A-law or µ-law
- AU, PCM, 8-bit, 16-bit, 24-bit, 32-bit, or float
- AU, G.711, A-law or µ-law
- FLAC, 8-bit, 16-bit, 24-bit, or 32-bit

## Usage
Download `aukit.lua` to your computer. You can also grab `austream` and `auplay` if you'd like. Then simply use `local aukit = require "aukit"` to load the library in a program.

Basic audio playback can be achieved in only two lines:

```lua
local aukit = require "aukit"
aukit.play(aukit.stream.wav(io.lines("file.wav", 48000)), peripheral.find("speaker"))
```

For information about the API, see [the Lua docs](https://mcjack123.github.io/AUKit/).

### `austream`/`auplay`
Both `austream` and `auplay` take a path as an argument. `austream` additionally supports HTTP(S), WS(S), and Rednet URLs. The difference between the two programs is that `auplay` preloads files, always plays in mono, and normalizes the audio. `austream` does all processing while playing, and supports multiple speakers, but does no processing outside of resampling (and mixing to mono if there's multiple audio channels but only one speaker).

Both programs require the argument to end with the correct file extension - this is used to detect the file type. The file type can also be forced by adding `type=` to the parameter list. If using WebSocket or Rednet URLs, add a path with a (fake) file name which has the required file extension. Rednet does not require a path, but if none is given then 8-bit signed PCM at 48kHz is assumed. Files with the extension `.pcm` or `.raw` are taken as raw PCM data. Unspecified arguments to PCM data use the defaults [listed by `aukit.stream.pcm`](https://mcjack123.github.io/AUKit/#aukit.stream.pcm).

`austream` accepts Rednet URIs in the format `rednet[+]://[/]`. If a protocol is specified, only messages with the specified protocol will be accepted. If a path is specified, it will be sent to the other computer before reading any data. If the ID is `-1`, all senders will be accepted, but no paths will be sent. The sender must send `nil` to report no more data is available. Example: `austream rednet+wav://6/file.wav`

To avoid overflowing the CC event queue, it is recommended that a delay is added to senders.

#### Parameter list
`austream` also accepts parameters for the file in a second argument using a table-like format (quotes are optional for strings): `austream file.bin type=pcm,sampleRate=44100,bitDepth=16,dataType=signed,channels=2,bigEndian=false`

The following options are supported in the parameter list:
- `type` [all]: Type of file to load (`pcm`, `dfpwm`, `wav`, `aiff`, `au`, `flac`)
- `streamData` [all]: Whether to force streaming file data instead of reading all at once (`true`, `false`) (default false)
- `volume` [all]: Playback volume from 0.0 to 3.0 (default 1.0)
- `mono` [all]: Whether to mix audio down to mono (`true`, `false`) (default false)
- `interpolation` [all]: Interpolation mode to use when resampling (`none`, `linear`, `cubic`)
- `sampleRate` [pcm, dfpwm]: Sample rate of the audio (default 48000 Hz)
- `channels` [pcm, dfpwm]: Number of channels in the file (default 1)
- `bitDepth` [pcm]: Bit depth of each sample (8, 16, 24, 32) (default 8)
- `dataType` [pcm]: Type of data of each sample (`signed`, `unsigned`, `float`) (default signed)
- `bigEndian` [pcm]: Whether integers are in big endian form (`true`, `false`) (default false)

### `auconvert`
`auconvert` is a program similar to FFmpeg that allows you to convert and modify audio files using AUKit. It is currently in beta, and has not been thoroughly tested; however, it appears to work.

```
auconvert - Modify and convert audio files

Usage: auconvert

Options:
-i|--input Input file (can specify multiple)
-o|--output Output file (can specify multiple)
-f|--input-format Format of the last input file
-F|--output-format Format of the last output file
For available formats, use `-[f|F] list`
-b|--input-bit-depth Bit depth of the last input file
-B|--output-bit-depth Bit depth of the last output file
-t|--input-data-type Data type of the last input file
-T|--output-data-type Data type of the last output file
-c|--input-channels Channel count of the last input file
-C|--output-channels Channel count of the last output file
-r|--input-sample-rate Sample rate of the last input file
-R|--output-sample-rate Sample rate of the last output file

-e|--effect [,] Apply an effect to the last output file before writing
For available effects, use `-e list`
-m|--map Map one or more input channels to an output channel
--interpolation Set the interpolation type for audio scaling (none, linear, cubic)
-h|--help Show this help

Map command format:
General form: []...=
Multiple files can be specified through : (defaults to file 1)
Only one map can be specified per output channel
Operators:
+: Concatenate channels
&: Mix channels
*: Repeat channel `n` times
[[start],[end]]: Split channel (start/end refer to time in seconds, negative = from end, if end = 0 then end is end of file)
Order of operations: () [] * + &
Parentheses may be used to override operation order
Examples:
1=1 -> map input channel 1 to output channel 1
1:2=2:1 -> map input file 1 channel 2 to output file 2 channel 1
1:1+2:1+3:1=1 -> map the concatenation of the first channels of input files 1-3 to output file 1 channel 1
1&2=1 -> mix input channels 1 & 2 to output channel 1 (can work as stereo-to-mono mixdown)
1[,10]=1 -> map first 10 seconds of input channel 1 to output channel 1
```

## License
AUKit is licensed under the MIT license.