|
AUKit
|
AUKit: Audio decoding and processing framework for ComputerCraft
All sample rates and channel counts are supported. Functions to convert to ComputerCraft's expected 48kHz are provided, and handled automatically while streaming.
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:
For information about the API, see the Lua docs.
austream/auplayBoth 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=<extension> 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.
austream accepts Rednet URIs in the format rednet[+<protocol>]://<id>[/<path>]. 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.
austream_tm is an alternate version of austream that takes advantage of the Taskmaster library to provide pausing and seeking while playing. Taskmaster must be downloaded next to austream_tm for it to function. Press space to pause/play, left/right arrow to seek back/forward 5 seconds, and Q to quit.
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)auconvertauconvert 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.
AUKit is licensed under the MIT license.