Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
SimTX Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Lua modulation API
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Reading audio and writing output == {| class="wikitable" ! Method !! Effect |- | <code>ctx:audio(index)</code> || Returns an incoming mono audio sample, normally in the range -1 to 1. |- | <code>ctx:iq(index, i, q)</code> || Writes one complex output sample. |- | <code>ctx:map(function(audio, index, time) ... end)</code> || Maps every input audio sample. The callback returns I and optional Q. |- | <code>ctx:generate(function(index, time) ... end)</code> || Generates every sample without using audio. The callback returns I and optional Q. |- | <code>ctx:passthrough()</code> || Copies incoming mono audio to the output. |- | <code>ctx:gain(amount)</code> || Copies incoming audio to the output with a constant linear gain. |- | <code>ctx:limit(peak)</code> || Limits both output components to the symmetric positive peak. |- | <code>ctx:mixTone(frequencyHz, level)</code> || Mixes a sine tone with incoming audio and reserves headroom for it. |- | <code>ctx:mixTone(frequencyHz, level, reserveHeadroom)</code> || Mixes a sine tone and selects whether the input is reduced by the tone level. |- | <code>ctx:fill(value)</code> || Fills an audio block, or the I component of an IQ block, with a constant value. |- | <code>ctx:fill(i, q)</code> || Fills the block with a constant complex sample. |- | <code>ctx:silence()</code> || Fills the block with zeroes. |} <code>map</code> and <code>generate</code> callbacks receive absolute sample time, not merely time within the current block. This permits phase-continuous generators. Omitting the Q return value sets Q to zero. <syntaxhighlight lang="lua"> process = function(ctx) local gain = ctx:control("gain") ctx:map(function(audio) return audio * gain end) ctx:limit(1) end </syntaxhighlight> Block operations such as <code>gain</code>, <code>mixTone</code>, and <code>fill</code> are preferable when they express the required operation because they avoid a Lua callback for every sample.
Summary:
Please note that all contributions to SimTX Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
SimTX Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)