Raw API: ("speaker" is the wrapped peripheral)
speaker.execute(address) - begin running code at the given address speaker.startup() - equivalent to speaker.execute(0) speaker.shutdown() - stops running code and stops all playing sounds speaker.reboot() - equivalent to speaker.shutdown() followed by speaker.startup() speaker.setAttenuation(db) - sets the attenuation (negative volume) in dB. A good default seems to be 20. speaker.write(address, data...) - writes data. multiple data words may be given, and they will be written to sequential addresses speaker.getMemorySize() - returns the size of memory, in words (this cannot be changed except by editing the mod's code) speaker.debugOn() - turns on debug mode - any output from the code will be printed to the chat of the player who placed the speaker. speaker.debugOff() - turns off debug mode
Speaker test program, including a reusable Forth compiler:
http://dl.dropbox.co...peaker-test.lua
Note: With this compiler, the entry point is a word called MAIN, which must exist.
At the end, commented out, is a short piece of code which shows the effect of debug mode.
"Forth streaming" compiles the tune to chunks of Forth, then executes them.
"Direct streaming" uses the simple API to send notes directly to clients.
Do whatever you want with that whole file.
APIs in the reusable code block: - speaker.compileForth(sourcecode) Returns compiled code (as a table of numbers) - speaker.uploadForth(code, side, hot) Uploads the given compiled code to the speaker on the given side, then starts it executing. If "hot" is true (defaults to false), it will not shut down the speaker so notes continue to play. - speaker.streamTuneUsingForth(tune, side) Implements the test program's Forth streaming mode. - speaker.streamTuneDirectly(tune, side) Implements the test program's direct streaming mode. For streamTuneUsingForth and streamTuneDirectly, the tune is a table containing a list of "commands" (nested tables) of the forms: {"p", channel, frequency} - starts a note {"s", channel} - stops a note {"w", ticks} - waits some ticks Non-standard FORTH words: TICK ( -- ) waits a tick. PLAY ( frequency channel -- ) starts playing a note STOP ( channel -- ) stops playing a note