mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
beeper update: proper equation. Need more work for low freqs
Former-commit-id: a98210ef06bea8f3a85af134fac8848225728c65 Former-commit-id: 901f266d529af99133f0605d2ce76c8cb52c7d17
This commit is contained in:
@@ -954,7 +954,7 @@ _G._VERSION = "Luaj-jse 3.0.1 (Lua 5.2.3)"
|
||||
_G.EMDASH = string.char(0xC4)
|
||||
_G.UNCHECKED = string.char(0x9C) -- box unchecked
|
||||
_G.CHECKED = string.char(0x9D) -- box checked
|
||||
_G.MONEYSYM = string.char(0x9E) -- currency sign
|
||||
_G.MONEY = string.char(0x9E) -- currency sign
|
||||
_G.MIDDOT = string.char(0xFA) -- middle dot sign
|
||||
_G.DC1 = string.char(17) -- black
|
||||
_G.DC2 = string.char(18) -- white
|
||||
@@ -988,6 +988,7 @@ computer.verbose = true -- print debug info
|
||||
computer.loadedCLayer = {} -- list of loaded compatibility layers
|
||||
computer.bootloader = "/boot/efi"
|
||||
computer.OEM = ""
|
||||
computer.beep = emittone
|
||||
computer.totalMemory = _G.totalMemory
|
||||
local getMemory = function()
|
||||
collectgarbage()
|
||||
|
||||
@@ -131,6 +131,9 @@ class BaseTerrarumComputer() {
|
||||
|
||||
// computer-related global functions
|
||||
luaJ_globals["totalMemory"] = LuaFunGetTotalMem(this)
|
||||
|
||||
luaJ_globals["computer"] = LuaTable()
|
||||
luaJ_globals["emittone"] = ComputerEmitTone(this)
|
||||
}
|
||||
|
||||
var threadTimer = 0
|
||||
@@ -233,7 +236,7 @@ class BaseTerrarumComputer() {
|
||||
}
|
||||
}
|
||||
|
||||
class EmitTone(val computer: BaseTerrarumComputer) : TwoArgFunction() {
|
||||
class ComputerEmitTone(val computer: BaseTerrarumComputer) : TwoArgFunction() {
|
||||
override fun call(millisec: LuaValue, freq: LuaValue): LuaValue {
|
||||
computer.playTone(millisec.toint(), freq.tofloat())
|
||||
return LuaValue.NONE
|
||||
@@ -251,18 +254,27 @@ class BaseTerrarumComputer() {
|
||||
|
||||
/**
|
||||
* @param duration : milliseconds
|
||||
* @param rampUp
|
||||
* @param rampDown
|
||||
*
|
||||
* ,---. (true, true) ,---- (true, false) ----. (false, true) ----- (false, false)
|
||||
*/
|
||||
private fun makeAudioData(duration: Int, freq: Float): ByteBuffer {
|
||||
private fun makeAudioData(duration: Int, freq: Float,
|
||||
rampUp: Boolean = true, rampDown: Boolean = true): ByteBuffer {
|
||||
val audioData = BufferUtils.createByteBuffer(duration.times(sampleRate).div(1000))
|
||||
|
||||
val realDuration = duration * sampleRate / 1000
|
||||
val chopSize = freq * 2f / sampleRate
|
||||
val chopSize = freq / sampleRate
|
||||
|
||||
val amp = Math.max(4600f / freq, 1f)
|
||||
val nHarmonics = 2
|
||||
val nHarmonics = if (freq >= 5400) 1
|
||||
else if (freq >= 3600) 2
|
||||
else if (freq >= 1800) 3
|
||||
else 4
|
||||
|
||||
val transitionThre = 2300f
|
||||
val transitionThre = 1150f
|
||||
|
||||
// TODO volume ramping?
|
||||
if (freq == 0f) {
|
||||
for (x in 0..realDuration - 1) {
|
||||
audioData.put(0x00.toByte())
|
||||
@@ -270,7 +282,7 @@ class BaseTerrarumComputer() {
|
||||
}
|
||||
else if (freq < transitionThre) { // chopper generator (for low freq)
|
||||
for (x in 0..realDuration - 1) {
|
||||
var sine: Float = amp * FastMath.cos(FastMath.PI * x * chopSize)
|
||||
var sine: Float = amp * FastMath.cos(FastMath.TWO_PI * x * chopSize)
|
||||
if (sine > 1f) sine = 1f
|
||||
else if (sine < -1f) sine = -1f
|
||||
audioData.put(
|
||||
@@ -281,9 +293,8 @@ class BaseTerrarumComputer() {
|
||||
else { // harmonics generator (for high freq)
|
||||
for (x in 0..realDuration - 1) {
|
||||
var sine: Float = 0f
|
||||
for (k in 0..nHarmonics) { // mix only odd harmonics to make squarewave
|
||||
sine += (1f / (2*k + 1)) *
|
||||
FastMath.sin((2 * k + 1) * FastMath.PI * x * chopSize)
|
||||
for (k in 1..nHarmonics) { // mix only odd harmonics in order to make a squarewave
|
||||
sine += FastMath.sin(FastMath.TWO_PI * (2*k - 1) * chopSize * x) / (2*k - 1)
|
||||
}
|
||||
audioData.put(
|
||||
(0.5f + 0.5f * sine).times(0xFF).toByte()
|
||||
|
||||
@@ -124,7 +124,7 @@ open class SimpleTextTerminal(
|
||||
// complete beep queue
|
||||
if (beepCursor >= beepQueue.size) {
|
||||
clearBeepQueue()
|
||||
println("!! Beep queue clear")
|
||||
// println("!! Beep queue clear")
|
||||
}
|
||||
|
||||
// actually play queue
|
||||
@@ -345,7 +345,7 @@ open class SimpleTextTerminal(
|
||||
* @param freg: Frequency (float)
|
||||
*/
|
||||
override fun beep(duration: Int, freq: Float) {
|
||||
println("!! Beep playing row $beepCursor, d ${Math.min(duration, maxDuration)} f $freq")
|
||||
// println("!! Beep playing row $beepCursor, d ${Math.min(duration, maxDuration)} f $freq")
|
||||
host.playTone(Math.min(duration, maxDuration), freq)
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ Non-colour terminals support colour index of 0--3.
|
||||
|
||||
\begin{center}\includegraphics[width=\cpimagew]{mda.png}\end{center}
|
||||
|
||||
Character 0x9E (currency symbol) and 0xFA (middle dot) can be accessed with following Lua constants: \emph{MONEYSYM} and \emph{MIDDOT}. See \emph{Lua Globals} > \emph{Constants} section.
|
||||
Character 0x9E (currency symbol) and 0xFA (middle dot) can be accessed with following Lua constants: \emph{MONEY} and \emph{MIDDOT}. See \emph{Lua Globals} > \emph{Constants} section.
|
||||
|
||||
\subsection{Accepted Control Sequences}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ ROMBASIC adds global functions and constants for operability.
|
||||
\endhead
|
||||
\unemph{\_G.}runScript(\textbf{fun}: str, \textbf{env}: str) & nil & Runs Lua script \textbf{fun} with the environment tag \textbf{env}.
|
||||
\\ \\
|
||||
\unemph{\_G.}bell(\textbf{pattern}: str) & nil & Strike bell (or beeper) with pattern. Accepted pattern letters: . - (space) Aliased to \unemph{\_G.}beep.
|
||||
\\ \\
|
||||
computer.totalMemory() & int & Returns the total size of the memory installed in the computer, in bytes.
|
||||
\\ \\
|
||||
computer.freeMemory() & int & Returns the amount of free memory on the computer.
|
||||
@@ -25,7 +27,7 @@ ROMBASIC adds global functions and constants for operability.
|
||||
\\ \\
|
||||
\unemph{\_G.}CHECKED & string & Checked checkbox. Code 0x9D
|
||||
\\ \\
|
||||
\unemph{\_G.}MONEYSYM & string & Currency symbol used in the world. Code 0x9E
|
||||
\unemph{\_G.}MONEY & string & Currency symbol used in the world. Code 0x9E
|
||||
\\ \\
|
||||
\unemph{\_G.}MIDDOT & string & Middle dot used in typography. Code 0xFA (note: 0xF9 is a Dot Product used in Mathematics)
|
||||
\\ \\
|
||||
@@ -48,4 +50,6 @@ ROMBASIC adds global functions and constants for operability.
|
||||
computer.bootloader & string & Path to the boot file. Should point to the EFI (/boot/efi).
|
||||
\\ \\
|
||||
computer.OEM & string & Manufacturer of the computer. If you \emph{are} a manufacturer, you may want to fill in this variable with your own company's name.
|
||||
\\ \\
|
||||
computer.beep(\textbf{len}, \textbf{freq}) & nil & Generates square wave. \textbf{len} is integer, in milliseconds, \textbf{freq} is number, in Hertz.
|
||||
\end{tabularx}
|
||||
@@ -87,9 +87,9 @@
|
||||
{1}{45.25516pt}\LT@entry
|
||||
{1}{155.61479pt}}
|
||||
\gdef \LT@xii {\LT@entry
|
||||
{2}{111.63007pt}\LT@entry
|
||||
{2}{118.04002pt}\LT@entry
|
||||
{2}{36.06001pt}\LT@entry
|
||||
{1}{187.30992pt}}
|
||||
{1}{180.89996pt}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {1.8}Lua Globals}{18}{section.1.8}}
|
||||
\@writefile{toc}{\contentsline {subsection}{\numberline {1.8.1}Functions}{18}{subsection.1.8.1}}
|
||||
\@writefile{toc}{\contentsline {subsection}{\numberline {1.8.2}Constants}{18}{subsection.1.8.2}}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
This is LuaTeX, Version beta-0.80.0 (TeX Live 2015) (rev 5238) (format=lualatex 2015.10.5) 26 SEP 2016 12:12
|
||||
This is LuaTeX, Version beta-0.80.0 (TeX Live 2015) (rev 5238) (format=lualatex 2015.10.5) 27 SEP 2016 00:50
|
||||
restricted \write18 enabled.
|
||||
file:line:error style messages enabled.
|
||||
**romapidoc.tex
|
||||
@@ -552,7 +552,7 @@ luatexbase-attr: luatexbase.attributes["luaotfload@cursbase"] = 6
|
||||
luatexbase-attr: luatexbase.attributes["luaotfload@curscurs"] = 7
|
||||
luatexbase-attr: luatexbase.attributes["luaotfload@cursdone"] = 8
|
||||
luatexbase-attr: luatexbase.attributes["luaotfload@state"] = 9
|
||||
luaotfload | main : fontloader loaded in 0.031 seconds
|
||||
luaotfload | main : fontloader loaded in 0.029 seconds
|
||||
luatexbase-mcb: inserting 'luaotfload.node_processor'
|
||||
at position 1 in 'pre_linebreak_filter'
|
||||
luatexbase-mcb: inserting 'luaotfload.node_processor'
|
||||
@@ -1595,39 +1595,53 @@ Underfull \hbox (badness 6658) in paragraph at lines 109--109
|
||||
[]
|
||||
|
||||
) [17<./mda.png>] (./luaglobals.tex
|
||||
Underfull \hbox (badness 1092) in paragraph at lines 14--14
|
||||
Underfull \hbox (badness 1092) in paragraph at lines 16--16
|
||||
\EU2/MyriadPro(0)/m/n/10 ory in-stalled in the com-puter, in
|
||||
[]
|
||||
|
||||
|
||||
Underfull \hbox (badness 10000) in paragraph at lines 51--51
|
||||
Overfull \hbox (38.91pt too wide) in alignment at lines 55--55
|
||||
[] [] []
|
||||
[]
|
||||
|
||||
|
||||
Underfull \hbox (badness 3168) in paragraph at lines 55--55
|
||||
[][]|\EU2/MyriadPro(0)/m/n/10 EM dash rep-re-sented by box-drawing
|
||||
[]
|
||||
|
||||
|
||||
Underfull \hbox (badness 2050) in paragraph at lines 55--55
|
||||
[][]|\EU2/MyriadPro(0)/m/n/10 Mid-dle dot used in ty-pog-ra-phy. Code
|
||||
[]
|
||||
|
||||
|
||||
Underfull \hbox (badness 5245) in paragraph at lines 55--55
|
||||
[][]|\EU2/MyriadPro(0)/m/n/10 Ascii con-trol se-quence DC1. Used to
|
||||
[]
|
||||
|
||||
|
||||
Underfull \hbox (badness 10000) in paragraph at lines 51--51
|
||||
Underfull \hbox (badness 5245) in paragraph at lines 55--55
|
||||
[][]|\EU2/MyriadPro(0)/m/n/10 Ascii con-trol se-quence DC2. Used to
|
||||
[]
|
||||
|
||||
|
||||
Underfull \hbox (badness 10000) in paragraph at lines 51--51
|
||||
Underfull \hbox (badness 5245) in paragraph at lines 55--55
|
||||
[][]|\EU2/MyriadPro(0)/m/n/10 Ascii con-trol se-quence DC3. Used to
|
||||
[]
|
||||
|
||||
|
||||
Underfull \hbox (badness 10000) in paragraph at lines 51--51
|
||||
Underfull \hbox (badness 5245) in paragraph at lines 55--55
|
||||
[][]|\EU2/MyriadPro(0)/m/n/10 Ascii con-trol se-quence DC4. Used to
|
||||
[]
|
||||
|
||||
|
||||
Underfull \hbox (badness 10000) in paragraph at lines 51--51
|
||||
Underfull \hbox (badness 6364) in paragraph at lines 55--55
|
||||
[][]|\EU2/MyriadPro(0)/m/n/10 Ascii con-trol se-quence DLE. Used to
|
||||
[]
|
||||
|
||||
|
||||
Underfull \hbox (badness 2781) in paragraph at lines 51--51
|
||||
\EU2/MyriadPro(0)/m/n/10 change fore-ground colour to ter-mi-nal’s
|
||||
[]
|
||||
Package longtable Warning: Column widths have changed
|
||||
(longtable) in table 1.12 on input line 55.
|
||||
|
||||
[18
|
||||
|
||||
@@ -1665,9 +1679,13 @@ luaotfload | load : Lookup/name: "MyriadPro" -> "MyriadPro-Bold.otf" [21
|
||||
\tf@toc=\write5
|
||||
|
||||
\openout5 = romapidoc.toc
|
||||
|
||||
|
||||
Package longtable Warning: Table widths have changed. Rerun LaTeX.
|
||||
|
||||
Package atveryend Info: Empty hook `BeforeClearDocument' on input line 165.
|
||||
Package atveryend Info: Empty hook `AfterLastShipout' on input line 165.
|
||||
(./romapidoc.aux)
|
||||
(./romapidoc.aux)
|
||||
Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 165.
|
||||
Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 165.
|
||||
Package rerunfilecheck Info: File `romapidoc.out' has not changed.
|
||||
@@ -1687,7 +1705,7 @@ bute_list, 2 write nodes
|
||||
67i,12n,59p,1189b,492s stack positions out of 5000i,500n,10000p,200000b,100000s
|
||||
</Library/Fonts/MyriadPro-It.otf></Library/Fonts/MyriadPro-Regular.otf></Library
|
||||
/Fonts/MyriadPro-Bold.otf>
|
||||
Output written on romapidoc.pdf (33 pages, 95180 bytes).
|
||||
Output written on romapidoc.pdf (33 pages, 95556 bytes).
|
||||
|
||||
PDF statistics: 304 PDF objects out of 1000 (max. 8388607)
|
||||
255 compressed objects within 3 object streams
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user